speculate-0.3.5: discovery of properties about Haskell functions

Copyright(c) 2016-2017 Rudy Matela
License3-Clause BSD (see the file LICENSE)
MaintainerRudy Matela <rudy@matela.com.br>
Safe HaskellNone
LanguageHaskell2010

Test.Speculate.Engine

Description

This module is part of Speculate.

Main engine to process data.

Synopsis

Documentation

vassignments :: Expr -> [Expr] Source #

List all relevant variable assignments in an expresssion. In pseudo-Haskell:

vassignments (0 + x) == [0 + x]
vassignments (0 + 0) == [0 + 0]
vassignments (0 + _) == [0 + x]
vassignments (_ + _) == [x + x, x + y]
vassignments (_ + (_ + ord _)) == [x + (x + ord c), x + (y + ord c)]

You should not use this on expression with already assinged variables (undefined, but currently defined behavior):

vassignments (ii -+- i_) == [ii -+- ii]

expansions :: Instances -> Int -> Expr -> [Expr] Source #

List all variable assignments for a given number of variables. It only assign variables to holes (variables with "" as its name).

> expansions preludeInstances 2 '(_ + _ + ord _)
[ (x + x) + ord c :: Int
, (x + x) + ord d :: Int
, (x + y) + ord c :: Int
, (x + y) + ord d :: Int
, (y + x) + ord c :: Int
, (y + x) + ord d :: Int
, (y + y) + ord c :: Int
, (y + y) + ord d :: Int ]

expansionsOfType :: TypeRep -> [String] -> Expr -> [Expr] Source #

List all variable assignments for a given type and list of variables.

mostGeneral :: Expr -> Expr Source #

List the most general assignment of holes in an expression

mostSpecific :: Expr -> Expr Source #

List the most specific assignment of holes in an expression

theoryAndRepresentativesFromAtoms :: Int -> (Expr -> Expr -> Ordering) -> (Expr -> Bool) -> (Expr -> Expr -> Bool) -> [[Expr]] -> (Thy, [[Expr]]) Source #

Given atomic expressions, compute theory and representative schema expressions.

representativesFromAtoms :: Int -> (Expr -> Expr -> Ordering) -> (Expr -> Bool) -> (Expr -> Expr -> Bool) -> [[Expr]] -> [[Expr]] Source #

theoryFromAtoms :: Int -> (Expr -> Expr -> Ordering) -> (Expr -> Bool) -> (Expr -> Expr -> Bool) -> [[Expr]] -> Thy Source #

Computes a theory from atomic expressions. Example:

> theoryFromAtoms 5 compare (const True) (equal preludeInstances 100)
>   [hole (undefined :: Int),constant "+" ((+) :: Int -> Int -> Int)]
Thy { rules = [ (x + y) + z == x + (y + z) ]
    , equations = [ y + x == x + y
                  , y + (x + z) == x + (y + z)
                  , z + (x + y) == x + (y + z)
                  , z + (y + x) == x + (y + z) ]
    , canReduceTo = (|>)
    , closureLimit = 2
    , keepE = keepUpToLength 5
    }

consider :: (Expr -> Expr -> Bool) -> Int -> Expr -> (Thy, [[Expr]]) -> (Thy, [[Expr]]) Source #

classesFromSchemas :: Instances -> Int -> Int -> Thy -> [Expr] -> [Class Expr] Source #

conditionalEquivalences :: (Expr -> Expr -> Ordering) -> ((Expr, Expr, Expr) -> Bool) -> (Expr -> Expr -> Expr -> Bool) -> (Expr -> Expr -> Bool) -> Int -> Thy -> [Class Expr] -> [Class Expr] -> Chy Source #

subConsequence :: Thy -> [Class Expr] -> Expr -> Expr -> Expr -> Bool Source #

Is the equation a consequence of substitution? > subConsequence (x == y) (x + y) (x + x) == True > subConsequence (x <= y) (x + y) (x + x) == False -- not sub > subConsequence (abs x == abs y) (abs x) (abs y) == True > subConsequence (abs x == 1) (x + abs x) (20) == False (artificial)

psortBy :: (a -> a -> Bool) -> [a] -> [(a, a)] Source #