Copyright | (c) Masahiro Sakai 2011 |
---|---|
License | BSD-style |
Maintainer | masahiro.sakai@gmail.com |
Stability | provisional |
Portability | non-portable (TypeFamilies) |
Safe Haskell | Safe |
Language | Haskell2010 |
Some definition for Theory of Linear Arithmetics.
- data Expr r
- type Var = Int
- var :: Num r => Var -> Expr r
- constant :: (Num r, Eq r) => r -> Expr r
- terms :: Expr r -> [(r, Var)]
- fromTerms :: (Num r, Eq r) => [(r, Var)] -> Expr r
- coeffMap :: Expr r -> IntMap r
- fromCoeffMap :: (Num r, Eq r) => IntMap r -> Expr r
- unitVar :: Var
- asConst :: Num r => Expr r -> Maybe r
- coeff :: Num r => Var -> Expr r -> r
- lookupCoeff :: Num r => Var -> Expr r -> Maybe r
- extract :: Num r => Var -> Expr r -> (r, Expr r)
- extractMaybe :: Num r => Var -> Expr r -> Maybe (r, Expr r)
- mapCoeff :: (Num b, Eq b) => (a -> b) -> Expr a -> Expr b
- mapCoeffWithVar :: (Num b, Eq b) => (a -> Var -> b) -> Expr a -> Expr b
- evalExpr :: Num r => Model r -> Expr r -> r
- evalLinear :: VectorSpace a => Model a -> a -> Expr (Scalar a) -> a
- lift1 :: VectorSpace x => x -> (Var -> x) -> Expr (Scalar x) -> x
- applySubst :: (Num r, Eq r) => VarMap (Expr r) -> Expr r -> Expr r
- applySubst1 :: (Num r, Eq r) => Var -> Expr r -> Expr r -> Expr r
- showExpr :: (Num r, Eq r, Show r) => Expr r -> String
- type Atom r = OrdRel (Expr r)
- showAtom :: (Num r, Eq r, Show r) => Atom r -> String
- evalAtom :: (Num r, Ord r) => Model r -> Atom r -> Bool
- applySubstAtom :: (Num r, Eq r) => VarMap (Expr r) -> Atom r -> Atom r
- applySubst1Atom :: (Num r, Eq r) => Var -> Expr r -> Atom r -> Atom r
- solveFor :: (Real r, Fractional r) => Atom r -> Var -> Maybe (RelOp, Expr r)
- module ToySolver.Data.OrdRel
- type BoundsEnv r = VarMap (Interval r)
- computeInterval :: (Real r, Fractional r) => BoundsEnv r -> Expr r -> Interval r
Expression of linear arithmetics
Linear combination of variables and constants.
Non-negative keys are used for variables's coefficients.
key unitVar
is used for constants.
Eq r => Eq (Expr r) Source # | |
Ord r => Ord (Expr r) Source # | |
(Num r, Eq r, Read r) => Read (Expr r) Source # | |
Show r => Show (Expr r) Source # | |
NFData r => NFData (Expr r) Source # | |
(Num r, Eq r) => VectorSpace (Expr r) Source # | |
(Num r, Eq r) => AdditiveGroup (Expr r) Source # | |
Variables (Expr r) Source # | |
IsOrdRel (Expr Integer) QFFormula Source # | |
IsEqRel (Expr Integer) QFFormula Source # | |
type Scalar (Expr r) Source # | |
Conversion
fromCoeffMap :: (Num r, Eq r) => IntMap r -> Expr r Source #
Create a Expr
from a mapping from variables to coefficients.
Query
coeff :: Num r => Var -> Expr r -> r Source #
lookup a coefficient of the variable.
coeff v e == fst (extract v e)
lookupCoeff :: Num r => Var -> Expr r -> Maybe r Source #
lookup a coefficient of the variable.
It returns Nothing
if the expression does not contain v
.
lookupCoeff v e == fmap fst (extractMaybe v e)
extract :: Num r => Var -> Expr r -> (r, Expr r) Source #
extract v e
returns (c, e')
such that e == c *^ v ^+^ e'
extractMaybe :: Num r => Var -> Expr r -> Maybe (r, Expr r) Source #
extractMaybe v e
returns Just (c, e')
such that e == c *^ v ^+^ e'
if e
contains v, and returns Nothing
otherwise.
Operations
evalLinear :: VectorSpace a => Model a -> a -> Expr (Scalar a) -> a Source #
evaluate the expression under the model.
applySubst1 :: (Num r, Eq r) => Var -> Expr r -> Expr r -> Expr r Source #
applySubst1 x e e1 == e1[e/x]
Atomic formula of linear arithmetics
evalAtom :: (Num r, Ord r) => Model r -> Atom r -> Bool Source #
evaluate the formula under the model.
applySubst1Atom :: (Num r, Eq r) => Var -> Expr r -> Atom r -> Atom r Source #
applySubst1 x e phi == phi[e/x]
solveFor :: (Real r, Fractional r) => Atom r -> Var -> Maybe (RelOp, Expr r) Source #
Solve linear (in)equation for the given variable.
solveFor a v
returns Just (op, e)
such that Atom v op e
is equivalent to a
.
module ToySolver.Data.OrdRel
misc
computeInterval :: (Real r, Fractional r) => BoundsEnv r -> Expr r -> Interval r Source #
compute bounds for a Expr
with respect to BoundsEnv
.