Copyright | (C) 2023 Alexey Tochin |
---|---|
License | BSD3 (see the file LICENSE) |
Maintainer | Alexey Tochin <Alexey.Tochin@gmail.com> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Extensions |
|
Minimalistic toolkit for simple mathematical expression developed for debug purposes.
See Tutorial
for a quick introduction.
Synopsis
- number :: Integer -> SimpleExpr
- variable :: String -> SimpleExpr
- unaryFunc :: String -> SimpleExpr -> SimpleExpr
- binaryFunc :: String -> SimpleExpr -> SimpleExpr -> SimpleExpr
- simplify :: SimpleExpr -> SimpleExpr
- type SimpleExpr = Fix SimpleExprF
- type Expr = ListOf SimpleExpr
- plotExpr :: Expr d => d -> IO ThreadId
- exprToGraph :: Expr d => d -> DGraph String ()
- plotDGraph :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => DGraph v e -> IO ThreadId
- plotDGraphPng :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => DGraph v e -> FilePath -> IO FilePath
- dependencies :: SimpleExpr -> [SimpleExpr]
- content :: ListOf inner outer => outer -> [inner]
Expression manipulation
number :: Integer -> SimpleExpr Source #
Initializes a single integer number expression.
Examples of usage
>>>
a = number 42
>>>
a
42>>>
:t a
a :: SimpleExpr
variable :: String -> SimpleExpr Source #
Initializes a single symbolic variable expression.
Examples of usage
>>>
x = variable "x"
>>>
x
x>>>
:t x
x :: SimpleExpr
unaryFunc :: String -> SimpleExpr -> SimpleExpr Source #
Inituialize unarry function
Examples of usage
>>>
x = variable "x"
>>>
f = unaryFunc "f"
>>>
f x
f(x)>>>
:t x
x :: SimpleExpr>>>
:t f
f :: SimpleExpr -> SimpleExpr
binaryFunc :: String -> SimpleExpr -> SimpleExpr -> SimpleExpr Source #
Inituialize unarry function
Examples of usage
>>>
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
simplify :: SimpleExpr -> SimpleExpr Source #
Simplify expression using some primitive rules like '0 * x -> 0' specified in simplifyStep
implementation.
Examples of usage
>>>
import Prelude (($))
>>>
import Debug.SimpleExpr (variable, simplify)
>>>
import NumHask ((+), (-), (*))
>>>
x = variable "x"
>>>
simplify $ (x + 0) * 1 - x * (3 - 2)
0
Base types
type SimpleExpr = Fix SimpleExprF Source #
Simple expression type, see tutorial
type Expr = ListOf SimpleExpr Source #
Expression typeclass.
It includes SimpleExpr
as well as list and tuples of SimpleExpr
etc.
Visualisation
plotExpr :: Expr d => d -> IO ThreadId Source #
Visualizes an expression.
Examples of usage
>>>
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]
exprToGraph :: Expr d => d -> DGraph String () Source #
Transforms an expression to graph.
Examples of usage
>>>
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",())])]
plotDGraphPng :: (Hashable v, Ord v, PrintDot v, Show v, Show e) => DGraph v e -> FilePath -> IO FilePath Source #
Auxiliary functions
dependencies :: SimpleExpr -> [SimpleExpr] Source #
Returns the list of head dependencies of an expression.
Examples of usage
>>>
import Prelude (($), id)
>>>
import NumHask ((+), (*))
>>>
dependencies (variable "x" + (variable "y" * variable "z"))
[x,y·z]