mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[solver] Fix Equation with new Poincare APi
This commit is contained in:
@@ -6,7 +6,7 @@ namespace Solver {
|
||||
|
||||
Equation::Equation() :
|
||||
Shared::ExpressionModel(),
|
||||
m_standardForm(nullptr)
|
||||
m_standardForm()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -27,33 +27,28 @@ void Equation::setContent(const char * c) {
|
||||
|
||||
void Equation::tidy() {
|
||||
ExpressionModel::tidy();
|
||||
if (m_standardForm) {
|
||||
delete m_standardForm;
|
||||
m_standardForm = nullptr;
|
||||
}
|
||||
tidyStandardForm();
|
||||
}
|
||||
|
||||
Expression * Equation::standardForm(Context * context) const {
|
||||
if (m_standardForm == nullptr) {
|
||||
Expression * e = expression(context);
|
||||
if (e->type() == ExpressionNode::Type::Equal) {
|
||||
m_standardForm = static_cast<const Equal *>(e)->standardEquation(*context, Preferences::sharedPreferences()->angleUnit());
|
||||
} else if (e->type() == ExpressionNode::Type::Rational && static_cast<Rational *>(e)->isOne()) {
|
||||
Expression Equation::standardForm(Context * context) const {
|
||||
if (m_standardForm.isUninitialized()) {
|
||||
const Expression e = expression(context);
|
||||
if (e.type() == ExpressionNode::Type::Equal) {
|
||||
m_standardForm = static_cast<const Equal&>(e).standardEquation(*context, Preferences::sharedPreferences()->angleUnit());
|
||||
} else if (e.type() == ExpressionNode::Type::Rational && static_cast<const Rational&>(e).isOne()) {
|
||||
// The equality was reduced which means the equality was always true.
|
||||
m_standardForm = RationalReference(0);
|
||||
m_standardForm = Rational(0);
|
||||
} else {
|
||||
// The equality has an undefined operand
|
||||
assert(e->type() == ExpressionNode::Type::Undefined);
|
||||
assert(e.type() == ExpressionNode::Type::Undefined);
|
||||
}
|
||||
}
|
||||
return m_standardForm;
|
||||
}
|
||||
|
||||
void Equation::tidyStandardForm() {
|
||||
if (m_standardForm) {
|
||||
delete m_standardForm;
|
||||
m_standardForm = nullptr;
|
||||
}
|
||||
// Free the pool of the m_standardForm
|
||||
m_standardForm = Expression();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ public:
|
||||
bool shouldBeClearedBeforeRemove() override {
|
||||
return false;
|
||||
}
|
||||
Poincare::Expression * standardForm(Poincare::Context * context) const;
|
||||
Poincare::Expression standardForm(Poincare::Context * context) const;
|
||||
private:
|
||||
void tidyStandardForm();
|
||||
mutable Poincare::Expression * m_standardForm;
|
||||
mutable Poincare::Expression m_standardForm;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ public:
|
||||
// ExpressionNode
|
||||
Type type() const override { return Type::Equal; }
|
||||
int polynomialDegree(char symbolName) const override { return -1; }
|
||||
// For the equation A = B, create the reduced expression A-B
|
||||
Expression standardEquation(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
private:
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
@@ -42,6 +40,8 @@ public:
|
||||
replaceChildAtIndexInPlace(1, child2);
|
||||
}
|
||||
|
||||
// For the equation A = B, create the reduced expression A-B
|
||||
Expression standardEquation(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
};
|
||||
|
||||
@@ -19,11 +19,6 @@ extern "C" {
|
||||
}
|
||||
namespace Poincare {
|
||||
|
||||
Expression EqualNode::standardEquation(Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
Expression sub = Subtraction(Expression(childAtIndex(0)).clone(), Expression(childAtIndex(1)).clone());
|
||||
return sub.deepReduce(context, angleUnit);
|
||||
}
|
||||
|
||||
Expression EqualNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
return Equal(this).shallowReduce(context, angleUnit);
|
||||
}
|
||||
@@ -45,6 +40,11 @@ Evaluation<T> EqualNode::templatedApproximate(Context& context, Preferences::Ang
|
||||
return Complex<T>::Undefined();
|
||||
}
|
||||
|
||||
Expression Equal::standardEquation(Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
Expression sub = Subtraction(childAtIndex(0).clone(), childAtIndex(1).clone());
|
||||
return sub.deepReduce(context, angleUnit);
|
||||
}
|
||||
|
||||
Expression Equal::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
|
||||
Reference in New Issue
Block a user