-
Notifications
You must be signed in to change notification settings - Fork 153
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
adds Inequality #717
adds Inequality #717
Conversation
Codecov Report
@@ Coverage Diff @@
## master #717 +/- ##
==========================================
- Coverage 75.82% 3.03% -72.80%
==========================================
Files 23 24 +1
Lines 2792 2737 -55
==========================================
- Hits 2117 83 -2034
- Misses 675 2654 +1979
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Should we add a compound inequality in order to represent |
Can't you use an |
BTW the |
If |
I have followed the implementation of |
I guess it would be somewhat important to be able to simplify inequalities into this form. Otherwise for e.g. Ipopt we would have double the amount of inequality constraints. |
I believe that you can't write a <= x <= b due to how Julia parses this. I think there may be an issue about that? |
However, this could be handled via a the constructor, doesn't it? <=(a,b) = Inequality(a, b, leq)
<=(a,b::Inequality) = IntervalInequality(a, b.lhs, b.rhs, leq) |
Yes but only if you write The problem is with the way Julia parses julia> Meta.@lower a <= b <= c
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope`
1 ─ %1 = a <= b
└── goto #3 if not %1
2 ─ %3 = b <= c
└── return %3
3 ─ return false
)))) |
@shashi If you are fine with the interface right now, can we merge this PR and leave a term interface or separate type as a follow-up? |
Sure we can merge this :) |
should fix #740 as well |
@@ -126,6 +126,10 @@ for T in [:Num, :Complex, :Number], S in [:Num, :Complex, :Number] | |||
end | |||
end | |||
|
|||
canonical_form(eq::Equation) = eq.lhs - eq.rhs ~ 0 | |||
|
|||
get_variables(eq::Equation) = unique(vcat(get_variables(eq.lhs), get_variables(eq.rhs))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ValentinKaisermayer, @YingboMa, @shashi Just note this is a breaking change as previously get_variables
only applied to the rhs. It also means get_variables
is no longer consistent with get_variables!
. Please be aware of this in making any new Symbolics releases. (It may not have any practical effect -- so far I haven't found anything that really relied on that behavior but I could have missed something in ModelingToolkit or Catalyst...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess there has been a release already and this was included, so it's a bit late to make sure the release is flagged as breaking...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can it be breaking if get_variables(eq::Equation)
is added and not altered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. We can remove it, it is after all just for convenience and not used in MTK. Only get_variables!
: https://github.com/SciML/ModelingToolkit.jl/blob/28b36c8f9932acfc6c54737c51437d35b192b0d7/src/systems/dependency_graphs.jl#L43
However, I must say, that without proper documentation it is not clear why only the rhs is considered. I guess it assumes 0~f(x)
or D(x)~f(x)
, but just by convention.
https://symbolics.juliasymbolics.org/stable/manual/expression_manipulation/#Symbolics.get_variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the change makes sense given ModelingToolkit is now allowing more flexibility in equation structure, but the in-place version should probably get updated for consistency. I agree the behavior should get documented in either case though!
x - y ≲ 0 | ||
``` | ||
""" | ||
function ≲(lhs, rhs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a one-line description for how to type ≲
? For example, Base.MathConstants.pi
.
Symbolics.jl is not in SciML, but SciMLStyle doesn't allow Unicode to be used in public APIs.
See SciMLStyle: General Naming Principles.
So it is probably better to change the function name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow up on #630
Indented use-case: