Commit 1468b5e1 authored by HEMERY Mathieu's avatar HEMERY Mathieu
Browse files

Format_pivp now export also the name of the variables

parent 30812478
......@@ -39,7 +39,7 @@ Rq: The distinction between pivp_string and pivp_list is not always obvious.
pode/1,
pivp/1,
%API
format_pivp/2
format_pivp/3
]).
:- use_module(library(clpfd)).
......@@ -313,7 +313,7 @@ compile_from_pivp(PIVP, Input, Output) :-
_Reduction,
'Determine if the binomial reduction has to be performed'
),
format_pivp(PIVP, P),
format_pivp(PIVP, P, Name_list),
main_compiler(P, Input, Output).
:- devdoc('\\begin{todo} Compilation of the cosine function as a function of time defined as the solution of a PIVP)\n
......@@ -390,14 +390,15 @@ main_compiler(PIVP_input, Input, Output):-
%%% Tools to format a PIVP_string to a PIVP_list %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%! format_pivp(+PIVP_string, -PIVP_list)
%! format_pivp(+PIVP_string, -PIVP_list, -Name_list)
%
% Generates the PIVP_list object corresponding to a given PIVP_string
% Generates the PIVP_list object and the Name_list corresponding to a given PIVP_string
format_pivp(P, [N, Pode, Init]):-
format_pivp(P, [N, Pode, Init], Name_list):-
find_variables(P, L, Init),
length(L, N), % should put 1 if no variable ?
parse_pivp(P, L, Pode).
parse_pivp(P, L, Pode),
extract_names(P, Name_list).
:- devdoc('
\\command{format_pivp/2} encodes a PIVP syntax tree into the internal list
......@@ -501,6 +502,16 @@ make_monomial([_|L], X, Y, [0|M]) :-
make_monomial(L, X, Y, M).
%! extract_names(+PIVP_string, -Name_list)
%
% Extract the names of the variables of the PIVP_string
extract_names((_IC, d(Name)/dt = _Deriv), [Name]) :- !.
extract_names((_IC, d(Name)/dt = _Deriv; Remainder), [Name|Tail]) :-
extract_names(Remainder, Tail).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Tools to manipulate PIVP_list internal objects %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......
......@@ -9,22 +9,27 @@
test(format_pivp_exp) :-
gpac:format_pivp(((1,(d(y)/dt=(-2*y)))),
[1,[[[-2,[1]]]],[1]] ).
[1,[[[-2,[1]]]],[1]],
[y]).
test(format_pivp_cosinus) :-
gpac:format_pivp(((1,(d(y)/dt=z)); (0,(d(z)/dt= (-1*y)))),
[2,[[[1,[0, 1]]],[[-1,[1, 0]]]],[1,0]] ).
[2,[[[1,[0, 1]]],[[-1,[1, 0]]]],[1,0]],
[y,z]).
% This PIVP generates choicepoints in the cutting of y*z+3*z, hence the once
test(format_pivp_higher_order) :-
once(gpac:format_pivp(((1,(d(y)/dt=y*z+3*z)); (5,(d(z)/dt= (-1*y^3)))),
[2,[[[1,[1, 1]],[3,[0, 1]]],[[-1,[3, 0]]]],[1,5]] )).
[2,[[[1,[1, 1]],[3,[0, 1]]],[[-1,[3, 0]]]],[1,5]],
[y,z])).
%
test(sort_output) :-
gpac:sort_output((1,d(cos)/dt=(-1*sin);0,d(sin)/dt=cos),cos,(1,d(cos)/dt=(-1*sin);0,d(sin)/dt=cos)),
gpac:sort_output((0,d(sin)/dt=cos;1,d(cos)/dt=(-1*sin)),cos,(1,d(cos)/dt=(-1*sin);0,d(sin)/dt=cos)).
test(extract_names) :-
gpac:extract_names((1, d(a)/dt = 1; 2, d(b)/dt = 2), [a,b]).
%%% Test of g_to_c %%%
test(g_to_c_PIVP) :-
Old_PIVP = [1, [[[-1,[1]]]], [1]],
......
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