mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +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 false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return !(expression.isUninitialized() || expression.type() == ExpressionNode::Type::Equal);
|
return !expression.isUninitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::didBecomeActive(Window * window) {
|
void App::didBecomeActive(Window * window) {
|
||||||
|
|||||||
@@ -31,9 +31,13 @@ void FunctionApp::willBecomeInactive() {
|
|||||||
::App::willBecomeInactive();
|
::App::willBecomeInactive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FunctionApp::isAcceptableExpression(const Poincare::Expression expression) {
|
||||||
bool FunctionApp::isAcceptableExpression(const Expression exp) {
|
/* We forbid functions whose type is equal because the input "2+f(3)" would be
|
||||||
return TextFieldDelegateApp::isAcceptableExpression(exp) && ExpressionCanBeSerialized(exp, false, Expression(), localContext());
|
* 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) {
|
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) {
|
bool TextFieldDelegateApp::ExpressionCanBeSerialized(const Expression expression, bool replaceAns, Expression ansExpression, Context * context) {
|
||||||
|
|||||||
@@ -68,10 +68,4 @@ void App::willBecomeInactive() {
|
|||||||
::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;
|
void willBecomeInactive() override;
|
||||||
TELEMETRY_ID("Solver");
|
TELEMETRY_ID("Solver");
|
||||||
private:
|
private:
|
||||||
// TextFieldDelegateApp
|
|
||||||
bool isAcceptableExpression(const Poincare::Expression expression) override;
|
|
||||||
|
|
||||||
App(Snapshot * snapshot);
|
App(Snapshot * snapshot);
|
||||||
SolutionsController m_solutionsController;
|
SolutionsController m_solutionsController;
|
||||||
IntervalController m_intervalController;
|
IntervalController m_intervalController;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
// For the equation A = B, create the reduced expression A-B
|
// 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 standardEquation(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Preferences::UnitFormat unitFormat, ExpressionNode::ReductionTarget reductionTarget) const;
|
||||||
// Expression
|
// Expression
|
||||||
Expression shallowReduce();
|
Expression shallowReduce(ExpressionNode::ReductionContext reductionContext);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ extern "C" {
|
|||||||
namespace Poincare {
|
namespace Poincare {
|
||||||
|
|
||||||
Expression EqualNode::shallowReduce(ReductionContext reductionContext) {
|
Expression EqualNode::shallowReduce(ReductionContext reductionContext) {
|
||||||
return Equal(this).shallowReduce();
|
return Equal(this).shallowReduce(reductionContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
Layout EqualNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
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));
|
return sub.reduce(ExpressionNode::ReductionContext(context, complexFormat, angleUnit, unitFormat, reductionTarget));
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression Equal::shallowReduce() {
|
Expression Equal::shallowReduce(ExpressionNode::ReductionContext reductionContext) {
|
||||||
{
|
|
||||||
Expression e = Expression::defaultShallowReduce();
|
Expression e = Equal::Builder(Subtraction::Builder(childAtIndex(0).clone(), childAtIndex(1).clone()).shallowReduce(reductionContext), Rational::Builder(0));
|
||||||
if (e.isUndefined()) {
|
if (e.childAtIndex(0).isIdenticalTo(e.childAtIndex(1))) {
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (childAtIndex(0).isIdenticalTo(childAtIndex(1))) {
|
|
||||||
Expression result = Rational::Builder(1);
|
Expression result = Rational::Builder(1);
|
||||||
replaceWithInPlace(result);
|
replaceWithInPlace(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return *this;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user