chakravala / Grassmann.jl

⟨Grassmann-Clifford-Hodge⟩ multilinear differential geometric algebra
https://grassmann.crucialflow.com
GNU Affero General Public License v3.0
470 stars 38 forks source link

grade selection syntax #101

Open ajahraus opened 2 years ago

ajahraus commented 2 years ago

When getting the elements of a MultiVector, you can use parentheses to select the grade, i.e.

A = 1 + 2v1 + 3v12 + 4v123 # 1 + 2v₁ + 3v₁₂ + 4v₁₂₃
typeof(A) # MultiVector{⟨1,1,1⟩, Int64, 8}
sizeof(A) # 64
A(0) # 1v

However, if the type if a Chain, then the parentheses act as an indexing operation, and only into the elements that are non-zero in the Chain. Attempting to access the scalar part of a Chain via `(0) returns an index error.

B =  3v12 + 4v23 #  B = 3v₁₂ + 0v₁₃ + 4v₂₃
typeof(B) # Chain{⟨1,1,1⟩, 2, Int64, 3}
sizeof(B) # 24
B(0) # BoundsError: attempt to access 3-element Vector{UInt64} at index [0]

There is a work-around for this, it is to wrap the Chain in a MultiVector, but a MultiVector is (depending on the basis) many times the size of a Chain. It seems to me that this behaviour of Chain is useful for the internal implementation, but at the user level, the difference between a Chain and a MultiVector should be abstracted away.

chakravala commented 2 years ago

No, you are mistaken. That is not a grade selection syntax. The grade selection syntax is handled with the grade function:

julia> grade(v1+v2,0)
𝟎

julia> grade(v1+v2,Val(0))
𝟎

The scalar part of an element is obtained with the scalar function:

julia> scalar(v1+v2)
𝟎

Note that you may have to use Grassmann v0.8 or later to reproduce these exact results.

ajahraus commented 2 years ago

That still doesn't work for me, I get a method error

MethodError: no method matching grade(::Grassmann.MultiVector{⟨1,1,1⟩, Int64, 8})

I'm importing using Grassmann, LinearAlgebra, AbstractTensors, Leibniz

ajahraus commented 2 years ago

Also, your documentation reads:

Taking a projection into a specific grade of a MultiVector is usually written $\langle A\rangle_n$ ​ and can be done using the soft brackets, like so

julia> A(0) 1v

julia> A(1) 2v₁ + 0v₂ + 0v₃

julia> A(2) 3v₁₂ + 0v₁₃ + 0v₂₃

Which is the only example of selecting elements of a grade I can find, and it fails if the type happens to be a Chain rather than a MultiVector

chakravala commented 2 years ago

That still doesn't work for me, I get a method error MethodError: no method matching grade(::Grassmann.MultiVector{⟨1,1,1⟩, Int64, 8})

Are you using Grassmann v0.8? That's the only currently supported version of Grassmann older versions are not supported.

Also, your documentation reads: ... and can be done using the soft brackets, like so

No, converting \langle and \rangle sandwhich into a parenthesis prefix argument form is grammatically not implied anywhere.

ajahraus commented 2 years ago

The line which shows this syntax in your documentation is here.

chakravala commented 2 years ago

I see, this is why I don't want to document any features that are works in progress. This package is not v1.0 yet, and is basically my scratch pad which is ever evolving. The syntax for grade selection is not yet firmly settled on a standard and is in flux.