Commit 5727c048 authored by Hemery Mathieu's avatar Hemery Mathieu
Browse files

Improve is_polynomial

parent 8a4c3d69
......@@ -1527,21 +1527,14 @@ multiply_them([Head|Tail], Term*Head) :-
%
% detect if a given term is a polynomial
is_polynomial(P) :-
is_monomial(P),!.
is_polynomial(P1 + P2) :-
is_polynomial(P1),
is_polynomial(P2).
is_polynomial(P1 - P2) :-
is_polynomial(P1),
is_polynomial(P2).
is_monomial(-(A)) :- is_monomial(A).
is_monomial(A*B) :- is_monomial(A), is_monomial(B).
is_monomial(A^N) :- is_molecule(A), is_numeric(N).
is_monomial(A/N) :- is_numeric(N), is_monomial(A).
is_monomial(A) :- is_numeric(A).
is_monomial(A) :- is_molecule(A).
is_polynomial(A + B) :- is_polynomial(A), is_polynomial(B).
is_polynomial(A - B) :- is_polynomial(A), is_polynomial(B).
is_polynomial(-(A)) :- is_polynomial(A).
is_polynomial(A*B) :- is_polynomial(A), is_polynomial(B).
is_polynomial(A^N) :- is_polynomial(A), is_numeric(N).
is_polynomial(A/N) :- is_numeric(N), is_polynomial(A).
is_polynomial(A) :- is_numeric(A).
is_polynomial(A) :- is_molecule(A).
is_molecule(A) :-
identifier_kind(_ModelId, A, object).
......
......@@ -125,6 +125,7 @@ test('is_polynomial', []) :-
%Ensure that a, b and c are recognized as molecules
add_ode([d(a)/dt = 1, d(b)/dt = 1, d(c)/dt = 1]),
is_polynomial(a*b + c^3 - 2*b),
is_polynomial(a*(c/4)^2),
\+(is_polynomial(exp(2*a))),
\+(is_polynomial(2*a/b)).
......
Supports Markdown
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