Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lifeware
biocham
Commits
756cdbc7
Commit
756cdbc7
authored
Aug 03, 2020
by
Mathieu Hemery
Browse files
Add a protected modulo function
parent
e93682b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
arithmetic_rules.pl
View file @
756cdbc7
...
...
@@ -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
).
formal_derivation.pl
View file @
756cdbc7
...
...
@@ -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
).
...
...
formal_derivation.plt
View file @
756cdbc7
...
...
@@ -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).
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment