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

replace variable access by symbol table API

parent 256192f8
......@@ -231,8 +231,8 @@ create_ode(_, OdeSystem) :-
set_counter( CounterName, CounterInit ),
constant( true, True ),
constant( false, False ),
add_constant( True ),
add_constant( False ),
new_symbol( True, dual ),
new_symbol( False, dual ),
new_variable( OdeSystem, [ Pre, PostPre ] ),
set_condition( precondition, Pre ),
set_condition( postcondition_pre, PostPre ),
......@@ -255,7 +255,7 @@ create_ode(FunctionList, OdeSystem) :-
% post process of PIVP compilation
create_ode(_, OdeSystem) :-
add_fast_annihilation( OdeSystem ),
remove_variable( _ ),
remove_symbol( _ ),
fail.
create_ode(_,_).
......@@ -389,7 +389,7 @@ simplify_variable_initialization( [ Variable = Expression | FunctionList ], NewF
number( PureExpression ),
!,
add_variable( Variable ),
new_symbol( Variable, dual ),
variable( Variable, [ P, N ] ),
(
PureExpression >= 0
......@@ -674,52 +674,6 @@ variable( [], [], list ).
variable( [ Name | NameList ], [ Variable | VariableList ], list ) :-
variable( Name, Variable ),
variable( NameList, VariableList, list ).
remove_variable( VariableName ) :-
% remove_variable( +VariableName )
type( VariableName, name ),
devdoc( "Remove variable with name \\emph{VariableName} from the database" ),
remove_symbol( VariableName ).
add_variable( VariableName ) :-
% add_variable( +VariableName )
type( VariableName, name ),
devdoc( "Add variable with name \\emph{VariableName} to the database." ),
devdoc( "It will implicitly add differential semantic [ \\emph{VariableName}_p, \\emph{VariableName}_n ]." ),
(
nonvar( VariableName )
->
true
;
throw( error( type_error( nonvar, VariableName ) ) )
),
new_symbol( VariableName, dual ).
add_constant( Constant ) :-
% add_constant( +Constant:int )
type( Constant, number ),
devdoc( "Add constant \\emph{Constant} to the variable database." ),
(
number( Constant )
->
true
;
throw( error( type_error( number, Constant ) ) )
),
new_symbol( Constant, dual ).
% }}}
% get_variable_name( ?Variable ){{{
:- devdoc( "\\item get variable name" ).
get_variable_name( VariableName ) :-
% get_variable_name( +Variable )
type( VariableName, name ),
devdoc( "Generate temperory variable name if \\emph{VariableName} is not instantiate, do nothing otherwise." ),
get_symbol_name( VariableName ).
% }}}
% get_variable_positive( ?VariableName, -VariableP ){{{
:- devdoc( "\\item get variable positive" ).
......@@ -732,7 +686,7 @@ get_variable_positive( VariableName, VariableP ) :-
(
var( VariableName )
->
get_variable_name( VariableP )
get_symbol_name( VariableP )
;
variable( VariableName, [ VariableP, _ ] )
).
......@@ -746,8 +700,8 @@ new_variable( Name ) :-
type( Name, name ),
devdoc( "Generate variable with name \\emph{Name} without initial value." ),
\+ list( Name ),
get_variable_name( Name ),
add_variable( Name ).
get_symbol_name( Name ),
new_symbol( Name, dual ).
new_variable( [ Name | NameList ] ) :-
% new_variable( ?NameList )
......@@ -1281,13 +1235,13 @@ expression_to_ODE( _, Constant, Constant ) :-% {{{
% expression_to_ODE( ?OdeSystem, +Constant, -Constant )
number( Constant ),
!,
add_constant( Constant ).
new_symbol( Constant, dual ).
% }}}
expression_to_ODE( _, BooleanConstant, Constant ) :-% {{{
% expression_to_ODE( ?OdeSystem, +BooleanConstant, -Constant )
constant( BooleanConstant, Constant ),
!,
add_constant( Constant ).
new_symbol( Constant, dual ).
% }}}
% end constant
% }}}
......@@ -1554,7 +1508,7 @@ expression_to_ODE( OdeSystem, switch_x( ExpressionSX, ExpressionSY ), Z ) :-
expression_to_ODE( OdeSystem, X, X ) :-
% expression_to_ODE( +OdeSystem, +VariableName, -VariableName )
!,
add_variable( X ),
new_symbol( X, dual ),
argument_to_PIVP( OdeSystem, X ).
expression_to_ODE( OdeSystem, X, Z ) :-
......@@ -2249,7 +2203,7 @@ pos_sigmoid_to_PIVP( OdeSystem, X, Z ) :-
constant( true, True ),
SwitchInit = 3,
Scale is True / SwitchInit,
add_constant( Scale ),
new_symbol( Scale, dual ),
switch_to_PIVP( OdeSystem, SX, X, _, T, [ x_init(SwitchInit), y_init(0) ] ),
multiplication_to_PIVP( OdeSystem, T, Scale, Z ).
......@@ -2270,7 +2224,7 @@ neg_sigmoid_to_PIVP( OdeSystem, X, Z ) :-
constant( true, True ),
SwitchInit = 3,
Scale is True / SwitchInit,
add_constant( Scale ),
new_symbol( Scale, dual ),
switch_to_PIVP( OdeSystem, X, SX, _, T, [ x_init(SwitchInit), y_init(0) ] ),
multiplication_to_PIVP( OdeSystem, T, Scale, Z ).
......@@ -2368,9 +2322,9 @@ hill_to_PIVP( OdeSystem, X, H, NH ) :- % non differential symantic
init_hill( OdeSystem, Scale, H, NH, G ) :-
% init_hill( +OdeSystem, +Scale, ?VariableHName, ?VariableNHName, -VariableGName )
get_variable_name( H ), set_ode_initial_value( OdeSystem, H, 0 ),
get_variable_name( NH ), set_ode_initial_value( OdeSystem, NH, Scale ),
get_variable_name( G ), set_ode_initial_value( OdeSystem, G, 0 ).
get_symbol_name( H ), set_ode_initial_value( OdeSystem, H, 0 ),
get_symbol_name( NH ), set_ode_initial_value( OdeSystem, NH, Scale ),
get_symbol_name( G ), set_ode_initial_value( OdeSystem, G, 0 ).
hill_to_ODE( OdeSystem, K, G, X, H, NH ) :-
% hill_to_ODE( +OdeSystem, +K, +VariableGName, +VariableXName, +VariableHName, +VariableNHName )
......@@ -2425,7 +2379,7 @@ 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 )
add_constant( Shift ),
new_symbol( Shift, dual ),
init_general_tanh( OdeSystem, Tanh, G ),
variable( [ Shift, X, G, Tanh ], [ ShiftDiff, XDiff, GDiff, TanhDiff ], list ),
......@@ -2516,7 +2470,7 @@ neg_tanh_to_ODE( OdeSystem, K, C, [ DGP, DGN ], [ TanhP, TanhN ] ) :-
*/
general_step_to_PIVP( OdeSystem, K, C, Shift, X, Step ) :- % differential symantic
!,
add_constant( Shift ),
new_symbol( Shift, dual ),
init_general_step( OdeSystem, K, Step, Tanh, G ),
variable( [ Shift, X, G, Tanh, Step ], [ ShiftDiff, XDiff, GDiff, TanhDiff, StepDiff ], list ),
......@@ -2754,7 +2708,7 @@ init_switch( OdeSystem, X, Y, B, Options ) :-
constant( false, YInit )
),
get_variable_name( B ),
get_symbol_name( B ),
set_ode_initial_value( OdeSystem, X, XInit ),
set_ode_initial_value( OdeSystem, Y, YInit ),
set_ode_initial_value( OdeSystem, B, 0 ).
......@@ -2853,7 +2807,7 @@ init_zero_order( OdeSystem, Threshold, X, Y, SX, KcatSX, KcatSY, KmSX, KmSY, Ini
KmSY is 0.001 * True,
SXInit is Threshold / KcatSX,
get_variable_name( SX ),
get_symbol_name( SX ),
(
Inverse == true
->
......@@ -2990,7 +2944,7 @@ 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 ] ),
add_constant( EvalValue ),
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