Commit 756cdbc7 by Mathieu Hemery

### Add a protected modulo function

parent e93682b3
 ... ... @@ -7,7 +7,8 @@ always_negative/1, always_positive/1, normalize_number/2, is_null/1 is_null/1, modulo/3 ]). % Insert here for separate compilation and linting ... ... @@ -788,6 +789,15 @@ is_null_sr(_A^(-_N)) :- !, false. is_null_sr(A^_N) :- is_null_sr(A). %! modulo(+A, +B) % % compute C is mod(A,B) but fail instead of raising an error when A or B are not integer modulo(A, B, C) :- catch( C is mod(A, B), error(type_error(integer,_n), _context), fail ).
 ... ... @@ -33,12 +33,12 @@ derivate_raw(A - B, Variable, Aprime - Bprime) :- derivate_raw(B, Variable, Bprime). derivate_raw(A * B, Variable, Aprime * B) :- derivate_raw(B, Variable, 0), derivate(B, Variable, 0), !, derivate_raw(A, Variable, Aprime). derivate_raw(A * B, Variable, A * Bprime) :- derivate_raw(A, Variable, 0), derivate(A, Variable, 0), !, derivate_raw(B, Variable, Bprime). ... ...
 ... ... @@ -12,10 +12,13 @@ test('dx/dt(x^2) = 2x', [true(E == 2 * x)]) :- derivate(x ^ 2, x, E). test('dx/dt(cos(sqrt(x))) = - 0.5 / sqrt(x) * sin(sqrt(x))', [true(E == - (1 / sqrt(x) / 2 * sin(sqrt(x))))]) :- [true(E == - ( x^(-0.5) / 2 * sin(sqrt(x))))]) :- derivate(cos(sqrt(x)), x, E). test('derivate quotient', [true(E == -1*x / y^2)]) :- derivate(x/y, y, E). test('derivate real test 1', [true(D == a*c^2)]) :- derivate(a*b*c^2, b, D). :- end_tests(formal_derivation).
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment