Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstraintParameter expression switches order when using an operation on a parameter #904

Open
MichaelAbdul-Masih opened this issue Jun 13, 2024 · 1 comment
Assignees
Labels

Comments

@MichaelAbdul-Masih
Copy link
Contributor

When trying to create a constraint, it appears that the order of an expression in parentheses changes when a math operation is applied to the parameter. For example, the below behaves normally:

>>> (1 - b['ecc@binary'])
<ConstraintParameter: 1.000000 - {ecc@binary@component} (SI) => 1.0>

but when an operation is applied to the eccentricity parameter the expression order changes moving the parameter to the front and flipping the signs:

>>> (1 - b['ecc@binary']**2)
<ConstraintParameter: ({ecc@binary@component} ** 2.000000) - 1.000000 (SI) => -1.0>

The same happens when other operations are applied.

>>> from phoebe.parameters.constraint import sin
>>> (1 - sin(b['ecc@binary']))
<ConstraintParameter: (sin({ecc@binary@component})) - 1.000000 (SI) => -1.0>

The code can be tricked by explicitly putting the parameter first though. So the mathmatically equivalent espression below produces the correct result:

>>> (-1 * b['ecc@binary']**2 + 1)
<ConstraintParameter: (-1.000000 * ({ecc@binary@component} ** 2.000000)) + 1.000000 (SI) => 1.0>
@kecnry
Copy link
Member

kecnry commented Jun 14, 2024

I'm not surprised that order matters (and you'll see lots of similar workarounds to what you showed in the built-in constraints themselves), but I think in the past this used to raise an error instead of giving the wrong expression - thanks for reporting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants