From 5bfa345b0b4a46072e498e6bcb1fa1d5df98b57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Sat, 14 Jan 2017 12:35:01 +0100 Subject: [PATCH] [poincare] Change name: product->multiplication Change-Id: Ie4f4580675a68ddad32256df568ec000e6f50ede --- poincare/Makefile | 2 +- poincare/include/poincare.h | 2 +- poincare/include/poincare/expression.h | 2 +- .../poincare/{product.h => multiplication.h} | 6 ++-- poincare/src/expression_parser.y | 2 +- .../src/{product.cpp => multiplication.cpp} | 20 ++++++------- poincare/src/power.cpp | 8 +++--- poincare/src/simplify/expression_builder.cpp | 6 ++-- poincare/src/simplify/rules.pr | 28 +++++++++---------- 9 files changed, 38 insertions(+), 38 deletions(-) rename poincare/include/poincare/{product.h => multiplication.h} (86%) rename poincare/src/{product.cpp => multiplication.cpp} (71%) diff --git a/poincare/Makefile b/poincare/Makefile index 61bbca55a..5b6fe17ad 100644 --- a/poincare/Makefile +++ b/poincare/Makefile @@ -23,12 +23,12 @@ objs += $(addprefix poincare/src/,\ logarithm.o\ matrix.o\ matrix_data.o\ + multiplication.o\ n_context.o\ nth_root.o\ opposite.o\ parenthesis.o\ power.o\ - product.o\ sine.o\ subtraction.o\ sum.o\ diff --git a/poincare/include/poincare.h b/poincare/include/poincare.h index f22d001c6..9c97b3c16 100644 --- a/poincare/include/poincare.h +++ b/poincare/include/poincare.h @@ -18,12 +18,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index 97baff133..75bff507c 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -19,12 +19,12 @@ class Expression { Integral, Logarithm, Matrix, + Multiplication, NthRoot, Opposite, Fraction, Parenthesis, Power, - Product, Sine, Sum, Subtraction, diff --git a/poincare/include/poincare/product.h b/poincare/include/poincare/multiplication.h similarity index 86% rename from poincare/include/poincare/product.h rename to poincare/include/poincare/multiplication.h index 24534d106..e03d20905 100644 --- a/poincare/include/poincare/product.h +++ b/poincare/include/poincare/multiplication.h @@ -1,11 +1,11 @@ -#ifndef POINCARE_PRODUCT_H -#define POINCARE_PRODUCT_H +#ifndef POINCARE_MULTIPLICATION_H +#define POINCARE_MULTIPLICATION_H #include #include #include -class Product : public BinaryOperation { +class Multiplication : public BinaryOperation { using BinaryOperation::BinaryOperation; public: Type type() const override; diff --git a/poincare/src/expression_parser.y b/poincare/src/expression_parser.y index 26ac384fb..beae77633 100644 --- a/poincare/src/expression_parser.y +++ b/poincare/src/expression_parser.y @@ -121,7 +121,7 @@ exp: | SYMBOL { $$ = new Symbol($1); } | exp PLUS exp { Expression * terms[2] = {$1,$3}; $$ = new Addition(terms, 2, false); } | exp MINUS exp { Expression * terms[2] = {$1,$3}; $$ = new Subtraction(terms, false); } - | exp MULTIPLY exp { Expression * terms[2] = {$1,$3}; $$ = new Product(terms, false); } + | exp MULTIPLY exp { Expression * terms[2] = {$1,$3}; $$ = new Multiplication(terms, false); } | exp DIVIDE exp { Expression * terms[2] = {$1,$3}; $$ = new Fraction(terms, false); } | exp POW exp { Expression * terms[2] = {$1,$3}; $$ = new Power(terms, false); } | MINUS exp { $$ = new Opposite($2, false); } diff --git a/poincare/src/product.cpp b/poincare/src/multiplication.cpp similarity index 71% rename from poincare/src/product.cpp rename to poincare/src/multiplication.cpp index db4b10be7..bae3ad2e0 100644 --- a/poincare/src/product.cpp +++ b/poincare/src/multiplication.cpp @@ -3,15 +3,15 @@ extern "C" { #include } -#include +#include #include "layout/string_layout.h" #include "layout/horizontal_layout.h" -Expression::Type Product::type() const { - return Expression::Type::Product; +Expression::Type Multiplication::type() const { + return Expression::Type::Multiplication; } -ExpressionLayout * Product::createLayout() const { +ExpressionLayout * Multiplication::createLayout() const { ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(3*sizeof(ExpressionLayout *)); children_layouts[0] = m_operands[0]->createLayout(); children_layouts[1] = new StringLayout("*", 1); @@ -19,18 +19,18 @@ ExpressionLayout * Product::createLayout() const { return new HorizontalLayout(children_layouts, 3); } -float Product::approximate(Context& context) const { +float Multiplication::approximate(Context& context) const { return m_operands[0]->approximate(context)*m_operands[1]->approximate(context);; } -Expression * Product::cloneWithDifferentOperands(Expression** newOperands, +Expression * Multiplication::cloneWithDifferentOperands(Expression** newOperands, int numberOfOperands, bool cloneOperands) const { assert(numberOfOperands == 2); assert(newOperands != nullptr); - return new Product(newOperands, cloneOperands); + return new Multiplication(newOperands, cloneOperands); } -Expression * Product::evaluateOnMatrixAndFloat(Matrix * m, Float * a, Context& context) const { +Expression * Multiplication::evaluateOnMatrixAndFloat(Matrix * m, Float * a, Context& context) const { Expression * operands[m->numberOfRows() * m->numberOfColumns()]; for (int i = 0; i < m->numberOfRows() * m->numberOfColumns(); i++) { operands[i] = new Float(m->operand(i)->approximate(context)*a->approximate(context)); @@ -38,11 +38,11 @@ Expression * Product::evaluateOnMatrixAndFloat(Matrix * m, Float * a, Context& c return new Matrix(operands, m->numberOfRows() * m->numberOfColumns(), m->numberOfColumns(), m->numberOfRows(), false); } -Expression * Product::evaluateOnFloatAndMatrix(Float * a, Matrix * m, Context& context) const { +Expression * Multiplication::evaluateOnFloatAndMatrix(Float * a, Matrix * m, Context& context) const { return evaluateOnMatrixAndFloat(m, a, context); } -Expression * Product::evaluateOnMatrices(Matrix * m, Matrix * n, Context& context) const { +Expression * Multiplication::evaluateOnMatrices(Matrix * m, Matrix * n, Context& context) const { if (m->numberOfColumns() != n->numberOfRows()) { return nullptr; } diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index a9b1e6a12..331ac70a1 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -3,7 +3,7 @@ extern "C" { #include } #include -#include +#include #include "layout/exponent_layout.h" float Power::approximate(Context& context) const { @@ -24,11 +24,11 @@ Expression * Power::evaluateOnMatrixAndFloat(Matrix * m, Float * a, Context& con Expression * operands[2]; operands[0] = result; operands[1] = m; - Expression * product = new Product(operands, true); - Expression * newResult = product->evaluate(context); + Expression * multiplication = new Multiplication(operands, true); + Expression * newResult = multiplication->evaluate(context); delete result; result = newResult; - delete product; + delete multiplication; } return result; } diff --git a/poincare/src/simplify/expression_builder.cpp b/poincare/src/simplify/expression_builder.cpp index 123136f16..da5cff6bc 100644 --- a/poincare/src/simplify/expression_builder.cpp +++ b/poincare/src/simplify/expression_builder.cpp @@ -1,7 +1,7 @@ #include "expression_builder.h" #include #include -#include +#include #include extern "C" { #include @@ -36,10 +36,10 @@ Expression * ExpressionBuilder::build(ExpressionMatch matches[]) { * before. */ result = new Addition(children_expressions, numberOfChildrenExpressions, false); break; - case Expression::Type::Product: + case Expression::Type::Multiplication: /* The children do not need to be cloned as they already have been * before. */ - result = new Product(children_expressions, false); + result = new Multiplication(children_expressions, false); break; default: assert(false); diff --git a/poincare/src/simplify/rules.pr b/poincare/src/simplify/rules.pr index 6df7b14ce..36f342187 100644 --- a/poincare/src/simplify/rules.pr +++ b/poincare/src/simplify/rules.pr @@ -2,19 +2,19 @@ Addition(Addition(a*),b*)->Addition(a*,b*); Addition(Integer.a,Integer.b)->$AddIntegers(a,b); Addition(Integer.a,Integer.b,c*)->Addition($AddIntegers(a,b),c*); -Subtraction(a,b)->Addition(a,Product(b,Integer[-1])); -Addition(a, Product(a,Integer[-1]))->Integer[0]; -Addition(a, Product(a,Integer[-1]), b)->b; -Addition(a, Product(a,Integer[-1]), b, c*)->Addition(b,c*); +Subtraction(a,b)->Addition(a,Multiplication(b,Integer[-1])); +Addition(a, Multiplication(a,Integer[-1]))->Integer[0]; +Addition(a, Multiplication(a,Integer[-1]), b)->b; +Addition(a, Multiplication(a,Integer[-1]), b, c*)->Addition(b,c*); -Addition(a,a,b*)->Addition(Product(a,Integer[2]),b*); -Addition(a,Product(a,b),c*)->Addition(Product(a,Addition(b,Integer[1])),c*); -Addition(Product(a,b),Product(a,c),d*)->Addition(Product(a,Addition(b,c)),d*); -Addition(a,a)->Product(a,Integer[2]); -Addition(a,Product(a,b))->Product(a,Addition(b,Integer[1])); -Addition(Product(a,b),Product(a,c))->Product(a,Addition(b,c)); +Addition(a,a,b*)->Addition(Multiplication(a,Integer[2]),b*); +Addition(a,Multiplication(a,b),c*)->Addition(Multiplication(a,Addition(b,Integer[1])),c*); +Addition(Multiplication(a,b),Multiplication(a,c),d*)->Addition(Multiplication(a,Addition(b,c)),d*); +Addition(a,a)->Multiplication(a,Integer[2]); +Addition(a,Multiplication(a,b))->Multiplication(a,Addition(b,Integer[1])); +Addition(Multiplication(a,b),Multiplication(a,c))->Multiplication(a,Addition(b,c)); -Product(Product(a*),b*)->Product(a*,b*); -Product(Integer[0],a*)->Integer[0]; -Product(Integer.a,Integer.b)->$MultiplyIntegers(a,b); -Product(Integer.a,Integer.b,c*)->Product($MultiplyIntegers(a,b),c*); +Multiplication(Multiplication(a*),b*)->Multiplication(a*,b*); +Multiplication(Integer[0],a*)->Integer[0]; +Multiplication(Integer.a,Integer.b)->$MultiplyIntegers(a,b); +Multiplication(Integer.a,Integer.b,c*)->Multiplication($MultiplyIntegers(a,b),c*);