[poincare] Complete implementation of AbsoluteValue::immediateSimplify

Change-Id: Iedc4d680ad8861932af96a5ec6f3a2289db9f346
This commit is contained in:
Émilie Feral
2017-10-17 11:34:33 +02:00
parent 7228e806db
commit 7fee8daccb
2 changed files with 6 additions and 0 deletions

View File

@@ -22,6 +22,11 @@ Expression * AbsoluteValue::immediateSimplify() {
if (operand(0)->sign() > 0) {
return replaceWith(const_cast<Expression *>(operand(0)), true);
}
if (operand(0)->sign() < 0) {
Expression * op = const_cast<Expression *>(operand(0));
Expression * newOp = op->turnIntoPositive();
return replaceWith(newOp, true);
}
return this;
}

View File

@@ -110,6 +110,7 @@ QUIZ_CASE(poincare_simplify_easy) {
assert_parsed_expression_simplify_to("R(x*144*P^2)", "12*P*R(x)");
assert_parsed_expression_simplify_to("R(x*144*P)", "12*R(xP)");
assert_parsed_expression_simplify_to("abs(P)", "P");
assert_parsed_expression_simplify_to("abs(-P)", "P");
assert_parsed_expression_simplify_to("R(2)*R(3)", "R(6)");
assert_parsed_expression_simplify_to("2*2^P", "2*2^P");
assert_parsed_expression_simplify_to("A-A", "0");