mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-23 15:50:49 +01:00
[poincare] Fix simplification engine and add tests
Change-Id: Ibde03afc9036baf8562c8c635874f4188e1f7f6d
This commit is contained in:
@@ -7,8 +7,10 @@ Expression * SimplificationEngine::map(Expression * e, Context & context, Expres
|
||||
Expression * op = e->editableOperand(0);
|
||||
for (int i = 0; i < op->numberOfOperands(); i++) {
|
||||
Expression * entry = op->editableOperand(i);
|
||||
e->replaceOperand(op, entry, false);
|
||||
op->replaceOperand(entry, op, false);
|
||||
Expression * eCopy = e->clone();
|
||||
eCopy->replaceOperand(eCopy->editableOperand(0), entry, true);
|
||||
op->replaceOperand(entry, eCopy, false);
|
||||
eCopy->shallowReduce(context, angleUnit);
|
||||
}
|
||||
return e->replaceWith(op, true)->shallowReduce(context, angleUnit);
|
||||
}
|
||||
|
||||
@@ -55,6 +55,13 @@ QUIZ_CASE(poincare_simplify_easy) {
|
||||
assert_parsed_expression_simplify_to("[[1,2,3][4,5,6][7,8,9]]^(-1)", "undef");
|
||||
assert_parsed_expression_simplify_to("[[1,2][3,4]]^(-1)", "[[-2,1][3/2,-1/2]]");
|
||||
|
||||
// Function on matrix
|
||||
assert_parsed_expression_simplify_to("abs([[1,-2][3,4]])", "[[1,2][3,4]]");
|
||||
assert_parsed_expression_simplify_to("acos([[1/R(2),1/2][1,-1]])", "[[P/4,P/3][0,P]]");
|
||||
assert_parsed_expression_simplify_to("asin([[1/R(2),1/2][1,-1]])", "[[P/4,P/6][P/2,-P/2]]");
|
||||
assert_parsed_expression_simplify_to("atan([[R(3),1][1/R(3),-1]])", "[[P/3,P/4][P/6,-P/4]]");
|
||||
assert_parsed_expression_simplify_to("acos([[1/R(2),1/2][1,-1]])", "[[P/4,P/3][0,P]]");
|
||||
|
||||
assert_parsed_expression_simplify_to("1*tan(2)*tan(5)", "tan(2)*tan(5)");
|
||||
assert_parsed_expression_simplify_to("P+(3R(2)-2R(3))/25", "(3R(2)-2R(3)+25P)/25");
|
||||
assert_parsed_expression_simplify_to("-1/3", "-1/3");
|
||||
|
||||
Reference in New Issue
Block a user