7 ms·
In Raku you can also use × (U+D7) for multiplication # this assumes that ϕ, ψ, and θ have already been set my \cϕ = ϕ.cos; my \sϕ = ϕ.sin; my \cψ
by b2gills 5y ago
In Raku you can also use × (U+D7) for multiplication
# this assumes that ϕ, ψ, and θ have already been set
my \cϕ = ϕ.cos; my \sϕ = ϕ.sin;
my \cψ = ψ.cos; my \sψ = ψ.sin;
my \cθ = θ.cos; my \sθ = θ.sin;
my \alpha = [ cψ×cϕ−cθ×sϕ×sψ, cψ×sϕ+cθ×cϕ×sψ, sψ×sθ;
−sψ×cϕ−cθ×sϕ×cψ, −sψ×sϕ+cθ×cϕ×cψ, cψ×sθ;
sθ×sϕ, −sθ×cϕ, cθ];
I'm not sure if using × helps or hurts in this case since I'm not really experienced in this area.
These all work because Unicode defines ϕψθ as "Letter lowercase"
say "ϕψθ".uniprops;
# (Ll Ll Ll)
---
I would like to note that I used the Unicode "Minus Sign" "−" U+2212 so that it wouldn't complain about not being able to find a routine named "cϕ-cθ". (A space next to the "-" would have also sufficed.)
- a1369209993 5y ago> × (U+D7) for multiplication Blech; looks like a letter and normalizes cross products. Better to use "·" (U+B7)[0]: alpha = [ cψ·cϕ−cθ·sϕ·sψ, cψ·sϕ+cθ·cϕ·sψ, sψ·sθ; −sψ·cϕ−cθ·sϕ·cψ, −sψ·sϕ+cθ·cϕ·cψ, cψ·sθ; sθ·sϕ, −sθ·cϕ, cθ]; Minus sign is a nice-to-have, though. 0: Also "∧" (U+2227, wedge), the real other vector product[1], but that doesn't matter for scalar multiplication. 1: http://en.wikipedia.org/wiki/Wedge_product http://en.wikipedia.org/wiki/Wedge_product
- b2gills 5y agoIt would be easy to just make `·` an alias. Then that code would work. my &infix:< · > = &infix:< × >; (After all `×` itself is just an alias of `*` in the source for Rakudo.) If you need more control you can write it out sub infix:< · > (+@vals) is equiv(&[×]) # uses the same precedence level etc. is assoc<chaining> # may not be necessary given previous line { [×] @vals # reduction using infix operator } I made it chaining for the same reason `+` and `×` are chaining. --- I don't know enough about the topic to know how to properly write `∧`. It looks like it may be useful to write it using multis. # I don't know what precedence level it is supposed to be proto infix:< ∧ > (|) is tighter(&[×]) {*} multi infix:< ∧ > ( Numeric $l, Numeric $r, ) { $l × $r } multi infix:< ∧ > ( Vector $l, # need to define this somewhere, or use List/Array Vector $r, ) { … } If it was as simple as just a normal cross product, that would have been easy. [[1,2,3],[4,5,6]] »×« [[10,20,30],[40,50,60]] # [[10,40,90],[160,250,360]] # generate a synthetic `»×«` operator, and give it an alias my &infix:< ∧ > = &infix:< »×« >; [[1,2,3],[4,5,6]] ∧ [[10,20,30],[40,50,60]] # [[10,40,90],[160,250,360]] Of course, I'm fairly confident that is wrong.