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

Implement methods like sqrt for pure scalar multivectors #18

Closed
karlwessel opened this issue May 31, 2019 · 3 comments
Closed

Implement methods like sqrt for pure scalar multivectors #18

karlwessel opened this issue May 31, 2019 · 3 comments
Labels

Comments

@karlwessel
Copy link

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.

@chakravala
Copy link
Owner

chakravala commented May 31, 2019

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.

@karlwessel
Copy link
Author

Ah, right, since grade 0 already defines the scalar base vector I don't have to check for that! Thanks!

@chakravala
Copy link
Owner

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

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