Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Made Integer^Integer return a Real number as per the Modelica spec
- Added simplify rule (e1^e2)^e3 => e1^(e2*e3)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8907 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed May 10, 2011
1 parent 5ee65d2 commit 7bf4d71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
26 changes: 6 additions & 20 deletions Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -2896,32 +2896,12 @@ algorithm
then
DAE.RCONST(re3);

case (DAE.POW(ty = _),DAE.ICONST(integer = ie1),DAE.ICONST(integer = ie2))
equation
val = safeIntOp(ie1,ie2,POWOP());
then
val;

case (DAE.POW(ty = _),DAE.RCONST(real = re1),DAE.RCONST(real = re2))
equation
re3 = re1 ^. re2;
then
DAE.RCONST(re3);

case (DAE.POW(ty = _),DAE.RCONST(real = re1),DAE.ICONST(integer = ie2))
equation
e2_1 = intReal(ie2);
re3 = re1 ^. e2_1;
then
DAE.RCONST(re3);

case (DAE.POW(ty = _),DAE.ICONST(integer = ie1),DAE.RCONST(real = re2))
equation
e1_1 = intReal(ie1);
re3 = e1_1 ^. re2;
then
DAE.RCONST(re3);

// Relation operations
case(DAE.LESS(ty=_),exp1,exp2)
equation
Expand Down Expand Up @@ -3421,6 +3401,12 @@ algorithm
res = Expression.makeProductLst(exp_lst_1);
then
res;
// (e1^e2)^e3 => e1^(e2*e3)
case (DAE.POW(ty = _),DAE.BINARY(e1,DAE.POW(ty = _),e2),e3)
equation
res = DAE.BINARY(e1,DAE.POW(DAE.ET_REAL()),DAE.BINARY(e2,DAE.MUL(DAE.ET_REAL()),e3));
then
res;

// relation: cr1 == cr2, where cr1 and cr2 are the same
case (DAE.EQUAL(_),DAE.CREF(cr1,_),DAE.CREF(cr2,_))
Expand Down
8 changes: 3 additions & 5 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -12295,15 +12295,13 @@ algorithm

case (cache,Absyn.POW(),env,t1,t2)
equation
real_scalar = DAE.T_REAL_DEFAULT "The POW operator. a^b is only defined for integer exponents, i.e. b must
be of type Integer" ;
// Note: POW_ARR uses Integer exponents, while POW only uses Real exponents
real_scalar = DAE.T_REAL_DEFAULT;
int_scalar = DAE.T_INTEGER_DEFAULT;
real_vector = (DAE.T_ARRAY(DAE.DIM_UNKNOWN(),real_scalar),NONE());
real_matrix = (DAE.T_ARRAY(DAE.DIM_UNKNOWN(),real_vector),NONE());
real_pow = DAE.POW(DAE.ET_REAL());
int_pow = DAE.POW(DAE.ET_INT());
scalars = {(int_pow,{int_scalar,int_scalar},int_scalar),
(real_pow,{real_scalar,real_scalar},real_scalar)};
scalars = {(real_pow,{real_scalar,real_scalar},real_scalar)};
arrscalar = {
(DAE.POW_ARR(DAE.ET_REAL()),{real_matrix,int_scalar},
real_matrix)};
Expand Down

0 comments on commit 7bf4d71

Please sign in to comment.