Numeric Prelude
From HaskellWiki
(HCAR spring 2008) 
m (→Overview) 

(6 intermediate revisions by 2 users not shown)  
Line 1:  Line 1:  
Numeric Prelude provides an alternative numeric type class hierarchy,  Numeric Prelude provides an alternative numeric type class hierarchy,  
which also makes use of type features beyond Haskell 98, e.g. [[multiparameter type class]]es.  which also makes use of type features beyond Haskell 98, e.g. [[multiparameter type class]]es.  
+  
+  == Overview ==  
+  
+  The hierarchy of numerical type classes is revised and oriented at algebraic structures. Axiomatics for fundamental operations are given as QuickCheck properties, superfluous superclasses like <hask>Show</hask> are removed, semantic and representationspecific operations are separated, the hierarchy of type classes is more fine grained, and identifiers are adapted to mathematical terms.  
+  
+  There are both certain new type classes representing algebraic structures and new types of mathematical objects. Currently supported algebraic structures are  
+  * group (additive),  
+  * ring,  
+  * principal ideal domain,  
+  * field,  
+  * algebraic closures,  
+  * transcendental closures,  
+  * module and vector space,  
+  * normed space,  
+  * lattice,  
+  * differential algebra,  
+  * monoid.  
+  
+  There is also a collection of mathematical object types, which is useful both for applications and testing the class hierarchy. The types are  
+  * lazy Peano number,  
+  * arbitrarily quantified nonnegative lazy number (generalisation of Peano number),  
+  * complex number, quaternion,  
+  * residue class,  
+  * fraction,  
+  * partial fraction,  
+  * numbers equipped with physical units in two variants:  
+  ** dynamically checked units,  
+  ** statically checked dimension terms (E.g., speed can be expressed by type argument <hask>Mul Length (Recip Time)</hask>. This is overly restrictive but does not require type extensions.)  
+  * fixed point arithmetic with respect to arbitrary bases and numbers of fraction digits,  
+  * infinite precision number in an arbitrary positional system as lazy lists of digits supporting also numbers with terminating representations,  
+  * polynomial, power series, Laurent series  
+  * root set of a polynomial,  
+  * matrix (basics only),  
+  * algebra, e.g., multivariate polynomial (basics only),  
+  * permutation group.  
+  
+  Due to Haskell's flexible type system,  
+  you can combine all these types,  
+  e.g., fractions of polynomials, residue classes of polynomials,  
+  complex numbers with physical units,  
+  power series with real numbers as coefficients.  
+  
+  Using the revised system requires hiding some of the standard functions  
+  provided by Prelude, which is fortunately supported by GHC.  
+  The library has basic Cabal support  
+  and a growing testsuite of QuickCheck tests  
+  for the implemented mathematical objects.  
+  
+  Each data type now resides in a separate module.  
+  Cyclic dependencies could be eliminated by fixing some types in class methods.  
+  E.g., power exponents became simply Integer instead of Integral,  
+  which has also the advantage of reduced type defaulting.  
+  
+  == Future plans ==  
+  
+  The code still misses proper linear algebra code.  
+  
+  A still unsolved problem arises for  
+  residue classes, matrix computations, infinite precision numbers,  
+  fixed point numbers, and others.  
+  It should be possible to assert statically  
+  that the arguments of a function are residue classes with  
+  respect to the same divisor, or that they are vectors of the same size.  
+  Possible ways out are encoding values in types or local type  
+  class instances. The latter one is still neither proposed nor  
+  implemented in any Haskell compiler.  
+  The modules are implemented in a way to keep all options open.  
+  That is, for each number type there is one module  
+  implementing the necessary operations  
+  which expect the context as a parameter.  
+  Then there are several modules  
+  which provide different interfaces through type class instances  
+  to these operations.  
+  
== Links ==  == Links ==  
−  * [http://  +  
+  {{PackageInfoBoxname=numericpreludedarcscode=numericprelude/}}  
+  
+  * [http://projects.haskell.org/cgibin/mailman/listinfo/numericprelude Mailing list]  
+  * [http://trac.haskell.org/numericprelude/ Bug and Feature Tracker]  
* [http://haskell.org/communities/052008/html/report.html#numericprelude HCAR report]  * [http://haskell.org/communities/052008/html/report.html#numericprelude HCAR report]  
−  
== See also ==  == See also == 
Latest revision as of 17:33, 9 July 2012
Numeric Prelude provides an alternative numeric type class hierarchy, which also makes use of type features beyond Haskell 98, e.g. multiparameter type classes.
Contents 
[edit] 1 Overview
The hierarchy of numerical type classes is revised and oriented at algebraic structures. Axiomatics for fundamental operations are given as QuickCheck properties, superfluous superclasses likeThere are both certain new type classes representing algebraic structures and new types of mathematical objects. Currently supported algebraic structures are
 group (additive),
 ring,
 principal ideal domain,
 field,
 algebraic closures,
 transcendental closures,
 module and vector space,
 normed space,
 lattice,
 differential algebra,
 monoid.
There is also a collection of mathematical object types, which is useful both for applications and testing the class hierarchy. The types are
 lazy Peano number,
 arbitrarily quantified nonnegative lazy number (generalisation of Peano number),
 complex number, quaternion,
 residue class,
 fraction,
 partial fraction,
 numbers equipped with physical units in two variants:
 dynamically checked units,
 statically checked dimension terms (E.g., speed can be expressed by type argument . This is overly restrictive but does not require type extensions.)Mul Length (Recip Time)
 fixed point arithmetic with respect to arbitrary bases and numbers of fraction digits,
 infinite precision number in an arbitrary positional system as lazy lists of digits supporting also numbers with terminating representations,
 polynomial, power series, Laurent series
 root set of a polynomial,
 matrix (basics only),
 algebra, e.g., multivariate polynomial (basics only),
 permutation group.
Due to Haskell's flexible type system, you can combine all these types, e.g., fractions of polynomials, residue classes of polynomials, complex numbers with physical units, power series with real numbers as coefficients.
Using the revised system requires hiding some of the standard functions provided by Prelude, which is fortunately supported by GHC. The library has basic Cabal support and a growing testsuite of QuickCheck tests for the implemented mathematical objects.
Each data type now resides in a separate module. Cyclic dependencies could be eliminated by fixing some types in class methods. E.g., power exponents became simply Integer instead of Integral, which has also the advantage of reduced type defaulting.
[edit] 2 Future plans
The code still misses proper linear algebra code.
A still unsolved problem arises for residue classes, matrix computations, infinite precision numbers, fixed point numbers, and others. It should be possible to assert statically that the arguments of a function are residue classes with respect to the same divisor, or that they are vectors of the same size. Possible ways out are encoding values in types or local type class instances. The latter one is still neither proposed nor implemented in any Haskell compiler. The modules are implemented in a way to keep all options open. That is, for each number type there is one module implementing the necessary operations which expect the context as a parameter. Then there are several modules which provide different interfaces through type class instances to these operations.
[edit] 3 Links
Hackage  http://hackage.haskell.org/package/numericprelude 
Repository  darcs get http://code.haskell.org/numericprelude/
