mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-23 07:40:42 +01:00
[poincare] Clean
Change-Id: I6a582a850f440572c99fe215167747626de6da8c
This commit is contained in:
@@ -142,7 +142,7 @@ void Addition::factorizeChildren(Expression * e1, Expression * e2, Context & con
|
||||
}
|
||||
|
||||
const Rational Addition::RationalFactor(Expression * e) {
|
||||
if (e->type() == Type::Multiplication && e->operand(0)->type() == Type::Rational) { // TODO: change integer for Rational
|
||||
if (e->type() == Type::Multiplication && e->operand(0)->type() == Type::Rational) {
|
||||
return *(static_cast<const Rational *>(e->operand(0)));
|
||||
}
|
||||
return Rational(Integer(1));
|
||||
|
||||
@@ -84,6 +84,36 @@ void DynamicHierarchy::removeOperand(const Expression * e, bool deleteAfterRemov
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DynamicHierarchy::sortOperands(ExpressionOrder order) {
|
||||
for (int i = numberOfOperands()-1; i > 0; i--) {
|
||||
bool isSorted = true;
|
||||
for (int j = 0; j < numberOfOperands()-1; j++) {
|
||||
if (order(operand(j), operand(j+1)) > 0) {
|
||||
swapOperands(j, j+1);
|
||||
isSorted = false;
|
||||
}
|
||||
}
|
||||
if (isSorted) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Expression * DynamicHierarchy::squashUnaryHierarchy() {
|
||||
if (numberOfOperands() == 1) {
|
||||
assert(parent() != nullptr);
|
||||
Expression * o = editableOperand(0);
|
||||
replaceWith(o, true);
|
||||
return o;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
void DynamicHierarchy::removeOperandAtIndex(int i, bool deleteAfterRemoval) {
|
||||
if (deleteAfterRemoval) {
|
||||
delete m_operands[i];
|
||||
@@ -130,29 +160,4 @@ int DynamicHierarchy::simplificationOrderGreaterType(const Expression * e) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DynamicHierarchy::sortOperands(ExpressionOrder order) {
|
||||
for (int i = numberOfOperands()-1; i > 0; i--) {
|
||||
bool isSorted = true;
|
||||
for (int j = 0; j < numberOfOperands()-1; j++) {
|
||||
if (order(operand(j), operand(j+1)) > 0) {
|
||||
swapOperands(j, j+1);
|
||||
isSorted = false;
|
||||
}
|
||||
}
|
||||
if (isSorted) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Expression * DynamicHierarchy::squashUnaryHierarchy() {
|
||||
if (numberOfOperands() == 1) {
|
||||
assert(parent() != nullptr);
|
||||
Expression * o = editableOperand(0);
|
||||
replaceWith(o, true);
|
||||
return o;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user