-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Minimalistic toolkit for simple mathematical expression. -- -- This is a minimalistic toolkit for simple mathematical expression -- developed for debug purposes similar to 'simple-reflect' package but -- based on slightly different principles. In particular, we use ordinary -- syntactic trees instead of turning them into strings. There is a -- primitive manipulation capability like -- --
-- >>> simplify $ (x + 0) * 1 - x * (3 - 2) -- 0 ---- -- Besides an expression visualization feature is supported. -- -- -- See tutorial for details. @package simple-expr @version 0.1.0.0 -- | Simple expressions base types and manipulations. module Debug.SimpleExpr.Expr -- | Initializes a single integer number expression. -- --
-- >>> a = number 42 -- -- >>> a -- 42 -- -- >>> :t a -- a :: SimpleExpr --number :: Integer -> SimpleExpr -- | Initializes a single symbolic variable expression. -- --
-- >>> x = variable "x" -- -- >>> x -- x -- -- >>> :t x -- x :: SimpleExpr --variable :: String -> SimpleExpr -- | Inituialize unarry function -- --
-- >>> x = variable "x" -- -- >>> f = unaryFunc "f" -- -- >>> f x -- f(x) -- -- >>> :t x -- x :: SimpleExpr -- -- >>> :t f -- f :: SimpleExpr -> SimpleExpr --unaryFunc :: String -> SimpleExpr -> SimpleExpr -- | Inituialize unarry function -- --
-- >>> x = variable "x" -- -- >>> y = variable "y" -- -- >>> (-*-) = binaryFunc "-*-" -- -- >>> x -*- y -- x-*-y -- -- >>> :t x -- x :: SimpleExpr -- -- >>> :t (-*-) -- (-*-) :: SimpleExpr -> SimpleExpr -> SimpleExpr -- -- >>> :t x-*-y -- x-*-y :: SimpleExpr --binaryFunc :: String -> SimpleExpr -> SimpleExpr -> SimpleExpr -- | Simplify expression using some primitive rules like '0 * x -> 0' -- specified in simplifyStep implementation. -- --
-- >>> import Prelude (($)) -- -- >>> import Debug.SimpleExpr (variable, simplify) -- -- >>> import NumHask ((+), (-), (*)) ---- --
-- >>> x = variable "x" -- -- >>> simplify $ (x + 0) * 1 - x * (3 - 2) -- 0 --simplify :: SimpleExpr -> SimpleExpr -- | Minimalistic simplification step. -- --
-- >>> import Prelude (($), id) -- -- >>> import NumHask ((+), (*), (**)) ---- --
-- >>> simplifyStep id (0 + (0 + (0 + 10))) -- 0+(0+10) ---- --
-- >>> simplifyStep id (1 * (0 + (10 ** 1))) -- 0+(10^1) --simplifyStep :: (SimpleExpr -> SimpleExpr) -> SimpleExpr -> SimpleExpr -- | Expression F-algebra functional. data SimpleExprF a NumberF :: Integer -> SimpleExprF a VariableF :: String -> SimpleExprF a BinaryFuncF :: String -> a -> a -> SimpleExprF a SymbolicFuncF :: String -> [a] -> SimpleExprF a -- | Simple expression type, see tutorial type SimpleExpr = Fix SimpleExprF -- | Expression typeclass. It includes SimpleExpr as well as list -- and tuples of SimpleExpr etc. type Expr = ListOf SimpleExpr -- | Entity that is representable as a list of in general other entities. -- In particular, X is a list of single [X], see the -- example below. -- --
-- >>> data Atom = Atom String deriving Show -- -- >>> type Particle = ListOf Atom ---- --
-- >>> content (Atom "He") :: [Atom] -- [Atom "He"] ---- --
-- >>> content (Atom "H", Atom "H") :: [Atom] -- [Atom "H",Atom "H"] ---- --
-- >>> content [Atom "H", Atom "O", Atom "H"] :: [Atom] -- [Atom "H",Atom "O",Atom "H"] --class ListOf inner outer -- | Returns a list of entities the argument consists of. content :: ListOf inner outer => outer -> [inner] -- | Returns the list of head dependencies of an expression. -- --
-- >>> import Prelude (($), id) -- -- >>> import NumHask ((+), (*)) ---- --
-- >>> dependencies (variable "x" + (variable "y" * variable "z")) -- [x,y·z] --dependencies :: SimpleExpr -> [SimpleExpr] -- | Shows expression adding brackets if it is needed for a context. showWithBrackets :: SimpleExpr -> String instance GHC.Classes.Eq a => GHC.Classes.Eq (Debug.SimpleExpr.Expr.SimpleExprF a) instance GHC.Base.Functor Debug.SimpleExpr.Expr.SimpleExprF instance Debug.SimpleExpr.Expr.ListOf inner () instance Debug.SimpleExpr.Expr.ListOf inner inner instance (Debug.SimpleExpr.Expr.ListOf inner outer1, Debug.SimpleExpr.Expr.ListOf inner outer2) => Debug.SimpleExpr.Expr.ListOf inner (outer1, outer2) instance (Debug.SimpleExpr.Expr.ListOf inner outer1, Debug.SimpleExpr.Expr.ListOf inner outer2, Debug.SimpleExpr.Expr.ListOf inner outer3) => Debug.SimpleExpr.Expr.ListOf inner (outer1, outer2, outer3) instance (Debug.SimpleExpr.Expr.ListOf inner outer1, Debug.SimpleExpr.Expr.ListOf inner outer2, Debug.SimpleExpr.Expr.ListOf inner outer3, Debug.SimpleExpr.Expr.ListOf inner outer4) => Debug.SimpleExpr.Expr.ListOf inner (outer1, outer2, outer3, outer4) instance (Debug.SimpleExpr.Expr.ListOf inner outer1, Debug.SimpleExpr.Expr.ListOf inner outer2, Debug.SimpleExpr.Expr.ListOf inner outer3, Debug.SimpleExpr.Expr.ListOf inner outer4, Debug.SimpleExpr.Expr.ListOf inner outer5) => Debug.SimpleExpr.Expr.ListOf inner (outer1, outer2, outer3, outer4, outer5) instance Debug.SimpleExpr.Expr.ListOf inner outer => Debug.SimpleExpr.Expr.ListOf inner [outer] instance GHC.Show.Show Debug.SimpleExpr.Expr.SimpleExpr instance NumHask.Algebra.Additive.Additive Debug.SimpleExpr.Expr.SimpleExpr instance NumHask.Algebra.Additive.Subtractive Debug.SimpleExpr.Expr.SimpleExpr instance NumHask.Algebra.Multiplicative.Multiplicative Debug.SimpleExpr.Expr.SimpleExpr instance NumHask.Algebra.Ring.Distributive Debug.SimpleExpr.Expr.SimpleExpr instance NumHask.Algebra.Multiplicative.Divisive Debug.SimpleExpr.Expr.SimpleExpr instance NumHask.Algebra.Field.Field Debug.SimpleExpr.Expr.SimpleExpr instance NumHask.Algebra.Field.ExpField Debug.SimpleExpr.Expr.SimpleExpr instance NumHask.Algebra.Field.TrigField Debug.SimpleExpr.Expr.SimpleExpr instance GHC.Num.Num Debug.SimpleExpr.Expr.SimpleExpr instance Data.Functor.Classes.Eq1 Debug.SimpleExpr.Expr.SimpleExprF instance NumHask.Data.Integral.FromIntegral (Debug.SimpleExpr.Expr.SimpleExprF a) GHC.Integer.Type.Integer instance NumHask.Data.Integral.FromIntegral (Data.Fix.Fix Debug.SimpleExpr.Expr.SimpleExprF) GHC.Integer.Type.Integer -- | Tools for transforming simple expressions to graphs from -- graphite. module Debug.SimpleExpr.GraphUtils -- | Transforms an expression to graph. -- --
-- >>> import Debug.SimpleExpr (variable) -- -- >>> import NumHask ((+), (-)) ---- --
-- >>> x = variable "x"
--
-- >>> y = variable "y"
--
-- >>> exprToGraph [x + y, x - y]
-- fromList [("x",[("x+y",()),("x-y",())]),("x+y",[]),("x-y",[]),("y",[("x+y",()),("x-y",())])]
--
exprToGraph :: Expr d => d -> DGraph String ()
-- | Visualizes an expression.
--
-- -- >>> import Debug.SimpleExpr (number, variable) -- -- >>> import NumHask ((+), (-)) -- -- >>> import Data.Graph.VisualizeAlternative (plotDGraphPng) ---- --
-- >>> plotExpr (number 1 + variable "x") ---- -- --
-- >>> x = variable "x" -- -- >>> y = variable "y" ---- --
-- >>> plotExpr [x + y, x - y] ---- plotExpr :: Expr d => d -> IO ThreadId -- | A copy of toDirectedDot method from Visualize but the -- parameter Sfdp is replaced by Dot. plotDGraphPng :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => DGraph v e -> FilePath -> IO FilePath -- | Transforms a simple expression to graph. simpleExprToGraph :: SimpleExpr -> DGraph String () -- | Appends a node to a graph using string valued keys. -- -- The first argumet is the new node name. -- -- The second argument is the list of dependent nodes. appendNodeToGraph :: String -> [String] -> DGraph String () -> DGraph String () -- | Minimalistic toolkit for simple mathematical expression developed for -- debug purposes. See Tutorial for a quick introduction. module Debug.SimpleExpr -- | Initializes a single integer number expression. -- --
-- >>> a = number 42 -- -- >>> a -- 42 -- -- >>> :t a -- a :: SimpleExpr --number :: Integer -> SimpleExpr -- | Initializes a single symbolic variable expression. -- --
-- >>> x = variable "x" -- -- >>> x -- x -- -- >>> :t x -- x :: SimpleExpr --variable :: String -> SimpleExpr -- | Inituialize unarry function -- --
-- >>> x = variable "x" -- -- >>> f = unaryFunc "f" -- -- >>> f x -- f(x) -- -- >>> :t x -- x :: SimpleExpr -- -- >>> :t f -- f :: SimpleExpr -> SimpleExpr --unaryFunc :: String -> SimpleExpr -> SimpleExpr -- | Inituialize unarry function -- --
-- >>> x = variable "x" -- -- >>> y = variable "y" -- -- >>> (-*-) = binaryFunc "-*-" -- -- >>> x -*- y -- x-*-y -- -- >>> :t x -- x :: SimpleExpr -- -- >>> :t (-*-) -- (-*-) :: SimpleExpr -> SimpleExpr -> SimpleExpr -- -- >>> :t x-*-y -- x-*-y :: SimpleExpr --binaryFunc :: String -> SimpleExpr -> SimpleExpr -> SimpleExpr -- | Simplify expression using some primitive rules like '0 * x -> 0' -- specified in simplifyStep implementation. -- --
-- >>> import Prelude (($)) -- -- >>> import Debug.SimpleExpr (variable, simplify) -- -- >>> import NumHask ((+), (-), (*)) ---- --
-- >>> x = variable "x" -- -- >>> simplify $ (x + 0) * 1 - x * (3 - 2) -- 0 --simplify :: SimpleExpr -> SimpleExpr -- | Simple expression type, see tutorial type SimpleExpr = Fix SimpleExprF -- | Expression typeclass. It includes SimpleExpr as well as list -- and tuples of SimpleExpr etc. type Expr = ListOf SimpleExpr -- | Visualizes an expression. -- --
-- >>> import Debug.SimpleExpr (number, variable) -- -- >>> import NumHask ((+), (-)) -- -- >>> import Data.Graph.VisualizeAlternative (plotDGraphPng) ---- --
-- >>> plotExpr (number 1 + variable "x") ---- -- --
-- >>> x = variable "x" -- -- >>> y = variable "y" ---- --
-- >>> plotExpr [x + y, x - y] ---- plotExpr :: Expr d => d -> IO ThreadId -- | Transforms an expression to graph. -- --
-- >>> import Debug.SimpleExpr (variable) -- -- >>> import NumHask ((+), (-)) ---- --
-- >>> x = variable "x"
--
-- >>> y = variable "y"
--
-- >>> exprToGraph [x + y, x - y]
-- fromList [("x",[("x+y",()),("x-y",())]),("x+y",[]),("x-y",[]),("y",[("x+y",()),("x-y",())])]
--
exprToGraph :: Expr d => d -> DGraph String ()
-- | A copy of plotDGraph method from Visualize but the
-- parameter Sfdp is replaced by Dot.
plotDGraph :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => DGraph v e -> IO ThreadId
-- | A copy of toDirectedDot method from Visualize but the
-- parameter Sfdp is replaced by Dot.
plotDGraphPng :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => DGraph v e -> FilePath -> IO FilePath
-- | Returns the list of head dependencies of an expression.
--
-- -- >>> import Prelude (($), id) -- -- >>> import NumHask ((+), (*)) ---- --
-- >>> dependencies (variable "x" + (variable "y" * variable "z")) -- [x,y·z] --dependencies :: SimpleExpr -> [SimpleExpr] -- | Returns a list of entities the argument consists of. content :: ListOf inner outer => outer -> [inner] -- | Tutorial, Quick start or Demo for 'simple-expr' package. module Debug.SimpleExpr.Tutorial