chakravala / chakravala/Reduce.jl

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

Open
#38 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Julia
Stars
249
Forks
16
PR merge metrics
No merged PRs in 30d

Description

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
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.