Commit 84a00a16 authored by HUANG Wei Chih's avatar HUANG Wei Chih
Browse files

fix: wrong result when simplifying variable initialization

parent 59069a45
......@@ -386,23 +386,17 @@ simplify_variable_initialization( [ Variable = Expression | FunctionList ], NewF
number( PureExpression ),
!,
new_symbol( Variable, dual ),
variable( Variable, [ P, N ] ),
(
PureExpression >= 0
->
present( [ P ], PureExpression ),
present( [ N ], 0 )
;
present( [ P ], 0 ),
present( [ N ], -PureExpression )
),
new_symbol( Variable, dual, PureExpression ),
simplify_variable_initialization( FunctionList, NewFunctionList, yes ).
simplify_variable_initialization( [ Variable = ( pre Expression ) | FunctionList ], NewFunctionList, yes ) :-
!,
append( [ Variable = ( Expression ) ], FunctionList, NewFunctionList ).
simplify_variable_initialization( [ Variable = ( pre Expression post ) | FunctionList ], NewFunctionList, yes ) :-
!,
append( [ Variable = ( Expression post ) ], FunctionList, NewFunctionList ).
simplify_variable_initialization( FunctionList, FunctionList, _ ).
% }}}
get_pure_expression( pre Expression, PureExpression ) :-% {{{
......@@ -561,19 +555,25 @@ new_symbol( Symbol, dual, Init ) :-
new_symbol( Symbol, dual, InitAttributeList ) :-
list( InitAttributeList ),
!,
get_symbol_name( Symbol ),
atom_concat( Symbol, '_p', P ),
atom_concat( Symbol, '_n', N ),
DualAttributeList = [ dual: yes, name: [ P, N ] ],
(
member( [ init: _ ], InitAttributeList )
symbol( Symbol, _ )
->
NewDualAttributeList = DualAttributeList
change_symbol_attr( Symbol, InitAttributeList )
;
append( DualAttributeList, [ init: [ 0, 0 ] ], NewDualAttributeList )
),
append( InitAttributeList, NewDualAttributeList, NewInitAttributeList ),
new_symbol( Symbol, NewInitAttributeList ).
get_symbol_name( Symbol ),
atom_concat( Symbol, '_p', P ),
atom_concat( Symbol, '_n', N ),
DualAttributeList = [ dual: yes, name: [ P, N ] ],
(
member( init: _, InitAttributeList )
->
NewDualAttributeList = DualAttributeList
;
append( DualAttributeList, [ init: [ 0, 0 ] ], NewDualAttributeList )
),
append( InitAttributeList, NewDualAttributeList, NewInitAttributeList ),
new_symbol( Symbol, NewInitAttributeList )
).
change_symbol_attr( Symbol, ChangeList ) :-
(
......@@ -753,7 +753,7 @@ new_variable( OdeSystem, Name ) :-
devdoc( "Generate variable with name \\emph{Name} and set initial value to 0 in the ode system \\emph{OdeSystem}." ),
\+ list( Name ),
new_variable( OdeSystem, Name, 0 ).
new_variable( Name ).
new_variable( OdeSystem, [ Name | NameList ] ) :-
% new_variable( +OdeSystem, ?NameList )
......@@ -828,17 +828,8 @@ clear_condition( Condition, Name ) :-
:- devdoc( "\\item xxx expression to ODE" ).
:- devdoc( "Here are some function to recursively parse and check the expression." ).
nnary_expression_to_ODE( OdeSystem, [], [], Z ) :-
new_variable( Z ),
\+ (
get_symbol_attr( Z, [ init: [ PInit, NInit ] ] ),
PInit is 0,
NInit is 0,
\+ (
get_initial_concentration( Z, Concentration ),
init_variable( OdeSystem, Z, Concentration )
)
).
nnary_expression_to_ODE( _, [], [], Z ) :-
new_variable( Z ).
nnary_expression_to_ODE( OdeSystem, [ Expression | ExpressionList ], [ E | EList ], Z ) :-
expression_to_ODE( OdeSystem, Expression, E ),
......@@ -1712,14 +1703,12 @@ eval( OdeSystem, X, Z ) :-
item( [ kind: ode_system, id: OdeSystem ] ),
!,
(
item( [ parent: OdeSystem, kind: initial_concentration, item: init( X = Z ) ] )
get_symbol_attr( X, [ dual: yes, init: Init ] )
->
true
Init = [ PInit, NInit ],
Z is PInit - NInit
;
variable( X, [ XP, XN ] ),
item( [ parent: OdeSystem, kind: initial_concentration, item: init( XP = XPInit ) ] ),
item( [ parent: OdeSystem, kind: initial_concentration, item: init( XN = XNInit ) ] ),
Z is XPInit - XNInit
get_symbol_attr( X, [ init: Z ] )
).
eval_condition( Condition, Z ) :-
......@@ -1940,19 +1929,8 @@ substraction_to_PIVP( OdeSystem, X, Y, Z ) :-
* x >= 0 : x_p = x, x_n = 0
* x < 0 : x_p = 0, x_n = -x
*/
argument_to_PIVP( OdeSystem, X ) :-
argument_to_PIVP( _, _ ).
% argument_to_PIVP( +OdeSystem, +VariableXName )
\+ (
variable( X, [ XP, XN ] ),
get_initial_concentration( XP, ConcentrationP ),
get_initial_concentration( XN, ConcentrationN ),
ConcentrationP is 0,
ConcentrationN is 0,
\+ (
get_initial_concentration( X, Concentration ),
init_variable( OdeSystem, X, Concentration )
)
).
% }}}
% functions{{{
/* z = abs( x ):{{{
......
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