6663b6c9
adorian
projet complet av...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# Poincare simplification architecture
## A three-tiered architecture
We formalize the simplification of an Expression the following way:
1. Find an interesting pattern in an Expression
2. Build a new Expression based on that pattern.
So in other words, a simplification is the association of a pattern and a gene-
ration rule. We formalize this approach with three classes : a `Simplification`
is made out of an `ExpressionSelector` (whose job is to detect a pattern in an
`Expression`) and of an `ExpressionBuilder` (which will build a new expression).
To give more details, it goes this way :
```
Expression * inputExpression;
ExpressionSelector * selector
ExpressionBuilder * builder;
ExpressionMatch * match = selector->match(inputExpression);
Expression * simplifiedExpression = builder->build(match);
```
## Rules
```
Addition(Integer(a),Integer(b),c*) -> Addition($Sum(a,b),c*)
```
Addition(Integer(a),Integer(b)) -> Function(Sum,a,b)
Addition(Addition(a*),b*) -> Addition(a*,b*)
- Matches have to be exhaustive i.e : capture all children
-> We can tell it at compile time (e.g. "Hey, Addition(a,b) can miss children,
you need a wildcard", but "ln(a)" is allright because ln has only one child)
Addition(Integer(0),...) -> Addition(...)
Product(Integer(0),...) -> Integer(0)
Fraction(Fraction(a,b),c) -> Fraction(a,Product(b,c))
Build(type=addition)
- integer(0)
- integer(1)
- and then all the clones of...
- and then all the clones of...
a*b+a*c -> a*(b+c)
a+(b+c)
|