Commit 80654973 by HUANG Wei Chih

### simplify code in expression evaluation

parent 5bcf4701
 ... ... @@ -1509,195 +1509,158 @@ eval( _, Constant, Constant ) :- number( Constant ), !. eval( _, BooleanConstant, Constant ) :- constant( BooleanConstant, Constant ), !. constant( BooleanConstant, Constant ), number( Constant ), !. eval( OdeSystem, X = Y, Z ) :- eval( InitSystem, X = Y, Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), ( T1 == T2 -> constant( true, Z ) ; constant( false, Z ) ). eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), eval_condition( T1 == T2, Z ). eval( OdeSystem, X < Y, Z ) :- eval( InitSystem, X < Y, Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), ( T1 < T2 -> constant( true, Z ) ; constant( false, Z ) ). eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), eval_condition( T1 < T2, Z ). eval( OdeSystem, X <= Y, Z ) :- eval( InitSystem, X <= Y, Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), ( T1 =< T2 -> constant( true, Z ) ; constant( false, Z ) ). eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), eval_condition( T1 =< T2, Z ). eval( OdeSystem, X > Y, Z ) :- !, eval( OdeSystem, Y < X, Z ). eval( InitSystem, X > Y, Z ) :- !, eval( InitSystem, Y < X, Z ). eval( OdeSystem, X >= Y, Z ) :- !, eval( OdeSystem, Y <= X, Z ). eval( InitSystem, X >= Y, Z ) :- !, eval( InitSystem, Y <= X, Z ). eval( OdeSystem, X or Y, Z ) :- eval( InitSystem, X or Y, Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), ( constant( false, T1 ), constant( false, T2 ) -> constant( false, Z ) ; constant( true, Z ) ). eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), eval_condition( ( constant( true, T1 ) ; constant( true, T2 ) ), Z ). eval( OdeSystem, X and Y, Z ) :- eval( InitSystem, X and Y, Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), ( constant( true, T1 ), constant( true, T2 ) -> constant( true, Z ) ; constant( false, Z ) ). eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), eval_condition( ( constant( true, T1 ), constant( true, T2 ) ), Z ). eval( OdeSystem, not X, Z ) :- eval( InitSystem, not X, Z ) :- !, eval( OdeSystem, X, T ), ( constant( true, T ) -> constant( false, Z ) ; constant( true, Z ) ). eval( InitSystem, X, T ), eval_condition( constant( false, T ), Z ). eval( OdeSystem, X + Y, Z ) :- eval( InitSystem, X + Y, Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), Z is T1 + T2. eval( OdeSystem, X - Y, Z ) :- eval( InitSystem, X - Y, Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), Z is T1 - T2. eval( OdeSystem, X * Y, Z ) :- eval( InitSystem, X * Y, Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), Z is T1 * T2. eval( OdeSystem, X / Y, Z ) :- eval( InitSystem, X / Y, Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), Z is T1 / T2. eval( OdeSystem, X ^ Y, Z ) :- eval( InitSystem, X ^ Y, Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), Z is T1 ^ T2. eval( OdeSystem, +X, Z ) :- eval( InitSystem, +X, Z ) :- !, eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is T. eval( OdeSystem, -X, Z ) :- eval( InitSystem, -X, Z ) :- !, eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is -T. eval( OdeSystem, abs( X ), Z ) :- eval( InitSystem, abs( X ), Z ) :- !, eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is abs( T ). eval( OdeSystem, min( X, Y ), Z ) :- eval( InitSystem, min( X, Y ), Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), Z is min( T1, T2 ). eval( OdeSystem, max( X, Y ), Z ) :- eval( InitSystem, max( X, Y ), Z ) :- !, eval( OdeSystem, X, T1 ), eval( OdeSystem, Y, T2 ), eval( InitSystem, X, T1 ), eval( InitSystem, Y, T2 ), Z is max( T1, T2 ). eval( OdeSystem, log( X ), Z ) :- eval( InitSystem, log( X ), Z ) :- !, eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is log( T ). eval( OdeSystem, exp( X ), Z ) :- eval( InitSystem, exp( X ), Z ) :- !, eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is exp( T ). eval( OdeSystem, cos( X ), Z ) :- eval( InitSystem, cos( X ), Z ) :- !, eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is cos( T ). eval( OdeSystem, sin( X ), Z ) :- eval( InitSystem, sin( X ), Z ) :- !, eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is sin( T ). eval( OdeSystem, hill( X ), Z ) :- eval( InitSystem, hill( X ), Z ) :- !, constant( true, True ), eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is True * T ^ 5 / ( 0.1 + T ^ 5 ). eval( OdeSystem, pos_tanh( X ), Z ) :- eval( InitSystem, pos_tanh( X ), Z ) :- !, constant( true, True ), eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is True * tanh( 6 * ( T - 0.8 ) ). eval( OdeSystem, neg_tanh( X ), Z ) :- eval( InitSystem, neg_tanh( X ), Z ) :- !, constant( true, True ), eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is True * tanh( -6 * ( T - 0.8 ) ). eval( OdeSystem, pos_step( X ), Z ) :- eval( InitSystem, pos_step( X ), Z ) :- !, constant( true, True ), eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is True * ( 1 + tanh( 6 * ( T - 0.8 ) ) ). eval( OdeSystem, neg_step( X ), Z ) :- eval( InitSystem, neg_step( X ), Z ) :- !, constant( true, True ), eval( OdeSystem, X, T ), eval( InitSystem, X, T ), Z is True * ( 1 + tanh( -6 * ( T - 0.8 ) ) ). eval( OdeSystem, X, Z ) :- item( [ kind: ode_system, id: OdeSystem ] ), !, ( item( [ parent: OdeSystem, kind: initial_concentration, item: init( X = Z ) ] ) ... ... @@ -1709,6 +1672,15 @@ eval( OdeSystem, X, Z ) :- item( [ parent: OdeSystem, kind: initial_concentration, item: init( XN = XNInit ) ] ), Z is XPInit - XNInit ). eval_condition( Condition, Z ) :- ( call( Condition ) -> constant( true, Z ) ; constant( false, Z ) ). % end expression evaluation %}}} % end expression parser ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!