Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#2265 closed enhancement (fixed)

simplify after replace variable

Reported by: Vitalij Ruge Owned by: Vitalij Ruge
Priority: normal Milestone: 1.9.0
Component: Backend Version: trunk
Keywords: simplify Cc: Jens Frenkel

Description (last modified by Lennart Ochel)

Simplify missing for der(x1) in

model missingSimplify
  Real x1(start = 1, fixed = true);
  Real x1_dummy;
  Real x2(start = 1);
  Real x3(start = 1);
equation
  x1_dummy = x1;
  der(x1) = sin(x1_dummy)/x1 - sin(x1)/x1; /*  != 0 (don't work) */
  der(x2) = sin(x1)/x1 - sin(x1)/x1; /* = 0 */
  der(x3) = x1_dummy - x1; /*  = 0 */
end missingSimplify;

with der(x2) = der(x1) . So simplify should work for der(x1) too.
Here the C code:

/*
 equation index: 3
 type: SIMPLE_ASSIGN
 
 der(x1) = DIVISION(sin(x1), x1, #SHARED_LITERAL_2(String)#) + DIVISION(-sin(x1), x1, #SHARED_LITERAL_3(String)#)
 */
static void eqFunction_3(DATA *data)
{
  modelica_real tmp0;
  modelica_real tmp1;
  modelica_real tmp2;
  modelica_real tmp3;
  tmp0 = sin($Px1);
  tmp1 = DIVISION(tmp0, $Px1, _OMC_LIT2);
  tmp2 = sin($Px1);
  tmp3 = DIVISION((-tmp2), $Px1, _OMC_LIT3);
  $P$DER$Px1 = (tmp1 + tmp3);
}

Change History (9)

comment:1 by Lennart Ochel, 12 years ago

Cc: Jens Frenkel added
Description: modified (diff)

There is probably no simplify after removing the alias variables?!

comment:2 by Jens Frenkel, 12 years ago

There is a simplify after removing the aliases because there is used BackendVarTransform.replaceEquation to do this. The problem is that

sin(x1) / x1 + (-sin(x1)) / x1

is not simplified to

(sin(x1) - sin(x1)) / x1

and finally to 0.

comment:3 by Martin Sjölund, 12 years ago

Because plus is simpler :) There is just a rule missing to simplify also the above one

comment:4 by Martin Sjölund, 12 years ago

Actually, if we had a rule to simplify:

f()/x + g()/x → (f()+g())/x

we would simplify the rest fine as well...

Last edited 12 years ago by Martin Sjölund (previous) (diff)

comment:5 by Vitalij Ruge, 12 years ago

Keywords: replace removed
Owner: changed from probably noone to Vitalij Ruge
Status: newaccepted

comment:6 by Vitalij Ruge, 12 years ago

Resolution: fixed
Status: acceptedclosed

Fixed in r16506

in reply to:  6 comment:7 by Martin Sjölund, 12 years ago

Replying to vitalij:

Fixed in r16506

I think that one looks a bit dodgy... Does it not simplify
(1+2) + (3+2) into (1+3)+2? I would be more confident if the last rule (the operator inside the parentheses was only * or /). Or show me how I'm wrong :)

comment:8 by Vitalij Ruge, 12 years ago

I felt a bit sheepish about it.
You are right.

comment:9 by Martin Sjölund, 11 years ago

Milestone: 2.0.01.9.0

BatchModify: Updating milestone since this ticket was closed in time for the 1.9.0 release

Note: See TracTickets for help on using tickets.