|      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~Nonenat n yields the Int! value of the type-level natural n. 0  !"#$%&'()*+,  !"#$%&'()*+,  !"#$%&'()*+/  !"#$%&'()*+NoneBThe length of a vector Dsnoc v a) appends the element a to the end of v. FHGet the last element, usually significant for some reason (quaternions, # homogenous coordinates, whatever) Hdrop n v strips the first n elements from v. n is a type-level  natural. For example  drop n2 v drops the first two elements. Jtake n v$ constructs a vector from the first n elements of v. n is a ! type-level natural. For example  take n3 v makes a 3-vector of the first  three elements of v. LAppend two vectors NNReverse helper function : accumulates the reversed list in its first argument P Fold a function over a vector. TICombine two vectors using a binary function. The length of the result is 9 the min of the lengths of the arguments. The constraint ZipWith a b c u v  w states that u is a vector of as, v is a vector of bs, w is a  vector of c&s, and the binary function is of type  a -> b -> c. V;Apply a function over each element in a vector. Constraint  Map a b u v  states that u is a vector of as, v is a vector of bs with the same  length as u, and the function is of type a -> b. XAll but the first element. ZThe first element. \.get or set a vector element, known at compile Ctime. Use the Nat types to access vector components. For instance, get n0 gets the x component,  set n2 44 sets the z component to 44. _EBuild a vector from a list, or access vector elements using run-time  indicies, numbered from 0. `HTurn a list into a vector of inferred length. The list must be at least E as long as the vector, but may be longer. Make a mental note of the  distinction between this and  , as you might accidentally use F this when you mean that. Because number literals can be converted to C vectors, and matrices are vectors of vectors, the following works  " fromList [1,2,3,4] :: Mat22 Int & > ((1):.(1):.()):.((2):.(2):.()):.()  even though we meant to do this % matFromList [1,2,3,4] :: Mat22 Int & > ((1):.(2):.()):.((3):.(4):.()):.() a7Get a vector element, which one determined at runtime. b6Set a vector element, which one determined at runtime cThe type constraint  Vec n a v infers the vector type v from the  length n6, a type-level natural, and underlying component type a.  So x :: Vec N4 a v => v declares x to be a 4-vector of as. d)Make a uniform vector of a given length. n is a type-level natural.  Use {" when the length can be inferred. yThe vector constructor. (:.) for vectors is like (:) for lists, and  () takes the place of []1. (The list of instances here is not meant to be  readable.) {/Make a uniform vector. The length is inferred. |Reverse a vector }sum of vector elements ~product of vector elements maximum vector element minimum vector element $convert a matrix to a list-of-lists .convert a matrix to a list in row-major order &convert a list-of-lists into a matrix 0convert a list into a matrix. (row-major order) ,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~[,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~[yzwxvutsrqponmlkjihgfecd{_`ab\]^Z[XYVWTUPQRS|NOLMJKHIFGDEBC}~A@?>=<;:9876543,-./012o,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~NonebackSubstitute'; takes a full rank matrix from row echelon form to reduced @ row echelon form. Returns garbage is matrix is rank deficient. IbackSubstitute takes a full rank matrix from row echelon form to reduced  row echelon form. Returns Nothing# if the matrix is rank deficient. /Gaussian elimination, adapted from Mirko Rahn:   Khttp://www.haskell.org/pipermail/glasgow-haskell-users/2007-May/012648.html HThis is more of a proof of concept. Using a foreign C function will run I slightly faster, and compile much faster. But where is the fun in that? 3 Set your unfolding threshold as high as possible.  gaussElim m returns a pair (m',d) where m' is m in row echelon  form and d is the determinant of m. The determinant of m' is 1 or 0, < i.e., the leading coefficient of each non-zero row is 1.  nearZero x5 should be true when x is close enough to 0 to cause ! significant error in division. 1get the diagonal of an n-by-n matrix as a vector 9set the diagonal of an n-by-n matrix to a given n-vector matrix transposition dot / inner / scalar product vector norm, squared vector / L2 / Euclidean norm  normalize v& is a unit vector in the direction of v. v is assumed  non-null. 3d cross product. )lift a point into homogenous coordinates ,point-at-infinity in homogenous coordinates Eproject a vector from homogenous coordinates. Last vector element is  assumed non-zero. row vector * matrix matrix * column vector matrix * matrix :apply a translation to a projective transformation matrix get the n-th column as a vector. n is a type-level natural. get the n-th row as a vector. n is a type-level natural.  scale v m# multiplies the diagonal of matrix m by the vector s, component-wise. So   scale 5 m' multiplies the diagonal by 5, whereas  scale 2:.1 m  only scales the x component.  diagonal v= is a square matrix with the vector v as the diagonal, and 0  elsewhere. identity matrix (square) ,Determinant by minor expansion, i.e. Laplace's formula. Unfolds into a N closed form expression. This should be the fastest way for 4x4 and smaller,  but snd . gaussElim works too. cramer' sRule m v computes the solution to m`multmv`x=v using the < eponymous method. For larger than 3x3 you will want to use , which  uses . Cramer',s rule, however, unfolds into a closed-form N expression, with no branches or allocations (other than the result). You may 7 need to increase the unfolding threshold to see this. invert m returns Just the inverse of m or Nothing if m is singular. Ainverse and determinant. If det = 0, inverted matrix is garbage. ;Solution of linear system by Gaussian elimination. Returns Nothing  if no solution. K      !"#$%&$0D      !"#$%&None?PackedVec class : relates a vector type to its space-optimized  representation. The packed representation of v ;Construct a semi-packed matrix, one whose rows are packed. 3'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLM0'()*+,-./0123456789:;<=>?@ABCDNone  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~EFGHIJKLMN      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJ Vec-0.9.9 Data.Vec.Nat Data.Vec.BaseData.Vec.LinAlgData.Vec.PackedData.VecPredNatnatN19N18N17N16N15N14N13N12N11N10N9N8N7N6N5N4N3N2N1SuccN0n0n1n2n3n4n5n6n7n8n9n10n11n12n13n14n15n16n17n18n19 VecArrayRWvaRead#vaWrite#vaIndex# vaSizeOf# vaLength#init#Mat48Mat47Mat46Mat45Mat44Mat43Mat42Mat36Mat35Mat34Mat33Mat32Mat24Mat23Mat22LengthlengthSnocsnocLastlastDropdropTaketakeAppendappendReverse'reverse'FoldfoldfoldlfoldrZipWithzipWithMapmapTailtailHeadheadAccessgetsetVecListfromListgetElemsetElemVecmkVecVec19Vec18Vec17Vec16Vec15Vec14Vec13Vec12Vec11Vec10Vec9Vec8Vec7Vec6Vec5Vec4Vec3Vec2ShowVecshowVec:.vecreversesumproductmaximumminimumtoList matToLists matToList matFromLists matFromListsizeOf#BackSubstitute'backSubstitute'BackSubstitutebackSubstitute GaussElim gaussElimPivotPivot1NearZeronearZero ReplConsec' ReplConsec NegateEvens NegateOdds DropConsec' DropConsecDet' GetDiagonal' GetDiagonal getDiagonal SetDiagonal' SetDiagonal setDiagonal Transpose' Transpose transposedotnormSqnorm normalizecrosshomPointhomVecprojectmultvmmultmvmultmm translatecolumnrowscalediagonalidentitydet cramer'sRuleinvert invertAndDetsolveMat44DMat34DMat33DMat24DMat23DMat22DVec4DVec3DVec2DVec4FVec3FVec2FVec4IVec3IVec2I PackedVecPackedpackunpackpackMat unpackMat$fPredSuccSucc $fPredSuccN0 $fNatSucc$fNatN0$fIArrayUArray:.$fMArraySTUArray:.ST$fVecArrayRW:.$fVecArrayRW:.0$fVecArrayRW:.1$fVecArrayRW:.2$fVecArrayRW:.3$fVecArrayRW:.4$fVecArrayRW:.5$fVecArrayRW:.6$fFractional:.$fNum:. $fStorable:. $fStorable:.0$fLength:.Succ $fLength()N0 $fSnoc:.a:. $fSnoc()a:. $fLast:.a $fLast:.a0$fDropSucc:.v' $fDropN0vv$fTakeSucc:.:. $fTakeN0v()$fAppend:.v2:. $fAppend:.v:. $fAppend()vv$fReverse'p:.v'$fReverse'p()p $fFold:.a $fFold:.a0$fZipWithabc:.:.:.$fZipWithabc:.:.:.0$fZipWithabc:.:.:.1$fZipWithabc:.:.:.2 $fMapab:.:. $fMapab:.:.0 $fTail:.as $fHead:.a$fAccessSucca:. $fAccessN0a:. $fVecLista:. $fVecLista:.0 $fVecSucca:. $fVecSucca:.0 $fShowVec:. $fShowVec()$fShow:.$fBackSubstitute':.$fBackSubstitute':.0$fBackSubstitute:.$fBackSubstitute:.0$fGaussElima:.$fGaussElima:.0 $fPivota:. $fPivota:.0 $fPivot1a:. $fPivot1a:.0 $fPivot1a:.1 $fPivot1a()$fNearZeroRatio$fNearZeroDouble$fNearZeroFloat$fReplConsec'ap:.:.$fReplConsec'ap()()$fReplConsecavvv$fNegateEvens:.$fNegateOdds:.$fNegateEvens()$fNegateOdds()$fDropConsec'p:.:.$fDropConsec'p:.:.0$fDropConsecvvv $fDet':.a $fDet':.a0$fGetDiagonal'np:.v$fGetDiagonal'np:.:.$fGetDiagonalmv$fSetDiagonal'n:.:.$fSetDiagonal'n()m$fSetDiagonalvm$fTranspose':.:.$fTranspose':.:.0$fTranspose':.vs'$fTranspose'()()$fTranspose:.:.$fTranspose()()$fIArrayUArrayPacked$fMArraySTUArrayPackedST$fVecListaPacked$fAccessnaPacked$fDropnPackedPacked$fTakeSuccPackedPacked$fReverse'()PackedPacked$fSnocPackedaPacked $fLastPackedl$fTailPackedPacked $fHeadPackedh$fLengthPackedn$fStorablePacked$fFractionalPacked $fNumPacked$fZipWithabcPackedPackedPacked $fFoldPackeda$fMapabPackedPacked $fShowPacked $fOrdPacked $fEqPacked $fPackedVec:.$fPackedVec:.0$fPackedVec:.1$fPackedVec:.2$fPackedVec:.3$fPackedVec:.4$fPackedVec:.5$fPackedVec:.6$fPackedVec:.7