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

Missing + overload when trying to create a point with symbolic coefficients #38

Open
micahscopes opened this issue Apr 20, 2020 · 1 comment
Labels

Comments

@micahscopes
Copy link

So I wanted to make a symbolic sphere using Reduce.jl symbols. I started off by making a point like this:

using Grassmann, Reduce;

X = :x*v1 + :y*v2 + :z*v3
pt = ↑(X)

But I get an error:

MethodError: no method matching +(::Float64, ::Expr)
Closest candidates are:
  +(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:529
  +(::Float64, !Matched::Float64) at float.jl:401
  +(::AbstractFloat, !Matched::Bool) at bool.jl:106
  ...

Stacktrace:
 [1] +(::Float64, ::Float64, ::Expr, ::Expr, ::Expr) at ./operators.jl:529
 [2] ∑(::Float64, ::Float64, ::Expr, ::Vararg{Expr,N} where N) at /home/micah/.julia/packages/AbstractTensors/4KbT3/src/AbstractTensors.jl:280
 [3] macro expansion at /home/micah/.julia/packages/Grassmann/EjCrQ/src/products.jl:0 [inlined]
 [4] *(::Chain{⟨∞∅+++⟩,1,Any,5}, ::Chain{⟨∞∅+++⟩,1,Any,5}) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/products.jl:856
 [5] ^(::Chain{⟨∞∅+++⟩,1,Any,5}, ::Int64) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/algebra.jl:615
 [6] macro expansion at ./none:0 [inlined]
 [7] literal_pow at ./none:0 [inlined]
 [8] ↑(::Chain{⟨∞∅+++⟩,1,Any,5}) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/Grassmann.jl:124
 [9] top-level scope at In[6]:2

I can get around this by first defining:

using Base;
Base.:+(a::Float64, b::Expr) = a*v+b;

It fixes the problem, for now, but seems a little too hacky to make a PR worthy solution. I tried:

using Base;
Base.:+(a::Number, b::Expr) = a*v+b;

and got:

MethodError: +(::Simplex{⟨∞∅+++⟩,0,v,Float64}, ::Expr) is ambiguous. Candidates:
  +(a::T, b::Union{Expr, Symbol, #s71, #s70} where #s70<:Complex where #s71<:Real) where T<:TensorGraded in Grassmann at /home/micah/.julia/packages/Grassmann/EjCrQ/src/algebra.jl:706
  +(a::Number, b::Expr) in Main at In[7]:2
Possible fix, define
  +(::T, ::Expr) where T<:TensorGraded

Stacktrace:
 [1] +(::Float64, ::Expr) at ./In[7]:2
 [2] +(::Float64, ::Float64, ::Expr, ::Expr, ::Expr) at ./operators.jl:529
 [3] ∑(::Float64, ::Float64, ::Expr, ::Vararg{Expr,N} where N) at /home/micah/.julia/packages/AbstractTensors/4KbT3/src/AbstractTensors.jl:280
 [4] macro expansion at /home/micah/.julia/packages/Grassmann/EjCrQ/src/products.jl:0 [inlined]
 [5] *(::Chain{⟨∞∅+++⟩,1,Any,5}, ::Chain{⟨∞∅+++⟩,1,Any,5}) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/products.jl:856
 [6] ^(::Chain{⟨∞∅+++⟩,1,Any,5}, ::Int64) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/algebra.jl:615
 [7] macro expansion at ./none:0 [inlined]
 [8] literal_pow at ./none:0 [inlined]
 [9] ↑(::Chain{⟨∞∅+++⟩,1,Any,5}) at /home/micah/.julia/packages/Grassmann/EjCrQ/src/Grassmann.jl:124
 [10] top-level scope at In[7]:3

By this point I got kinda lost trying to define

Possible fix, define
  +(::T, ::Expr) where T<:TensorGraded
@chakravala chakravala transferred this issue from chakravala/Grassmann.jl Apr 20, 2020
@chakravala chakravala transferred this issue from chakravala/AbstractTensors.jl Apr 20, 2020
@chakravala chakravala added the bug label Apr 20, 2020
chakravala added a commit that referenced this issue Apr 20, 2020
@chakravala
Copy link
Owner

It's recommended to have using Reduce, Grassmann instead of using Grassmann, Reduce due to performance reasons. It is in fact faster to load Reduce before Grassmann.

The issue should now be resolved for your use case, although it's not a completely general fix.

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