Commit 8106df1d authored by Mathieu Hemery's avatar Mathieu Hemery
Browse files

Don't remember

parent b66bdfc7
......@@ -54,8 +54,8 @@
ode/3,
ode_add_expression_to_molecule/2,
ode_predicate/1,
remove_fraction/2,
normalize_ode/1
remove_fraction/3,
normalize_ode/2
]).
% Only for separate compilation/linking
......@@ -426,9 +426,9 @@ remove_fraction :-
by the GCD. WARNING: the resulting ODE system is NOT equivalent to the starting one.'),
new_ode_system(NewId),
set_ode_system_name(NewId, without_fraction_ode),
normalize_ode(ListOde),
normalize_ode(ListOde, ListVar),
debug(remove_fraction, "List normalized:~n~w~n",[ListOde]),
maplist(remove_fraction, ListOde, NewListOde),
maplist(remove_fraction(ListVar), ListOde, NewListOde),
debug(remove_fraction, "List without fraction:~n~w~n",[NewListOde]),
maplist(add_ode(NewId), NewListOde),
with_current_ode_system((
......@@ -1290,15 +1290,23 @@ ode_add_expression_to_molecule(NewExpression, Molecule) :-
).
%! remove_fraction(+Expr, +ListVar, -NewExpr)
%! remove_fraction(+ListVar, +Expr, -NewExpr)
%
% remove all the fraction in an expression by multiplying all terms by the common
% denominator
remove_fraction(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, ExprTempo),
simplify(ExprTempo, NewExpr).
multiply_each_term(Expr, Denominator, Expr2),
simplify(Expr2, Expr3),
(
Expr = Expr2
->
NewExpr = Expr3
;
normalize_expression(Expr3, ListVar, Expr4),
remove_fraction(ListVar, d(X)/dt = Expr4, d(X)/dt = NewExpr)
).
%! find_common_denominator(+Expr, +ListVariable, -ListDenominator)
......@@ -1348,11 +1356,11 @@ mult_by(Num, [], Num).
%%% ODE NORMALIZATION %%%
%%%%%%%%%%%%%%%%%%%%%%%%%
%! normalize_ode(-Assoc)
%! normalize_ode(-Assoc, -ListVar)
%
% Return the normal form of the current ode system as a list: [d( X )/dt = Expr, etc.]
normalize_ode(NormalForm) :-
normalize_ode(NormalForm, ListVar) :-
with_current_ode_system((
get_current_ode_system(Id),
findall(X, ode(Id, X, Expr), ListVar),
......
......@@ -98,18 +98,18 @@ test(
test(
'remove_fraction',[]) :-
remove_fraction(d(a)/dt = a/b, d(a)/dt = a),
remove_fraction(d(a)/dt = a/(b+c) + d, d(a)/dt = a + d*b + d*c),
remove_fraction(d(a)/dt = a/(b+c) + -1*d, d(a)/dt = a - d*b - d*c),
remove_fraction(d(a)/dt = a/b + c/d + e, d(a)/dt = a*d + c*b + e*b*d),
remove_fraction(d(a)/dt = a/b + c/d, d(a)/dt = a*d + c*b).
remove_fraction([a], d(a)/dt = a/b, d(a)/dt = a),
remove_fraction([a], d(a)/dt = a/(b+c) + d, d(a)/dt = a + d*b + d*c),
remove_fraction([a], d(a)/dt = a/(b+c) + -1*d, d(a)/dt = a - d*b - d*c),
remove_fraction([a], d(a)/dt = a/b + c/d + e, d(a)/dt = d*a + c*b + e*b*d),
remove_fraction([a], d(a)/dt = a/b + c/d, d(a)/dt = d*a + c*b).
test(
'normalize_ode1', []) :-
clear_model,
with_current_ode_system((
add_ode(d(x)/dt = (1*(k9*k1*k2) + (-1)*(k9*k3*x1) + (-1)*(k9*k8*x*x/(x+k7)))/k9),
normalize_ode([d(x)/dt = k9*k1*k2/k9+ - (k9*k3*x1)/k9+ - (k9*k8*x^2)/(k9*(x+k7))])
normalize_ode([d(x)/dt = k9*k1*k2/k9+ - (k9*k3*x1)/k9+ - (k9*k8*x^2)/(k9*(x+k7))], [x])
)).
test(
......@@ -117,7 +117,7 @@ test(
clear_model,
with_current_ode_system((
add_ode(d(x)/dt = k7+ -1*k8*x + -1*k9*x/(x+k1)),
normalize_ode([d(x)/dt = k7+ - (k8*x)+ - (k9*x)/(x+k1)])
normalize_ode([d(x)/dt = k7+ - (k8*x)+ - (k9*x)/(x+k1)], [x])
)).
:- 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