Commit 8a4c3d69 authored by Hemery Mathieu's avatar Hemery Mathieu
Browse files

Move is_polynomial to the ode module and make it a biocham command

parent f0342ac2
......@@ -100,7 +100,7 @@ polynomial_ODE :-
ode:ode(_A, Expr),
(
util:expand_polynomial(Expr, Simp_expr),
reduction:is_polynomial(Simp_expr)
ode:is_polynomial(Simp_expr)
)
)
)
......@@ -1056,32 +1056,6 @@ to_int(String, Int) :-
integer(Int).
%! is_polynomial(+Poly)
%
% 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_molecule(A) :-
identifier_kind(_ModelId, A, object).
is_numeric(N) :-
item([kind:parameter, key:N]);
number(N).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% FAST BINOMIAL REDUCTION %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......
......@@ -104,6 +104,7 @@ commands = [
"influence_model",
"inherits",
"init",
"is_polynomial",
"keep_temporary_files",
"list_aliases",
"list_attributes",
......
......@@ -23,6 +23,7 @@
add_influences_from_ode_system/0,
(init)/1,
remove_fraction/0,
is_polynomial/0,
% load_ode_system/1,
load_reactions_from_ode/1,
% add_ode_system/1,
......@@ -55,7 +56,8 @@
ode_add_expression_to_molecule/2,
ode_predicate/1,
remove_fraction/3,
normalize_ode/2
normalize_ode/2,
is_polynomial/1
]).
% Only for separate compilation/linking
......@@ -451,6 +453,23 @@ remove_fraction :-
select_ode_system(without_fraction_ode).
is_polynomial :-
biocham_command,
doc('Check if the current ODE system is polynomial and print YES or NO accordingly.'),
(
with_current_ode_system(
forall(
ode(_Var, Expr),
is_polynomial(Expr)
)
)
->
format('Yes, the current ode system is polynomial.~n', [])
;
format('No, the current ode system is not polynomial.~n', [])
).
:- devdoc('\\section{Public API}').
......@@ -1297,7 +1316,7 @@ ode_add_expression_to_molecule(NewExpression, Molecule) :-
% remove all the fraction in an expression by multiplying all terms by the common
% denominator
remove_fraction(ListVar, d( X )/dt = Expr, d( X )/dt = NewExpr) :-
remove_fraction(_ListVar, d( X )/dt = Expr, d( X )/dt = NewExpr) :-
find_common_denominator(Expr, Denominator),
multiply_each_term(Expr, Denominator, Expr2),
simplify(Expr2, NewExpr).
......@@ -1464,7 +1483,7 @@ filter_other(Tail*Head, LV, Numbers, Parameters*Head, Variables) :- !,
filter_other(Last,_LV,Last,1,1) :-
number(Last),!.
filter_other(Last,_LV,1,1,Last) :-
filter_other(Last,LV,1,1,Last) :-
member(Last, LV),!.
filter_other(Last,_LV,1,Last,1).
......@@ -1503,3 +1522,29 @@ multiply_them([Term], Term) :- !.
multiply_them([Head|Tail], Term*Head) :-
multiply_them(Tail, Term).
%! is_polynomial(+Poly)
%
% 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_molecule(A) :-
identifier_kind(_ModelId, A, object).
is_numeric(N) :-
item([kind:parameter, key:N]);
number(N).
......@@ -120,4 +120,12 @@ test(
normalize_ode([d(x)/dt=k7/1+ - (k8*x)/1+ - (k9*x)/(x+k1)], [x])
)).
test('is_polynomial', []) :-
clear_model,
%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(exp(2*a))),
\+(is_polynomial(2*a/b)).
:- end_tests(ode).
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