mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[calculation][poincare] Revert 'b8544e3' and improve equal simplification
This commit is contained in:
@@ -72,7 +72,7 @@ bool App::isAcceptableExpression(const Poincare::Expression expression) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !(expression.isUninitialized() || expression.type() == ExpressionNode::Type::Equal);
|
||||
return !expression.isUninitialized();
|
||||
}
|
||||
|
||||
void App::didBecomeActive(Window * window) {
|
||||
|
||||
@@ -31,9 +31,13 @@ void FunctionApp::willBecomeInactive() {
|
||||
::App::willBecomeInactive();
|
||||
}
|
||||
|
||||
|
||||
bool FunctionApp::isAcceptableExpression(const Expression exp) {
|
||||
return TextFieldDelegateApp::isAcceptableExpression(exp) && ExpressionCanBeSerialized(exp, false, Expression(), localContext());
|
||||
bool FunctionApp::isAcceptableExpression(const Poincare::Expression expression) {
|
||||
/* We forbid functions whose type is equal because the input "2+f(3)" would be
|
||||
* simplify to an expression with an nested equal node which makes no sense. */
|
||||
if (!TextFieldDelegateApp::ExpressionCanBeSerialized(expression, false, Expression(), localContext()) || expression.type() == ExpressionNode::Type::Equal) {
|
||||
return false;
|
||||
}
|
||||
return TextFieldDelegateApp::isAcceptableExpression(expression);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -85,7 +85,13 @@ bool TextFieldDelegateApp::isFinishingEvent(Ion::Events::Event event) {
|
||||
}
|
||||
|
||||
bool TextFieldDelegateApp::isAcceptableExpression(const Expression exp) {
|
||||
return !(exp.isUninitialized() || exp.type() == ExpressionNode::Type::Store || exp.type() == ExpressionNode::Type::Equal);
|
||||
if (exp.isUninitialized()) {
|
||||
return false;
|
||||
}
|
||||
if (exp.type() == ExpressionNode::Type::Store) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TextFieldDelegateApp::ExpressionCanBeSerialized(const Expression expression, bool replaceAns, Expression ansExpression, Context * context) {
|
||||
|
||||
@@ -68,10 +68,4 @@ void App::willBecomeInactive() {
|
||||
::App::willBecomeInactive();
|
||||
}
|
||||
|
||||
|
||||
bool App::isAcceptableExpression(const Poincare::Expression exp) {
|
||||
return TextFieldDelegateApp::ExpressionCanBeSerialized(exp, false, Poincare::Expression(), localContext())
|
||||
&& !(exp.isUninitialized() || exp.type() == Poincare::ExpressionNode::Type::Store);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,9 +47,6 @@ public:
|
||||
void willBecomeInactive() override;
|
||||
TELEMETRY_ID("Solver");
|
||||
private:
|
||||
// TextFieldDelegateApp
|
||||
bool isAcceptableExpression(const Poincare::Expression expression) override;
|
||||
|
||||
App(Snapshot * snapshot);
|
||||
SolutionsController m_solutionsController;
|
||||
IntervalController m_intervalController;
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
// For the equation A = B, create the reduced expression A-B
|
||||
Expression standardEquation(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Preferences::UnitFormat unitFormat, ExpressionNode::ReductionTarget reductionTarget) const;
|
||||
// Expression
|
||||
Expression shallowReduce();
|
||||
Expression shallowReduce(ExpressionNode::ReductionContext reductionContext);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ extern "C" {
|
||||
namespace Poincare {
|
||||
|
||||
Expression EqualNode::shallowReduce(ReductionContext reductionContext) {
|
||||
return Equal(this).shallowReduce();
|
||||
return Equal(this).shallowReduce(reductionContext);
|
||||
}
|
||||
|
||||
Layout EqualNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
@@ -49,19 +49,15 @@ Expression Equal::standardEquation(Context * context, Preferences::ComplexFormat
|
||||
return sub.reduce(ExpressionNode::ReductionContext(context, complexFormat, angleUnit, unitFormat, reductionTarget));
|
||||
}
|
||||
|
||||
Expression Equal::shallowReduce() {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
if (childAtIndex(0).isIdenticalTo(childAtIndex(1))) {
|
||||
Expression Equal::shallowReduce(ExpressionNode::ReductionContext reductionContext) {
|
||||
|
||||
Expression e = Equal::Builder(Subtraction::Builder(childAtIndex(0).clone(), childAtIndex(1).clone()).shallowReduce(reductionContext), Rational::Builder(0));
|
||||
if (e.childAtIndex(0).isIdenticalTo(e.childAtIndex(1))) {
|
||||
Expression result = Rational::Builder(1);
|
||||
replaceWithInPlace(result);
|
||||
return result;
|
||||
}
|
||||
return *this;
|
||||
return e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user