mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Change the way Expression are built
This commit is contained in:
committed by
LeaNumworks
parent
902dda34d6
commit
7b5f3c570d
@@ -125,7 +125,7 @@ Expression Calculation::exactOutput() {
|
||||
* 'cos(pi/4) = 0.999906' (which is true in degree). */
|
||||
Expression exactOutput = Expression::Parse(m_exactOutputText);
|
||||
if (exactOutput.isUninitialized()) {
|
||||
return Undefined();
|
||||
return Undefined::Builder();
|
||||
}
|
||||
return exactOutput;
|
||||
}
|
||||
@@ -178,7 +178,7 @@ Calculation::EqualSign Calculation::exactAndApproximateDisplayedOutputsAreEqual(
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
Expression exactOutputExpression = PoincareHelpers::ParseAndSimplify(m_exactOutputText, *context);
|
||||
if (exactOutputExpression.isUninitialized()) {
|
||||
exactOutputExpression = Undefined();
|
||||
exactOutputExpression = Undefined::Builder();
|
||||
}
|
||||
Preferences::ComplexFormat complexFormat = Expression::UpdatedComplexFormatWithTextInput(preferences->complexFormat(), m_inputText);
|
||||
m_equalSign = exactOutputExpression.isEqualToItsApproximationLayout(approximateOutput(context), buffer, bufferSize, complexFormat, preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context) ? EqualSign::Equal : EqualSign::Approximation;
|
||||
|
||||
@@ -88,7 +88,7 @@ void CalculationStore::tidy() {
|
||||
|
||||
Expression CalculationStore::ansExpression(Context * context) {
|
||||
if (numberOfCalculations() == 0) {
|
||||
return Rational(0);
|
||||
return Rational::Builder(0);
|
||||
}
|
||||
Calculation * lastCalculation = calculationAtIndex(numberOfCalculations()-1);
|
||||
/* Special case: the exact output is a Store/Equal expression.
|
||||
|
||||
@@ -25,7 +25,7 @@ CalculationController::CalculationController(Responder * parentResponder, Button
|
||||
m_hideableCell(),
|
||||
m_store(store)
|
||||
{
|
||||
m_r2Layout = HorizontalLayout::Builder(CharLayout('r', KDFont::SmallFont), VerticalOffsetLayout::Builder(CharLayout('2', KDFont::SmallFont), VerticalOffsetLayoutNode::Type::Superscript));
|
||||
m_r2Layout = HorizontalLayout::Builder(CharLayout::Builder('r', KDFont::SmallFont), VerticalOffsetLayout::Builder(CharLayout::Builder('2', KDFont::SmallFont), VerticalOffsetLayoutNode::Type::Superscript));
|
||||
m_selectableTableView.setVerticalCellOverlap(0);
|
||||
m_selectableTableView.setBackgroundColor(Palette::WallScreenDark);
|
||||
m_selectableTableView.setMargins(k_margin, k_scrollBarMargin, k_scrollBarMargin, k_margin);
|
||||
|
||||
@@ -20,27 +20,27 @@ namespace Regression {
|
||||
Layout CubicModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
const Layout layoutChildren[] = {
|
||||
CharLayout('a', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('a', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CharLayout('3', KDFont::SmallFont),
|
||||
CharLayout::Builder('3', KDFont::SmallFont),
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('b', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('b', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CharLayout('2', KDFont::SmallFont),
|
||||
CharLayout::Builder('2', KDFont::SmallFont),
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('c', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('d', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('c', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('d', KDFont::SmallFont),
|
||||
};
|
||||
m_layout = HorizontalLayout::Builder(layoutChildren, 15);
|
||||
}
|
||||
@@ -56,16 +56,16 @@ Expression CubicModel::simplifiedExpression(double * modelCoefficients, Poincare
|
||||
Multiplication::Builder(
|
||||
Number::DecimalNumber(a),
|
||||
Power::Builder(
|
||||
Symbol('x'),
|
||||
Decimal(3.0))),
|
||||
Symbol::Builder('x'),
|
||||
Decimal::Builder(3.0))),
|
||||
Multiplication::Builder(
|
||||
Number::DecimalNumber(b),
|
||||
Power::Builder(
|
||||
Symbol('x'),
|
||||
Decimal(2.0))),
|
||||
Symbol::Builder('x'),
|
||||
Decimal::Builder(2.0))),
|
||||
Multiplication::Builder(
|
||||
Number::DecimalNumber(c),
|
||||
Symbol('x')),
|
||||
Symbol::Builder('x')),
|
||||
Number::DecimalNumber(d)
|
||||
};
|
||||
// a*x^3+b*x^2+c*x+d
|
||||
|
||||
@@ -12,14 +12,14 @@ namespace Regression {
|
||||
Layout ExponentialModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
const Layout layoutChildren[] = {
|
||||
CharLayout('a', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('e', KDFont::SmallFont),
|
||||
CharLayout::Builder('a', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('e', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
HorizontalLayout::Builder(
|
||||
CharLayout('b', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont)
|
||||
CharLayout::Builder('b', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont)
|
||||
),
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
)
|
||||
|
||||
@@ -12,11 +12,11 @@ namespace Regression {
|
||||
Layout LinearModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
const Layout layoutChildren[] = {
|
||||
CharLayout('a', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('b', KDFont::SmallFont),
|
||||
CharLayout::Builder('a', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('b', KDFont::SmallFont),
|
||||
};
|
||||
m_layout = HorizontalLayout::Builder(layoutChildren, 5);
|
||||
}
|
||||
|
||||
@@ -12,15 +12,15 @@ namespace Regression {
|
||||
Layout LogarithmicModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
const Layout layoutChildren[] = {
|
||||
CharLayout('a', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('l', KDFont::SmallFont),
|
||||
CharLayout('n', KDFont::SmallFont),
|
||||
CharLayout('(', KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout(')', KDFont::SmallFont),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('b', KDFont::SmallFont)
|
||||
CharLayout::Builder('a', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('l', KDFont::SmallFont),
|
||||
CharLayout::Builder('n', KDFont::SmallFont),
|
||||
CharLayout::Builder('(', KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
CharLayout::Builder(')', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('b', KDFont::SmallFont)
|
||||
};
|
||||
m_layout = HorizontalLayout::Builder(layoutChildren, 9);
|
||||
}
|
||||
|
||||
@@ -13,24 +13,24 @@ namespace Regression {
|
||||
Layout LogisticModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
const Layout exponentLayoutChildren[] = {
|
||||
CharLayout('-', KDFont::SmallFont),
|
||||
CharLayout('b', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont)
|
||||
CharLayout::Builder('-', KDFont::SmallFont),
|
||||
CharLayout::Builder('b', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont)
|
||||
};
|
||||
const Layout layoutChildren[] = {
|
||||
CharLayout('1', KDFont::SmallFont),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('a', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('e', KDFont::SmallFont),
|
||||
CharLayout::Builder('1', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('a', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('e', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
HorizontalLayout::Builder(exponentLayoutChildren, 4),
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
)
|
||||
};
|
||||
m_layout = FractionLayout::Builder(
|
||||
CharLayout('c', KDFont::SmallFont),
|
||||
CharLayout::Builder('c', KDFont::SmallFont),
|
||||
HorizontalLayout::Builder(layoutChildren, 6)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ namespace Regression {
|
||||
Layout PowerModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
const Layout layoutChildren[] = {
|
||||
CharLayout('a', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('a', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CharLayout('b', KDFont::SmallFont),
|
||||
CharLayout::Builder('b', KDFont::SmallFont),
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
),
|
||||
};
|
||||
|
||||
@@ -20,19 +20,19 @@ namespace Regression {
|
||||
Layout QuadraticModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
const Layout layoutChildren[] = {
|
||||
CharLayout('a', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('a', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CharLayout('2', KDFont::SmallFont),
|
||||
CharLayout::Builder('2', KDFont::SmallFont),
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('b', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('c', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('b', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('c', KDFont::SmallFont),
|
||||
};
|
||||
m_layout = HorizontalLayout::Builder(layoutChildren, 10);
|
||||
}
|
||||
@@ -48,11 +48,11 @@ Expression QuadraticModel::simplifiedExpression(double * modelCoefficients, Poin
|
||||
Multiplication::Builder(
|
||||
Number::DecimalNumber(a),
|
||||
Power::Builder(
|
||||
Symbol('x'),
|
||||
Decimal(2.0))),
|
||||
Symbol::Builder('x'),
|
||||
Decimal::Builder(2.0))),
|
||||
Multiplication::Builder(
|
||||
Number::DecimalNumber(b),
|
||||
Symbol('x')),
|
||||
Symbol::Builder('x')),
|
||||
Number::DecimalNumber(c)
|
||||
};
|
||||
Expression result = Addition::Builder(addChildren, 3);
|
||||
|
||||
@@ -20,35 +20,35 @@ namespace Regression {
|
||||
Layout QuarticModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
const Layout layoutChildren[] = {
|
||||
CharLayout('a', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('a', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CharLayout('4', KDFont::SmallFont),
|
||||
CharLayout::Builder('4', KDFont::SmallFont),
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('b', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('b', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CharLayout('3', KDFont::SmallFont),
|
||||
CharLayout::Builder('3', KDFont::SmallFont),
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('c', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('c', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CharLayout('2', KDFont::SmallFont),
|
||||
CharLayout::Builder('2', KDFont::SmallFont),
|
||||
VerticalOffsetLayoutNode::Type::Superscript
|
||||
),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('d', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('e', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('d', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('e', KDFont::SmallFont),
|
||||
};
|
||||
m_layout = HorizontalLayout::Builder(layoutChildren, 20);
|
||||
}
|
||||
@@ -66,24 +66,24 @@ Expression QuarticModel::simplifiedExpression(double * modelCoefficients, Poinca
|
||||
Multiplication::Builder(
|
||||
Number::DecimalNumber(a),
|
||||
Power::Builder(
|
||||
Symbol('x'),
|
||||
Decimal(4.0))),
|
||||
Symbol::Builder('x'),
|
||||
Decimal::Builder(4.0))),
|
||||
// b*x^3
|
||||
Multiplication::Builder(
|
||||
Number::DecimalNumber(b),
|
||||
Power::Builder(
|
||||
Symbol('x'),
|
||||
Decimal(3.0))),
|
||||
Symbol::Builder('x'),
|
||||
Decimal::Builder(3.0))),
|
||||
// c*x^2
|
||||
Multiplication::Builder(
|
||||
Number::DecimalNumber(c),
|
||||
Power::Builder(
|
||||
Symbol('x'),
|
||||
Decimal(2.0))),
|
||||
Symbol::Builder('x'),
|
||||
Decimal::Builder(2.0))),
|
||||
// d*x
|
||||
Multiplication::Builder(
|
||||
Number::DecimalNumber(d),
|
||||
Symbol('x')),
|
||||
Symbol::Builder('x')),
|
||||
// e
|
||||
Number::DecimalNumber(e)
|
||||
};
|
||||
|
||||
@@ -21,20 +21,20 @@ namespace Regression {
|
||||
Layout TrigonometricModel::layout() {
|
||||
if (m_layout.isUninitialized()) {
|
||||
const Layout layoutChildren[] = {
|
||||
CharLayout('a', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('s', KDFont::SmallFont),
|
||||
CharLayout('i', KDFont::SmallFont),
|
||||
CharLayout('n', KDFont::SmallFont),
|
||||
CharLayout('(', KDFont::SmallFont),
|
||||
CharLayout('b', KDFont::SmallFont),
|
||||
CharLayout(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout('X', KDFont::SmallFont),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('c', KDFont::SmallFont),
|
||||
CharLayout(')', KDFont::SmallFont),
|
||||
CharLayout('+', KDFont::SmallFont),
|
||||
CharLayout('d', KDFont::SmallFont)
|
||||
CharLayout::Builder('a', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('s', KDFont::SmallFont),
|
||||
CharLayout::Builder('i', KDFont::SmallFont),
|
||||
CharLayout::Builder('n', KDFont::SmallFont),
|
||||
CharLayout::Builder('(', KDFont::SmallFont),
|
||||
CharLayout::Builder('b', KDFont::SmallFont),
|
||||
CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont),
|
||||
CharLayout::Builder('X', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('c', KDFont::SmallFont),
|
||||
CharLayout::Builder(')', KDFont::SmallFont),
|
||||
CharLayout::Builder('+', KDFont::SmallFont),
|
||||
CharLayout::Builder('d', KDFont::SmallFont)
|
||||
};
|
||||
m_layout = HorizontalLayout::Builder(layoutChildren, 14);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ Expression TrigonometricModel::simplifiedExpression(double * modelCoefficients,
|
||||
Addition::Builder(
|
||||
Multiplication::Builder(
|
||||
Number::DecimalNumber(b),
|
||||
Symbol('x')),
|
||||
Symbol::Builder('x')),
|
||||
Number::DecimalNumber(c)))),
|
||||
Number::DecimalNumber(d));
|
||||
PoincareHelpers::Simplify(&result, *context);
|
||||
|
||||
@@ -22,7 +22,7 @@ const Expression RegressionContext::expressionForSymbol(const SymbolAbstract & s
|
||||
|
||||
assert(m_seriesPairIndex >= 0);
|
||||
assert(m_seriesPairIndex < m_store->numberOfPairsOfSeries(series));
|
||||
return Float<double>(m_store->get(series, storeI, m_seriesPairIndex));
|
||||
return Float<double>::Builder(m_store->get(series, storeI, m_seriesPairIndex));
|
||||
} else {
|
||||
return m_parentContext->expressionForSymbol(symbol, clone);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ const Expression CacheContext<T>::expressionForSymbol(const SymbolAbstract & sym
|
||||
&& (strcmp(symbol.name()+1, "(n)") == 0 || strcmp(symbol.name()+1, "(n+1)") == 0))
|
||||
{
|
||||
Symbol s = const_cast<Symbol &>(static_cast<const Symbol &>(symbol));
|
||||
return Float<T>(m_values[nameIndexForSymbol(s)][rankIndexForSymbol(s)]);
|
||||
return Float<T>::Builder(m_values[nameIndexForSymbol(s)][rankIndexForSymbol(s)]);
|
||||
}
|
||||
return VariableContext::expressionForSymbol(symbol, clone);
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ double TermSumController::cursorNextStep(double x, int direction) {
|
||||
|
||||
Layout TermSumController::createFunctionLayout(const char * functionName) {
|
||||
return HorizontalLayout::Builder(
|
||||
CharLayout(functionName[0], KDFont::SmallFont),
|
||||
CharLayout::Builder(functionName[0], KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(
|
||||
CharLayout('n', KDFont::SmallFont),
|
||||
CharLayout::Builder('n', KDFont::SmallFont),
|
||||
VerticalOffsetLayoutNode::Type::Subscript
|
||||
)
|
||||
);
|
||||
|
||||
@@ -77,18 +77,18 @@ void SequenceToolbox::buildExtraCellsLayouts(const char * sequenceName, int recu
|
||||
for (int j = 0; j < recurrenceDepth; j++) {
|
||||
const char * indice = j == 0 ? "n" : "n+1";
|
||||
m_addedCellLayout[j] = HorizontalLayout::Builder(
|
||||
CharLayout(sequenceName[0], KDFont::LargeFont),
|
||||
CharLayout::Builder(sequenceName[0], KDFont::LargeFont),
|
||||
VerticalOffsetLayout::Builder(LayoutHelper::String(indice, strlen(indice), KDFont::LargeFont), VerticalOffsetLayoutNode::Type::Subscript)
|
||||
);
|
||||
m_addedCellLayout[j+recurrenceDepth] = HorizontalLayout::Builder(
|
||||
CharLayout(otherSequenceName[0], KDFont::LargeFont),
|
||||
CharLayout::Builder(otherSequenceName[0], KDFont::LargeFont),
|
||||
VerticalOffsetLayout::Builder(LayoutHelper::String(indice, strlen(indice), KDFont::LargeFont), VerticalOffsetLayoutNode::Type::Subscript)
|
||||
);
|
||||
}
|
||||
if (recurrenceDepth < 2) {
|
||||
const char * indice = recurrenceDepth == 0 ? "n" : (recurrenceDepth == 1 ? "n+1" : "n+2");
|
||||
m_addedCellLayout[2*recurrenceDepth] = HorizontalLayout::Builder(
|
||||
CharLayout(otherSequenceName[0], KDFont::LargeFont),
|
||||
CharLayout::Builder(otherSequenceName[0], KDFont::LargeFont),
|
||||
VerticalOffsetLayout::Builder(LayoutHelper::String(indice, strlen(indice), KDFont::LargeFont), VerticalOffsetLayoutNode::Type::Subscript)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ void TypeParameterController::willDisplayCellAtLocation(HighlightCell * cell, in
|
||||
}
|
||||
const char * subscripts[3] = {"n", "n+1", "n+2"};
|
||||
m_layouts[j] = HorizontalLayout::Builder(
|
||||
CharLayout(nextName[0], font),
|
||||
CharLayout::Builder(nextName[0], font),
|
||||
VerticalOffsetLayout::Builder(LayoutHelper::String(subscripts[j], strlen(subscripts[j]), font), VerticalOffsetLayoutNode::Type::Subscript)
|
||||
);
|
||||
ExpressionTableCellWithPointer * myCell = (ExpressionTableCellWithPointer *)cell;
|
||||
|
||||
@@ -147,8 +147,8 @@ int Sequence::numberOfElements() {
|
||||
Poincare::Layout Sequence::nameLayout() {
|
||||
if (m_nameLayout.isUninitialized()) {
|
||||
m_nameLayout = HorizontalLayout::Builder(
|
||||
CharLayout(name()[0], KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(CharLayout('n', KDFont::SmallFont), VerticalOffsetLayoutNode::Type::Subscript)
|
||||
CharLayout::Builder(name()[0], KDFont::SmallFont),
|
||||
VerticalOffsetLayout::Builder(CharLayout::Builder('n', KDFont::SmallFont), VerticalOffsetLayoutNode::Type::Subscript)
|
||||
);
|
||||
}
|
||||
return m_nameLayout;
|
||||
@@ -158,16 +158,16 @@ Poincare::Layout Sequence::definitionName() {
|
||||
if (m_definitionName.isUninitialized()) {
|
||||
if (m_type == Type::Explicit) {
|
||||
m_definitionName = HorizontalLayout::Builder(
|
||||
CharLayout(name()[0], k_layoutFont),
|
||||
CharLayout::Builder(name()[0], k_layoutFont),
|
||||
VerticalOffsetLayout::Builder(LayoutHelper::String("n", 1, k_layoutFont), VerticalOffsetLayoutNode::Type::Subscript));
|
||||
} else if (m_type == Type::SingleRecurrence) {
|
||||
m_definitionName = HorizontalLayout::Builder(
|
||||
CharLayout(name()[0], k_layoutFont),
|
||||
CharLayout::Builder(name()[0], k_layoutFont),
|
||||
VerticalOffsetLayout::Builder(LayoutHelper::String("n+1", 3, k_layoutFont), VerticalOffsetLayoutNode::Type::Subscript));
|
||||
} else {
|
||||
assert(m_type == Type::DoubleRecurrence);
|
||||
m_definitionName = HorizontalLayout::Builder(
|
||||
CharLayout(name()[0], k_layoutFont),
|
||||
CharLayout::Builder(name()[0], k_layoutFont),
|
||||
VerticalOffsetLayout::Builder(LayoutHelper::String("n+2", 3, k_layoutFont), VerticalOffsetLayoutNode::Type::Subscript));
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,7 @@ Poincare::Layout Sequence::firstInitialConditionName() {
|
||||
{
|
||||
Layout indexLayout = LayoutHelper::String(buffer, strlen(buffer), k_layoutFont);
|
||||
m_firstInitialConditionName = HorizontalLayout::Builder(
|
||||
CharLayout(name()[0], k_layoutFont),
|
||||
CharLayout::Builder(name()[0], k_layoutFont),
|
||||
VerticalOffsetLayout::Builder(indexLayout, VerticalOffsetLayoutNode::Type::Subscript));
|
||||
}
|
||||
return m_firstInitialConditionName;
|
||||
@@ -196,7 +196,7 @@ Poincare::Layout Sequence::secondInitialConditionName() {
|
||||
if (m_type == Type::DoubleRecurrence) {
|
||||
Layout indexLayout = LayoutHelper::String(buffer, strlen(buffer), k_layoutFont);
|
||||
m_secondInitialConditionName = HorizontalLayout::Builder(
|
||||
CharLayout(name()[0], k_layoutFont),
|
||||
CharLayout::Builder(name()[0], k_layoutFont),
|
||||
VerticalOffsetLayout::Builder(indexLayout, VerticalOffsetLayoutNode::Type::Subscript));
|
||||
}
|
||||
}
|
||||
@@ -247,10 +247,10 @@ T Sequence::approximateToNextRank(int n, SequenceContext * sqctx) const {
|
||||
T vn = sqctx->valueOfSequenceAtPreviousRank<T>(1, 0);
|
||||
T vnm1 = sqctx->valueOfSequenceAtPreviousRank<T>(1, 1);
|
||||
T vnm2 = sqctx->valueOfSequenceAtPreviousRank<T>(1, 2);
|
||||
Poincare::Symbol vnSymbol("v(n)", 4);
|
||||
Poincare::Symbol vn1Symbol("v(n+1)", 6);
|
||||
Poincare::Symbol unSymbol("u(n)", 4);
|
||||
Poincare::Symbol un1Symbol("u(n+1)", 6);
|
||||
Poincare::Symbol vnSymbol = Symbol::Builder("v(n)", 4);
|
||||
Poincare::Symbol vn1Symbol = Symbol::Builder("v(n+1)", 6);
|
||||
Poincare::Symbol unSymbol = Symbol::Builder("u(n)", 4);
|
||||
Poincare::Symbol un1Symbol = Symbol::Builder("u(n+1)", 6);
|
||||
switch (m_type) {
|
||||
case Type::Explicit:
|
||||
{
|
||||
|
||||
@@ -84,7 +84,7 @@ Layout layoutForPreferences(I18n::Message message) {
|
||||
// Complex format
|
||||
case I18n::Message::Real:
|
||||
{
|
||||
return CharLayout('x', KDFont::SmallFont);
|
||||
return CharLayout::Builder('x', KDFont::SmallFont);
|
||||
}
|
||||
case I18n::Message::Cartesian:
|
||||
{
|
||||
|
||||
@@ -71,7 +71,7 @@ void GlobalContext::setExpressionForSymbol(const Expression & expression, const
|
||||
Ion::Storage::Record record = SymbolAbstractRecordWithBaseName(symbol.name());
|
||||
Expression e = ExpressionFromRecord(record);
|
||||
if (e.isUninitialized()) {
|
||||
e = Undefined();
|
||||
e = Undefined::Builder();
|
||||
}
|
||||
Expression finalExpression = expression.clone().replaceSymbolWithExpression(symbol, e);
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ void StorageCartesianFunction::setDisplayDerivative(bool display) {
|
||||
}
|
||||
|
||||
double StorageCartesianFunction::approximateDerivative(double x, Poincare::Context * context) const {
|
||||
Poincare::Derivative derivative = Poincare::Derivative::Builder(expressionReduced(context).clone(), Symbol(Symbol::SpecialSymbols::UnknownX), Poincare::Float<double>(x)); // derivative takes ownership of Poincare::Float<double>(x) and the clone of expression
|
||||
Poincare::Derivative derivative = Poincare::Derivative::Builder(expressionReduced(context).clone(), Symbol::Builder(Symbol::SpecialSymbols::UnknownX), Poincare::Float<double>::Builder(x)); // derivative takes ownership of Poincare::Float<double>::Builder(x) and the clone of expression
|
||||
/* TODO: when we approximate derivative, we might want to simplify the
|
||||
* derivative here. However, we might want to do it once for all x (to avoid
|
||||
* lagging in the derivative table. */
|
||||
@@ -94,7 +94,7 @@ double StorageCartesianFunction::approximateDerivative(double x, Poincare::Conte
|
||||
|
||||
double StorageCartesianFunction::sumBetweenBounds(double start, double end, Poincare::Context * context) const {
|
||||
// TODO: this does not work yet because integral does not understand UnknownX
|
||||
Poincare::Integral integral = Poincare::Integral::Builder(expressionReduced(context).clone(), Symbol(Symbol::SpecialSymbols::UnknownX), Poincare::Float<double>(start), Poincare::Float<double>(end)); // Integral takes ownership of args
|
||||
Poincare::Integral integral = Poincare::Integral::Builder(expressionReduced(context).clone(), Symbol::Builder(Symbol::SpecialSymbols::UnknownX), Poincare::Float<double>::Builder(start), Poincare::Float<double>::Builder(end)); // Integral takes ownership of args
|
||||
/* TODO: when we approximate integral, we might want to simplify the integral
|
||||
* here. However, we might want to do it once for all x (to avoid lagging in
|
||||
* the derivative table. */
|
||||
|
||||
@@ -87,7 +87,7 @@ Ion::Storage::Record::ErrorStatus StorageExpressionModel::setContent(const char
|
||||
// Compute the expression to store, without replacing symbols
|
||||
expressionToStore = Expression::Parse(c);
|
||||
if (!expressionToStore.isUninitialized()) {
|
||||
expressionToStore = expressionToStore.replaceUnknown(Symbol('x')); //TODO Beware of non x unknowns! (for instance whe sequences are in the storage)
|
||||
expressionToStore = expressionToStore.replaceUnknown(Symbol::Builder('x')); //TODO Beware of non x unknowns! (for instance whe sequences are in the storage)
|
||||
}
|
||||
}
|
||||
return setExpressionContent(expressionToStore);
|
||||
|
||||
@@ -243,7 +243,7 @@ void StorageSumGraphController::LegendView::setSumSymbol(Step step, double start
|
||||
m_sumLayout = CondensedSumLayout::Builder(
|
||||
LayoutHelper::String(sigma, sizeof(sigma)),
|
||||
LayoutHelper::String(buffer, strlen(buffer), k_font),
|
||||
EmptyLayout(EmptyLayoutNode::Color::Yellow, false, k_font, false));
|
||||
EmptyLayout::Builder(EmptyLayoutNode::Color::Yellow, false, k_font, false));
|
||||
} else {
|
||||
m_sumLayout = LayoutHelper::String(sigma, sizeof(sigma));
|
||||
char buffer[2+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
|
||||
@@ -242,7 +242,7 @@ void SumGraphController::LegendView::setSumSymbol(Step step, double start, doubl
|
||||
m_sumLayout = CondensedSumLayout::Builder(
|
||||
LayoutHelper::String(sigma, sizeof(sigma)),
|
||||
LayoutHelper::String(buffer, strlen(buffer), KDFont::SmallFont),
|
||||
EmptyLayout(EmptyLayoutNode::Color::Yellow, false, KDFont::SmallFont, false));
|
||||
EmptyLayout::Builder(EmptyLayoutNode::Color::Yellow, false, KDFont::SmallFont, false));
|
||||
} else {
|
||||
m_sumLayout = LayoutHelper::String(sigma, sizeof(sigma));
|
||||
constexpr size_t bufferSize = 2+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
|
||||
|
||||
@@ -30,11 +30,11 @@ Expression Equation::standardForm(Context * context) const {
|
||||
if (m_standardForm.isUninitialized()) {
|
||||
const Expression e = expression(context);
|
||||
if (e.type() == ExpressionNode::Type::Unreal) {
|
||||
m_standardForm = Unreal();
|
||||
m_standardForm = Unreal::Builder();
|
||||
return m_standardForm;
|
||||
}
|
||||
if (e.recursivelyMatches([](const Expression e, Context & context, bool replaceSymbols) { return e.type() == ExpressionNode::Type::Undefined || e.type() == ExpressionNode::Type::Infinity || Expression::IsMatrix(e, context, replaceSymbols); }, *context, true)) {
|
||||
m_standardForm = Undefined();
|
||||
m_standardForm = Undefined::Builder();
|
||||
return m_standardForm;
|
||||
}
|
||||
if (e.type() == ExpressionNode::Type::Equal) {
|
||||
@@ -43,7 +43,7 @@ Expression Equation::standardForm(Context * context) const {
|
||||
} else {
|
||||
assert(e.type() == ExpressionNode::Type::Rational && static_cast<const Rational&>(e).isOne());
|
||||
// The equality was reduced which means the equality was always true.
|
||||
m_standardForm = Rational(0);
|
||||
m_standardForm = Rational::Builder(0);
|
||||
}
|
||||
}
|
||||
return m_standardForm;
|
||||
|
||||
@@ -257,20 +257,20 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact
|
||||
/* Equation ax^2+bx+c = 0 */
|
||||
assert(degree == 2);
|
||||
// Compute delta = b*b-4ac
|
||||
Expression delta = Subtraction::Builder(Power::Builder(coefficients[1].clone(), Rational(2)), Multiplication::Builder(Rational(4), coefficients[0].clone(), coefficients[2].clone()));
|
||||
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(*context, updatedComplexFormat(), Poincare::Preferences::sharedPreferences()->angleUnit());
|
||||
if (delta.isUninitialized()) {
|
||||
delta = Poincare::Undefined();
|
||||
delta = Poincare::Undefined::Builder();
|
||||
}
|
||||
if (delta.isRationalZero()) {
|
||||
// if delta = 0, x0=x1= -b/(2a)
|
||||
exactSolutions[0] = Division::Builder(Opposite::Builder(coefficients[1]), Multiplication::Builder(Rational(2), coefficients[2]));
|
||||
exactSolutions[0] = Division::Builder(Opposite::Builder(coefficients[1]), Multiplication::Builder(Rational::Builder(2), coefficients[2]));
|
||||
m_numberOfSolutions = 2;
|
||||
} else {
|
||||
// x0 = (-b-sqrt(delta))/(2a)
|
||||
exactSolutions[0] = Division::Builder(Subtraction::Builder(Opposite::Builder(coefficients[1].clone()), SquareRoot::Builder(delta.clone())), Multiplication::Builder(Rational(2), coefficients[2].clone()));
|
||||
exactSolutions[0] = Division::Builder(Subtraction::Builder(Opposite::Builder(coefficients[1].clone()), SquareRoot::Builder(delta.clone())), Multiplication::Builder(Rational::Builder(2), coefficients[2].clone()));
|
||||
// x1 = (-b+sqrt(delta))/(2a)
|
||||
exactSolutions[1] = Division::Builder(Addition::Builder(Opposite::Builder(coefficients[1]), SquareRoot::Builder(delta.clone())), Multiplication::Builder(Rational(2), coefficients[2]));
|
||||
exactSolutions[1] = Division::Builder(Addition::Builder(Opposite::Builder(coefficients[1]), SquareRoot::Builder(delta.clone())), Multiplication::Builder(Rational::Builder(2), coefficients[2]));
|
||||
m_numberOfSolutions = 3;
|
||||
}
|
||||
exactSolutions[m_numberOfSolutions-1] = delta;
|
||||
@@ -285,47 +285,47 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact
|
||||
Expression * c = coefficients[1];
|
||||
Expression * d = coefficients[0];
|
||||
// Delta = b^2*c^2+18abcd-27a^2*d^2-4ac^3-4db^3
|
||||
Expression * mult0Operands[2] = {new Power::Builder(b->clone(), new Rational(2), false), new Power::Builder(c->clone(), new Rational(2), false)};
|
||||
Expression * mult1Operands[5] = {new Rational(18), a->clone(), b->clone(), c->clone(), d->clone()};
|
||||
Expression * mult2Operands[3] = {new Rational(-27), new Power::Builder(a->clone(), new Rational(2), false), new Power::Builder(d->clone(), new Rational(2), false)};
|
||||
Expression * mult3Operands[3] = {new Rational(-4), a->clone(), new Power::Builder(c->clone(), new Rational(3), false)};
|
||||
Expression * mult4Operands[3] = {new Rational(-4), d->clone(), new Power::Builder(b->clone(), new Rational(3), false)};
|
||||
Expression * mult0Operands[2] = {new Power::Builder(b->clone(), new Rational::Builder(2), false), new Power::Builder(c->clone(), new Rational::Builder(2), false)};
|
||||
Expression * mult1Operands[5] = {new Rational::Builder(18), a->clone(), b->clone(), c->clone(), d->clone()};
|
||||
Expression * mult2Operands[3] = {new Rational::Builder(-27), new Power::Builder(a->clone(), new Rational::Builder(2), false), new Power::Builder(d->clone(), new Rational::Builder(2), false)};
|
||||
Expression * mult3Operands[3] = {new Rational::Builder(-4), a->clone(), new Power::Builder(c->clone(), new Rational::Builder(3), false)};
|
||||
Expression * mult4Operands[3] = {new Rational::Builder(-4), d->clone(), new Power::Builder(b->clone(), new Rational::Builder(3), false)};
|
||||
Expression * add0Operands[5] = {new Multiplication::Builder(mult0Operands, 2, false), new Multiplication::Builder(mult1Operands, 5, false), new Multiplication::Builder(mult2Operands, 3, false), new Multiplication::Builder(mult3Operands, 3, false), new Multiplication::Builder(mult4Operands, 3, false)};
|
||||
Expression * delta = new Addition(add0Operands, 5, false);
|
||||
PoincareHelpers::Simplify(&delta, *context);
|
||||
// Delta0 = b^2-3ac
|
||||
Expression * mult5Operands[3] = {new Rational(3), a->clone(), c->clone()};
|
||||
Expression * delta0 = new Subtraction::Builder(new Power::Builder(b->clone(), new Rational(2), false), new Multiplication::Builder(mult5Operands, 3, false), false);
|
||||
Expression * mult5Operands[3] = {new Rational::Builder(3), a->clone(), c->clone()};
|
||||
Expression * delta0 = new Subtraction::Builder(new Power::Builder(b->clone(), new Rational::Builder(2), false), new Multiplication::Builder(mult5Operands, 3, false), false);
|
||||
Reduce(&delta0, *context);
|
||||
if (delta->isRationalZero()) {
|
||||
if (delta0->isRationalZero()) {
|
||||
// delta0 = 0 && delta = 0 --> x0 = -b/(3a)
|
||||
delete delta0;
|
||||
m_exactSolutions[0] = new Opposite::Builder(new Division::Builder(b, new Multiplication::Builder(new Rational(3), a, false), false), false);
|
||||
m_exactSolutions[0] = new Opposite::Builder(new Division::Builder(b, new Multiplication::Builder(new Rational::Builder(3), a, false), false), false);
|
||||
m_numberOfSolutions = 1;
|
||||
delete c;
|
||||
delete d;
|
||||
} else {
|
||||
// delta = 0 --> x0 = (9ad-bc)/(2delta0)
|
||||
// --> x1 = (4abc-9a^2d-b^3)/(a*delta0)
|
||||
Expression * mult6Operands[3] = {new Rational(9), a, d};
|
||||
m_exactSolutions[0] = new Division::Builder(new Subtraction::Builder(new Multiplication::Builder(mult6Operands, 3, false), new Multiplication::Builder(b, c, false), false), new Multiplication::Builder(new Rational(2), delta0, false), false);
|
||||
Expression * mult7Operands[4] = {new Rational(4), a->clone(), b->clone(), c->clone()};
|
||||
Expression * mult8Operands[3] = {new Rational(-9), new Power::Builder(a->clone(), new Rational(2), false), d->clone()};
|
||||
Expression * add1Operands[3] = {new Multiplication::Builder(mult7Operands, 4, false), new Multiplication::Builder(mult8Operands,3, false), new Opposite::Builder(new Power::Builder(b->clone(), new Rational(3), false), false)};
|
||||
Expression * mult6Operands[3] = {new Rational::Builder(9), a, d};
|
||||
m_exactSolutions[0] = new Division::Builder(new Subtraction::Builder(new Multiplication::Builder(mult6Operands, 3, false), new Multiplication::Builder(b, c, false), false), new Multiplication::Builder(new Rational::Builder(2), delta0, false), false);
|
||||
Expression * mult7Operands[4] = {new Rational::Builder(4), a->clone(), b->clone(), c->clone()};
|
||||
Expression * mult8Operands[3] = {new Rational::Builder(-9), new Power::Builder(a->clone(), new Rational::Builder(2), false), d->clone()};
|
||||
Expression * add1Operands[3] = {new Multiplication::Builder(mult7Operands, 4, false), new Multiplication::Builder(mult8Operands,3, false), new Opposite::Builder(new Power::Builder(b->clone(), new Rational::Builder(3), false), false)};
|
||||
m_exactSolutions[1] = new Division::Builder(new Addition(add1Operands, 3, false), new Multiplication::Builder(a->clone(), delta0, false), false);
|
||||
m_numberOfSolutions = 2;
|
||||
}
|
||||
} else {
|
||||
// delta1 = 2b^3-9abc+27a^2*d
|
||||
Expression * mult9Operands[4] = {new Rational(-9), a, b, c};
|
||||
Expression * mult10Operands[3] = {new Rational(27), new Power::Builder(a->clone(), new Rational(2), false), d};
|
||||
Expression * add2Operands[3] = {new Multiplication::Builder(new Rational(2), new Power::Builder(b->clone(), new Rational(3), false), false), new Multiplication::Builder(mult9Operands, 4, false), new Multiplication::Builder(mult10Operands, 3, false)};
|
||||
Expression * mult9Operands[4] = {new Rational::Builder(-9), a, b, c};
|
||||
Expression * mult10Operands[3] = {new Rational::Builder(27), new Power::Builder(a->clone(), new Rational::Builder(2), false), d};
|
||||
Expression * add2Operands[3] = {new Multiplication::Builder(new Rational::Builder(2), new Power::Builder(b->clone(), new Rational::Builder(3), false), false), new Multiplication::Builder(mult9Operands, 4, false), new Multiplication::Builder(mult10Operands, 3, false)};
|
||||
Expression * delta1 = new Addition(add2Operands, 3, false);
|
||||
// C = Root((delta1+sqrt(-27a^2*delta))/2, 3)
|
||||
Expression * mult11Operands[3] = {new Rational(-27), new Power::Builder(a->clone(), new Rational(2), false), (*delta)->clone()};
|
||||
Expression * c = new Power::Builder(new Division::Builder(new Addition(delta1, new SquareRoot(new Multiplication::Builder(mult11Operands, 3, false), false), false), new Rational(2), false), new Rational(1,3), false);
|
||||
Expression * unary3roots[2] = {new Addition(new Rational(-1,2), new Division::Builder(new Multiplication::Builder(new SquareRoot(new Rational(3), false), new Constant(Ion::Charset::IComplex), false), new Rational(2), false), false), new Subtraction::Builder(new Rational(-1,2), new Division::Builder(new Multiplication::Builder(new SquareRoot(new Rational(3), false), new Constant(Ion::Charset::IComplex), false), new Rational(2), false), false)};
|
||||
Expression * mult11Operands[3] = {new Rational::Builder(-27), new Power::Builder(a->clone(), new Rational::Builder(2), false), (*delta)->clone()};
|
||||
Expression * c = new Power::Builder(new Division::Builder(new Addition(delta1, new SquareRoot(new Multiplication::Builder(mult11Operands, 3, false), false), false), new Rational::Builder(2), false), new Rational::Builder(1,3), false);
|
||||
Expression * unary3roots[2] = {new Addition(new Rational::Builder(-1,2), new Division::Builder(new Multiplication::Builder(new SquareRoot(new Rational::Builder(3), false), new Constant::Builder(Ion::Charset::IComplex), false), new Rational::Builder(2), false), false), new Subtraction::Builder(new Rational::Builder(-1,2), new Division::Builder(new Multiplication::Builder(new SquareRoot(new Rational::Builder(3), false), new Constant::Builder(Ion::Charset::IComplex), false), new Rational::Builder(2), false), false)};
|
||||
// x_k = -1/(3a)*(b+C*z+delta0/(zC)) with z = unary cube root
|
||||
for (int k = 0; k < 3; k++) {
|
||||
Expression * ccopy = c;
|
||||
@@ -335,7 +335,7 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact
|
||||
delta0copy = delta0->clone();
|
||||
}
|
||||
Expression * add3Operands[3] = {b->clone(), ccopy, new Division::Builder(delta0copy, ccopy->clone(), false)};
|
||||
m_exactSolutions[k] = new Multiplication::Builder(new Division::Builder(new Rational(-1), new Multiplication::Builder(new Rational(3), a->clone(), false), false), new Addition(add3Operands, 3, false), false);
|
||||
m_exactSolutions[k] = new Multiplication::Builder(new Division::Builder(new Rational::Builder(-1), new Multiplication::Builder(new Rational::Builder(3), a->clone(), false), false), new Addition(add3Operands, 3, false), false);
|
||||
}
|
||||
m_numberOfSolutions = 3;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ SolutionsController::SolutionsController(Responder * parentResponder, EquationSt
|
||||
m_delta2Layout(),
|
||||
m_contentView(this)
|
||||
{
|
||||
m_delta2Layout = HorizontalLayout::Builder(VerticalOffsetLayout::Builder(CharLayout('2', KDFont::SmallFont), VerticalOffsetLayoutNode::Type::Superscript), LayoutHelper::String("-4ac", 4, KDFont::SmallFont));
|
||||
m_delta2Layout = HorizontalLayout::Builder(VerticalOffsetLayout::Builder(CharLayout::Builder('2', KDFont::SmallFont), VerticalOffsetLayoutNode::Type::Superscript), LayoutHelper::String("-4ac", 4, KDFont::SmallFont));
|
||||
char deltaB[] = {Ion::Charset::CapitalDelta, '=', 'b'};
|
||||
static_cast<HorizontalLayout&>(m_delta2Layout).addOrMergeChildAtIndex(LayoutHelper::String(deltaB, 3, KDFont::SmallFont), 0, false);
|
||||
for (int i = 0; i < EquationStore::k_maxNumberOfExactSolutions; i++) {
|
||||
|
||||
@@ -22,7 +22,7 @@ const Expression StatisticsContext::expressionForSymbol(const SymbolAbstract & s
|
||||
|
||||
assert(m_seriesPairIndex >= 0);
|
||||
assert(m_seriesPairIndex < m_store->numberOfPairsOfSeries(series));
|
||||
return Float<double>(m_store->get(series, storeI, m_seriesPairIndex));
|
||||
return Float<double>::Builder(m_store->get(series, storeI, m_seriesPairIndex));
|
||||
} else {
|
||||
return m_parentContext->expressionForSymbol(symbol, clone);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ SFLAGS += -Ipoincare/include
|
||||
#include poincare/src/simplify/Makefile
|
||||
#include poincare/src/simplification/Makefile
|
||||
objs += $(addprefix poincare/src/,\
|
||||
absolute_value_layout.o\
|
||||
binomial_coefficient_layout.o\
|
||||
bracket_layout.o\
|
||||
bracket_pair_layout.o\
|
||||
@@ -11,6 +12,7 @@ objs += $(addprefix poincare/src/,\
|
||||
condensed_sum_layout.o\
|
||||
conjugate_layout.o\
|
||||
empty_layout.o\
|
||||
floor_layout.o\
|
||||
fraction_layout.o\
|
||||
grid_layout.o\
|
||||
horizontal_layout.o\
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
|
||||
// Approximation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
return Complex<T>(std::abs(c));
|
||||
return Complex<T>::Builder(std::abs(c));
|
||||
}
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override {
|
||||
return ApproximationHelper::Map<float>(this, context, complexFormat, angleUnit, computeOnComplex<float>);
|
||||
@@ -49,15 +49,12 @@ class AbsoluteValue final : public Expression {
|
||||
friend class AbsoluteValueNode;
|
||||
public:
|
||||
AbsoluteValue(const AbsoluteValueNode * n) : Expression(n) {}
|
||||
static AbsoluteValue Builder(Expression child) { return AbsoluteValue(child); }
|
||||
static AbsoluteValue Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("abs", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit AbsoluteValue(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<AbsoluteValueNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
};
|
||||
|
||||
|
||||
@@ -33,13 +33,8 @@ private:
|
||||
|
||||
class AbsoluteValueLayout final : public Layout {
|
||||
public:
|
||||
static AbsoluteValueLayout Builder(Layout l) { return AbsoluteValueLayout(l); }
|
||||
private:
|
||||
explicit AbsoluteValueLayout(Layout l) :
|
||||
Layout(TreePool::sharedPool()->createTreeNode<AbsoluteValueLayoutNode>())
|
||||
{
|
||||
replaceChildAtIndexInPlace(0, l);
|
||||
}
|
||||
static AbsoluteValueLayout Builder(Layout l);
|
||||
AbsoluteValueLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const override;
|
||||
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d, Preferences::ComplexFormat complexFormat) { return Complex<T>(c+d); }
|
||||
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d, Preferences::ComplexFormat complexFormat) { return Complex<T>::Builder(c+d); }
|
||||
template<typename T> static MatrixComplex<T> computeOnMatrices(const MatrixComplex<T> m, const MatrixComplex<T> n, Preferences::ComplexFormat complexFormat) {
|
||||
return ApproximationHelper::ElementWiseOnComplexMatrices(m, n, complexFormat, compute<T>);
|
||||
}
|
||||
@@ -61,23 +61,15 @@ private:
|
||||
class Addition final : public NAryExpression {
|
||||
public:
|
||||
Addition(const AdditionNode * n) : NAryExpression(n) {}
|
||||
static Addition Builder() { return Addition(); }
|
||||
static Addition Builder();
|
||||
static Addition Builder(Expression e1) { return Addition::Builder(&e1, 1); }
|
||||
static Addition Builder(Expression e1, Expression e2) { return Addition::Builder(ArrayBuilder<Expression>(e1, e2).array(), 2); }
|
||||
static Addition Builder(Expression * children, size_t numberOfChildren) {
|
||||
Addition a = Addition::Builder();
|
||||
for (size_t i = 0; i < numberOfChildren; i++) {
|
||||
a.addChildAtIndexInPlace(children[i], i, i);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
static Addition Builder(Expression * children, size_t numberOfChildren);
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const;
|
||||
private:
|
||||
Addition() : NAryExpression(TreePool::sharedPool()->createTreeNode<AdditionNode>()) {}
|
||||
|
||||
static const Number NumeralFactor(const Expression & e);
|
||||
static inline int NumberOfNonNumeralFactors(const Expression & e);
|
||||
static inline const Expression FirstNonNumeralFactor(const Expression & e);
|
||||
|
||||
@@ -41,15 +41,11 @@ private:
|
||||
class ArcCosine final : public Expression {
|
||||
public:
|
||||
ArcCosine(const ArcCosineNode * n) : Expression(n) {}
|
||||
static ArcCosine Builder(Expression child) { return ArcCosine(child); }
|
||||
static ArcCosine Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("acos", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit ArcCosine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ArcCosineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -40,15 +40,11 @@ private:
|
||||
class ArcSine final : public Expression {
|
||||
public:
|
||||
ArcSine(const ArcSineNode * n) : Expression(n) {}
|
||||
static ArcSine Builder(Expression child) { return ArcSine(child); }
|
||||
static ArcSine Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("asin", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit ArcSine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ArcSineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -44,15 +44,11 @@ private:
|
||||
class ArcTangent final : public Expression {
|
||||
public:
|
||||
ArcTangent(const ArcTangentNode * n) : Expression(n) {}
|
||||
static ArcTangent Builder(Expression child) { return ArcTangent(child); }
|
||||
static ArcTangent Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("atan", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit ArcTangent(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ArcTangentNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -39,17 +39,13 @@ private:
|
||||
class BinomialCoefficient final : public Expression {
|
||||
public:
|
||||
BinomialCoefficient(const BinomialCoefficientNode * n) : Expression(n) {}
|
||||
static BinomialCoefficient Builder(Expression child0, Expression child1) { return BinomialCoefficient(child0, child1); }
|
||||
static BinomialCoefficient Builder(Expression child0, Expression child1);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("binomial", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
BinomialCoefficient(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<BinomialCoefficientNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
constexpr static int k_maxNValue = 300;
|
||||
};
|
||||
|
||||
|
||||
@@ -43,15 +43,8 @@ private:
|
||||
|
||||
class BinomialCoefficientLayout final : public Layout {
|
||||
public:
|
||||
static BinomialCoefficientLayout Builder(Layout n, Layout k) { return BinomialCoefficientLayout(n, k); }
|
||||
|
||||
private:
|
||||
BinomialCoefficientLayout(Layout n, Layout k) :
|
||||
Layout(TreePool::sharedPool()->createTreeNode<BinomialCoefficientLayoutNode>())
|
||||
{
|
||||
replaceChildAtIndexInPlace(0, n);
|
||||
replaceChildAtIndexInPlace(1, k);
|
||||
}
|
||||
static BinomialCoefficientLayout Builder(Layout n, Layout k);
|
||||
BinomialCoefficientLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -42,15 +42,11 @@ private:
|
||||
class Ceiling final : public Expression {
|
||||
public:
|
||||
Ceiling(const CeilingNode * n) : Expression(n) {}
|
||||
static Ceiling Builder(Expression child) { return Ceiling(child); }
|
||||
static Ceiling Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("ceil", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
explicit Ceiling(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<CeilingNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -30,11 +30,8 @@ protected:
|
||||
|
||||
class CeilingLayout final : public Layout {
|
||||
public:
|
||||
static CeilingLayout Builder(Layout l) { return CeilingLayout(l); }
|
||||
private:
|
||||
explicit CeilingLayout(Layout l) : Layout(TreePool::sharedPool()->createTreeNode<CeilingLayoutNode>()) {
|
||||
replaceChildAtIndexInPlace(0, l);
|
||||
}
|
||||
static CeilingLayout Builder(Layout l);
|
||||
CeilingLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -17,10 +17,8 @@ public:
|
||||
{}
|
||||
|
||||
// CharLayout
|
||||
virtual void setChar(char c) { m_char = c; }
|
||||
char character() const { return m_char; }
|
||||
const KDFont * font() const { return m_font; }
|
||||
void setFont(const KDFont * font) { m_font = font; }
|
||||
|
||||
// LayoutNode
|
||||
void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override;
|
||||
@@ -62,7 +60,7 @@ private:
|
||||
class CharLayout final : public Layout {
|
||||
public:
|
||||
CharLayout(const CharLayoutNode * n) : Layout(n) {}
|
||||
CharLayout(char c, const KDFont * font = KDFont::LargeFont);
|
||||
static CharLayout Builder(char c, const KDFont * font = KDFont::LargeFont);
|
||||
const KDFont * font() const { return const_cast<CharLayout *>(this)->node()->font(); }
|
||||
char character() const {return const_cast<CharLayout *>(this)->node()->character();}
|
||||
private:
|
||||
|
||||
@@ -9,9 +9,9 @@ template<typename T>
|
||||
class Complex;
|
||||
|
||||
template<typename T>
|
||||
class ComplexNode final : public std::complex<T>, public EvaluationNode<T> {
|
||||
class ComplexNode final : public EvaluationNode<T>, public std::complex<T> {
|
||||
public:
|
||||
ComplexNode() : std::complex<T>(NAN, NAN) {}
|
||||
ComplexNode(std::complex<T> c);
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(ComplexNode<T>); }
|
||||
@@ -26,7 +26,6 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual void setComplex(std::complex<T> c);
|
||||
typename Poincare::EvaluationNode<T>::Type type() const override { return Poincare::EvaluationNode<T>::Type::Complex; }
|
||||
bool isUndefined() const override {
|
||||
return (std::isnan(this->real()) && std::isnan(this->imag()));
|
||||
@@ -41,10 +40,10 @@ template<typename T>
|
||||
class Complex final : public Evaluation<T> {
|
||||
public:
|
||||
Complex(ComplexNode<T> * n) : Evaluation<T>(n) {}
|
||||
explicit Complex(T a, T b = 0.0) : Complex(std::complex<T>(a, b)) {}
|
||||
explicit Complex(std::complex<T> c);
|
||||
static Complex<T> Builder(std::complex<T> c);
|
||||
static Complex<T> Builder(T a, T b = 0.0) { return Complex<T>::Builder(std::complex<T>(a, b)); }
|
||||
static Complex<T> Undefined() {
|
||||
return Complex<T>(NAN, NAN);
|
||||
return Complex<T>::Builder(NAN, NAN);
|
||||
}
|
||||
std::complex<T> stdComplex() { return *node(); }
|
||||
T real() { return node()->real(); }
|
||||
|
||||
@@ -41,15 +41,11 @@ private:
|
||||
class ComplexArgument final : public Expression {
|
||||
public:
|
||||
ComplexArgument(const ComplexArgumentNode * n) : Expression(n) {}
|
||||
static ComplexArgument Builder(Expression child) { return ComplexArgument(child); }
|
||||
static ComplexArgument Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("arg", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit ComplexArgument(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ComplexArgumentNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ class ComplexCartesian final : public Expression {
|
||||
public:
|
||||
ComplexCartesian() : Expression() {}
|
||||
ComplexCartesian(const ComplexCartesianNode * node) : Expression(node) {}
|
||||
static ComplexCartesian Builder() { ComplexCartesianNode * node = TreePool::sharedPool()->createTreeNode<ComplexCartesianNode>(); return ComplexCartesian(node); }
|
||||
static ComplexCartesian Builder(Expression child0, Expression child1) { return ComplexCartesian(child0, child1); }
|
||||
static ComplexCartesian Builder();
|
||||
static ComplexCartesian Builder(Expression child0, Expression child1);
|
||||
|
||||
// Getters
|
||||
Expression real() { return childAtIndex(0); }
|
||||
@@ -60,10 +60,6 @@ public:
|
||||
ComplexCartesian power(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
static constexpr int k_maxNumberOfNodesBeforeInterrupting = 50;
|
||||
ComplexCartesian(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<ComplexCartesianNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
void factorAndArgumentOfFunction(Expression e, ExpressionNode::Type searchedType, Expression * factor, Expression * argument, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
ComplexCartesian interruptComputationIfManyNodes();
|
||||
static Multiplication squareRootHelper(Expression e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
|
||||
@@ -51,15 +51,8 @@ private:
|
||||
|
||||
class CondensedSumLayout final : public Layout {
|
||||
public:
|
||||
static CondensedSumLayout Builder(Layout base, Layout subscript, Layout superscript) { return CondensedSumLayout(base, subscript, superscript); }
|
||||
private:
|
||||
CondensedSumLayout(Layout base, Layout subscript, Layout superscript) :
|
||||
Layout(TreePool::sharedPool()->createTreeNode<CondensedSumLayoutNode>())
|
||||
{
|
||||
replaceChildAtIndexInPlace(0, base);
|
||||
replaceChildAtIndexInPlace(1, subscript);
|
||||
replaceChildAtIndexInPlace(2, superscript);
|
||||
}
|
||||
static CondensedSumLayout Builder(Layout base, Layout subscript, Layout superscript);
|
||||
CondensedSumLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -45,31 +45,22 @@ class ConfidenceInterval : public Expression {
|
||||
friend class SimplePredictionInterval;
|
||||
public:
|
||||
ConfidenceInterval(const ConfidenceIntervalNode * n) : Expression(n) {}
|
||||
static ConfidenceInterval Builder(Expression child0, Expression child1) { return ConfidenceInterval(child0, child1); }
|
||||
static ConfidenceInterval Builder(Expression child0, Expression child1);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("confidence", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
ConfidenceInterval(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<ConfidenceIntervalNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
constexpr static int k_maxNValue = 300;
|
||||
};
|
||||
|
||||
class SimplePredictionInterval final : public ConfidenceInterval {
|
||||
public:
|
||||
SimplePredictionInterval(const SimplePredictionIntervalNode * n) : ConfidenceInterval(n) {}
|
||||
static SimplePredictionInterval Builder(Expression child0, Expression child1) { return SimplePredictionInterval(child0, child1); }
|
||||
static SimplePredictionInterval Builder(Expression child0, Expression child1);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("prediction", 2, &UntypedBuilder);
|
||||
private:
|
||||
SimplePredictionInterval(Expression child0, Expression child1) : ConfidenceInterval(TreePool::sharedPool()->createTreeNode<SimplePredictionIntervalNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -41,15 +41,11 @@ private:
|
||||
class Conjugate final : public Expression {
|
||||
public:
|
||||
Conjugate(const ConjugateNode * n) : Expression(n) {}
|
||||
static Conjugate Builder(Expression child) { return Conjugate(child); }
|
||||
static Conjugate Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("conj", 1, &UntypedBuilder);;
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit Conjugate(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ConjugateNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -40,11 +40,8 @@ private:
|
||||
|
||||
class ConjugateLayout final : public Layout {
|
||||
public:
|
||||
static ConjugateLayout Builder(Layout l) { return ConjugateLayout(l); }
|
||||
private:
|
||||
explicit ConjugateLayout(Layout l) : Layout(TreePool::sharedPool()->createTreeNode<ConjugateLayoutNode>()) {
|
||||
replaceChildAtIndexInPlace(0, l);
|
||||
}
|
||||
static ConjugateLayout Builder(Layout child);
|
||||
ConjugateLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace Poincare {
|
||||
|
||||
class ConstantNode final : public SymbolAbstractNode {
|
||||
public:
|
||||
ConstantNode(const char * newName, int length);
|
||||
|
||||
const char * name() const override { return m_name; }
|
||||
|
||||
// TreeNode
|
||||
@@ -52,8 +54,8 @@ private:
|
||||
|
||||
class Constant final : public SymbolAbstract {
|
||||
public:
|
||||
Constant(char name);
|
||||
Constant(const ConstantNode * node) : SymbolAbstract(node) {}
|
||||
static Constant Builder(char name);
|
||||
|
||||
// Constant properties
|
||||
bool isPi() const { return node()->isPi(); }
|
||||
|
||||
@@ -46,15 +46,11 @@ private:
|
||||
class Cosine final : public Expression {
|
||||
public:
|
||||
Cosine(const CosineNode * n) : Expression(n) {}
|
||||
static Cosine Builder(Expression child) { return Cosine(child); }
|
||||
static Cosine Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("cos", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit Cosine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<CosineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -18,19 +18,13 @@ class Decimal;
|
||||
class DecimalNode final : public NumberNode {
|
||||
friend class Decimal;
|
||||
public:
|
||||
DecimalNode() :
|
||||
m_negative(false),
|
||||
m_exponent(0),
|
||||
m_numberOfDigitsInMantissa(0) {}
|
||||
|
||||
virtual void setValue(const native_uint_t * mantissaDigits, uint8_t mantissaSize, int exponent, bool negative);
|
||||
DecimalNode(const native_uint_t * mantissaDigits, uint8_t mantissaSize, int exponent, bool negative);
|
||||
|
||||
Integer signedMantissa() const;
|
||||
Integer unsignedMantissa() const;
|
||||
int exponent() const { return m_exponent; }
|
||||
|
||||
// TreeNode
|
||||
void initToMatchSize(size_t size) override;
|
||||
size_t size() const override;
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const override {
|
||||
@@ -52,10 +46,10 @@ public:
|
||||
|
||||
// Approximation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override {
|
||||
return Complex<float>(templatedApproximate<float>());
|
||||
return Complex<float>::Builder(templatedApproximate<float>());
|
||||
}
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override {
|
||||
return Complex<double>(templatedApproximate<double>());
|
||||
return Complex<double>::Builder(templatedApproximate<double>());
|
||||
}
|
||||
|
||||
// Comparison
|
||||
@@ -88,11 +82,12 @@ friend class DecimalNode;
|
||||
template<typename T>
|
||||
friend class ComplexNode;
|
||||
public:
|
||||
static int Exponent(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, const char * exponent, int exponentLength, bool exponentIsNegative = false);
|
||||
Decimal(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, int exponent);
|
||||
Decimal(DecimalNode * node) : Number(node) {}
|
||||
Decimal(Integer m, int e);
|
||||
template <typename T> Decimal(T f);
|
||||
static Decimal Builder(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, int exponent);
|
||||
static Decimal Builder(Integer m, int e);
|
||||
template <typename T> static Decimal Builder(T f);
|
||||
static int Exponent(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, const char * exponent, int exponentLength, bool exponentIsNegative = false);
|
||||
|
||||
/* k_maxExponentLength caps the string length we parse to create the exponent.
|
||||
* It prevents m_exponent (int32_t) from overflowing and giving wrong results. */
|
||||
constexpr static int k_maxExponentLength = 8;
|
||||
@@ -101,7 +96,7 @@ public:
|
||||
private:
|
||||
constexpr static int k_maxMantissaLength = 20;
|
||||
DecimalNode * node() const { return static_cast<DecimalNode *>(Number::node()); }
|
||||
Decimal(size_t size, const Integer & m, int e);
|
||||
static Decimal Builder(size_t size, const Integer & m, int e);
|
||||
Expression setSign(ExpressionNode::Sign s);
|
||||
// Simplification
|
||||
Expression shallowReduce();
|
||||
|
||||
@@ -51,7 +51,7 @@ private:
|
||||
class Derivative final : public Expression {
|
||||
public:
|
||||
Derivative(const DerivativeNode * n) : Expression(n) {}
|
||||
static Derivative Builder(Expression child0, Symbol child1, Expression child2) { return Derivative(child0, child1, child2); }
|
||||
static Derivative Builder(Expression child0, Symbol child1, Expression child2);
|
||||
static Expression UntypedBuilder(Expression children) {
|
||||
if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) {
|
||||
// Second parameter must be a Symbol.
|
||||
@@ -62,13 +62,6 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("diff", 3, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
Derivative(Expression child0, Expression child1, Expression child2) : Expression(TreePool::sharedPool()->createTreeNode<DerivativeNode>()) {
|
||||
assert(child1.type() == ExpressionNode::Type::Symbol);
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
replaceChildAtIndexInPlace(2, child2);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -35,15 +35,11 @@ private:
|
||||
class Determinant final : public Expression {
|
||||
public:
|
||||
Determinant(const DeterminantNode * n) : Expression(n) {}
|
||||
static Determinant Builder(Expression child) { return Determinant(child); }
|
||||
static Determinant Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("det", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context);
|
||||
private:
|
||||
explicit Determinant(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<DeterminantNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -61,18 +61,10 @@ private:
|
||||
class Division final : public Expression {
|
||||
public:
|
||||
Division(const DivisionNode * n) : Expression(n) {}
|
||||
static Division Builder() { return Division(); }
|
||||
static Division Builder(Expression numerator, Expression denominator) {
|
||||
Division d;
|
||||
d.replaceChildAtIndexInPlace(0, numerator);
|
||||
d.replaceChildAtIndexInPlace(1, denominator);
|
||||
return d;
|
||||
}
|
||||
static Division Builder();
|
||||
static Division Builder(Expression numerator, Expression denominator);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
|
||||
private:
|
||||
Division() : Expression(TreePool::sharedPool()->createTreeNode<DivisionNode>()) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -38,17 +38,12 @@ private:
|
||||
class DivisionQuotient final : public Expression {
|
||||
public:
|
||||
DivisionQuotient(const DivisionQuotientNode * n) : Expression(n) {}
|
||||
static DivisionQuotient Builder(Expression child0, Expression child1) { return DivisionQuotient(child0, child1); }
|
||||
static DivisionQuotient Builder(Expression child0, Expression child1);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("quo", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
DivisionQuotient(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<DivisionQuotientNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -39,17 +39,12 @@ private:
|
||||
class DivisionRemainder final : public Expression {
|
||||
public:
|
||||
DivisionRemainder(const DivisionRemainderNode * n) : Expression(n) {}
|
||||
static DivisionRemainder Builder(Expression child0, Expression child1) { return DivisionRemainder(child0, child1); }
|
||||
static DivisionRemainder Builder(Expression child0, Expression child1);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("rem", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
DivisionRemainder(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<DivisionRemainderNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ private:
|
||||
|
||||
class EmptyExpression final : public Expression {
|
||||
public:
|
||||
EmptyExpression();
|
||||
static EmptyExpression Builder();
|
||||
EmptyExpression(const EmptyExpressionNode * n) : Expression(n) {}
|
||||
};
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ public:
|
||||
void setColor(Color color) { m_color = color; }
|
||||
bool isVisible() const { return m_isVisible; }
|
||||
void setVisible(bool visible) { m_isVisible = visible; }
|
||||
void setMargins(bool margins) { m_margins = margins; }
|
||||
void setFont(const KDFont * font) { m_font = font; }
|
||||
|
||||
// LayoutNode
|
||||
void deleteBeforeCursor(LayoutCursor * cursor) override;
|
||||
@@ -75,7 +73,7 @@ private:
|
||||
class EmptyLayout final : public Layout {
|
||||
public:
|
||||
EmptyLayout(const EmptyLayoutNode * n);
|
||||
EmptyLayout(EmptyLayoutNode::Color color = EmptyLayoutNode::Color::Yellow, bool visible = true, const KDFont * font = KDFont::LargeFont, bool margins = true);
|
||||
static EmptyLayout Builder(EmptyLayoutNode::Color color = EmptyLayoutNode::Color::Yellow, bool visible = true, const KDFont * font = KDFont::LargeFont, bool margins = true);
|
||||
void setVisible(bool visible) {
|
||||
node()->setVisible(visible);
|
||||
}
|
||||
|
||||
@@ -35,10 +35,7 @@ private:
|
||||
class Equal final : public Expression {
|
||||
public:
|
||||
Equal(const EqualNode * n) : Expression(n) {}
|
||||
Equal(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<EqualNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
static Equal Builder(Expression child0, Expression child1);
|
||||
|
||||
// For the equation A = B, create the reduced expression A-B
|
||||
Expression standardEquation(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
@@ -37,16 +37,12 @@ private:
|
||||
class Factor final : public Expression {
|
||||
public:
|
||||
Factor(const FactorNode * n) : Expression(n) {}
|
||||
static Factor Builder(Expression child) { return Factor(child); }
|
||||
static Factor Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("factor", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Multiplication createMultiplicationOfIntegerPrimeDecomposition(Integer i, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
private:
|
||||
explicit Factor(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<FactorNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -52,18 +52,13 @@ private:
|
||||
class Factorial final : public Expression {
|
||||
public:
|
||||
Factorial(const FactorialNode * n) : Expression(n) {}
|
||||
static Factorial Builder() { return Factorial(); }
|
||||
static Factorial Builder(Expression child) {
|
||||
Factorial f;
|
||||
f.replaceChildAtIndexInPlace(0, child);
|
||||
return f;
|
||||
}
|
||||
static Factorial Builder();
|
||||
static Factorial Builder(Expression child);
|
||||
|
||||
Expression shallowReduce();
|
||||
Expression shallowBeautify();
|
||||
private:
|
||||
constexpr static int k_maxOperandValue = 100;
|
||||
Factorial() : Expression(TreePool::sharedPool()->createTreeNode<FactorialNode>()) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -20,10 +20,8 @@ namespace Poincare {
|
||||
template<typename T>
|
||||
class FloatNode final : public NumberNode {
|
||||
public:
|
||||
FloatNode() : m_value(0.0) {}
|
||||
FloatNode(T value = 0.0) : m_value(value) {}
|
||||
|
||||
|
||||
void setFloat(T a) { m_value = a; }
|
||||
T value() const { return m_value; }
|
||||
|
||||
// TreeNode
|
||||
@@ -52,7 +50,7 @@ public:
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, complexFormat, angleUnit); }
|
||||
private:
|
||||
template<typename U> Evaluation<U> templatedApproximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
|
||||
return Complex<U>((U)m_value);
|
||||
return Complex<U>::Builder((U)m_value);
|
||||
}
|
||||
T m_value;
|
||||
};
|
||||
@@ -60,7 +58,7 @@ private:
|
||||
template<typename T>
|
||||
class Float final : public Number {
|
||||
public:
|
||||
Float(T value);
|
||||
static Float Builder(T value);
|
||||
private:
|
||||
FloatNode<T> * node() const { return static_cast<FloatNode<T> *>(Number::node()); }
|
||||
};
|
||||
|
||||
@@ -44,15 +44,11 @@ private:
|
||||
class Floor final : public Expression {
|
||||
public:
|
||||
Floor(const FloorNode * n) : Expression(n) {}
|
||||
static Floor Builder(Expression child) { return Floor(child); }
|
||||
static Floor Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("floor", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
explicit Floor(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<FloorNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -29,11 +29,8 @@ protected:
|
||||
|
||||
class FloorLayout final : public Layout {
|
||||
public:
|
||||
static FloorLayout Builder(Layout l) { return FloorLayout(l); }
|
||||
private:
|
||||
explicit FloorLayout(Layout l) : Layout(TreePool::sharedPool()->createTreeNode<FloorLayoutNode>()) {
|
||||
replaceChildAtIndexInPlace(0, l);
|
||||
}
|
||||
static FloorLayout Builder(Layout child);
|
||||
FloorLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -44,15 +44,11 @@ private:
|
||||
class FracPart final : public Expression {
|
||||
public:
|
||||
FracPart(const FracPartNode * n) : Expression(n) {}
|
||||
static FracPart Builder(Expression child) { return FracPart(child); }
|
||||
static FracPart Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("frac", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
explicit FracPart(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<FracPartNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -58,14 +58,8 @@ private:
|
||||
|
||||
class FractionLayout final : public Layout {
|
||||
public:
|
||||
static FractionLayout Builder(Layout numerator, Layout denominator) { return FractionLayout(numerator, denominator); }
|
||||
private:
|
||||
FractionLayout(Layout numerator, Layout denominator) :
|
||||
Layout(TreePool::sharedPool()->createTreeNode<FractionLayoutNode>())
|
||||
{
|
||||
replaceChildAtIndexInPlace(0, numerator);
|
||||
replaceChildAtIndexInPlace(1, denominator);
|
||||
}
|
||||
static FractionLayout Builder(Layout numerator, Layout denominator);
|
||||
FractionLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace Poincare {
|
||||
|
||||
class FunctionNode : public SymbolAbstractNode {
|
||||
public:
|
||||
FunctionNode(const char * newName, int length);
|
||||
|
||||
// SymbolAbstractNode
|
||||
const char * name() const override { return m_name; }
|
||||
|
||||
@@ -49,15 +51,12 @@ private:
|
||||
class Function : public SymbolAbstract {
|
||||
friend class FunctionNode;
|
||||
public:
|
||||
Function(const char * name, size_t length);
|
||||
Function(const FunctionNode * n) : SymbolAbstract(n) {}
|
||||
Function(const char * name, size_t length, Expression child) : Function(name, length) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
static Function Builder(const char * name, size_t length, Expression child = Expression());
|
||||
static Expression UntypedBuilder(const char * name, size_t length, Expression child, Context * context) {
|
||||
/* Create an expression only if it is not in the context or defined as a
|
||||
* function */
|
||||
Function f(name, length, child);
|
||||
Function f = Function::Builder(name, length, child);
|
||||
if (SymbolAbstract::ValidInContext(f, context)) {
|
||||
return f;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,12 @@ namespace Poincare {
|
||||
|
||||
class Ghost final : public TreeHandle {
|
||||
public:
|
||||
static Ghost Builder() { return Ghost(); }
|
||||
private:
|
||||
Ghost() : TreeHandle(TreePool::sharedPool()->createTreeNode<GhostNode>()) {}
|
||||
static Ghost Builder() {
|
||||
void * bufferNode = TreePool::sharedPool()->alloc(sizeof(GhostNode));
|
||||
GhostNode * node = new (bufferNode) GhostNode();
|
||||
TreeHandle h = TreeHandle::BuildWithBasicChildren(node);
|
||||
return static_cast<Ghost &>(h);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -37,17 +37,12 @@ private:
|
||||
class GreatCommonDivisor final : public Expression {
|
||||
public:
|
||||
GreatCommonDivisor(const GreatCommonDivisorNode * n) : Expression(n) {}
|
||||
static GreatCommonDivisor Builder(Expression child0, Expression child1) { return GreatCommonDivisor(child0, child1); }
|
||||
static GreatCommonDivisor Builder(Expression child0, Expression child1);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("gcd", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
GreatCommonDivisor(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<GreatCommonDivisorNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ private:
|
||||
class GridLayout : public Layout {
|
||||
public:
|
||||
GridLayout(const GridLayoutNode * n) : Layout(n) {}
|
||||
static GridLayout Builder() { return GridLayout(); }
|
||||
static GridLayout Builder();
|
||||
void setDimensions(int rows, int columns);
|
||||
void addChildAtIndex(Layout l, int index, int currentNumberOfChildren, LayoutCursor * cursor) {
|
||||
Layout::addChildAtIndex(l, index, currentNumberOfChildren, cursor);
|
||||
@@ -97,7 +97,6 @@ public:
|
||||
int numberOfRows() const { return node()->numberOfRows(); }
|
||||
int numberOfColumns() const { return node()->numberOfColumns(); }
|
||||
private:
|
||||
GridLayout() : Layout(TreePool::sharedPool()->createTreeNode<GridLayoutNode>()) {}
|
||||
virtual GridLayoutNode * node() const { return static_cast<GridLayoutNode *>(Layout::node()); }
|
||||
void setNumberOfRows(int rows) {
|
||||
assert(rows >= 0);
|
||||
|
||||
@@ -68,7 +68,7 @@ class HorizontalLayout final : public Layout {
|
||||
public:
|
||||
// Constructors
|
||||
HorizontalLayout(HorizontalLayoutNode * n) : Layout(n) {}
|
||||
static HorizontalLayout Builder() { return HorizontalLayout(); }
|
||||
static HorizontalLayout Builder();
|
||||
static HorizontalLayout Builder(Layout l) { return HorizontalLayout::Builder(&l, 1); }
|
||||
static HorizontalLayout Builder(Layout l1, Layout l2) { return HorizontalLayout::Builder(ArrayBuilder<Layout>(l1, l2).array(), 2); }
|
||||
static HorizontalLayout Builder(Layout l1, Layout l2, Layout l3) { return HorizontalLayout::Builder(ArrayBuilder<Layout>(l1, l2, l3).array(), 3); }
|
||||
@@ -93,7 +93,6 @@ public:
|
||||
void mergeChildrenAtIndex(HorizontalLayout h, int index, bool removeEmptyChildren, LayoutCursor * cursor = nullptr);
|
||||
|
||||
private:
|
||||
HorizontalLayout() : Layout(TreePool::sharedPool()->createTreeNode<HorizontalLayoutNode>()) {}
|
||||
void removeEmptyChildBeforeInsertionAtIndex(int * index, int * currentNumberOfChildren, bool shouldRemoveOnLeft, LayoutCursor * cursor = nullptr);
|
||||
};
|
||||
|
||||
|
||||
@@ -36,13 +36,9 @@ private:
|
||||
class HyperbolicArcCosine final : public HyperbolicTrigonometricFunction {
|
||||
public:
|
||||
HyperbolicArcCosine(const HyperbolicArcCosineNode * n) : HyperbolicTrigonometricFunction(n) {}
|
||||
static HyperbolicArcCosine Builder(Expression child) { return HyperbolicArcCosine(child); }
|
||||
static HyperbolicArcCosine Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("acosh", 1, &UntypedBuilder);
|
||||
private:
|
||||
explicit HyperbolicArcCosine(Expression child) : HyperbolicTrigonometricFunction(TreePool::sharedPool()->createTreeNode<HyperbolicArcCosineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -36,13 +36,9 @@ private:
|
||||
class HyperbolicArcSine final : public HyperbolicTrigonometricFunction {
|
||||
public:
|
||||
HyperbolicArcSine(const HyperbolicArcSineNode * n) : HyperbolicTrigonometricFunction(n) {}
|
||||
static HyperbolicArcSine Builder(Expression child) { return HyperbolicArcSine(child); }
|
||||
static HyperbolicArcSine Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("asinh", 1, &UntypedBuilder);
|
||||
private:
|
||||
explicit HyperbolicArcSine(Expression child) : HyperbolicTrigonometricFunction(TreePool::sharedPool()->createTreeNode<HyperbolicArcSineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -36,13 +36,9 @@ private:
|
||||
class HyperbolicArcTangent final : public HyperbolicTrigonometricFunction {
|
||||
public:
|
||||
HyperbolicArcTangent(const HyperbolicArcTangentNode * n) : HyperbolicTrigonometricFunction(n) {}
|
||||
static HyperbolicArcTangent Builder(Expression child) { return HyperbolicArcTangent(child); }
|
||||
static HyperbolicArcTangent Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("atanh", 1, &UntypedBuilder);
|
||||
private:
|
||||
explicit HyperbolicArcTangent(Expression child) : HyperbolicTrigonometricFunction(TreePool::sharedPool()->createTreeNode<HyperbolicArcTangentNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -36,13 +36,9 @@ private:
|
||||
class HyperbolicCosine final : public HyperbolicTrigonometricFunction {
|
||||
public:
|
||||
HyperbolicCosine(const HyperbolicCosineNode * n) : HyperbolicTrigonometricFunction(n) {}
|
||||
static HyperbolicCosine Builder(Expression child) { return HyperbolicCosine(child); }
|
||||
static HyperbolicCosine Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("cosh", 1, &UntypedBuilder);
|
||||
private:
|
||||
explicit HyperbolicCosine(Expression child) : HyperbolicTrigonometricFunction(TreePool::sharedPool()->createTreeNode<HyperbolicCosineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -36,13 +36,9 @@ private:
|
||||
class HyperbolicSine final : public HyperbolicTrigonometricFunction {
|
||||
public:
|
||||
HyperbolicSine(const HyperbolicSineNode * n) : HyperbolicTrigonometricFunction(n) {}
|
||||
static HyperbolicSine Builder(Expression child) { return HyperbolicSine(child); }
|
||||
static HyperbolicSine Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sinh", 1, &UntypedBuilder);
|
||||
private:
|
||||
explicit HyperbolicSine(Expression child) : HyperbolicTrigonometricFunction(TreePool::sharedPool()->createTreeNode<HyperbolicSineNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -36,13 +36,9 @@ private:
|
||||
class HyperbolicTangent final : public HyperbolicTrigonometricFunction {
|
||||
public:
|
||||
HyperbolicTangent(const HyperbolicTangentNode * n) : HyperbolicTrigonometricFunction(n) {}
|
||||
static HyperbolicTangent Builder(Expression child) { return HyperbolicTangent(child); }
|
||||
static HyperbolicTangent Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("tanh", 1, &UntypedBuilder);
|
||||
private:
|
||||
explicit HyperbolicTangent(Expression child) : HyperbolicTrigonometricFunction(TreePool::sharedPool()->createTreeNode<HyperbolicTangentNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ private:
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> computeOnComplex(const std::complex<T> c, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) {
|
||||
return Complex<T>(std::imag(c));
|
||||
return Complex<T>::Builder(std::imag(c));
|
||||
}
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override {
|
||||
return ApproximationHelper::Map<float>(this, context, complexFormat, angleUnit,computeOnComplex<float>);
|
||||
@@ -45,15 +45,11 @@ private:
|
||||
class ImaginaryPart final : public Expression {
|
||||
public:
|
||||
ImaginaryPart(const ImaginaryPartNode * n) : Expression(n) {}
|
||||
static ImaginaryPart Builder(Expression child) { return ImaginaryPart(child); }
|
||||
static ImaginaryPart Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("im", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit ImaginaryPart(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<ImaginaryPartNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace Poincare {
|
||||
|
||||
class InfinityNode final : public NumberNode {
|
||||
public:
|
||||
InfinityNode(bool negative) : NumberNode(), m_negative(negative) {}
|
||||
|
||||
void setNegative(bool negative) { m_negative = negative; }
|
||||
Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override;
|
||||
|
||||
// TreeNode
|
||||
@@ -45,9 +45,7 @@ private:
|
||||
class Infinity final : public Number {
|
||||
public:
|
||||
Infinity(InfinityNode * n) : Number(n) {}
|
||||
Infinity(bool negative) : Number(TreePool::sharedPool()->createTreeNode<InfinityNode>()) {
|
||||
node()->setNegative(negative);
|
||||
}
|
||||
static Infinity Builder(bool negative);
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
static const char * Name() {
|
||||
return "inf";
|
||||
|
||||
@@ -31,8 +31,8 @@ struct IntegerDivision;
|
||||
|
||||
class IntegerNode final : public TreeNode {
|
||||
public:
|
||||
IntegerNode(const native_uint_t * digits, uint8_t numberOfDigits);
|
||||
// TreeNode
|
||||
void initToMatchSize(size_t goalSize) override;
|
||||
size_t size() const override;
|
||||
int numberOfChildren() const override { return 0; }
|
||||
#if POINCARE_TREE_LOG
|
||||
@@ -43,7 +43,6 @@ public:
|
||||
virtual void logAttributes(std::ostream & stream) const override;
|
||||
#endif
|
||||
|
||||
virtual void setDigits(const native_uint_t * digits, uint8_t numberOfDigits);
|
||||
const native_uint_t * digits() const { return m_digits; }
|
||||
uint8_t numberOfDigits() const { return m_numberOfDigits; }
|
||||
private:
|
||||
|
||||
@@ -55,7 +55,7 @@ private:
|
||||
class Integral final : public Expression {
|
||||
public:
|
||||
Integral(const IntegralNode * n) : Expression(n) {}
|
||||
static Integral Builder(Expression child0, Symbol child1, Expression child2, Expression child3) { return Integral(child0, child1, child2, child3); }
|
||||
static Integral Builder(Expression child0, Symbol child1, Expression child2, Expression child3);
|
||||
static Expression UntypedBuilder(Expression children) {
|
||||
if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) {
|
||||
// Second parameter must be a Symbol.
|
||||
@@ -67,14 +67,6 @@ public:
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
Integral(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode<IntegralNode>()) {
|
||||
assert(child1.type() == ExpressionNode::Type::Symbol);
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
replaceChildAtIndexInPlace(2, child2);
|
||||
replaceChildAtIndexInPlace(3, child3);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -56,16 +56,8 @@ private:
|
||||
|
||||
class IntegralLayout final : public Layout {
|
||||
public:
|
||||
static IntegralLayout Builder(Layout integrand, Layout differential, Layout lowerBound, Layout upperBound) { return IntegralLayout(integrand, differential, lowerBound, upperBound); }
|
||||
private:
|
||||
IntegralLayout(Layout integrand, Layout differential, Layout lowerBound, Layout upperBound) :
|
||||
Layout(TreePool::sharedPool()->createTreeNode<IntegralLayoutNode>())
|
||||
{
|
||||
replaceChildAtIndexInPlace(0, integrand);
|
||||
replaceChildAtIndexInPlace(1, differential);
|
||||
replaceChildAtIndexInPlace(2, lowerBound);
|
||||
replaceChildAtIndexInPlace(3, upperBound);
|
||||
}
|
||||
static IntegralLayout Builder(Layout integrand, Layout differential, Layout lowerBound, Layout upperBound);
|
||||
IntegralLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -37,17 +37,12 @@ private:
|
||||
class LeastCommonMultiple final : public Expression {
|
||||
public:
|
||||
LeastCommonMultiple(const LeastCommonMultipleNode * n) : Expression(n) {}
|
||||
static LeastCommonMultiple Builder(Expression child0, Expression child1) { return LeastCommonMultiple(child0, child1); }
|
||||
static LeastCommonMultiple Builder(Expression child0, Expression child1);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("lcm", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
LeastCommonMultiple(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<LeastCommonMultipleNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -35,9 +35,8 @@ protected:
|
||||
|
||||
class LeftParenthesisLayout final : public Layout {
|
||||
public:
|
||||
static LeftParenthesisLayout Builder() { return LeftParenthesisLayout(); }
|
||||
private:
|
||||
LeftParenthesisLayout() : Layout(TreePool::sharedPool()->createTreeNode<LeftParenthesisLayoutNode>()) {}
|
||||
static LeftParenthesisLayout Builder();
|
||||
LeftParenthesisLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -29,9 +29,8 @@ protected:
|
||||
|
||||
class LeftSquareBracketLayout final : public Layout {
|
||||
public:
|
||||
static LeftSquareBracketLayout Builder() { return LeftSquareBracketLayout(); }
|
||||
private:
|
||||
LeftSquareBracketLayout() : Layout(TreePool::sharedPool()->createTreeNode<LeftSquareBracketLayoutNode>()) {}
|
||||
static LeftSquareBracketLayout Builder();
|
||||
LeftSquareBracketLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
/* log has a branch cut on ]-inf, 0]: it is then multivalued on this cut. We
|
||||
* followed the convention chosen by the lib c++ of llvm on ]-inf+0i, 0+0i]
|
||||
* (warning: log takes the other side of the cut values on ]-inf-0i, 0-0i]). */
|
||||
return Complex<U>(std::log10(c));
|
||||
return Complex<U>::Builder(std::log10(c));
|
||||
}
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, complexFormat, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, complexFormat, angleUnit); }
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
class Logarithm final : public Expression {
|
||||
public:
|
||||
Logarithm(const LogarithmNode<2> * n) : Expression(n) {}
|
||||
static Logarithm Builder(Expression child0, Expression child1) { return Logarithm(child0, child1); }
|
||||
static Logarithm Builder(Expression child0, Expression child1);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("log", 2, &UntypedBuilder);
|
||||
|
||||
@@ -52,10 +52,6 @@ public:
|
||||
Expression shallowBeautify();
|
||||
|
||||
private:
|
||||
Logarithm(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<LogarithmNode<2> >()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
Expression simpleShallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit);
|
||||
Integer simplifyLogarithmIntegerBaseInteger(Integer i, Integer & base, Addition & a, bool isDenominator);
|
||||
Expression splitLogarithmInteger(Integer i, bool isDenominator, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
@@ -65,15 +61,11 @@ private:
|
||||
class CommonLogarithm : public Expression {
|
||||
public:
|
||||
CommonLogarithm(const LogarithmNode<1> * n) : Expression(n) {}
|
||||
static CommonLogarithm Builder(Expression child) { return CommonLogarithm(child); }
|
||||
static CommonLogarithm Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("log", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit CommonLogarithm(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<LogarithmNode<1> >()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class Matrix final : public Expression {
|
||||
friend class GlobalContext;
|
||||
public:
|
||||
Matrix(const MatrixNode * node) : Expression(node) {}
|
||||
static Matrix Builder() { return Matrix(); }
|
||||
static Matrix Builder();
|
||||
|
||||
void setDimensions(int rows, int columns);
|
||||
int numberOfRows() const { return node()->numberOfRows(); }
|
||||
@@ -85,7 +85,6 @@ public:
|
||||
Expression inverse(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
#endif
|
||||
private:
|
||||
Matrix() : Matrix(TreePool::sharedPool()->createTreeNode<MatrixNode>()) {}
|
||||
// TODO: find another solution for inverse and determinant (avoid capping the matrix)
|
||||
static constexpr int k_maxNumberOfCoefficients = 100;
|
||||
|
||||
|
||||
@@ -57,8 +57,8 @@ class MatrixComplex final : public Evaluation<T> {
|
||||
friend class MatrixComplexNode<T>;
|
||||
public:
|
||||
MatrixComplex(MatrixComplexNode<T> * node) : Evaluation<T>(node) {}
|
||||
MatrixComplex();
|
||||
MatrixComplex(std::complex<T> * operands, int numberOfRows, int numberOfColumns);
|
||||
static MatrixComplex Builder();
|
||||
static MatrixComplex Builder(std::complex<T> * operands, int numberOfRows, int numberOfColumns);
|
||||
static MatrixComplex<T> Undefined();
|
||||
static MatrixComplex<T> createIdentity(int dim);
|
||||
MatrixComplex<T> inverse() const { return node()->inverse(); }
|
||||
|
||||
@@ -35,15 +35,11 @@ private:
|
||||
class MatrixDimension final : public Expression {
|
||||
public:
|
||||
MatrixDimension(const MatrixDimensionNode * n) : Expression(n) {}
|
||||
static MatrixDimension Builder(Expression child) { return MatrixDimension(child); }
|
||||
static MatrixDimension Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("dim", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
explicit MatrixDimension(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<MatrixDimensionNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -34,15 +34,11 @@ private:
|
||||
class MatrixInverse final : public Expression {
|
||||
public:
|
||||
MatrixInverse(const MatrixInverseNode * n) : Expression(n) {}
|
||||
static MatrixInverse Builder(Expression child) { return MatrixInverse(child); }
|
||||
static MatrixInverse Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("inverse", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit MatrixInverse(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<MatrixInverseNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ private:
|
||||
class MatrixLayout /*final*/ : public GridLayout {
|
||||
friend class MatrixLayoutNode;
|
||||
public:
|
||||
static MatrixLayout Builder() { return MatrixLayout(); }
|
||||
MatrixLayout(const MatrixLayoutNode * n) : GridLayout(n) {}
|
||||
static MatrixLayout Builder();
|
||||
static MatrixLayout Builder(Layout l1, Layout l2, Layout l3, Layout l4) {
|
||||
MatrixLayout m = MatrixLayout::Builder();
|
||||
m.addChildAtIndexInPlace(l1, 0, 0);
|
||||
@@ -73,7 +73,6 @@ public:
|
||||
void addGreySquares() { node()->addGreySquares(); }
|
||||
void removeGreySquares() { node()->removeGreySquares(); }
|
||||
private:
|
||||
MatrixLayout() : GridLayout(TreePool::sharedPool()->createTreeNode<MatrixLayoutNode>()) {}
|
||||
MatrixLayoutNode * node() const { return static_cast<MatrixLayoutNode *>(Layout::node()); }
|
||||
};
|
||||
|
||||
|
||||
@@ -34,15 +34,11 @@ private:
|
||||
class MatrixTrace final : public Expression {
|
||||
public:
|
||||
MatrixTrace(const MatrixTraceNode * n) : Expression(n) {}
|
||||
static MatrixTrace Builder(Expression child) { return MatrixTrace(child); }
|
||||
static MatrixTrace Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("trace", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
explicit MatrixTrace(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<MatrixTraceNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -34,15 +34,11 @@ private:
|
||||
class MatrixTranspose final : public Expression {
|
||||
public:
|
||||
MatrixTranspose(const MatrixTransposeNode * n) : Expression(n) {}
|
||||
static MatrixTranspose Builder(Expression child) { return MatrixTranspose(child); }
|
||||
static MatrixTranspose Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("transpose", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
explicit MatrixTranspose(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<MatrixTransposeNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const override;
|
||||
|
||||
// Approximation
|
||||
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d, Preferences::ComplexFormat complexFormat) { return Complex<T>(c*d); }
|
||||
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d, Preferences::ComplexFormat complexFormat) { return Complex<T>::Builder(c*d); }
|
||||
template<typename T> static MatrixComplex<T> computeOnComplexAndMatrix(const std::complex<T> c, const MatrixComplex<T> m, Preferences::ComplexFormat complexFormat) {
|
||||
return ApproximationHelper::ElementWiseOnMatrixComplexAndComplex(m, c, complexFormat, compute<T>);
|
||||
}
|
||||
@@ -67,10 +67,10 @@ class Multiplication final : public NAryExpression {
|
||||
friend class Power;
|
||||
public:
|
||||
Multiplication(const MultiplicationNode * n) : NAryExpression(n) {}
|
||||
static Multiplication Builder() { return Multiplication(); }
|
||||
static Multiplication Builder(Expression e1) { return Multiplication(&e1, 1); }
|
||||
static Multiplication Builder(Expression e1, Expression e2) { return Multiplication(ArrayBuilder<Expression>(e1, e2).array(), 2); }
|
||||
static Multiplication Builder(Expression e1, Expression e2, Expression e3) { return Multiplication(ArrayBuilder<Expression>(e1, e2, e3).array(), 3); }
|
||||
static Multiplication Builder();
|
||||
static Multiplication Builder(Expression e1) { return Multiplication::Builder(&e1, 1); }
|
||||
static Multiplication Builder(Expression e1, Expression e2) { return Multiplication::Builder(ArrayBuilder<Expression>(e1, e2).array(), 2); }
|
||||
static Multiplication Builder(Expression e1, Expression e2, Expression e3) { return Multiplication::Builder(ArrayBuilder<Expression>(e1, e2, e3).array(), 3); }
|
||||
|
||||
template<typename T> static void computeOnArrays(T * m, T * n, T * result, int mNumberOfColumns, int mNumberOfRows, int nNumberOfColumns);
|
||||
// Expression
|
||||
@@ -81,12 +81,8 @@ public:
|
||||
Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
private:
|
||||
// Constructors
|
||||
Multiplication() : NAryExpression(TreePool::sharedPool()->createTreeNode<MultiplicationNode>()) {}
|
||||
explicit Multiplication(Expression * children, size_t numberOfChildren) : Multiplication() {
|
||||
for (size_t i = 0; i < numberOfChildren; i++) {
|
||||
addChildAtIndexInPlace(children[i], i, i);
|
||||
}
|
||||
}
|
||||
static Multiplication Builder(Expression * children, size_t numberOfChildren);
|
||||
|
||||
// Simplification
|
||||
Expression privateShallowReduce(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool expand, bool canBeInterrupted);
|
||||
void mergeMultiplicationChildrenInPlace();
|
||||
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
/* ln has a branch cut on ]-inf, 0]: it is then multivalued on this cut. We
|
||||
* followed the convention chosen by the lib c++ of llvm on ]-inf+0i, 0+0i]
|
||||
* (warning: ln takes the other side of the cut values on ]-inf-0i, 0-0i]). */
|
||||
return Complex<T>(std::log(c));
|
||||
return Complex<T>::Builder(std::log(c));
|
||||
}
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override {
|
||||
return ApproximationHelper::Map<float>(this, context, complexFormat, angleUnit,computeOnComplex<float>);
|
||||
@@ -44,15 +44,11 @@ private:
|
||||
class NaperianLogarithm final : public Expression {
|
||||
public:
|
||||
NaperianLogarithm(const NaperianLogarithmNode * n) : Expression(n) {}
|
||||
static NaperianLogarithm Builder(Expression child) { return NaperianLogarithm(child); }
|
||||
static NaperianLogarithm Builder(Expression child);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("ln", 1, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
explicit NaperianLogarithm(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<NaperianLogarithmNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -35,16 +35,11 @@ private:
|
||||
class NthRoot final : public Expression {
|
||||
public:
|
||||
NthRoot(const NthRootNode * n) : Expression(n) {}
|
||||
static NthRoot Builder(Expression child0, Expression child1) { return NthRoot(child0, child1); }
|
||||
static NthRoot Builder(Expression child0, Expression child1);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("root", 2, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
private:
|
||||
NthRoot(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<NthRootNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ public:
|
||||
constexpr static KDCoordinate k_leftRadixHeight = 8;
|
||||
constexpr static KDCoordinate k_leftRadixWidth = 5;
|
||||
|
||||
NthRootLayoutNode() :
|
||||
NthRootLayoutNode(bool hasIndex) :
|
||||
LayoutNode(),
|
||||
m_hasIndex(false)
|
||||
m_hasIndex(hasIndex)
|
||||
{}
|
||||
|
||||
// LayoutNode
|
||||
@@ -50,14 +50,6 @@ private:
|
||||
constexpr static KDCoordinate k_heightMargin = 2;
|
||||
constexpr static KDCoordinate k_widthMargin = 2;
|
||||
constexpr static KDCoordinate k_radixLineThickness = 1;
|
||||
void setNumberOfChildren(int number) {
|
||||
assert(number == 1 || number == 2);
|
||||
if (number == 1) {
|
||||
m_hasIndex = false;
|
||||
} else {
|
||||
m_hasIndex = true;
|
||||
}
|
||||
}
|
||||
KDSize adjustedIndexSize();
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
|
||||
LayoutNode * radicandLayout() { return childAtIndex(0); }
|
||||
@@ -67,17 +59,9 @@ private:
|
||||
|
||||
class NthRootLayout final : public Layout {
|
||||
public:
|
||||
static NthRootLayout Builder(Layout radicand) { return NthRootLayout(radicand); }
|
||||
static NthRootLayout Builder(Layout radicand, Layout index) {
|
||||
NthRootLayout n(radicand);
|
||||
n.addChildAtIndexInPlace(index, 1, 1);
|
||||
static_cast<NthRootLayoutNode *>(n.node())->setNumberOfChildren(2);
|
||||
return n;
|
||||
}
|
||||
private:
|
||||
NthRootLayout(Layout radicand) : Layout(TreePool::sharedPool()->createTreeNode<NthRootLayoutNode>()) {
|
||||
replaceChildAtIndexInPlace(0, radicand);
|
||||
}
|
||||
NthRootLayout() = delete;
|
||||
static NthRootLayout Builder(Layout child);
|
||||
static NthRootLayout Builder(Layout radicand, Layout index);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class Opposite;
|
||||
|
||||
class OppositeNode /*final*/ : public ExpressionNode {
|
||||
public:
|
||||
template<typename T> static Complex<T> compute(const std::complex<T> c, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit = Preferences::AngleUnit::Degree) { return Complex<T>(-c); }
|
||||
template<typename T> static Complex<T> compute(const std::complex<T> c, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit = Preferences::AngleUnit::Degree) { return Complex<T>::Builder(-c); }
|
||||
|
||||
|
||||
// TreeNode
|
||||
@@ -47,16 +47,10 @@ public:
|
||||
class Opposite final : public Expression {
|
||||
public:
|
||||
Opposite(const OppositeNode * n) : Expression(n) {}
|
||||
static Opposite Builder() { return Opposite(); }
|
||||
static Opposite Builder(Expression child) { return Opposite(child); }
|
||||
static Opposite Builder();
|
||||
static Opposite Builder(Expression child);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
|
||||
private:
|
||||
Opposite() : Expression(TreePool::sharedPool()->createTreeNode<OppositeNode>()) {}
|
||||
explicit Opposite(Expression child) : Expression(TreePool::sharedPool()->createTreeNode<OppositeNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -38,14 +38,9 @@ private:
|
||||
class Parenthesis final : public Expression {
|
||||
public:
|
||||
Parenthesis(const ParenthesisNode * n) : Expression(n) {}
|
||||
static Parenthesis Builder(Expression child) { return Parenthesis(child); }
|
||||
static Parenthesis Builder(Expression child);
|
||||
// Expression
|
||||
Expression shallowReduce();
|
||||
|
||||
private:
|
||||
Parenthesis(Expression exp) : Expression(TreePool::sharedPool()->createTreeNode<ParenthesisNode>()) {
|
||||
replaceChildAtIndexInPlace(0, exp);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -41,17 +41,13 @@ private:
|
||||
class PermuteCoefficient final : public Expression {
|
||||
public:
|
||||
PermuteCoefficient(const PermuteCoefficientNode * n) : Expression(n) {}
|
||||
static PermuteCoefficient Builder(Expression child0, Expression child1) { return PermuteCoefficient(child0, child1); }
|
||||
static PermuteCoefficient Builder(Expression child0, Expression child1);
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); }
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("permute", 2, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce();
|
||||
private:
|
||||
PermuteCoefficient(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode<PermuteCoefficientNode>()) {
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
}
|
||||
|
||||
constexpr static int k_maxNValue = 100;
|
||||
};
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class Power final : public Expression {
|
||||
friend class Round;
|
||||
public:
|
||||
Power(const PowerNode * n) : Expression(n) {}
|
||||
static Power Builder(Expression base, Expression exponent) { return Power(base, exponent); }
|
||||
static Power Builder(Expression base, Expression exponent);
|
||||
|
||||
Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target);
|
||||
int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const;
|
||||
@@ -78,12 +78,6 @@ private:
|
||||
constexpr static int k_maxExactPowerMatrix = 100;
|
||||
constexpr static int k_maxNumberOfTermsInExpandedMultinome = 25;
|
||||
|
||||
// Constructors
|
||||
Power(Expression base, Expression exponent) : Expression(TreePool::sharedPool()->createTreeNode<PowerNode>()) {
|
||||
replaceChildAtIndexInPlace(0, base);
|
||||
replaceChildAtIndexInPlace(1, exponent);
|
||||
}
|
||||
|
||||
// Simplification
|
||||
Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user