summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-06-18 13:10:24 +0200
committertomsmeding <tom.smeding@gmail.com>2016-06-18 13:10:24 +0200
commit712dfe8a117207f1d70e0e14f9d6e7ee62c8eadd (patch)
treecad454b41a5cc73981dc856518c80eaa5215a817
parentfeb0e2129ee4b65c8dc4f1e3c7a532908418d417 (diff)
More patterns
-rw-r--r--simplify.hs36
1 files changed, 35 insertions, 1 deletions
diff --git a/simplify.hs b/simplify.hs
index f2eaa28..f0fcd6e 100644
--- a/simplify.hs
+++ b/simplify.hs
@@ -137,6 +137,17 @@ canonicaliseOrder node = case node of
patterndb :: [(AST,AST)]
patterndb = [
+ (Reciprocal $ Product [Reciprocal (CaptureTerm "x"),Capture "rest"], -- 1/(1/x * [rest]) -> x * 1/[rest]
+ Product [Capture "x",Reciprocal $ Capture "rest"]),
+
+ (Product [CaptureTerm "x",Reciprocal (CaptureTerm "x"),Capture "rest"], -- x * 1/x * [rest] -> [rest]
+ Capture "rest"),
+
+ (Product [CaptureTerm "x", -- x * 1/(x*[rrest]) * [rest] -> [rest] * 1/[rrest]
+ Reciprocal (Product [CaptureTerm "x",Capture "rrest"]),
+ Capture "rest"],
+ Product [Capture "rest",Reciprocal (Capture "rrest")]),
+
(Sum [CaptureTerm "x",CaptureTerm "x",Capture "rest"], -- x + x + [rest] -> 2*x + [rest]
Sum [Product [Number 2,Capture "x"],Capture "rest"]),
@@ -179,6 +190,15 @@ patterndb = [
(Apply "pow" [CaptureTerm "x",Number 1], -- x^1 -> x
Capture "x"),
+ (Product [Number 0,Capture "rest"], -- 0*[rest] -> 0
+ Number 0),
+
+ (Product [Number 1,Capture "rest"], -- 1*[rest] -> [rest]
+ Capture "rest"),
+
+
+ (Apply "d" [CaptureConstr "n" (Number undefined),Capture "x"], -- d(n,x) -> 0
+ Number 0),
(Apply "d" [CaptureConstr "x" (Variable undefined),CaptureTerm "x"], -- d(x,x) -> 1
Number 1),
@@ -188,7 +208,21 @@ patterndb = [
Product [Capture "n",Apply "pow" [Capture "x",Sum [Capture "n",Number (-1)]]]),
(Apply "d" [Sum [CaptureTerm "a",Capture "b"],CaptureTerm "x"], -- d(a+[b],x) -> d(a,x) + d([b],x)
- Sum [Apply "d" [Capture "a",Capture "x"],Apply "d" [Capture "b",Capture "x"]])
+ Sum [Apply "d" [Capture "a",Capture "x"],Apply "d" [Capture "b",Capture "x"]]),
+
+ (Apply "d" [Product [CaptureTerm "a",Capture "b"],Capture "x"], -- d(ab,x) -> d(a,x)*b + a*d(b,x)
+ Sum [Product [Apply "d" [Capture "a",Capture "x"],Capture "b"],
+ Product [Capture "a",Apply "d" [Capture "b",Capture "x"]]]),
+
+ (Apply "d" [Apply "pow" [CaptureConstr "a" (Variable undefined), -- d(a^expr,x) -> a^expr * ln(a) * d(expr,x)
+ Capture "expr"],
+ Capture "x"],
+ Product [Apply "pow" [Capture "a",Capture "expr"],
+ Apply "ln" [Capture "a"],
+ Apply "d" [Capture "expr",Capture "x"]]),
+
+ (Apply "d" [Apply "ln" [Capture "args"],Capture "x"], -- d(ln([args]),x) -> 1/[args]*d([args],x)
+ Product [Reciprocal (Capture "args"),Apply "d" [Capture "args",Capture "x"]])
]
astChildMap :: AST -> (AST -> AST) -> AST