-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A library of constructive algebra. -- -- A library of algebra focusing mainly on commutative ring theory from a -- constructive point of view. -- -- Classical structures are implemented without Noetherian assumptions. -- This means that it is not assumed that all ideals are finitely -- generated. For example, instead of principal ideal domains one gets -- Bezout domains which are integral domains in which all finitely -- generated ideals are principal (and not necessarily that all ideals -- are principal). This give a good framework for implementing many -- interesting algorithms. @package constructive-algebra @version 0.3.0 -- | Type level characters. Used for representing the variable name in -- univariate polynomials. module Algebra.TypeChar.Char data A_ data B_ data C_ data D_ data E_ data F_ data G_ data H_ data I_ data J_ data K_ data L_ data M_ data N_ data O_ data P_ data Q_ data R_ data S_ data T_ data U_ data V_ data W_ data X_ data Y_ data Z_ data A data B data C data D data E data F data G data H data I data J data K data L data M data N data O data P data Q data R data S data T data U data V data W data X data Y data Z instance Show Z instance Show Y instance Show X instance Show W instance Show V instance Show U instance Show T instance Show S instance Show R instance Show Q instance Show P instance Show O instance Show N instance Show M instance Show L instance Show K instance Show J instance Show I instance Show H instance Show G instance Show F instance Show E instance Show D instance Show C instance Show B instance Show A instance Show Z_ instance Show Y_ instance Show X_ instance Show W_ instance Show V_ instance Show U_ instance Show T_ instance Show S_ instance Show R_ instance Show Q_ instance Show P_ instance Show O_ instance Show N_ instance Show M_ instance Show L_ instance Show K_ instance Show J_ instance Show I_ instance Show H_ instance Show G_ instance Show F_ instance Show E_ instance Show D_ instance Show C_ instance Show B_ instance Show A_ -- | The representation of the ring structure. module Algebra.Structures.Ring -- | Definition of rings. class Ring a (<+>) :: Ring a => a -> a -> a (<*>) :: Ring a => a -> a -> a neg :: Ring a => a -> a zero :: Ring a => a one :: Ring a => a -- | Addition is associative. propAddAssoc :: (Ring a, Eq a) => a -> a -> a -> (Bool, String) -- | Zero is the additive identity. propAddIdentity :: (Ring a, Eq a) => a -> (Bool, String) -- | Negation give the additive inverse. propAddInv :: (Ring a, Eq a) => a -> (Bool, String) -- | Addition is commutative. propAddComm :: (Ring a, Eq a) => a -> a -> (Bool, String) -- | Multiplication is associative. propMulAssoc :: (Ring a, Eq a) => a -> a -> a -> (Bool, String) -- | One is the multiplicative identity. propMulIdentity :: (Ring a, Eq a) => a -> (Bool, String) -- | Multiplication is right-distributive over addition. propRightDist :: (Ring a, Eq a) => a -> a -> a -> (Bool, String) -- | Multiplication is left-ditributive over addition. propLeftDist :: (Ring a, Eq a) => a -> a -> a -> (Bool, String) -- | Specification of rings. Test that the arguments satisfy the ring -- axioms. propRing :: (Ring a, Eq a) => a -> a -> a -> Property -- | Subtraction (<->) :: Ring a => a -> a -> a -- | Exponentiation (<^>) :: Ring a => a -> Integer -> a -- | Summation sumRing :: Ring a => [a] -> a -- | Product productRing :: Ring a => [a] -> a -- | Structure for commutative rings. module Algebra.Structures.CommutativeRing -- | Definition of commutative rings. class Ring a => CommutativeRing a propMulComm :: (CommutativeRing a, Eq a) => a -> a -> Bool -- | Specification of commutative rings. Test that multiplication is -- commutative and that it satisfies the ring axioms. propCommutativeRing :: (CommutativeRing a, Eq a) => a -> a -> a -> Property module Algebra.Structures.Group class Group a (<+>) :: Group a => a -> a -> a zero :: Group a => a neg :: Group a => a -> a propAssoc :: (Group a, Eq a) => a -> a -> a -> Bool propId :: (Group a, Eq a) => a -> Bool propInv :: (Group a, Eq a) => a -> Bool propGroup :: (Group a, Eq a) => a -> a -> a -> Property -- | Abelian groups: class Group a => AbelianGroup a propComm :: (AbelianGroup a, Eq a) => a -> a -> Bool propAbelianGroup :: (AbelianGroup a, Eq a) => a -> a -> a -> Property sumGroup :: AbelianGroup a => [a] -> a instance (Group a, Ring a) => AbelianGroup a instance Ring a => Group a instance (Group a, Group b) => Group (a, b) -- | Finitely generated ideals in commutative rings. module Algebra.Ideal -- | Ideals characterized by their list of generators. data CommutativeRing a => Ideal a Id :: [a] -> Ideal a -- | The zero ideal. zeroIdeal :: CommutativeRing a => Ideal a -- | Test if an ideal is principal. isPrincipal :: CommutativeRing a => Ideal a -> Bool fromId :: CommutativeRing a => Ideal a -> [a] -- | Evaluate the ideal at a certain point. eval :: CommutativeRing a => a -> Ideal a -> a -- | Addition of ideals. addId :: (CommutativeRing a, Eq a) => Ideal a -> Ideal a -> Ideal a -- | Multiplication of ideals. mulId :: (CommutativeRing a, Eq a) => Ideal a -> Ideal a -> Ideal a -- | Test if an operations compute the correct ideal. The operation should -- give a witness that the comuted ideal contains the same elements. -- -- If [ x_1, ..., x_n ] `op` [ y_1, ..., y_m ] = [ z_1, ..., z_l ] -- -- Then the witness should give that -- -- z_k = a_k1 * x_1 + ... + a_kn * x_n = b_k1 * y_1 + ... + b_km * y_m -- -- This is used to check that the intersection computed is correct. isSameIdeal :: (CommutativeRing a, Eq a) => (Ideal a -> Ideal a -> (Ideal a, [[a]], [[a]])) -> Ideal a -> Ideal a -> Bool -- | Compute witnesses for two lists for the zero ideal. This is used when -- computing the intersection of two ideals. zeroIdealWitnesses :: CommutativeRing a => [a] -> [a] -> (Ideal a, [[a]], [[a]]) instance (CommutativeRing a, Arbitrary a, Eq a) => Arbitrary (Ideal a) instance (CommutativeRing a, Show a) => Show (Ideal a) module Algebra.Structures.StronglyDiscrete -- | Strongly discrete rings -- -- A ring is called strongly discrete if ideal membership is decidable. -- Nothing correspond to that x is not in the ideal and Just is the -- witness. Examples include all Bezout domains and polynomial rings. class Ring a => StronglyDiscrete a member :: StronglyDiscrete a => a -> Ideal a -> Maybe [a] -- | Test that the witness is actually a witness that the element is in the -- ideal. propStronglyDiscrete :: (CommutativeRing a, StronglyDiscrete a, Eq a) => a -> Ideal a -> Bool module Algebra.Structures.IntegralDomain -- | Definition of integral domains. class CommutativeRing a => IntegralDomain a propZeroDivisors :: (IntegralDomain a, Eq a) => a -> a -> Bool -- | Specification of integral domains. Test that there are no -- zero-divisors and that it satisfies the axioms of commutative rings. propIntegralDomain :: (IntegralDomain a, Eq a) => a -> a -> a -> Property -- | Representation of Euclidean domains. That is integral domains with an -- Euclidean functions and decidable division. module Algebra.Structures.EuclideanDomain -- | Euclidean domains -- -- Given a and b compute (q,r) such that a = bq + r and r = 0 || norm r -- < norm b. Where norm is the Euclidean function. class IntegralDomain a => EuclideanDomain a norm :: EuclideanDomain a => a -> Integer quotientRemainder :: EuclideanDomain a => a -> a -> (a, a) -- | Check both that |a| = |ab| and |a| = 0 for all a,b. propNorm :: (EuclideanDomain a, Eq a) => a -> a -> Bool propQuotRem :: (EuclideanDomain a, Eq a) => a -> a -> Bool propEuclideanDomain :: (EuclideanDomain a, Eq a) => a -> a -> a -> Property modulo :: EuclideanDomain a => a -> a -> a quotient :: EuclideanDomain a => a -> a -> a divides :: (EuclideanDomain a, Eq a) => a -> a -> Bool -- | The Euclidean algorithm for calculating the GCD of a and b. euclidAlg :: (EuclideanDomain a, Eq a) => a -> a -> a -- | Generalized Euclidean algorithm to compute GCD of a list of elements. genEuclidAlg :: (EuclideanDomain a, Eq a) => [a] -> a -- | Lowest common multiple, (a*b)/gcd(a,b). lcmE :: (EuclideanDomain a, Eq a) => a -> a -> a -- | Generalized lowest common multiple to compute lcm of a list of -- elements. genLcmE :: (EuclideanDomain a, Eq a) => [a] -> a -- | The extended Euclidean algorithm. -- -- Computes x and y in ax + by = gcd(a,b). extendedEuclidAlg :: (EuclideanDomain a, Eq a) => a -> a -> (a, a) -- | Generalized extended Euclidean algorithm. -- -- Solves a_1 x_1 + ... + a_n x_n = gcd (a_1,...,a_n) genExtendedEuclidAlg :: (EuclideanDomain a, Eq a) => [a] -> [a] -- | Structure for fields. module Algebra.Structures.Field -- | Definition of fields. class IntegralDomain a => Field a inv :: Field a => a -> a propMulInv :: (Field a, Eq a) => a -> Bool -- | Specification of fields. Test that the multiplicative inverses behave -- as expected and that it satisfies the axioms of integral domains. propField :: (Field a, Eq a) => a -> a -> a -> Property -- | Division (>) :: Field a => a -> a -> a -- | A small simple matrix library. module Algebra.Matrix -- | Row vectors newtype Vector r Vec :: [r] -> Vector r unVec :: Vector r -> [r] lengthVec :: Vector r -> Int -- | Matrices newtype Matrix r M :: [Vector r] -> Matrix r -- | Construct a mxn matrix. matrix :: [[r]] -> Matrix r matrixToVector :: Matrix r -> Vector r vectorToMatrix :: Vector r -> Matrix r unMVec :: Matrix r -> [[r]] unM :: Matrix r -> [Vector r] (!!!) :: Matrix a -> (Int, Int) -> a -- | Construct a nxn identity matrix. identity :: IntegralDomain r => Int -> Matrix r propLeftIdentity :: (IntegralDomain r, Eq r) => Matrix r -> Bool propRightIdentity :: (IntegralDomain r, Eq r) => Matrix r -> Bool -- | Matrix multiplication. mulM :: Ring r => Matrix r -> Matrix r -> Matrix r -- | Matrix addition. addM :: Ring r => Matrix r -> Matrix r -> Matrix r -- | Transpose a matrix. transpose :: Matrix r -> Matrix r isSquareMatrix :: Matrix r -> Bool -- | Compute the dimension of a matrix. dimension :: Matrix r -> (Int, Int) -- | Scale a row in a matrix. scale :: CommutativeRing a => Matrix a -> Int -> a -> Matrix a -- | Swap two rows of a matrix. swap :: Matrix a -> Int -> Int -> Matrix a pivot :: CommutativeRing a => Matrix a -> a -> Int -> Int -> Matrix a addRow :: CommutativeRing a => Matrix a -> Vector a -> Int -> Matrix a subRow :: CommutativeRing a => Matrix a -> Vector a -> Int -> Matrix a addCol :: CommutativeRing a => Matrix a -> Vector a -> Int -> Matrix a subCol :: CommutativeRing a => Matrix a -> Vector a -> Int -> Matrix a findPivot :: (CommutativeRing a, Eq a) => Matrix a -> (Int, Int) -> Maybe (a, Int) -- | Compute row echelon form of a system Ax=b. forwardElim :: (Field a, Eq a) => (Matrix a, Vector a) -> (Matrix a, Vector a) -- | Gauss-Jordan elimination: Given A and B solve Ax=B. gaussElim :: (Field a, Eq a, Show a) => (Matrix a, Vector a) -> (Matrix a, Vector a) gaussElimCorrect :: (Field a, Eq a, Arbitrary a, Show a) => (Matrix a, Vector a) -> Property instance Eq r => Eq (Vector r) instance Eq r => Eq (Matrix r) instance Functor Matrix instance Arbitrary r => Arbitrary (Matrix r) instance Show r => Show (Matrix r) instance Functor Vector instance Arbitrary r => Arbitrary (Vector r) instance Show r => Show (Vector r) -- | Representation of coherent rings. Traditionally a ring is coherent if -- every finitely generated ideal is finitely presented. This means that -- it is possible to solve homogenous linear equations in them. module Algebra.Structures.Coherent -- | Definition of coherent rings. -- -- We say that R is coherent iff for any M, we can find L such that ML=0 -- and -- -- MX=0 <-> exists Y. X=LY -- -- that is, iff we can generate the solutions of any linear homogeous -- system of equations. -- -- The main point here is that ML=0, it is not clear how to represent the -- equivalence in Haskell. This would probably be possible in type -- theory. class IntegralDomain a => Coherent a solve :: Coherent a => Vector a -> Matrix a propCoherent :: (Coherent a, Eq a) => Vector a -> Bool -- | Test that the second matrix is a solution to the first. isSolution :: (CommutativeRing a, Eq a) => Matrix a -> Matrix a -> Bool -- | Solves a system of equations. solveMxN :: (Coherent a, Eq a) => Matrix a -> Matrix a -- | Test that the solution of an MxN system is in fact a solution of the -- system propSolveMxN :: (Coherent a, Eq a) => Matrix a -> Bool -- | Intersection computable -> Coherence. -- -- Proof that if there is an algorithm to compute a f.g. set of -- generators for the intersection of two f.g. ideals then the ring is -- coherent. -- -- Takes the vector to solve, [x1,...,xn], and a function (int) that -- computes the intersection of two ideals. -- -- If [ x_1, ..., x_n ] `int` [ y_1, ..., y_m ] = [ z_1, ..., z_l ] -- -- then int should give witnesses us and vs such that: -- -- z_k = n_k1 * x_1 + ... + u_kn * x_n = u_k1 * y_1 + ... + n_km * y_m solveWithIntersection :: (IntegralDomain a, Eq a) => Vector a -> (Ideal a -> Ideal a -> (Ideal a, [[a]], [[a]])) -> Matrix a -- | Strongly discrete coherent rings. -- -- If the ring is strongly discrete and coherent then we can solve -- arbitrary equations of the type AX=b. solveGeneralEquation :: (Coherent a, StronglyDiscrete a) => Vector a -> a -> Maybe (Matrix a) propSolveGeneralEquation :: (Coherent a, StronglyDiscrete a, Eq a) => Vector a -> a -> Bool -- | Solves general linear systems of the kind AX = B. -- -- A is given as a matrix and B is given as a row vector (it should be -- column vector). solveGeneral :: (Coherent a, StronglyDiscrete a, Eq a) => Matrix a -> Vector a -> Maybe (Matrix a, Matrix a) propSolveGeneral :: (Coherent a, StronglyDiscrete a, Eq a) => Matrix a -> Vector a -> Property -- | Representation of Bezout domains. That is non-Noetherian analogues of -- principal ideal domains. This means that all finitely generated ideals -- are principal. module Algebra.Structures.BezoutDomain -- | Bezout domains -- -- Has a Bezout function which given a and b give g, a1, b1, x and y such -- that: -- --