Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lifeware
biocham
Commits
84a00a16
Commit
84a00a16
authored
Aug 11, 2019
by
HUANG Wei Chih
Browse files
fix: wrong result when simplifying variable initialization
parent
59069a45
Changes
1
Hide whitespace changes
Inline
Side-by-side
odefunction.pl
View file @
84a00a16
...
...
@@ -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
=
Dual
AttributeList
change_symbol_attr
(
Symbol
,
Init
AttributeList
)
;
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
:
i
nit
(
X
=
Z
)
]
)
get_symbol_attr
(
X
,
[
dual
:
yes
,
init
:
I
nit
]
)
->
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 ):{{{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment