-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I think canonicalize
is maybe a bit too weak; for instance, does not include commutativity:
BScProj2018/Physics/src/Calculus/SyntaxTree.lhs
Lines 112 to 119 in 30fb209
> canonify :: FunExpr -> FunExpr | |
Addition | |
> canonify (e :+ Const 0) = canonify e | |
> canonify (Const 0 :+ e) = canonify e | |
> canonify (Const x :+ Const y) = Const (x + y) | |
> canonify (e1 :+ e2) = canonify e1 :+ canonify e2 |
One way to improve this is to have a notion of canonical form which is a sorted lists of sum terms each consisting of a sorted list of factors which are functions which can again be composed with sums of products of functions... (recursive).
Further, I noticed the overlap with simplify
:
BScProj2018/Physics/src/Calculus/DifferentialCalc.lhs
Lines 443 to 452 in 30fb209
> simplify (f :+ g) = case (simplify f, simplify g) of | |
> (Const 0, g') -> g' | |
> (f', Const 0) -> f' | |
> (Const a, Const b) -> Const (a + b) | |
> (f', g') | f' == g' -> simplify (Const 2 :* f') | |
> (Const a :* f', g') | f' == g' -> simplify (Const (a + 1) :* f') | |
> (f', Const a :* g') | f' == g' -> simplify (Const (a + 1) :* f') | |
> (Const a :* f', Const b :* g') | f' == g' | |
> -> simplify (Const (a + b) :* f') | |
> (f', g') -> f' :+ g' |
Metadata
Metadata
Assignees
Labels
No labels