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

Counting the number of times equations hold #322

Open
dourouc05 opened this issue Jul 28, 2021 · 0 comments
Open

Counting the number of times equations hold #322

dourouc05 opened this issue Jul 28, 2021 · 0 comments

Comments

@dourouc05
Copy link

dourouc05 commented Jul 28, 2021

Follow-up from jump-dev/MathOptInterface.jl#846.

In standard Julia, you can compare arrays of numbers, and see the number of equalities that hold:

t = 1
σ = 2
ρ = 1
β = 4
[t, σ] .== [ρ, β] # BitVector: [true, false]
sum([t, σ] .== [ρ, β]) # 1: one of the two equalities hold

However, the closest syntax with Symbolics does not work yet:

@parameters t σ ρ β
sum([t, σ] .~ [ρ, β])

It seems that it's trying to sum the equations side by side:

ERROR: MethodError: no method matching +(::Equation, ::Equation)
Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...) at operators.jl:560
  +(::ChainRulesCore.AbstractThunk, ::Any) at C:\Users\Thibaut\.julia\packages\ChainRulesCore\GciYT\src\differential_arithmetic.jl:138
  +(::ChainRulesCore.Tangent{P, T} where T, ::P) where P at C:\Users\Thibaut\.julia\packages\ChainRulesCore\GciYT\src\differential_arithmetic.jl:162
  ...
Stacktrace:
  [1] add_sum(x::Equation, y::Equation)
    @ Base .\reduce.jl:24
  [2] _mapreduce
    @ .\reduce.jl:408 [inlined]
  [3] _mapreduce_dim
    @ .\reducedim.jl:318 [inlined]
  [4] #mapreduce#672
    @ .\reducedim.jl:310 [inlined]
  [5] mapreduce
    @ .\reducedim.jl:310 [inlined]
  [6] #_sum#682
    @ .\reducedim.jl:878 [inlined]
  [7] _sum
    @ .\reducedim.jl:878 [inlined]
  [8] #_sum#681
    @ .\reducedim.jl:877 [inlined]
  [9] _sum
    @ .\reducedim.jl:877 [inlined]
 [10] #sum#679
    @ .\reducedim.jl:873 [inlined]
 [11] sum(a::Vector{Equation})
    @ Base .\reducedim.jl:873
 [12] top-level scope
    @ REPL[13]:1

Similarly, it would be nice to allow count, the simplest usage being very similar:

julia> count([t, σ] .~ [ρ, β])
ERROR: TypeError: non-boolean (Equation) used in boolean context
Stacktrace:
 [1] _simple_count
   @ .\reduce.jl:970 [inlined]
 [2] _count
   @ .\reducedim.jl:395 [inlined]
 [3] #count#676
   @ .\reducedim.jl:393 [inlined]
 [4] #count#675
   @ .\reducedim.jl:392 [inlined]
 [5] count(A::Vector{Equation})
   @ Base .\reducedim.jl:392
 [6] top-level scope
   @ REPL[4]:1```



┆Issue is synchronized with this [Trello card](https://trello.com/c/ab5g3mEa) by [Unito](https://www.unito.io)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant