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

Inverse not defined for MBlade? #13

Closed
eschnett opened this issue May 10, 2019 · 4 comments
Closed

Inverse not defined for MBlade? #13

eschnett opened this issue May 10, 2019 · 4 comments

Comments

@eschnett
Copy link
Contributor

I'm trying to calculate the inverse of a blade with Grassmann v0.1.3:

julia> basis"3"
(⟨+++⟩, v, v₁, v₂, v₃, v₁₂, v₁₃, v₂₃, v₁₂₃)
julia> inv(v1+v2)
ERROR: MethodError: no method matching inv(::MBlade{Int64,⟨+++⟩,1,3})

Is this function missing, or am I looking in the wrong place?

@chakravala
Copy link
Owner

Currently, the implementation of inv is only for single Basis and SValue elements. It can be extended to MBlade elements but not for mixed-grade MultiVector elements, I believe.

@chakravala
Copy link
Owner

A naive implementation would be the following formula

julia> using Grassmann; basis"3"
(⟨+++⟩, v, v₁, v₂, v₃, v₁₂, v₁₃, v₂₃, v₁₂₃)

julia> Base.inv(a::TensorAlgebra) = (A=~a; A/(Aa))

julia> inv(v1+v2)
0.0 + 0.5v₁ + 0.5v₂

However, a more optimized method could also be defined, similar to the other operations.

@chakravala
Copy link
Owner

The MBlade should now be invertible with the inv method on master branch, which will be on v0.1.4

@chakravala
Copy link
Owner

The inv method has now been fully generalized to arbitrary MultiVector elements, provided that the it is defined for the given input value.

julia> 1/(0v+2v1)
0.0 + 0.5v₁

julia> @btime inv(0v+2v1)
  5.677 μs (80 allocations: 4.81 KiB)
0.0 + 0.5v₁

julia> @btime inv(2v1)
  62.522 ns (4 allocations: 64 bytes)
0.5v₁

julia> @btime inv(0v2+2v1)
  136.415 ns (6 allocations: 128 bytes)
0.5v₁ + 0.0v₂ + 0.0v₃

However, it is much slower for an arbitrary MultiVector input at the moment, due to type instability.

This may be improved in the future with the MultiGrade type, when it is further implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants