Implement methods like sqrt for pure scalar multivectors
karlwessel opened this issue · comments
I'm trying to implement sqrt
for pure scalar multivectors (so for Basis{V, 0, 0}
, MValue{V, 0, v, T}
and SValue{V, 0, v, T}
), but I have a hard time to find the right syntax for the methods type declaration. It is easy for Basis
:
sqrt(t::Basis{B, 0, 0x0000000000000000}) where {B} = 1
But I'm not sure how to define the type of MValue
and SValue
for scalar basis v
. I can get v
into the scope and write
julia> basis"2"
(⟨++⟩, v, v₁, v₂, v₁₂)
julia> sqrt(x::SValue{B, 0, v, T}) where {B, T} = sqrt(x.v)
sqrt (generic function with 23 methods)
julia> sqrt(13*v)
3.605551275463989
but that seems ugly and does not make sure that v
matches the scalar basis for any B
.
I guess I have to use the function indexbasis
but I'm not sure about its syntax.
So this is more like a question than an actual issue (except maybe a documentation issue).
Btw: What is the difference between SValue and MValue?
PS: I hope that its clear, but I'm saying it anyway: I really like this package, thanks for all the work you are putting into it.
This is how to define sqrt
for grade 0 values (and indexbasis
would not be used for that):
Base.sqrt(x::SValue{V,0}) where V = sqrt(value(x))*basis(x)
The difference between MValue
and SValue
is that M
stands for mutable and S
for static.
Ah, right, since grade 0 already defines the scalar base vector I don't have to check for that! Thanks!
More generally, you can define this method for Basis,SValue,MValue
simultaneously with TensorTerm
Base.sqrt(x::T) where T<:TensorTerm{V,0} where V = sqrt(value(x))*basis(x)
since TensorTerm
has Basis,SValue,MValue
as a subtypes
julia> subtypes(TensorTerm{ℝ^2,0})
3-element Array{Any,1}:
Basis{⟨++⟩,0,B} where B
MValue{⟨++⟩,0,B,T} where T where B
SValue{⟨++⟩,0,B,T} where T where B