mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Add multiplication rules.
Change-Id: I5e91414e8c6ad45e0ff2d19fc7c5dc3914fa247a
This commit is contained in:
@@ -3,3 +3,5 @@ Addition(Integer.a,Integer.b)->$AddIntegers(a,b);
|
||||
Addition(Integer.a,Integer.b,c*)->Addition($AddIntegers(a,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*);
|
||||
|
||||
@@ -8,8 +8,22 @@ Expression * SimplificationGenerator::AddIntegers(Expression ** parameters, int
|
||||
Integer * result = new Integer((native_int_t)0);
|
||||
for (int i=0; i<numberOfParameters; i++) {
|
||||
assert(parameters[i]->type() == Expression::Type::Integer);
|
||||
// FIXME: get rid of this operator overloading.
|
||||
*result = *result + *(Integer *)parameters[i];
|
||||
*result = result->add(*(Integer *)parameters[i], false);
|
||||
/* Note We have to delete the parameters as they have been cloned before and
|
||||
* we are the last ones to use them here. */
|
||||
delete parameters[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Expression * SimplificationGenerator::MultiplyIntegers(Expression ** parameters, int numberOfParameters) {
|
||||
Integer * result = new Integer((native_int_t)1);
|
||||
for (int i=0; i<numberOfParameters; i++) {
|
||||
assert(parameters[i]->type() == Expression::Type::Integer);
|
||||
// FIXME: get rid of this operator overloading, there are to many stars.
|
||||
*result = *result * *(Integer *)parameters[i];
|
||||
/* Note We have to delete the parameters as they have been cloned before and
|
||||
* we are the last ones to use them here. */
|
||||
delete parameters[i];
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
class SimplificationGenerator {
|
||||
public:
|
||||
static Expression * AddIntegers(Expression ** parameters, int numberOfParameters);
|
||||
static Expression * MultiplyIntegers(Expression ** parameters, int numberOfParameters);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
QUIZ_CASE(poincare_simplify_product_by_zero) {
|
||||
assert(simplifies_to("3*0", "0"));
|
||||
assert(simplifies_to("foo*0", "0"));
|
||||
|
||||
assert(simplifies_to("0*3", "0"));
|
||||
assert(simplifies_to("0*foo", "0"));
|
||||
|
||||
assert(simplifies_to("3*5", "15"));
|
||||
assert(simplifies_to("8*6", "48"));
|
||||
|
||||
assert(simplifies_to("3*(5+4)", "27"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user