č      !"#$%&'( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H IJKLMNOPQ R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f ghijklmnopqrstuvwxyz{|}~portable provisionalEdward Kmett <ekmett@gmail.com> Trustworthy portable provisionalEdward Kmett <ekmett@gmail.com> Trustworthy9A vector is an additive group with additional structure. The zero vector Compute the sum of two vectors V2 1 2 ^+^ V2 3 4V2 4 6+Compute the difference between two vectors V2 4 5 - V2 3 1V2 1 4*Linearly interpolate between two vectors. Apply a function to merge the  'non-zero'= components of two vectors, unioning the rest of the values. * For a dense vector this is equivalent to . + For a sparse vector this is equivalent to . 3Apply a function to the components of two vectors. * For a dense vector this is equivalent to . + For a sparse vector this is equivalent to . !Compute the negation of a vector negated (V2 2 4) V2 (-2) (-4)  Compute the left scalar product  2 *^ V2 3 4V2 6 8 !Compute the right scalar product  V2 3 4 ^* 2V2 6 8 +Compute division by a scalar on the right. BProduce a default basis for a vector space. If the dimensionality 2 of the vector space is not statically known, see  . :Produce a default basis for a vector space from which the  argument is drawn. )Produce a diagonal matrix from a vector. &Outer (tensor) product of two vectors #    portable provisionalEdward Kmett <ekmett@gmail.com> Safe-InferredEProvides a fairly subjective test to see if a quantity is near zero. nearZero (1e-11 :: Double)FalsenearZero (1e-17 :: Double)TruenearZero (1e-5 :: Float)FalsenearZero (1e-7 :: Float)True&Determine if a quantity is near zero.  a  1e-12  a  1e-6  a  1e-12  a  1e-6 non-portable experimentalEdward Kmett <ekmett@gmail.com> TrustworthyFree and sparse inner product/metric spaces. ;Compute the inner product of two vectors or (equivalently)  convert a vector f a into a covector f a -> a. V2 1 2 `dot` V2 3 4119Compute the squared norm. The name quadrance arises from  Norman J. Wildberger's rational trigonometry. (Compute the quadrance of the difference ;Compute the distance between two vectors in a metric space /Compute the norm of a vector in a metric space *Convert a non-zero vector to unit vector.  Normalize a  functor to have unit . This function $ does not change the functor if its  is 0 or 1.  non-portable experimentalEdward Kmett <ekmett@gmail.com> Safe-InferredA  f+ is corepresentable if it is isomorphic to (x -> a) E for some x. Nearly all such functors can be represented by choosing x to be ? the set of lenses that are polymorphic in the contents of the ,  that is to say x = Rep f is a valid choice of x for (nearly) every   Representable .  non-portable experimentalEdward Kmett <ekmett@gmail.com> TrustworthyA 0-dimensional vector pure 1 :: V0 IntV0V0 + V0V0 non-portable experimentalEdward Kmett <ekmett@gmail.com> Trustworthy)A space that has at least 1 basis vector .  V1 2 ^._x2V1 2 & _x .~ 3V1 3    :: Lens' (t a) a  A 1-dimensional vector pure 1 :: V1 IntV1 1 V1 2 + V1 3V1 5 V1 2 * V1 3V1 6 sum (V1 2)2 ! ! ! ! non-portable experimentalEdward Kmett <ekmett@gmail.com> Trustworthy"6A space that distinguishes 2 orthogonal basis vectors  and #, but may have more. # V2 1 2 ^._y2V2 1 2 & _y .~ 3V2 1 3   # :: Lens' (t a) a $   $ :: Lens' (t a) (% a) %A 2-dimensional vector pure 1 :: V2 IntV2 1 1V2 1 2 + V2 3 4V2 4 6V2 1 2 * V2 3 4V2 3 8 sum (V2 1 2)3'+the counter-clockwise perpendicular vector perp $ V2 10 20 V2 (-20) 10"#$%&'"#$%&'%&"#$'"#$%&'  non-portable experimentalEdward Kmett <ekmett@gmail.com> Trustworthy(7A space that distinguishes 3 orthogonal basis vectors: , #, and ). (It may have more) )   ) :: Lens' (t a) a *   * :: Lens' (t a) (+ a) +A 3-dimensional vector -cross product .scalar triple product ()*+,-. "#$()*+,-. +,-."#$()*()*+,-.  non-portable experimentalEdward Kmett <ekmett@gmail.com> Trustworthy/4A space that distinguishes orthogonal basis vectors , #, ), 0. (It may have more.) 0   0 :: Lens' (t a) a 1   1 :: Lens' (t a) (2 a) 2A 4-dimensional vector. 4OConvert a 3-dimensional affine vector into a 4-dimensional homogeneous vector. 5NConvert a 3-dimensional affine point into a 4-dimensional homogeneous vector. /012345     "#$()*/0123452345"#$()*/01/012345       non-portable experimentalEdward Kmett <ekmett@gmail.com> Trustworthy68Plcker coordinates for lines in a 3-dimensional space. 8[Given a pair of points represented by homogeneous coordinates generate Plcker coordinates  for the line through them. 9OThese elements form a basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   9 :: Lens' (6 a) a  : :: Lens' (6 a) a  ; :: Lens' (6 a) a  < :: Lens' (6 a) a  = :: Lens' (6 a) a  > :: Lens' (6 a) a :OThese elements form a basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   9 :: Lens' (6 a) a  : :: Lens' (6 a) a  ; :: Lens' (6 a) a  < :: Lens' (6 a) a  = :: Lens' (6 a) a  > :: Lens' (6 a) a ;OThese elements form a basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   9 :: Lens' (6 a) a  : :: Lens' (6 a) a  ; :: Lens' (6 a) a  < :: Lens' (6 a) a  = :: Lens' (6 a) a  > :: Lens' (6 a) a <OThese elements form a basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   9 :: Lens' (6 a) a  : :: Lens' (6 a) a  ; :: Lens' (6 a) a  < :: Lens' (6 a) a  = :: Lens' (6 a) a  > :: Lens' (6 a) a =OThese elements form a basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   9 :: Lens' (6 a) a  : :: Lens' (6 a) a  ; :: Lens' (6 a) a  < :: Lens' (6 a) a  = :: Lens' (6 a) a  > :: Lens' (6 a) a >OThese elements form a basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   9 :: Lens' (6 a) a  : :: Lens' (6 a) a  ; :: Lens' (6 a) a  < :: Lens' (6 a) a  = :: Lens' (6 a) a  > :: Lens' (6 a) a ?ZThese elements form an alternate basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   ? ::  a => Lens' (6 a) a  @ ::  a => Lens' (6 a) a  A ::  a => Lens' (6 a) a  B ::  a => Lens' (6 a) a  C ::  a => Lens' (6 a) a  D ::  a => Lens' (6 a) a @ZThese elements form an alternate basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   ? ::  a => Lens' (6 a) a  @ ::  a => Lens' (6 a) a  A ::  a => Lens' (6 a) a  B ::  a => Lens' (6 a) a  C ::  a => Lens' (6 a) a  D ::  a => Lens' (6 a) a AZThese elements form an alternate basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   ? ::  a => Lens' (6 a) a  @ ::  a => Lens' (6 a) a  A ::  a => Lens' (6 a) a  B ::  a => Lens' (6 a) a  C ::  a => Lens' (6 a) a  D ::  a => Lens' (6 a) a BZThese elements form an alternate basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   ? ::  a => Lens' (6 a) a  @ ::  a => Lens' (6 a) a  A ::  a => Lens' (6 a) a  B ::  a => Lens' (6 a) a  C ::  a => Lens' (6 a) a  D ::  a => Lens' (6 a) a CZThese elements form an alternate basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   ? ::  a => Lens' (6 a) a  @ ::  a => Lens' (6 a) a  A ::  a => Lens' (6 a) a  B ::  a => Lens' (6 a) a  C ::  a => Lens' (6 a) a  D ::  a => Lens' (6 a) a DZThese elements form an alternate basis for the Plcker space, or the Grassmanian manifold Gr(2,V4).   ? ::  a => Lens' (6 a) a  @ ::  a => Lens' (6 a) a  A ::  a => Lens' (6 a) a  B ::  a => Lens' (6 a) a  C ::  a => Lens' (6 a) a  D ::  a => Lens' (6 a) a EValid Plcker coordinates p will have E p  0 PThat said, floating point makes a mockery of this claim, so you may want to use . FThis isn'Yt th actual metric because this bilinear form gives rise to an isotropic quadratic space GrChecks if the line is near-isotropic (isotropic vectors in this quadratic space represent lines in real 3d space) H:Checks if the two vectors intersect (or nearly intersect) &6789:;<=>?@ABCDEFGH !"#$%&'()6789:;<=>?@ABCDEFGH67EGF8H9:;?>C@D<A=B%6789:;<=>?@ABCDEFGH !"#$%&'() non-portable experimentalEdward Kmett <ekmett@gmail.com> Trustworthy*I+JKLM,NOP-./0123456789:;<=> IJKLMNOP IJMKLNOP*I+JKLM,NOP-./0123456789:;<=>  non-portable experimentalEdward Kmett <ekmett@gmail.com> Safe-InferredQAn involutive ring R<Conjugate a value. This defaults to the trivial involution. conjugate (1 :+ 2) 1.0 :+ (-2.0) conjugate 11QR?@ABCDEFGHIJKLMNQRQRQR?@ABCDEFGHIJKLMN  non-portable experimentalEdward Kmett <ekmett@gmail.com> TrustworthyS0A vector space that includes the basis elements X, Y, T and U T   T :: Lens' (t a) a U   U :: Lens' (t a) a V   V :: Lens' (t a) (V3 a) W0A vector space that includes the basis elements X and Y X   X :: Lens' (t a) a Y   Y :: Lens' (t a) a Z Quaternions O%quadrance of the imaginary component \ norm of the imaginary component ]raise a Z to a scalar power P1Helper for calculating with specific branch cuts Q1Helper for calculating with specific branch cuts ^R with a specified branch cut. _S with a specified branch cut. `T with a specified branch cut. aU with a specified branch cut. bV with a specified branch cut. cW with a specified branch cut. d8Spherical linear interpolation between two quaternions. eApply a rotation to a vector. ff axis theta builds a Z representing a  rotation of theta radians about axis. .STUVWXYZ[XYO\]PQ^_`abcdefZ[\]^_`abcdefghijklmnSTUVWXYZ[\]^_`abcdefZ[WXYSTUVd^_`abc\]ef(STUVWXYZ[XYO\]PQ^_`abcdefZ[\]^_`abcdefghijklmn non-portable experimentalEdward Kmett <ekmett@gmail.com> TrustworthyhCompute the trace of a matrix trace (V2 (V2 a b) (V2 c d))a + di!Compute the diagonal of a matrix diagonal (V2 (V2 a b) (V2 c d))V2 a dghiopqrstuvwxyz{ghighighiopqrstuvwxyz{ non-portable experimentalEdward Kmett <ekmett@gmail.com> Trustworthyj+A 4x3 matrix with row-major representation k+A 4x4 matrix with row-major representation l+A 3x3 matrix with row-major representation m+A 2x2 matrix with row-major representation ndMatrix product. This can compute mixed dense-dense, sparse-dense and sparse-sparse matrix products. :V2 (V3 1 2 3) (V3 4 5 6) !*! V3 (V2 1 2) (V2 3 4) (V2 4 5)V2 (V2 19 25) (V2 43 58)SV2 (fromList [(1,2)]) (fromList [(2,3)]) !*! fromList [(1,V3 0 0 1), (2, V3 0 0 5)]V2 (V3 0 0 2) (V3 0 0 15)oEntry-wise matrix addition. 5V2 (V3 1 2 3) (V3 4 5 6) !+! V2 (V3 7 8 9) (V3 1 2 3)V2 (V3 8 10 12) (V3 5 7 9)pEntry-wise matrix subtraction. 5V2 (V3 1 2 3) (V3 4 5 6) !-! V2 (V3 7 8 9) (V3 1 2 3)!V2 (V3 (-6) (-6) (-6)) (V3 3 3 3)qMatrix * column vector $V2 (V3 1 2 3) (V3 4 5 6) !* V3 7 8 9 V2 50 122rRow vector * matrix "V2 1 2 *! V2 (V3 3 4 5) (V3 6 7 8) V3 15 18 21sScalar-matrix product 5 *!! V2 (V2 1 2) (V2 3 4)V2 (V2 5 10) (V2 15 20)tMatrix-scalar product V2 (V2 1 2) (V2 3 4) !!* 5V2 (V2 5 10) (V2 15 20)u+Hermitian conjugate or conjugate transpose :adjoint (V2 (V2 (1 :+ 2) (3 :+ 4)) (V2 (5 :+ 6) (7 :+ 8)))LV2 (V2 (1.0 :+ (-2.0)) (5.0 :+ (-6.0))) (V2 (3.0 :+ (-4.0)) (7.0 :+ (-8.0)))v$Build a rotation matrix from a unit Z. w;Build a transformation matrix from a rotation matrix and a  translation vector. x=Build a transformation matrix from a rotation expressed as a  Z and a translation vector. yAConvert from a 4x3 matrix to a 4x4 matrix, extending it with the  [ 0 0 0 1 ] column vector z8Convert a 3x3 matrix to a 4x4 matrix extending it with 0's in the new row and column. {2x2 identity matrix. eye2V2 (V2 1 0) (V2 0 1)|3x3 identity matrix. eye3#V3 (V3 1 0 0) (V3 0 1 0) (V3 0 0 1)}4x4 identity matrix. eye46V4 (V4 1 0 0 0) (V4 0 1 0 0) (V4 0 0 1 0) (V4 0 0 0 1)~@Extract the translation vector (first three entries of the last " column) from a 3x4 or 4x4 matrix 2x2 matrix determinant. det22 (V2 (V2 a b) (V2 c d)) a * d - b * c3x3 matrix determinant. +det33 (V3 (V3 a b c) (V3 d e f) (V3 g h i))?a * (e * i - f * h) - d * (b * i - c * h) + g * (b * f - c * e)2x2 matrix inverse. inv22 $ V2 (V2 1 2) (V2 3 4))Just (V2 (V2 (-2.0) 1.0) (V2 1.5 (-0.5)))3x3 matrix inverse. +inv33 $ V3 (V3 1 2 4) (V3 4 2 2) (V3 1 1 1)JJust (V3 (V3 0.0 0.5 (-1.0)) (V3 (-0.5) (-0.75) 3.5) (V3 0.5 0.25 (-1.5)))jklmnopqrstuvwxyz{|}~ghijklmnopqrstuvwxyz{|}~nopqrtsumlkjzy{|}ghi~vxwjklmnopqrstuvwxyz{|}~portable provisionalEdward Kmett <ekmett@gmail.com> Trustworthy?A handy wrapper to help distinguish points from vectors at the  type level ;An affine space is roughly a vector space in which we have = forgotten or at least pretend to have forgotten the origin.  a .+^ (b .-. a) = b@ & (a .+^ u) .+^ v = a .+^ (u ^+^ v)@ & (a .-. b) ^+^ v = (a .+^ v) .-. q@ :Get the difference between two points as a vector offset.  Add a vector offset to a point. 'Subtract a vector offset from a point. ECompute the quadrance of the difference (the square of the distance) /Distance between two points in an affine space Vector spaces have origins. |}~ |}~ non-portable experimentalEdward Kmett <ekmett@gmail.com> Safe-Inferredz  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !"#$%&'()*+,-./0112344567889 : ; < = = > ? @ A B C C D E F F G H I J K L M N O P Q R S T U V WXYZ[\]^_ ` a b c d e f g h i i j k l m n o p q r s tuvwxyz{|}~                                  ! " # $ % & ' ( ) *+, - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?@XABCDEFGHIJKLMNOPQRS T U V W X Y Z [ \ ] ^ _ ` a b c d e fghgigjgkglgm n o p q r s t u v w x y z { | } ~       linear-1.1.4Linear.V Linear.VectorLinear.Epsilon Linear.Metric Linear.Core Linear.V0 Linear.V1 Linear.V2 Linear.V3 Linear.V4Linear.PluckerLinear.ConjugateLinear.Quaternion Linear.Trace Linear.Matrix Linear.AffineLinear.InstancesLinearreflection-1.3.2Data.ReflectionintAdditivezero^+^^-^lerpliftU2liftI2negated*^^*^/basisbasisFor kroneckerouterEpsilonnearZeroMetricdot quadranceqddistancenormsignorm normalizeCorecoreV0R1_xV1R2_y_xyV2perpR3_z_xyzV3crosstripleR4_w_xyzwV4vectorpointPluckerpluckerp01p02p03p23p31p12p10p20p30p32p13p21 squaredError>< isotropic intersectsVtoVectorDim reflectDimdimreifyDim reifyVector fromVector Conjugate conjugate Hamiltonian_j_k_ijk Complicated_e_i Quaternionabsipowasinqacosqatanqasinhqacoshqatanhqslerprotate axisAngleTracetracediagonalM43M44M33M22!*!!+!!-!!**!*!!!!*adjointfromQuaternionmkTransformationMatmkTransformation m43_to_m44 m33_to_m44eye2eye3eye4 translationdet22det33inv22inv33PointPAffineDiff.-..+^.-^qdA distanceAorigin$fTraversable1Complex$fFoldable1Complex$fTraversableComplex$fFoldableComplex$fMonadComplex $fBindComplex$fApplicativeComplex$fApplyComplex$fFunctorComplex $fBindHashMap$fApplyHashMapbaseControl.ApplicativeliftA2containers-0.5.0.0 Data.Map.Base unionWithintersectionWith GAdditivegzerogliftU2gliftI2 setElement$fAdditiveIdentity$fAdditiveComplex$fAdditive(->)$fAdditiveHashMap $fAdditiveMap$fAdditiveIntMap $fAdditive[]$fAdditiveMaybe$fAdditiveVector$fAdditiveZipList$fGAdditivePar1 $fGAdditiveM1$fGAdditiveRec1$fGAdditive:*: $fGAdditiveU1$fEpsilonCDoubleGHC.Numabsghc-prim GHC.Classes<=$fEpsilonCFloat$fEpsilonDouble$fEpsilonFloat$fMetricVector$fMetricIdentityGHC.BaseFunctor $fStorableV0 $fEpsilonV0$fDistributiveV0$fCoreV0 $fMetricV0$fFractionalV0$fNumV0 $fMonadV0$fBindV0 $fAdditiveV0$fApplicativeV0 $fApplyV0$fTraversableV0 $fFoldableV0 $fFunctorV0$fIxV1$fDistributiveV1$fCoreV1 $fR1Identity$fR1V1 $fMetricV1$fFractionalV1$fNumV1 $fMonadV1$fBindV1 $fAdditiveV1$fApplicativeV1 $fApplyV1$fTraversable1V1 $fFoldable1V1$fIxV2 $fStorableV2 $fEpsilonV2$fDistributiveV2$fCoreV2$fR2V2$fR1V2 $fMetricV2$fFractionalV2$fNumV2 $fMonadV2$fBindV2 $fAdditiveV2$fApplicativeV2 $fApplyV2$fTraversable1V2 $fFoldable1V2$fTraversableV2 $fFoldableV2 $fFunctorV2$fIxV3 $fEpsilonV3 $fStorableV3$fCoreV3$fR3V3$fR2V3$fR1V3$fDistributiveV3 $fMetricV3$fFractionalV3$fNumV3 $fMonadV3$fBindV3 $fAdditiveV3$fApplicativeV3 $fApplyV3$fTraversable1V3 $fFoldable1V3$fTraversableV3 $fFoldableV3 $fFunctorV3$fIxV4 $fEpsilonV4 $fStorableV4$fCoreV4$fR4V4$fR3V4$fR2V4$fR1V4$fDistributiveV4 $fMetricV4$fFractionalV4$fNumV4 $fMonadV4$fBindV4 $fAdditiveV4 $fApplyV4$fApplicativeV4$fTraversable1V4 $fFoldable1V4$fTraversableV4 $fFoldableV4 $fFunctorV4Num==anti$fEpsilonPlucker$fMetricPlucker$fStorablePlucker$fFractionalPlucker $fNumPlucker $fIxPlucker$fTraversable1Plucker$fFoldable1Plucker$fTraversablePlucker$fFoldablePlucker $fCorePlucker$fDistributivePlucker$fMonadPlucker $fBindPlucker$fAdditivePlucker$fApplicativePlucker$fApplyPlucker$fFunctorPlucker ReifiedDimretagDim $fMetricV $fEpsilonV $fStorableV$fDistributiveV$fCoreV $fFractionalV$fNumV $fAdditiveV$fMonadV$fBindV$fApplicativeV$fApplyV$fTraversableV $fFoldableV $fFunctorV$fDim*V$fDim*ReifiedDim $fDimNatn$fConjugateComplex$fConjugateCDouble$fConjugateCFloat$fConjugateFloat$fConjugateDouble$fConjugateWord8$fConjugateWord16$fConjugateWord32$fConjugateWord64$fConjugateWord$fConjugateInt8$fConjugateInt16$fConjugateInt32$fConjugateInt64$fConjugateInt$fConjugateIntegerqicutcutWith GHC.FloatasinacosatanasinhacoshatanhqNaN reimagine$fEpsilonQuaternion$fFloatingQuaternion$fConjugateQuaternion$fDistributiveQuaternion$fHamiltonianQuaternion$fComplicatedQuaternion$fComplicatedComplex$fMetricQuaternion$fFractionalQuaternion$fNumQuaternion$fStorableQuaternion$fTraversableQuaternion$fFoldableQuaternion$fCoreQuaternion$fIxQuaternion$fMonadQuaternion$fBindQuaternion$fAdditiveQuaternion$fApplicativeQuaternion$fApplyQuaternion$fFunctorQuaternion$fTraceCompose$fTraceProduct$fTraceComplex$fTraceQuaternion$fTracePlucker $fTraceV4 $fTraceV3 $fTraceV2 $fTraceV0$fTraceV$fTraceHashMap $fTraceMap $fTraceIntMap $fAffinePoint $fAffineV$fAffineHashMap $fAffineMap $fAffine(->)$fAffineQuaternion$fAffinePlucker $fAffineV4 $fAffineV3 $fAffineV2 $fAffineV1 $fAffineV0$fAffineVector$fAffineIdentity$fAffineIntMap $fAffineMaybe$fAffineZipList$fAffineComplex $fAffine[]