| Copyright | (c) 2017 Rudy Matela |
|---|---|
| License | 3-Clause BSD (see the file LICENSE) |
| Maintainer | Rudy Matela <rudy@matela.com.br> |
| Safe Haskell | None |
| Language | Haskell2010 |
Test.Extrapolate.Exprs
Description
This module is part of Extrapolate, a library for generalization of counter-examples.
This module re-exports some functionality from Test.Speculate.Expr, but instead of working on single expressions it works in lists of expressions (the choosen representation for counter-examples).
Synopsis
- type Exprs = [Expr]
- canonicalizeWith :: Instances -> [Expr] -> [Expr]
- grounds :: Instances -> [Expr] -> [[Expr]]
- groundsAndBinds :: Instances -> [Expr] -> [(Binds, [Expr])]
- vassignments :: [Expr] -> [[Expr]]
- vars :: [Expr] -> [(TypeRep, String)]
- fold :: [Expr] -> Expr
- unfold :: Expr -> [Expr]
- isAssignmentTest :: Instances -> Int -> Expr -> Bool
- nameWith :: Typeable a => String -> a -> Instances
- type TypeRep = SomeTypeRep
- canonicalWith :: Instances -> Expr -> Bool
- canonicalize :: Expr -> Expr
- false :: Instances -> Int -> Expr -> Bool
- trueRatio :: Instances -> Int -> Expr -> Ratio Int
- trueBinds :: Instances -> Int -> Expr -> [Binds]
- true :: Instances -> Int -> Expr -> Bool
- inequal :: Instances -> Int -> Expr -> Expr -> Bool
- less :: Instances -> Int -> Expr -> Expr -> Bool
- lessOrEqual :: Instances -> Int -> Expr -> Expr -> Bool
- condEqualM :: Instances -> Int -> Int -> Expr -> Expr -> Expr -> Bool
- condEqual :: Instances -> Int -> Expr -> Expr -> Expr -> Bool
- equal :: Instances -> Int -> Expr -> Expr -> Bool
- groundAndBinds :: Instances -> Expr -> [(Binds, Expr)]
- groundBinds :: Instances -> Expr -> [Binds]
- unConditionalComparison :: Expr -> (Expr, Expr, Expr)
- conditionalComparisonLT :: Instances -> Expr -> Expr -> Expr -> Maybe Expr
- conditionalComparisonLE :: Instances -> Expr -> Expr -> Expr -> Maybe Expr
- usefulConditionalEquation :: Expr -> Bool
- unConditionalEquation :: Expr -> (Expr, Expr, Expr)
- conditionalEquation :: Instances -> Expr -> Expr -> Expr -> Maybe Expr
- usefulImplication :: Expr -> Bool
- unImplication :: Expr -> (Expr, Expr)
- implication :: Expr -> Expr -> Maybe Expr
- unComparison :: Expr -> (Expr, Expr)
- comparisonLE :: Instances -> Expr -> Expr -> Maybe Expr
- comparisonLT :: Instances -> Expr -> Expr -> Maybe Expr
- inequality :: Instances -> Expr -> Expr -> Maybe Expr
- usefulEquation :: Expr -> Bool
- uselessEquation :: Expr -> Bool
- isEquation :: Expr -> Bool
- unEquation :: Expr -> (Expr, Expr)
- phonyEquation :: Expr -> Expr -> Expr
- equation :: Instances -> Expr -> Expr -> Maybe Expr
- defNames :: [String]
- preludeInstances :: Instances
- leE :: Instances -> TypeRep -> Maybe Expr
- ltE :: Instances -> TypeRep -> Maybe Expr
- iqE :: Instances -> TypeRep -> Maybe Expr
- eqE :: Instances -> TypeRep -> Maybe Expr
- tiersE :: Instances -> TypeRep -> [[Expr]]
- names :: Instances -> TypeRep -> [String]
- findInfo :: (Instance -> Maybe a) -> Instances -> Maybe a
- isListable :: Instances -> TypeRep -> Bool
- isEqOrdE :: Instances -> Expr -> Bool
- isOrdE :: Instances -> Expr -> Bool
- isEqE :: Instances -> Expr -> Bool
- isEqOrd :: Instances -> TypeRep -> Bool
- isOrd :: Instances -> TypeRep -> Bool
- isEq :: Instances -> TypeRep -> Bool
- listableWith :: (Typeable a, Show a) => [[a]] -> Instances
- ordWith :: (Typeable a, Ord a) => (a -> a -> Bool) -> Instances
- eqWith :: (Typeable a, Eq a) => (a -> a -> Bool) -> Instances
- listable :: (Typeable a, Show a, Listable a) => a -> Instances
- eqOrd :: (Typeable a, Eq a, Ord a) => a -> Instances
- ord :: (Typeable a, Ord a) => a -> Instances
- eq :: (Typeable a, Eq a) => a -> Instances
- instanceType :: Instance -> TypeRep
- data Instance = Instance String TypeRep [Expr]
- type Instances = [Instance]
- hasCanonInstanceOf :: Expr -> Expr -> Bool
- isCanonInstanceOf :: Expr -> Expr -> Bool
- hasInstanceOf :: Expr -> Expr -> Bool
- isInstanceOf :: Expr -> Expr -> Bool
- unification :: Expr -> Expr -> Maybe Binds
- unify :: Expr -> Expr -> Maybe Expr
- matchWith :: Binds -> Expr -> Expr -> Maybe Binds
- match2 :: (Expr, Expr) -> (Expr, Expr) -> Maybe Binds
- match :: Expr -> Expr -> Maybe Binds
- renameBy :: (String -> String) -> Expr -> Expr
- sub :: Expr -> Expr -> Expr -> Expr
- assigning :: Expr -> Binds -> Expr
- assign :: String -> Expr -> Expr -> Expr
- fill :: Expr -> [Expr] -> Expr
- type Binds = [(String, Expr)]
- unfoldApp :: Expr -> [Expr]
- isConstantNamed :: Expr -> String -> Bool
- isSub :: Expr -> Expr -> Bool
- subexprsV :: Expr -> [Expr]
- subexprs :: Expr -> [Expr]
- isAssignment :: Expr -> Bool
- unrepeatedVars :: Expr -> Bool
- countVars :: Expr -> [(TypeRep, String, Int)]
- countVar :: TypeRep -> String -> Expr -> Int
- countHoles :: TypeRep -> Expr -> Int
- depthE :: Expr -> Int
- lengthE :: Expr -> Int
- consts :: Expr -> [Expr]
- hasVar :: Expr -> Bool
- atomicConstants :: Expr -> [Expr]
- holes :: Expr -> [TypeRep]
- arity :: Expr -> Int
- typeCorrect :: Expr -> Bool
- etyp :: Expr -> Either Expr TypeRep
- typ :: Expr -> TypeRep
- eval :: Typeable a => a -> Expr -> a
- evaluate :: Typeable a => Expr -> Maybe a
- falseE :: Expr
- compareComplexity :: Expr -> Expr -> Ordering
- compareComplexityThen :: (Expr -> Expr -> Ordering) -> Expr -> Expr -> Ordering
- lexicompare :: Expr -> Expr -> Ordering
- lexicompareBy :: (Expr -> Expr -> Ordering) -> Expr -> Expr -> Ordering
- eqExprCommuting :: [Expr] -> Expr -> Expr -> Bool
- showExpr :: Expr -> String
- showPrecExpr :: Int -> Expr -> String
- showOpExpr :: String -> Expr -> String
- showsOpExpr :: String -> Expr -> String -> String
- unfoldTuple :: Expr -> [Expr]
- isTuple :: Expr -> Bool
- showsPrecExpr :: Int -> Expr -> String -> String
- ($$) :: Expr -> Expr -> Maybe Expr
- holeOfTy :: TypeRep -> Expr
- hole :: (Listable a, Typeable a) => a -> Expr
- var :: (Listable a, Typeable a) => String -> a -> Expr
- showConstant :: (Typeable a, Show a) => a -> Expr
- constant :: Typeable a => String -> a -> Expr
- data Expr
- mkEqnTy :: TypeRep -> TypeRep
- boolTy :: TypeRep
Documentation
canonicalizeWith :: Instances -> [Expr] -> [Expr] #
vassignments :: [Expr] -> [[Expr]] #
type TypeRep = SomeTypeRep #
A quantified type representation.
canonicalWith :: Instances -> Expr -> Bool #
canonicalize :: Expr -> Expr #
false :: Instances -> Int -> Expr -> Bool #
Is an expression ALWAYS false? This is *NOT* the same as not true
trueRatio :: Instances -> Int -> Expr -> Ratio Int #
Under a maximum number of tests, returns the ratio for which an expression holds true.
trueBinds :: Instances -> Int -> Expr -> [Binds] #
List variable bindings for which an expression holds true.
true :: Instances -> Int -> Expr -> Bool #
Is a boolean expression true for all variable assignments?
inequal :: Instances -> Int -> Expr -> Expr -> Bool #
Are two expressions inequal for *all* variable assignments?
Note this is different than not . equal.
less :: Instances -> Int -> Expr -> Expr -> Bool #
Are two expressions less-than for a given number of tests?
lessOrEqual :: Instances -> Int -> Expr -> Expr -> Bool #
Are two expressions less-than-or-equal for a given number of tests?
condEqualM :: Instances -> Int -> Int -> Expr -> Expr -> Expr -> Bool #
Are two expressions equal under a given condition for a given number of tests and a minimum amount of tests
condEqual :: Instances -> Int -> Expr -> Expr -> Expr -> Bool #
Are two expressions equal under a given condition for a given number of tests?
equal :: Instances -> Int -> Expr -> Expr -> Bool #
Are two expressions equal for a given number of tests?
groundAndBinds :: Instances -> Expr -> [(Binds, Expr)] #
List all possible variable bindings and valuations to an expression
groundAndBinds ti e == zipWith (,) (grounds ti e) (groundBinds ti e)
groundBinds :: Instances -> Expr -> [Binds] #
List all possible variable bindings to an expression
take 3 $ groundBinds preludeInstances ((x + x) + y)
== [ [("x",0),("y",0)]
, [("x",0),("y",1)]
, [("x",1),("y",0)] ]usefulConditionalEquation :: Expr -> Bool #
usefulImplication :: Expr -> Bool #
unImplication :: Expr -> (Expr, Expr) #
unComparison :: Expr -> (Expr, Expr) #
usefulEquation :: Expr -> Bool #
uselessEquation :: Expr -> Bool #
isEquation :: Expr -> Bool #
unEquation :: Expr -> (Expr, Expr) #
phonyEquation :: Expr -> Expr -> Expr #
isListable :: Instances -> TypeRep -> Bool #
listableWith :: (Typeable a, Show a) => [[a]] -> Instances #
instanceType :: Instance -> TypeRep #
Type information needed to Speculate expressions (single type / single class).
hasCanonInstanceOf :: Expr -> Expr -> Bool #
isCanonInstanceOf :: Expr -> Expr -> Bool #
hasInstanceOf :: Expr -> Expr -> Bool #
isInstanceOf :: Expr -> Expr -> Bool #
matchWith :: Binds -> Expr -> Expr -> Maybe Binds #
List matches with preexisting bindings:
0 + 1 `matchWith [(x,0)]` x + y = Just [x=0, y=1] 0 + 1 `matchWith [(x,1)]` x + y = Nothing
match2 :: (Expr, Expr) -> (Expr, Expr) -> Maybe Binds #
List matches of pairs of expressions if possible
(0,1) `match2` (x,y) = Just [x=0, y=1] (0,1+2) `match2` (x,y+y) = Nothing
match :: Expr -> Expr -> Maybe Binds #
List matches if possible
0 + 1 `match` x + y = Just [x=0, y=1] 0 + (1 + 2) `match` x + y = Just [x=0, y=1 + 2] 0 + (1 + 2) `match` x + (y + y) = Nothing (x + x) + (1 + 2) `match` x + (y + y) = Nothing
renameBy :: (String -> String) -> Expr -> Expr #
Primeify variable names in an expression.
renameBy (++ "'") (x + y) = (x' + y') renameBy (++ "'") (y + (z + x)) = (y' + (z' + x')) renameBy (++ "1") abs x = abs x1 renameBy (++ "2") abs (x + y) = abs (x2 + y2)
Note this will affect holes!
sub :: Expr -> Expr -> Expr -> Expr #
Substitute matching subexpressios.
sub (x + y) 0 ((x + y) + z) == (0 + z) sub (x + y) 0 (x + (y + z)) == (x + (y + z))
assigning :: Expr -> Binds -> Expr #
Assign all occurrences of several variables in an expression.
For single variables, this works as assign:
x + y `assigning` [("x",10)] = (10 + y)
((x + y) + (y + z)) `assigning` [("y",y+z)] = (x + (y + z)) + ((y + z) + z)Note this is not equivalent to foldr (uncurry assign). Variables inside
expressions being assigned will not be assigned.
assign :: String -> Expr -> Expr -> Expr #
Assign all occurences of a variable in an expression.
Examples in pseudo-Haskell:
assign "x" (10) (x + y) = (10 + y) assign "y" (y + z) ((x + y) + (y + z)) = (x + (y + z)) + ((y + z) + z)
This respects the type (won't change occurrences of a similarly named variable of a different type).
fill :: Expr -> [Expr] -> Expr #
Fill holes in an expression. Silently skips holes that are not of the right type. Silently discard remaining expressions.
isConstantNamed :: Expr -> String -> Bool #
Sub-expressions of an expression including variables and the expression itself.
Non-variable sub-expressions of an expression
This includes the expression itself
isAssignment :: Expr -> Bool #
unrepeatedVars :: Expr -> Bool #
countVar :: TypeRep -> String -> Expr -> Int #
Number of occurrences of a given variable name. In term rewriting terms: |s|_x
countHoles :: TypeRep -> Expr -> Int #
Number of occurrences of holes with a given type.
atomicConstants :: Expr -> [Expr] #
typeCorrect :: Expr -> Bool #
etyp :: Expr -> Either Expr TypeRep #
etyp returns either: the Right type a Left expression with holes with the structure of the I'll typed expression
The type of an expression. This raises errors, but those should not happen if expressions are smart-constructed.
eval :: Typeable a => a -> Expr -> a #
Evaluates an expression when possible (correct type, no holes). Returns a default value otherwise.
compareComplexity :: Expr -> Expr -> Ordering #
Compares two expressions first by their complexity: 1st length; 2nd number of variables (more variables is less complex); 3nd sum of number of variable occurrences; 4th their depth; 5th lexicompare.
compareComplexityThen :: (Expr -> Expr -> Ordering) -> Expr -> Expr -> Ordering #
Compares two expressions first by their complexity:
1st length;
2nd number of variables (more variables is less complex);
3nd sum of number of variable occurrences;
4th their depth;
5th normal compare.
lexicompare :: Expr -> Expr -> Ordering #
Compare two expressiosn lexicographically
1st their type arity; 2nd their type; 3rd var < constants < apps 4th lexicographic order on names
showPrecExpr :: Int -> Expr -> String #
showOpExpr :: String -> Expr -> String #
unfoldTuple :: Expr -> [Expr] #
hole :: (Listable a, Typeable a) => a -> Expr #
(intended for advanced users)
hole (undefined :: Ty) returns a hole of type Ty
By convention, a Hole is a variable named with the empty string.
var :: (Listable a, Typeable a) => String -> a -> Expr #
var "x" (undefined :: Ty) returns a variable of type Ty named "x"
showConstant :: (Typeable a, Show a) => a -> Expr #
constant :: Typeable a => String -> a -> Expr #
Encode a constant Haskell expression for use by Speculate.
It takes a string representation of a value and a value, returning an
Expr. Examples:
constant "0" 0 constant "'a'" 'a' constant "True" True constant "id" (id :: Int -> Int) constant "(+)" ((+) :: Int -> Int -> Int) constant "sort" (sort :: [Bool] -> [Bool])