From f54403ae2191644bf38cf4fe20f74034890a6dc4 Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Fri, 1 Apr 2016 14:22:39 +0200 Subject: [PATCH] Poincare: Add a README for the simplification Change-Id: Ife72d5914a6968bdc7c52ad93a329b37fe2c01a6 --- poincare/src/simplify/README.md | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 poincare/src/simplify/README.md diff --git a/poincare/src/simplify/README.md b/poincare/src/simplify/README.md new file mode 100644 index 000000000..5da55835f --- /dev/null +++ b/poincare/src/simplify/README.md @@ -0,0 +1,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)