mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare] Derivative, Integral, Product, Sum constructors check
their second parameter is of Symbol type.
This commit is contained in:
committed by
Émilie Feral
parent
4b72e4cef2
commit
93d8f60619
@@ -2,6 +2,7 @@
|
||||
#define POINCARE_DERIVATIVE_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/variable_context.h>
|
||||
|
||||
namespace Poincare {
|
||||
@@ -46,13 +47,20 @@ private:
|
||||
class Derivative final : public Expression {
|
||||
public:
|
||||
Derivative(const DerivativeNode * n) : Expression(n) {}
|
||||
static Derivative Builder(Expression child0, Expression child1, Expression child2) { return Derivative(child0, child1, child2); }
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1), children.childAtIndex(2)); }
|
||||
static Derivative Builder(Expression child0, Symbol child1, Expression child2) { return Derivative(child0, child1, child2); }
|
||||
static Expression UntypedBuilder(Expression children) {
|
||||
if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) {
|
||||
// Second parameter must be a Symbol.
|
||||
return Expression();
|
||||
}
|
||||
return Builder(children.childAtIndex(0), children.childAtIndex(1).convert<Symbol>(), children.childAtIndex(2));
|
||||
}
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("diff", 3, &UntypedBuilder);
|
||||
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols = true);
|
||||
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);
|
||||
|
||||
@@ -62,12 +62,14 @@ class Expression : public TreeHandle {
|
||||
friend class PermuteCoefficient;
|
||||
friend class Power;
|
||||
friend class PredictionInterval;
|
||||
friend class Product;
|
||||
friend class RealPart;
|
||||
friend class Round;
|
||||
friend class Sine;
|
||||
friend class SquareRoot;
|
||||
friend class Store;
|
||||
friend class Subtraction;
|
||||
friend class Sum;
|
||||
friend class Symbol;
|
||||
friend class Tangent;
|
||||
friend class Trigonometry;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define POINCARE_INTEGRAL_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/symbol.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -49,14 +50,21 @@ private:
|
||||
class Integral final : public Expression {
|
||||
public:
|
||||
Integral(const IntegralNode * n) : Expression(n) {}
|
||||
static Integral Builder(Expression child0, Expression child1, Expression child2, Expression child3) { return Integral(child0, child1, child2, child3); }
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1), children.childAtIndex(2), children.childAtIndex(3)); }
|
||||
static Integral Builder(Expression child0, Symbol child1, Expression child2, Expression child3) { return Integral(child0, child1, child2, child3); }
|
||||
static Expression UntypedBuilder(Expression children) {
|
||||
if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) {
|
||||
// Second parameter must be a Symbol.
|
||||
return Expression();
|
||||
}
|
||||
return Builder(children.childAtIndex(0), children.childAtIndex(1).convert<Symbol>(), children.childAtIndex(2), children.childAtIndex(3));
|
||||
}
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("int", 4, &UntypedBuilder);
|
||||
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols = true);
|
||||
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);
|
||||
|
||||
@@ -33,11 +33,18 @@ class Product final : public Expression {
|
||||
friend class ProductNode;
|
||||
public:
|
||||
Product(const ProductNode * n) : Expression(n) {}
|
||||
static Product Builder(Expression child0, Expression child1, Expression child2, Expression child3) { return Product(child0, child1, child2, child3); }
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1), children.childAtIndex(2), children.childAtIndex(3)); }
|
||||
static Product Builder(Expression child0, Symbol child1, Expression child2, Expression child3) { return Product(child0, child1, child2, child3); }
|
||||
static Expression UntypedBuilder(Expression children) {
|
||||
if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) {
|
||||
// Second parameter must be a Symbol.
|
||||
return Expression();
|
||||
}
|
||||
return Builder(children.childAtIndex(0), children.childAtIndex(1).convert<Symbol>(), children.childAtIndex(2), children.childAtIndex(3));
|
||||
}
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("product", 4, &UntypedBuilder);
|
||||
private:
|
||||
Product(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode<ProductNode>()) {
|
||||
assert(child1.type() == ExpressionNode::Type::Symbol);
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
replaceChildAtIndexInPlace(2, child2);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define POINCARE_SEQUENCE_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/approximation_helper.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -33,11 +33,18 @@ class Sum final : public Expression {
|
||||
friend class SumNode;
|
||||
public:
|
||||
Sum(const SumNode * n) : Expression(n) {}
|
||||
static Sum Builder(Expression child0, Expression child1, Expression child2, Expression child3) { return Sum(child0, child1, child2, child3); }
|
||||
static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1), children.childAtIndex(2), children.childAtIndex(3)); }
|
||||
static Sum Builder(Expression child0, Symbol child1, Expression child2, Expression child3) { return Sum(child0, child1, child2, child3); }
|
||||
static Expression UntypedBuilder(Expression children) {
|
||||
if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) {
|
||||
// Second parameter must be a Symbol.
|
||||
return Expression();
|
||||
}
|
||||
return Builder(children.childAtIndex(0), children.childAtIndex(1).convert<Symbol>(), children.childAtIndex(2), children.childAtIndex(3));
|
||||
}
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sum", 4, &UntypedBuilder);
|
||||
private:
|
||||
Sum(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode<SumNode>()) {
|
||||
assert(child1.type() == ExpressionNode::Type::Symbol);
|
||||
replaceChildAtIndexInPlace(0, child0);
|
||||
replaceChildAtIndexInPlace(1, child1);
|
||||
replaceChildAtIndexInPlace(2, child2);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <poincare/sequence.h>
|
||||
#include <poincare/decimal.h>
|
||||
#include <poincare/symbol.h>
|
||||
#include <poincare/undefined.h>
|
||||
#include <poincare/variable_context.h>
|
||||
extern "C" {
|
||||
|
||||
Reference in New Issue
Block a user