Commit 190ee85a authored by Mathieu Hemery's avatar Mathieu Hemery
Browse files

Adapt the test suite and the doc to the new formalism

parent c016a0a5
......@@ -30,6 +30,7 @@ Rq: The distinction between pivp_string and pivp_list is not always obvious.
gpac,
[
%Commands
compile_from_expression/2,
compile_from_expression/3,
compile_from_pivp/2,
compile_from_pivp/3,
......@@ -64,6 +65,42 @@ Rq: The distinction between pivp_string and pivp_list is not always obvious.
:- initial(option(binomial_reduction: no)).
:- initial(option(lazy_negatives: yes)).
%! compile_from_expression(+Expr, +Output)
%
% biocham command
%
% Creates a biochemical reaction network such that Output = Expr(t)
%
% Typical usage will be:
% ==
% :- compile_from_expression(4 + id*id, output).
% ==
compile_from_expression(Expr, Output) :-
biocham_command,
type(Expr, arithmetic_expression),
type(Output, name),
doc('
creates a biochemical reaction network such that Output = Expr(t).
'),
option(
binomial_reduction,
yesno,
_Reduction,
'Determine if the binomial reduction has to be performed'
),
option(
lazy_negatives,
yesno,
_Lazyness,
'Switch between a brutal or a lazy negation'
),
expression_to_PIVP(Expr, PIVP),
PIVP = [N, _PODE, _IC],
abstract_names(N, Output, Name_list),
main_compiler(PIVP, Name_list, time).
%! compile_from_expression(+Expr, +Input, +Output)
%
% biocham command
......@@ -72,7 +109,7 @@ Rq: The distinction between pivp_string and pivp_list is not always obvious.
%
% Typical usage will be:
% ==
% :- compile_from_expression(4 + id*id, time, output).
% :- compile_from_expression(4 + id*id, Input, Output).
% ==
compile_from_expression(Expr, Input, Output) :-
......@@ -81,8 +118,7 @@ compile_from_expression(Expr, Input, Output) :-
type(Input, name),
type(Output, name),
doc('
creates a biochemical reaction network such that Output = Expr(Input). Use \'time\' as
input to get Output = Expr(t).
creates a biochemical reaction network such that Output = Expr(Input).
'),
option(
binomial_reduction,
......@@ -104,7 +140,7 @@ compile_from_expression(Expr, Input, Output) :-
:- doc('
\\begin{example} Compilation of the expression 4+time^2:\n
').
:- biocham(compile_from_expression(4 + id*id, time, output)).
:- biocham(compile_from_expression(4 + id*id, output)).
:- biocham(list_model).
:- biocham(numerical_simulation(time:4)). %, method:msbdf)).
:- biocham(plot).
......@@ -115,7 +151,7 @@ compile_from_expression(Expr, Input, Output) :-
:- doc('
\\begin{example} Compilation of the expression cos(time):\n
').
:- biocham(compile_from_expression(cos, time, f)).
:- biocham(compile_from_expression(cos, cos)).
:- biocham(list_model).
:- biocham(numerical_simulation(time:10)). %, method:msbdf)).
:- biocham(plot).
......@@ -127,7 +163,7 @@ compile_from_expression(Expr, Input, Output) :-
:- doc('
\\begin{example} Compilation of the expression cos(x) and computation of cos(4):\n
').
:- biocham(compile_from_expression(cos, x, r)).
:- biocham(compile_from_expression(cos, x, cos)).
:- biocham(list_model).
:- biocham(parameter(input = 4)).
:- biocham(numerical_simulation(time:10)). %, method:msbdf)).
......@@ -140,31 +176,92 @@ compile_from_expression(Expr, Input, Output) :-
:- doc('One can also compile real valued functions defined as solutions of Polynomial Initial Value Problems (PIVP), i.e. solutions of polynomial differential equations, using the following syntax:').
%! compile_from_pivp(+PIVP_string, +Output)
%
% biocham command
%
% Creates a biochemical reaction network that computes the projection of multivariate function f(t) on one variable Output,
% where f(t) is the solution of the PIVP.
%
% Typical usage will be:
% ==
% :- compile_from_pivp( ((1,(d(y)/dt=z)); (0,(d(z)/dt= (-1*y)))), y).
% ==
compile_from_pivp(PIVP, Output) :-
biocham_command,
type(PIVP, pivp),
type(Output, name),
doc('
compiles a PIVP into a CRN (with initial concentration values) that computes the projection on one variable Output as a function of time, of the multivariate function f(t) solution of the PIVP.
'),
option(
binomial_reduction,
yesno,
_Reduction,
'Determine if the binomial reduction has to be performed'
),
sort_output(PIVP, Output, PIVP_sorted),
compile_from_pivp(PIVP_sorted, time, Output).
%! compile_from_pivp(+PIVP_string, +Input , +Output)
%
% biocham command
%
% Creates a biochemical reaction network that computes the projection of multivariate function f(Input) on one variable Output,
% where f(t) is the solution of the PIVP, and Input is a time value
%
% Typical usage will be:
% ==
% :- compile_from_pivp( ((1,(d(y)/dt=z)); (0,(d(z)/dt= (-1*y)))), 4, y).
% ==
compile_from_pivp(PIVP, Input, Output) :-
biocham_command,
type(PIVP, pivp),
type(Input, name), % FF type(Input, expr),
type(Output, name),
doc('
compiles a PIVP into a CRN (with initial concentration values) that computes the value of variable Output at time Input, of the multivariate function f(t) solution of the PIVP.
'),
option(
binomial_reduction,
yesno,
_Reduction,
'Determine if the binomial reduction has to be performed'
),
sort_output(PIVP, Output, PIVP_sorted),
format_pivp(PIVP_sorted, P, Name_list),
main_compiler(P, Name_list, Input).
:- doc('
\\begin{example} Compilation of a simple oscillator with 2 species\n
\\begin{example} Compilation of a simple oscillator with 2 species (Lotka-Volterra)\n
').
:- biocham(option(lazy_negatives:yes)).
:- biocham(compile_from_pivp((0.5,(d(x)/dt= x - x*y));(0.25,(d(y)/dt= x*y - 0.5*y)),time,output)).
:- biocham(compile_from_pivp((0.5,(d(x)/dt= x - x*y));(0.25,(d(y)/dt= x*y - 0.5*y)), x)).
:- biocham(list_model).
:- biocham(numerical_simulation(time:10)). % method:msbdf
:- biocham(plot(show:{output,'A'})).
:- biocham(plot(show:{'x','y'})).
:- doc('
\\end{example}
').
%:- doc('
% \\begin{example} Compilation of a Hill function of order 2 as a function of input\n
%').
%:- biocham(option(lazy_negatives:yes)).
%:- biocham(option(binomial_reduction:yes)).
%:- biocham(compile_from_pivp((0.0,(d(h)/dt= 2*x*x*y)),(1.0,(d(x)/dt= -2*x*x*y));(0.0,(d(y)/dt= 1)),input,hill)).
%:- biocham(list_model).
%:- biocham(numerical_simulation(time:10)). % method:msbdf
%:- biocham(plot(show:{hill})).
%:- biocham(plot(show:{hill}, logscale:x)).
%:- doc('
% \\end{example}
%').
:- doc('
\\begin{example} Compilation of a Hill function of order 2 as a function of input\n
').
:- biocham(option(lazy_negatives:yes)).
:- biocham(option(binomial_reduction:yes)).
:- biocham(compile_from_pivp((0.0,d(h)/dt= 2*x*x*y;1.0,d(x)/dt= -2*x*x*y;0.0,d(y)/dt=1),in,h)).
:- biocham(parameter(input=2)).
:- biocham(list_model).
:- biocham(numerical_simulation(time:10)). % method:msbdf
:- biocham(plot(show:{h})).
:- biocham(plot(show:{h}, logscale:x)).
:- doc('
\\end{example}
').
% Definition of the various grammars used in this module:
......@@ -243,92 +340,6 @@ monomial(X) :-
name(X).
%! compile_from_pivp(+PIVP_string, +Output)
%
% biocham command
%
% Creates a biochemical reaction network that computes the projection of multivariate function f(t) on one variable Output,
% where f(t) is the solution of the PIVP.
%
% Typical usage will be:
% ==
% :- compile_from_pivp( ((1,(d(y)/dt=z)); (0,(d(z)/dt= (-1*y)))), y).
% ==
compile_from_pivp(PIVP, Output) :-
biocham_command,
type(PIVP, pivp),
type(Output, name),
doc('
compiles a PIVP into a CRN (with initial concentration values) that computes the projection on one variable Output as a function of time, of the multivariate function f(t) solution of the PIVP.
'),
option(
binomial_reduction,
yesno,
_Reduction,
'Determine if the binomial reduction has to be performed'
),
sort_output(PIVP, Output, PIVP_sorted),
compile_from_pivp(PIVP_sorted, time, Output).
%! sort_output(+PIVP, +Output, -PIVP_sorted)
%
% Ensure that Output is the first variable of the PIVP
sort_output((IC, d(Out)/dt = Deriv), Out, (IC, d(Out)/dt = Deriv)) :- !.
sort_output((IC, d(Out)/dt = Deriv);Remainder, Out, (IC, d(Out)/dt = Deriv);Remainder) :- !.
sort_output(Remainder;(IC, d(Out)/dt = Deriv), Out, (IC, d(Out)/dt = Deriv);Remainder) :- !.
sort_output(R1;(IC, d(Out)/dt = Deriv);R2, Out, (IC, d(Out)/dt = Deriv);R1;R2) :- !.
sort_output(_PIVP1, _Out, _PIVP2) :-
print_message(warning, 'Output should be a variable of the PIVP'),
fail.
%! compile_from_pivp(+PIVP_string, +Input , +Output)
%
% biocham command
%
% Creates a biochemical reaction network that computes the projection of multivariate function f(Input) on one variable Output,
% where f(t) is the solution of the PIVP, and Input is a time value
%
% Typical usage will be:
% ==
% :- compile_from_pivp( ((1,(d(y)/dt=z)); (0,(d(z)/dt= (-1*y)))), 4, y).
% ==
compile_from_pivp(PIVP, Input, Output) :-
biocham_command,
type(PIVP, pivp),
type(Input, name), % FF type(Input, expr),
type(Output, name),
doc('
compiles a PIVP into a CRN (with initial concentration values) that computes the value of variable Output at time Input, of the multivariate function f(t) solution of the PIVP.
'),
option(
binomial_reduction,
yesno,
_Reduction,
'Determine if the binomial reduction has to be performed'
),
sort_output(PIVP, Output, PIVP_sorted),
format_pivp(PIVP_sorted, P, Name_list),
main_compiler(P, Name_list, Input).
:- devdoc('\\begin{todo} Compilation of the cosine function as a function of time defined as the solution of a PIVP)\n
\\texttt{
:- biocham(compile_from_pivp(((1,(d(y)/dt=z)); (0,(d(z)/dt= (-1*y)))), time, output)).
:- biocham(list_model).
:- biocham(numerical_simulation(time:10)).
:- biocham(plot).
}
\\end{todo}
').
:- devdoc('
The internal data structure for PIVPs (Polynomial differential equations
Initial Value Problems) is
......@@ -425,6 +436,23 @@ find_variables((X;Y), L, Init):-
append(I1, I2, Init).
%! sort_output(+PIVP, +Output, -PIVP_sorted)
%
% Ensure that Output is the first variable of the PIVP (here as a string)
sort_output((IC, d(Out)/dt = Deriv), Out, (IC, d(Out)/dt = Deriv)) :- !.
sort_output((IC, d(Out)/dt = Deriv);Remainder, Out, (IC, d(Out)/dt = Deriv);Remainder) :- !.
sort_output(Remainder;(IC, d(Out)/dt = Deriv), Out, (IC, d(Out)/dt = Deriv);Remainder) :- !.
sort_output(R1;(IC, d(Out)/dt = Deriv);R2, Out, (IC, d(Out)/dt = Deriv);R1;R2) :- !.
sort_output(_PIVP1, _Out, _PIVP2) :-
print_message(warning, 'Output should be a variable of the PIVP'),
fail.
%! parse_pivp(+PIVP_string, +ListVariableNames, -Pode)
%
% Giving the PIVP_string and its variable, extract the list representation
......
......@@ -31,7 +31,7 @@ test(extract_names) :-
gpac:extract_names((1, d(a)/dt = 1; 2, d(b)/dt = 2), [a,b]).
test(generate_names) :-
gpac:generate_names(["a","Out"], [[1,2],[1,0]], ["aOut2", "a"]).
gpac:generate_names([a,'Out'], [[1,2],[1,0]], [aOut2, a]).
%%% Test of g_to_c %%%
test(g_to_c_PIVP) :-
......@@ -63,11 +63,11 @@ test(generate_sufficient_variables3) :-
once(permutation(Set, [[1,0],[0,1],[0,2]])).
test(reduce_to_binomial_nomodif) :-
once(gpac:reduce_to_binomial([2,[[[1,[1, 1]]],[[-1,[1, 0]]]],[1,2]],P)),
once(gpac:reduce_to_binomial([2,[[[1,[1, 1]]],[[-1,[1, 0]]]],[1,2]],[a,b],P,[a,b])),
P = [2,[[[1,[1, 1]]],[[-1,[1, 0]]]],[1,2]].
test(reduce_to_binomial_simple) :-
once(gpac:reduce_to_binomial([2,[[[1,[1, 2]]],[[-1,[1, 0]]]],[1,2]],P)),
once(gpac:reduce_to_binomial([2,[[[1,[1, 2]]],[[-1,[1, 0]]]],[1,2]],[a,b],P,[a,b,b2])),
P = [3,[[[1, [1, 0, 1]]], [[-1, [1, 0, 0]]], [[-2, [1, 1, 0]]]],[1,2,4]].
test(scan_order_multivar) :-
......
Markdown is supported
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