Commit a27ff232 authored by HEMERY Mathieu's avatar HEMERY Mathieu
Browse files

Start the handling of names through the compilation

parent 1468b5e1
......@@ -314,7 +314,7 @@ compile_from_pivp(PIVP, Input, Output) :-
'Determine if the binomial reduction has to be performed'
),
format_pivp(PIVP, P, Name_list),
main_compiler(P, Input, Output).
main_compiler(P, Name_list, Input, Output).
:- devdoc('\\begin{todo} Compilation of the cosine function as a function of time defined as the solution of a PIVP)\n
\\texttt{
......@@ -339,7 +339,7 @@ compile_from_pivp(PIVP, Input, Output) :-
').
%! main_compiler(+PIVP_list, +Input, +Output)
%! main_compiler(+PIVP_list, +Name_list, +Input, +Output)
%
% Compile a PIVP_list, this predicate dispatch the various options of compilation
% it first check if the PIVP should be reduce to a binomial form
......@@ -347,7 +347,7 @@ compile_from_pivp(PIVP, Input, Output) :-
% when Input is not time it then call g_to_c_PIVP/3.
% and finally make a call to compile_to_biocham_model to make the final implementation
main_compiler(PIVP_input, Input, Output):-
main_compiler(PIVP_input, Name_list_raw, Input, Output):-
clear_model,
get_option(fast_rate, Fast),
get_option(lazy_negatives, Lazyness),
......@@ -355,16 +355,19 @@ main_compiler(PIVP_input, Input, Output):-
(
Input = time
->
PIVP_non_bin = PIVP_input
PIVP_non_bin = PIVP_input,
Name_list_non_bin = Name_list_raw
;
g_to_c_PIVP(PIVP_input, PIVP_non_bin, 1.0)
g_to_c_PIVP(PIVP_input, PIVP_non_bin, 1.0),
append(Name_list_non_raw, [Input], Name_list_non_bin)
),
(
Reduction = yes
->
reduce_to_binomial(PIVP_non_bin,PIVP_unsigned)
reduce_to_binomial(PIVP_non_bin, Name_list_non_bin, PIVP_unsigned, Name_list_unsigned)
;
PIVP_unsigned = PIVP_non_bin
PIVP_unsigned = PIVP_non_bin,
Name_list_unsigned = Name_list_non_bin
),
PIVP_unsigned = [N,_PODE,_IV],
get_option(lazy_negatives, Lazyness),
......@@ -401,7 +404,7 @@ format_pivp(P, [N, Pode, Init], Name_list):-
extract_names(P, Name_list).
:- devdoc('
\\command{format_pivp/2} encodes a PIVP syntax tree into the internal list
\\command{format_pivp/3} encodes a PIVP syntax tree into the internal list
representation for PIVPs.
').
......@@ -776,7 +779,7 @@ compose_multivar_vector([P|PV], PL, [Q|QV]) :-
%%% Reduction to binomial PIVP %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%! reduce_to_binomial(PIVP,Modified_PIVP)
%! reduce_to_binomial(+PIVP, +Name_list, -Modified_PIVP, -Modified_Names)
%
% Reduce a given PIVP to a new one which only need binomial
......@@ -790,11 +793,13 @@ reduce_to_binomial([N,PODE,IV],[NewN,NewPODE,NewIV]) :-
length(ListVariable,NewN),
% binomial_branch_bound(ListAllVariable, PODE, ListVariable, NewN),
rewrite_pode(ListVariable,PODE,ListVariable,NewPODE),
generate_iv(ListVariable,IV,NewIV)
generate_iv(ListVariable,IV,NewIV),
generate_names(Name_list, ListVariable, Modified_Names)
; % PIVP is already binomial
NewN = N,
NewPODE = PODE,
NewIV = IV
NewIV = IV,
Modified_Names = Name_list
).
......@@ -1104,6 +1109,29 @@ set_new_iv([Exp|TailE],[Value|TailV],NewValue) :-
NewValue = NewValueTempo * Value^Exp
).
%! generate_names(+Name_list, +List_variable, -Modified_Names)
%
% Generate the names of the new variable
generate_names(_Name_list, [], []) :- !.
generate_names(Name_list, [Var|TailVar], [Name|TailName]) :-
write_new_name(Name_list, Var, Name_as_list),
atomics_to_string(Name_as_list, Name),
generate_names(Name_list, TailVar, TailName).
write_new_name([], [], []) :- !.
write_new_name([_Name|TailName], [0|TailExp], Name_as_list) :- !,
write_new_name(TailName, TailExp, Name_as_list).
write_new_name([Name|TailName], [1|TailExp], [Name|Name_as_list]) :- !,
write_new_name(TailName, TailExp, Name_as_list).
write_new_name([Name|TailName], [N|TailExp], [Name,N|Name_as_list]) :- !,
write_new_name(TailName, TailExp, Name_as_list).
%! scan_order_multivarvector(+MultivarVector,-Order)
%
......
......@@ -30,6 +30,9 @@ test(sort_output) :-
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"]).
%%% 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