mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 08:47:28 +01:00
[poincare] Create a a flag on Expression that is set when the
approximation encouters a complex value All approximation methods take the complex format into account.
This commit is contained in:
@@ -19,7 +19,8 @@ double Model::levelSet(double * modelCoefficients, double xMin, double step, dou
|
||||
Expression yExpression = Number::DecimalNumber(y);
|
||||
PoincareHelpers::Simplify(&yExpression, *context);
|
||||
Expression modelExpression = simplifiedExpression(modelCoefficients, context);
|
||||
double result = modelExpression.nextIntersection("x", xMin, step, xMax, *context, Preferences::sharedPreferences()->angleUnit(), yExpression).abscissa;
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
double result = modelExpression.nextIntersection("x", xMin, step, xMax, *context, preferences->complexFormat(), preferences->angleUnit(), yExpression).abscissa;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -251,13 +251,12 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx) const {
|
||||
Poincare::Symbol vn1Symbol("v(n+1)", 6);
|
||||
Poincare::Symbol unSymbol("u(n)", 4);
|
||||
Poincare::Symbol un1Symbol("u(n+1)", 6);
|
||||
Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
switch (m_type) {
|
||||
case Type::Explicit:
|
||||
{
|
||||
ctx.setValueForSymbol(un, unSymbol);
|
||||
ctx.setValueForSymbol(vn, vnSymbol);
|
||||
return expression(sqctx).approximateWithValueForSymbol(symbol(), (T)n, ctx, preferences->angleUnit());
|
||||
return PoincareHelpers::ApproximateWithValueForSymbol(expression(sqctx), symbol(), (T)n, ctx);
|
||||
}
|
||||
case Type::SingleRecurrence:
|
||||
{
|
||||
@@ -268,7 +267,7 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx) const {
|
||||
ctx.setValueForSymbol(unm1, unSymbol);
|
||||
ctx.setValueForSymbol(vn, vn1Symbol);
|
||||
ctx.setValueForSymbol(vnm1, vnSymbol);
|
||||
return expression(sqctx).approximateWithValueForSymbol(symbol(), (T)(n-1), ctx, preferences->angleUnit());
|
||||
return PoincareHelpers::ApproximateWithValueForSymbol(expression(sqctx), symbol(), (T)(n-1), ctx);
|
||||
}
|
||||
default:
|
||||
{
|
||||
@@ -282,7 +281,7 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx) const {
|
||||
ctx.setValueForSymbol(unm2, unSymbol);
|
||||
ctx.setValueForSymbol(vnm1, vn1Symbol);
|
||||
ctx.setValueForSymbol(vnm2, vnSymbol);
|
||||
return expression(sqctx).approximateWithValueForSymbol(symbol(), (T)(n-2), ctx, preferences->angleUnit());
|
||||
return PoincareHelpers::ApproximateWithValueForSymbol(expression(sqctx), symbol(), (T)(n-2), ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "function.h"
|
||||
#include "poincare_helpers.h"
|
||||
#include <string.h>
|
||||
#include <cmath>
|
||||
#include <assert.h>
|
||||
@@ -41,7 +42,7 @@ void Function::setActive(bool active) {
|
||||
|
||||
template<typename T>
|
||||
T Function::templatedApproximateAtAbscissa(T x, Poincare::Context * context) const {
|
||||
return expression(context).approximateWithValueForSymbol(symbol(), x, *context, Preferences::sharedPreferences()->angleUnit());
|
||||
return PoincareHelpers::ApproximateWithValueForSymbol(expression(context), symbol(), x, *context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace Shared {
|
||||
namespace PoincareHelpers {
|
||||
|
||||
inline Poincare::Layout CreateLayout(const Poincare::Expression e) {
|
||||
return e.createLayout(Poincare::Preferences::sharedPreferences()->displayMode(), Poincare::Preferences::sharedPreferences()->numberOfSignificantDigits());
|
||||
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
return e.createLayout(preferences->displayMode(), preferences->numberOfSignificantDigits());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -24,25 +25,39 @@ inline int Serialize(const Poincare::Expression e, char * buffer, int bufferSize
|
||||
|
||||
template <class T>
|
||||
inline Poincare::Expression Approximate(const Poincare::Expression e, Poincare::Context & context) {
|
||||
Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat();
|
||||
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
Poincare::Preferences::ComplexFormat complexFormat = preferences->complexFormat();
|
||||
complexFormat = Poincare::Expression::UpdatedComplexFormatWithExpressionInput(complexFormat, e, context);
|
||||
return e.approximate<T>(context, complexFormat, Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
return e.approximate<T>(context, complexFormat, preferences->angleUnit());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T ApproximateToScalar(const Poincare::Expression e, Poincare::Context & context) {
|
||||
return e.approximateToScalar<T>(context, Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
Poincare::Preferences::ComplexFormat complexFormat = preferences->complexFormat();
|
||||
complexFormat = Poincare::Expression::UpdatedComplexFormatWithExpressionInput(complexFormat, e, context);
|
||||
return e.approximateToScalar<T>(context, complexFormat, preferences->angleUnit());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T ApproximateWithValueForSymbol(const Poincare::Expression e, const char * symbol, T x, Poincare::Context & context) {
|
||||
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
Poincare::Preferences::ComplexFormat complexFormat = preferences->complexFormat();
|
||||
complexFormat = Poincare::Expression::UpdatedComplexFormatWithExpressionInput(complexFormat, e, context);
|
||||
return e.approximateWithValueForSymbol<T>(symbol, x, context, complexFormat, preferences->angleUnit());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T ApproximateToScalar(const char * text, Poincare::Context & context) {
|
||||
Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat();
|
||||
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
Poincare::Preferences::ComplexFormat complexFormat = preferences->complexFormat();
|
||||
complexFormat = Poincare::Expression::UpdatedComplexFormatWithTextInput(complexFormat, text);
|
||||
return Poincare::Expression::approximateToScalar<T>(text, context, complexFormat, Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
return Poincare::Expression::approximateToScalar<T>(text, context, complexFormat, preferences->angleUnit());
|
||||
}
|
||||
|
||||
inline Poincare::Expression ParseAndSimplify(const char * text, Poincare::Context & context) {
|
||||
return Poincare::Expression::ParseAndSimplify(text, context, Poincare::Preferences::sharedPreferences()->complexFormat(), Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
return Poincare::Expression::ParseAndSimplify(text, context, preferences->complexFormat(), preferences->angleUnit());
|
||||
}
|
||||
|
||||
inline void Simplify(Poincare::Expression * e, Poincare::Context & context, Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat()) {
|
||||
@@ -51,7 +66,8 @@ inline void Simplify(Poincare::Expression * e, Poincare::Context & context, Poin
|
||||
}
|
||||
|
||||
inline void ParseAndSimplifyAndApproximate(const char * text, Poincare::Expression * simplifiedExpression, Poincare::Expression * approximateExpression, Poincare::Context & context) {
|
||||
Poincare::Expression::ParseAndSimplifyAndApproximate(text, simplifiedExpression, approximateExpression, context, Poincare::Preferences::sharedPreferences()->complexFormat(), Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
Poincare::Expression::ParseAndSimplifyAndApproximate(text, simplifiedExpression, approximateExpression, context, preferences->complexFormat(), preferences->angleUnit());
|
||||
}
|
||||
|
||||
inline void SimplifyAndApproximate(Poincare::Expression * e, Poincare::Expression * approximate, Poincare::Context & context, Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat()) {
|
||||
|
||||
@@ -103,22 +103,26 @@ double StorageCartesianFunction::sumBetweenBounds(double start, double end, Poin
|
||||
|
||||
Expression::Coordinate2D StorageCartesianFunction::nextMinimumFrom(double start, double step, double max, Context * context) const {
|
||||
const char unknownX[2] = {Poincare::Symbol::UnknownX, 0};
|
||||
return expressionReduced(context).nextMinimum(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit());
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
return expressionReduced(context).nextMinimum(unknownX, start, step, max, *context, preferences->complexFormat(), preferences->angleUnit());
|
||||
}
|
||||
|
||||
Expression::Coordinate2D StorageCartesianFunction::nextMaximumFrom(double start, double step, double max, Context * context) const {
|
||||
const char unknownX[2] = {Poincare::Symbol::UnknownX, 0};
|
||||
return expressionReduced(context).nextMaximum(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit());
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
return expressionReduced(context).nextMaximum(unknownX, start, step, max, *context, preferences->complexFormat(), preferences->angleUnit());
|
||||
}
|
||||
|
||||
double StorageCartesianFunction::nextRootFrom(double start, double step, double max, Context * context) const {
|
||||
const char unknownX[2] = {Poincare::Symbol::UnknownX, 0};
|
||||
return expressionReduced(context).nextRoot(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit());
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
return expressionReduced(context).nextRoot(unknownX, start, step, max, *context, preferences->complexFormat(), preferences->angleUnit());
|
||||
}
|
||||
|
||||
Expression::Coordinate2D StorageCartesianFunction::nextIntersectionFrom(double start, double step, double max, Poincare::Context * context, Expression e) const {
|
||||
const char unknownX[2] = {Poincare::Symbol::UnknownX, 0};
|
||||
return expressionReduced(context).nextIntersection(unknownX, start, step, max, *context, Preferences::sharedPreferences()->angleUnit(), e);
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
return expressionReduced(context).nextIntersection(unknownX, start, step, max, *context, preferences->complexFormat(), preferences->angleUnit(), e);
|
||||
}
|
||||
|
||||
StorageCartesianFunction::CartesianFunctionRecordData * StorageCartesianFunction::recordData() const {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "storage_function.h"
|
||||
#include "poincare_helpers.h"
|
||||
#include <poincare/symbol.h>
|
||||
#include "poincare/src/parsing/parser.h"
|
||||
#include <string.h>
|
||||
@@ -76,7 +77,7 @@ T StorageFunction::templatedApproximateAtAbscissa(T x, Poincare::Context * conte
|
||||
return NAN;
|
||||
}
|
||||
const char unknownX[2] = {Poincare::Symbol::UnknownX, 0};
|
||||
return expressionReduced(context).approximateWithValueForSymbol(unknownX, x, *context, Preferences::sharedPreferences()->angleUnit());
|
||||
return PoincareHelpers::ApproximateWithValueForSymbol(expressionReduced(context), unknownX, x, *context);
|
||||
}
|
||||
|
||||
StorageFunction::FunctionRecordData * StorageFunction::recordData() const {
|
||||
|
||||
@@ -78,7 +78,8 @@ bool EquationStore::haveMoreApproximationSolutions(Context * context) {
|
||||
return false;
|
||||
}
|
||||
double step = (m_intervalApproximateSolutions[1]-m_intervalApproximateSolutions[0])*k_precision;
|
||||
return !std::isnan(definedModelAtIndex(0)->standardForm(context).nextRoot(m_variables[0], m_approximateSolutions[m_numberOfSolutions-1], step, m_intervalApproximateSolutions[1], *context, Preferences::sharedPreferences()->angleUnit()));
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
return !std::isnan(definedModelAtIndex(0)->standardForm(context).nextRoot(m_variables[0], m_approximateSolutions[m_numberOfSolutions-1], step, m_intervalApproximateSolutions[1], *context, preferences->complexFormat(), preferences->angleUnit()));
|
||||
}
|
||||
|
||||
void EquationStore::approximateSolve(Poincare::Context * context) {
|
||||
@@ -87,8 +88,9 @@ void EquationStore::approximateSolve(Poincare::Context * context) {
|
||||
m_numberOfSolutions = 0;
|
||||
double start = m_intervalApproximateSolutions[0];
|
||||
double step = (m_intervalApproximateSolutions[1]-m_intervalApproximateSolutions[0])*k_precision;
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
for (int i = 0; i < k_maxNumberOfApproximateSolutions; i++) {
|
||||
m_approximateSolutions[i] = definedModelAtIndex(0)->standardForm(context).nextRoot(m_variables[0], start, step, m_intervalApproximateSolutions[1], *context, Preferences::sharedPreferences()->angleUnit());
|
||||
m_approximateSolutions[i] = definedModelAtIndex(0)->standardForm(context).nextRoot(m_variables[0], start, step, m_intervalApproximateSolutions[1], *context, preferences->complexFormat(), preferences->angleUnit());
|
||||
if (std::isnan(m_approximateSolutions[i])) {
|
||||
break;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user