opty icon indicating copy to clipboard operation
opty copied to clipboard

All assumptions applied to functions of time should be transferred to their discrete versions

Open moorepants opened this issue 1 year ago • 11 comments

The generation of discrete variables looks like:

        self.previous_discrete_state_symbols = \
            tuple([sm.Symbol(f.__class__.__name__ + 'p', real=True)
                   for f in self.state_symbols])

This sets a real=True assumption on each new discrete symbol but any other assumptions that may have been applied to the continuous symbol would be lost. This can have an unexpected effect when the Jacobian is calculated if some assumptions would change the output of the Jacobian wrt to any discrete symbol.

moorepants avatar Aug 29 '24 15:08 moorepants

A related issue is that the CSE variables don't have the assumptions of the expressions they replace. See #216 for related info.

moorepants avatar Aug 30 '24 04:08 moorepants

As far as opty is concerned, does this mean the following: Say, the state variable is x1, and has certain assumptions, say, real=True, positive=True Then x1i, x1p, x1n should have the same assumptions?

Similar with other variables that will be discretized?

Peter230655 avatar Jan 26 '25 13:01 Peter230655

Yes, but this may need more thought than I've explained here. I recall thinking the fix isn't so simple. That's why I didn't pursue.

moorepants avatar Jan 26 '25 14:01 moorepants

Yes, this is a bit deeper issue: https://github.com/csu-hmc/opty/issues/215#issuecomment-2320003714

moorepants avatar Jan 26 '25 14:01 moorepants

Yes, this is a bit deeper issue: #215 (comment)

So I better stay away from it.

Peter230655 avatar Jan 26 '25 14:01 Peter230655

If you have symbols with assumptions and your form an expression with those symbols, you can then ask what assumptions hold for the expression. When you apply CSE to a large expression you get all these subexpressions and the associated substitution variable. You then have to ask what assumptions apply to that substitution variable.

This needs to be thought out wrt to the CSEd jacobian we do.

moorepants avatar Jan 26 '25 15:01 moorepants

If you have symbols with assumptions and your form an expression with those symbols, you can then ask what assumptions hold for the expression. When you apply CSE to a large expression you get all these subexpressions and the associated substitution variable. You then have to ask what assumptions apply to that substitution variable.

This needs to be thought out wrt to the CSEd jacobian we do.

If I understand correctly:

  • Say, a, b are real positive. Then for c = a - b a positivity assumption for c does not make sense anymore unless a > b is guaranteed for some reason.
  • If, say, a is an integer, then for c = sin(a) an integer assumption does for c not make sense in general.

If this is right, then if c = arbitrary_function(a1, a2, ...., an) pretty much the only assumption left for c is real=True?

Peter230655 avatar Jan 26 '25 16:01 Peter230655

What if the arbitrary function calculates eigenvalues, then real=True can't be assumed!

moorepants avatar Jan 26 '25 16:01 moorepants

What if the arbitrary function calculates eigenvalues, then real=True can't be assumed!

....unless the matrix in question is guaranteed to be symmetric. So, even real=True cannot be assumed in general. Not much left.

Peter230655 avatar Jan 26 '25 16:01 Peter230655

Technically these kinds of things can be with sympy's "new" assumption system.

moorepants avatar Jan 26 '25 17:01 moorepants

Technically these kinds of things can be with sympy's "new" assumption system.

I think, I keep my hands off this one.

Peter230655 avatar Jan 26 '25 17:01 Peter230655