Commit a281ef21 authored by HUANG Wei Chih's avatar HUANG Wei Chih
Browse files

remote constant value from symbol table

parent 4d7ed901
......@@ -229,10 +229,6 @@ create_ode(_, OdeSystem) :-
CounterInit = 0
),
set_counter( CounterName, CounterInit ),
constant( true, True ),
constant( false, False ),
new_symbol( True, dual ),
new_symbol( False, dual ),
new_variable( OdeSystem, [ Pre, PostPre ] ),
set_condition( precondition, Pre ),
set_condition( postcondition_pre, PostPre ),
......@@ -470,22 +466,44 @@ replace_symbol( Symbol, AttributeList ) :-
remove_symbol( Symbol ),
add_symbol( Symbol, AttributeList ).
default_symbol_attr( Variable, AttributeList ) :-
\+ number( Variable ),
default_symbol_attr( Variable, no, no, 0, 0, 0, 0, AttributeList ).
default_symbol_attr( Constant, AttributeList ) :-
default_symbol_attr( Constant,
[ const: yes,
dual: yes,
name: [ P, N ],
value: [ P, N ],
init: [ P, N ],
max: Constant,
min: Constant
], dual ) :-
number( Constant ),
default_symbol_attr( Constant, yes, no, Constant, Constant, Constant, Constant, AttributeList ).
default_symbol_attr( Symbol, Const, Dual, Value, Init, Max, Min,
[ const: Const,
dual: Dual,
name: Symbol,
value: Value,
init: Init,
max: Max,
min: Min
!,
(
Constant >= 0
->
P is Constant, N is 0
;
P is 0, N is -Constant
).
default_symbol_attr( Constant,
[ const: yes,
dual: no,
name: Constant,
value: Constant,
init: Constant,
max: Constant,
min: Constant
] ) :-
number( Constant ), !.
default_symbol_attr( Variable,
[ const: no,
dual: no,
name: Variable,
value: 0,
init: 0,
max: 0,
min: 0
] ).
get_symbol_name( Symbol ) :-
......@@ -533,24 +551,12 @@ new_symbol( Symbol, dual, Init ) :-
),
new_symbol( Symbol, dual, [ init: [ P, N ] ] ).
new_symbol( Symbol, dual, InitAttributeList ) :-
new_symbol( Symbol, dual, InitAttributeList ) :-
list( InitAttributeList ),
!,
(
number( Symbol )
->
(
Symbol >= 0
->
P is Symbol, N is 0
;
P is 0, N is -Symbol
)
;
get_symbol_name( Symbol ),
atom_concat( Symbol, '_p', P ),
atom_concat( Symbol, '_n', N )
),
get_symbol_name( Symbol ),
atom_concat( Symbol, '_p', P ),
atom_concat( Symbol, '_n', N ),
DualAttributeList = [ dual: yes, name: [ P, N ] ],
(
member( [ init: _ ], InitAttributeList )
......@@ -589,6 +595,18 @@ replace_attr( AttributeList, [ Key: Value | ReplaceList ], ResultList ) :-
select( Key: _, AttributeList, Key: Value, AttributeListT ),
replace_attr( AttributeListT, ReplaceList, ResultList ).
get_symbol_attr( Constant, QueryList ) :-
number( Constant ),
!,
(
member( dual: yes, QueryList )
->
default_symbol_attr( Constant, AttributeList, dual )
;
default_symbol_attr( Constant, AttributeList )
),
instantiate_symbol_attr( AttributeList, QueryList ).
get_symbol_attr( Symbol, QueryList ) :-
symbol( Symbol, AttributeList ),
instantiate_symbol_attr( AttributeList, QueryList ).
......@@ -666,6 +684,11 @@ get_ode( OdeSystem, [ P, N ], DP, DN ) :-
Either using variable name to get the differential semantic, or using differential semantic to get the variable name.
Here are some functions to handle the variable database." ).
variable( Constant, ConstantDiff ) :-
number( Constant ),
!,
get_symbol_attr( Constant, [ dual: yes, name: ConstantDiff ] ).
variable( VariableName, VariableDiff ) :-
get_symbol_attr( VariableName, [ name: VariableDiff ] ).
......@@ -1230,15 +1253,11 @@ split_self_assignment( Expression, T, InterExpression, NewExpression ) :- % {{{
% constant{{{
expression_to_ODE( _, Constant, Constant ) :-% {{{
% expression_to_ODE( ?OdeSystem, +Constant, -Constant )
number( Constant ),
!,
new_symbol( Constant, dual ).
number( Constant ), !.
% }}}
expression_to_ODE( _, BooleanConstant, Constant ) :-% {{{
% expression_to_ODE( ?OdeSystem, +BooleanConstant, -Constant )
constant( BooleanConstant, Constant ),
!,
new_symbol( Constant, dual ).
constant( BooleanConstant, Constant ), !.
% }}}
% end constant
% }}}
......@@ -2199,7 +2218,6 @@ pos_sigmoid_to_PIVP( OdeSystem, X, Z ) :-
constant( true, True ),
SwitchInit = 3,
Scale is True / SwitchInit,
new_symbol( Scale, dual ),
switch_to_PIVP( OdeSystem, SX, X, _, T, [ x_init(SwitchInit), y_init(0) ] ),
multiplication_to_PIVP( OdeSystem, T, Scale, Z ).
......@@ -2220,7 +2238,6 @@ neg_sigmoid_to_PIVP( OdeSystem, X, Z ) :-
constant( true, True ),
SwitchInit = 3,
Scale is True / SwitchInit,
new_symbol( Scale, dual ),
switch_to_PIVP( OdeSystem, X, SX, _, T, [ x_init(SwitchInit), y_init(0) ] ),
multiplication_to_PIVP( OdeSystem, T, Scale, Z ).
......@@ -2375,7 +2392,6 @@ hill_to_ODE( OdeSystem, K, G, X, H, NH ) :-
*/
general_tanh_to_PIVP( OdeSystem, K, C, Shift, X, Tanh ) :-
% general_tanh_to_PIVP( +OdeSystem, +K:unsigned_int, +C:int, +Shift:int, +VariableXName, +VariableTanhName )
new_symbol( Shift, dual ),
init_general_tanh( OdeSystem, Tanh, G ),
variable( [ Shift, X, G, Tanh ], [ ShiftDiff, XDiff, GDiff, TanhDiff ], list ),
......@@ -2466,7 +2482,6 @@ neg_tanh_to_ODE( OdeSystem, K, C, [ DGP, DGN ], [ TanhP, TanhN ] ) :-
*/
general_step_to_PIVP( OdeSystem, K, C, Shift, X, Step ) :- % differential symantic
!,
new_symbol( Shift, dual ),
init_general_step( OdeSystem, K, Step, Tanh, G ),
variable( [ Shift, X, G, Tanh, Step ], [ ShiftDiff, XDiff, GDiff, TanhDiff, StepDiff ], list ),
......@@ -2938,7 +2953,6 @@ post_post_pre_to_PIVP( OdeSystem, X, Z, EvalValue, PreReal, PostPreNext, PostPre
% post_post_pre_to_PIVP( +OdeSystem, +VariableXName, +VariableZName, +EvalValue:int, +VariablePreRealName, +VariablePrePostNextName, +VariablePostPreName, +VariablePreName )
constant( switchNull, SwitchNull ),
new_variable( OdeSystem, [ Stable, ProgramStart, ProgramStartNot ] ),
new_symbol( EvalValue ),
inter_post_pre_to_PIVP( OdeSystem, X, Z, PreReal, PostPreNext, PostPre ),
......
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