Commit 831b1d38 authored by Mathieu Hemery's avatar Mathieu Hemery
Browse files

Correct some difficulties with parsing for model 3 and 4

parent b148a77f
......@@ -54,6 +54,7 @@
ode/3,
ode_add_expression_to_molecule/2,
ode_predicate/1,
remove_fraction/2,
normalize_ode/1
]).
......@@ -1336,7 +1337,7 @@ multiply_term(Num/Den, Denominator, NewNum) :-
multiply_term(Num, Denominator, NewNum) :-
mult_by(Num, Denominator, NewNum).
mult_by(Num, [Head|Tail], NNum) :-
mult_by(Num, [Head|Tail], NNum) :- !,
mult_by(Num, Tail, NumTempo),
distribute(NumTempo*Head, NNum).
mult_by(Num, [], Num).
......@@ -1366,11 +1367,11 @@ normalize_ode(NormalForm) :-
normalize_expression(Expr + Term, ListVar, NExpr + NTerm) :- !,
normalize_term(Term, ListVar, NTerm),
normalize_expression(Expr, ListVar, NExpr).
normalize_expression(Expr - Term, ListVar, NExpr + -1*NTerm) :- !,
normalize_term(Term, ListVar, NTerm),
normalize_expression(Expr - Term, ListVar, NExpr + NTerm) :- !,
normalize_term(Term*(-1), ListVar, NTerm),
normalize_expression(Expr, ListVar, NExpr).
normalize_expression(-Term, ListVar, -1*NTerm) :- !,
normalize_term(Term, ListVar, NTerm).
normalize_expression(-Term, ListVar, NTerm) :- !,
normalize_term(Term*(-1), ListVar, NTerm).
normalize_expression(Term, ListVar, NTerm) :-
normalize_term(Term, ListVar, NTerm).
......@@ -1381,9 +1382,16 @@ normalize_term(Term, ListVar, NewTerm) :-
%! filter_denominator(Term, Numerator, Denominator)
filter_denominator(Term*X^N, Num, [X^Nm|Den]) :-
filter_denominator(Term*X^N, Num, [NTerm|Den]) :-
number(N), N<0, !,
Nm is -N,
(
Nm = 1
->
NTerm = X
;
NTerm = X^Nm
),
filter_denominator(Term, Num, Den).
filter_denominator(Term*X^N, [X^N|Num], Den) :- !,
number(N), N>0, !,
......@@ -1392,9 +1400,16 @@ filter_denominator(Term*X, [X|Num], Den) :- !,
filter_denominator(Term, Num, Den).
filter_denominator(Term/X, Num, [X|Den]) :- !,
filter_denominator(Term, Num, Den).
filter_denominator(X^N, [], [X^Nm]) :- !,
filter_denominator(X^N, [], [NTerm]) :- !,
number(N), N<0, !,
Nm is -N.
Nm is -N,
(
Nm = 1
->
NTerm = X
;
NTerm = X^Nm
).
filter_denominator(X, [X], []).
......
......@@ -96,4 +96,12 @@ test(
list_file_lines('test.tex', Lines),
delete_file('test.tex').
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).
:- 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