mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Add unitFormat to ReductionContext
Change-Id: I1d3fcd2f47c973c041e1be84e9a902dd58de3562
This commit is contained in:
committed by
Émilie Feral
parent
6c676782aa
commit
fad375c11c
@@ -1,4 +1,5 @@
|
||||
#include "equation.h"
|
||||
#include <apps/global_preferences.h>
|
||||
#include <apps/shared/poincare_helpers.h>
|
||||
#include <poincare/constant.h>
|
||||
#include <poincare/empty_context.h>
|
||||
@@ -49,7 +50,7 @@ Expression Equation::Model::standardForm(const Storage::Record * record, Context
|
||||
*returnedExpression = Undefined::Builder();
|
||||
} else if (expressionRed.type() == ExpressionNode::Type::Equal) {
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
*returnedExpression = static_cast<const Equal&>(expressionRed).standardEquation(contextToUse, Expression::UpdatedComplexFormatWithExpressionInput(preferences->complexFormat(), expressionInputWithoutFunctions, contextToUse), preferences->angleUnit());
|
||||
*returnedExpression = static_cast<const Equal&>(expressionRed).standardEquation(contextToUse, Expression::UpdatedComplexFormatWithExpressionInput(preferences->complexFormat(), expressionInputWithoutFunctions, contextToUse), preferences->angleUnit(), GlobalPreferences::sharedGlobalPreferences()->unitFormat());
|
||||
} else {
|
||||
assert(expressionRed.type() == ExpressionNode::Type::Rational && static_cast<const Rational&>(expressionRed).isOne());
|
||||
// The equality was reduced which means the equality was always true.
|
||||
|
||||
@@ -180,7 +180,7 @@ EquationStore::Error EquationStore::privateExactSolve(Poincare::Context * contex
|
||||
bool isLinear = true; // Invalid the linear system if one equation is non-linear
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
for (int i = 0; i < numberOfDefinedModels(); i++) {
|
||||
isLinear = isLinear && modelForRecord(definedRecordAtIndex(i))->standardForm(context, replaceFunctionsButNotSymbols).getLinearCoefficients((char *)m_variables, Poincare::SymbolAbstract::k_maxNameSize, coefficients[i], &constants[i], context, updatedComplexFormat(context), preferences->angleUnit(), replaceFunctionsButNotSymbols ? ExpressionNode::SymbolicComputation::ReplaceDefinedFunctionsWithDefinitions : ExpressionNode::SymbolicComputation::ReplaceAllDefinedSymbolsWithDefinition);
|
||||
isLinear = isLinear && modelForRecord(definedRecordAtIndex(i))->standardForm(context, replaceFunctionsButNotSymbols).getLinearCoefficients((char *)m_variables, Poincare::SymbolAbstract::k_maxNameSize, coefficients[i], &constants[i], context, updatedComplexFormat(context), preferences->angleUnit(), GlobalPreferences::sharedGlobalPreferences()->unitFormat(), replaceFunctionsButNotSymbols ? ExpressionNode::SymbolicComputation::ReplaceDefinedFunctionsWithDefinitions : ExpressionNode::SymbolicComputation::ReplaceAllDefinedSymbolsWithDefinition);
|
||||
if (!isLinear) {
|
||||
// TODO: should we clean pool allocated memory if the system is not linear
|
||||
#if 0
|
||||
@@ -218,6 +218,7 @@ EquationStore::Error EquationStore::privateExactSolve(Poincare::Context * contex
|
||||
context,
|
||||
updatedComplexFormat(context),
|
||||
preferences->angleUnit(),
|
||||
GlobalPreferences::sharedGlobalPreferences()->unitFormat(),
|
||||
replaceFunctionsButNotSymbols ?
|
||||
ExpressionNode::SymbolicComputation::ReplaceDefinedFunctionsWithDefinitions :
|
||||
ExpressionNode::SymbolicComputation::ReplaceAllDefinedSymbolsWithDefinition);
|
||||
@@ -259,7 +260,7 @@ EquationStore::Error EquationStore::privateExactSolve(Poincare::Context * contex
|
||||
* solutions. */
|
||||
m_exactSolutionIdentity[solutionIndex] = forbidExactSolutions || strcmp(exactBuffer, approximateBuffer) == 0;
|
||||
if (!m_exactSolutionIdentity[solutionIndex]) {
|
||||
m_exactSolutionEquality[solutionIndex] = Expression::ParsedExpressionsAreEqual(exactBuffer, approximateBuffer, context, updatedComplexFormat(context), preferences->angleUnit());
|
||||
m_exactSolutionEquality[solutionIndex] = Expression::ParsedExpressionsAreEqual(exactBuffer, approximateBuffer, context, updatedComplexFormat(context), preferences->angleUnit(), GlobalPreferences::sharedGlobalPreferences()->unitFormat());
|
||||
}
|
||||
solutionIndex++;
|
||||
}
|
||||
@@ -269,6 +270,7 @@ EquationStore::Error EquationStore::privateExactSolve(Poincare::Context * contex
|
||||
|
||||
EquationStore::Error EquationStore::resolveLinearSystem(Expression exactSolutions[k_maxNumberOfExactSolutions], Expression exactSolutionsApproximations[k_maxNumberOfExactSolutions], Expression coefficients[k_maxNumberOfEquations][Expression::k_maxNumberOfVariables], Expression constants[k_maxNumberOfEquations], Context * context) {
|
||||
Preferences::AngleUnit angleUnit = Preferences::sharedPreferences()->angleUnit();
|
||||
Preferences::UnitFormat unitFormat = GlobalPreferences::sharedGlobalPreferences()->unitFormat();
|
||||
// n unknown variables
|
||||
int n = 0;
|
||||
while (n < Expression::k_maxNumberOfVariables && m_variables[n][0] != 0) {
|
||||
@@ -286,7 +288,7 @@ EquationStore::Error EquationStore::resolveLinearSystem(Expression exactSolution
|
||||
Ab.setDimensions(m, n+1);
|
||||
|
||||
// Compute the rank of (A | b)
|
||||
int rankAb = Ab.rank(context, updatedComplexFormat(context), angleUnit, true);
|
||||
int rankAb = Ab.rank(context, updatedComplexFormat(context), angleUnit, unitFormat, true);
|
||||
|
||||
// Initialize the number of solutions
|
||||
m_numberOfSolutions = INT_MAX;
|
||||
@@ -311,7 +313,7 @@ EquationStore::Error EquationStore::resolveLinearSystem(Expression exactSolution
|
||||
m_numberOfSolutions = n;
|
||||
for (int i = 0; i < m_numberOfSolutions; i++) {
|
||||
exactSolutions[i] = Ab.matrixChild(i,n);
|
||||
exactSolutions[i].simplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], context, updatedComplexFormat(context), Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
exactSolutions[i].simplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], context, updatedComplexFormat(context), angleUnit, unitFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -323,7 +325,7 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact
|
||||
assert(degree == 2);
|
||||
// Compute delta = b*b-4ac
|
||||
Expression delta = Subtraction::Builder(Power::Builder(coefficients[1].clone(), Rational::Builder(2)), Multiplication::Builder(Rational::Builder(4), coefficients[0].clone(), coefficients[2].clone()));
|
||||
delta = delta.simplify(ExpressionNode::ReductionContext(context, updatedComplexFormat(context), Poincare::Preferences::sharedPreferences()->angleUnit(), ExpressionNode::ReductionTarget::SystemForApproximation));
|
||||
delta = delta.simplify(ExpressionNode::ReductionContext(context, updatedComplexFormat(context), Poincare::Preferences::sharedPreferences()->angleUnit(), GlobalPreferences::sharedGlobalPreferences()->unitFormat(), ExpressionNode::ReductionTarget::SystemForApproximation));
|
||||
if (delta.isUninitialized()) {
|
||||
delta = Poincare::Undefined::Builder();
|
||||
}
|
||||
@@ -340,7 +342,7 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact
|
||||
}
|
||||
exactSolutions[m_numberOfSolutions-1] = delta;
|
||||
for (int i = 0; i < m_numberOfSolutions; i++) {
|
||||
exactSolutions[i].simplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], context, updatedComplexFormat(context), Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
exactSolutions[i].simplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], context, updatedComplexFormat(context), Poincare::Preferences::sharedPreferences()->angleUnit(), GlobalPreferences::sharedGlobalPreferences()->unitFormat());
|
||||
}
|
||||
return Error::NoError;
|
||||
#if 0
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <quiz.h>
|
||||
#include <apps/global_preferences.h>
|
||||
#include <apps/shared/global_context.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
@@ -147,7 +148,8 @@ void set(const char * variable, const char * value) {
|
||||
buffer,
|
||||
&globalContext,
|
||||
Preferences::sharedPreferences()->complexFormat(),
|
||||
Preferences::sharedPreferences()->angleUnit()
|
||||
Preferences::sharedPreferences()->angleUnit(),
|
||||
GlobalPreferences::sharedGlobalPreferences()->unitFormat()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user