mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +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
|
#define POINCARE_DERIVATIVE_H
|
||||||
|
|
||||||
#include <poincare/expression.h>
|
#include <poincare/expression.h>
|
||||||
|
#include <poincare/symbol.h>
|
||||||
#include <poincare/variable_context.h>
|
#include <poincare/variable_context.h>
|
||||||
|
|
||||||
namespace Poincare {
|
namespace Poincare {
|
||||||
@@ -46,13 +47,20 @@ private:
|
|||||||
class Derivative final : public Expression {
|
class Derivative final : public Expression {
|
||||||
public:
|
public:
|
||||||
Derivative(const DerivativeNode * n) : Expression(n) {}
|
Derivative(const DerivativeNode * n) : Expression(n) {}
|
||||||
static Derivative Builder(Expression child0, Expression child1, Expression child2) { return Derivative(child0, child1, child2); }
|
static Derivative Builder(Expression child0, Symbol 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 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);
|
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("diff", 3, &UntypedBuilder);
|
||||||
|
|
||||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols = true);
|
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols = true);
|
||||||
private:
|
private:
|
||||||
Derivative(Expression child0, Expression child1, Expression child2) : Expression(TreePool::sharedPool()->createTreeNode<DerivativeNode>()) {
|
Derivative(Expression child0, Expression child1, Expression child2) : Expression(TreePool::sharedPool()->createTreeNode<DerivativeNode>()) {
|
||||||
|
assert(child1.type() == ExpressionNode::Type::Symbol);
|
||||||
replaceChildAtIndexInPlace(0, child0);
|
replaceChildAtIndexInPlace(0, child0);
|
||||||
replaceChildAtIndexInPlace(1, child1);
|
replaceChildAtIndexInPlace(1, child1);
|
||||||
replaceChildAtIndexInPlace(2, child2);
|
replaceChildAtIndexInPlace(2, child2);
|
||||||
|
|||||||
@@ -62,12 +62,14 @@ class Expression : public TreeHandle {
|
|||||||
friend class PermuteCoefficient;
|
friend class PermuteCoefficient;
|
||||||
friend class Power;
|
friend class Power;
|
||||||
friend class PredictionInterval;
|
friend class PredictionInterval;
|
||||||
|
friend class Product;
|
||||||
friend class RealPart;
|
friend class RealPart;
|
||||||
friend class Round;
|
friend class Round;
|
||||||
friend class Sine;
|
friend class Sine;
|
||||||
friend class SquareRoot;
|
friend class SquareRoot;
|
||||||
friend class Store;
|
friend class Store;
|
||||||
friend class Subtraction;
|
friend class Subtraction;
|
||||||
|
friend class Sum;
|
||||||
friend class Symbol;
|
friend class Symbol;
|
||||||
friend class Tangent;
|
friend class Tangent;
|
||||||
friend class Trigonometry;
|
friend class Trigonometry;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define POINCARE_INTEGRAL_H
|
#define POINCARE_INTEGRAL_H
|
||||||
|
|
||||||
#include <poincare/expression.h>
|
#include <poincare/expression.h>
|
||||||
|
#include <poincare/symbol.h>
|
||||||
|
|
||||||
namespace Poincare {
|
namespace Poincare {
|
||||||
|
|
||||||
@@ -49,14 +50,21 @@ private:
|
|||||||
class Integral final : public Expression {
|
class Integral final : public Expression {
|
||||||
public:
|
public:
|
||||||
Integral(const IntegralNode * n) : Expression(n) {}
|
Integral(const IntegralNode * n) : Expression(n) {}
|
||||||
static Integral Builder(Expression child0, Expression child1, Expression child2, Expression child3) { return Integral(child0, child1, child2, child3); }
|
static Integral Builder(Expression child0, Symbol 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 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);
|
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("int", 4, &UntypedBuilder);
|
||||||
|
|
||||||
// Expression
|
// Expression
|
||||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols = true);
|
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols = true);
|
||||||
private:
|
private:
|
||||||
Integral(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode<IntegralNode>()) {
|
Integral(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode<IntegralNode>()) {
|
||||||
|
assert(child1.type() == ExpressionNode::Type::Symbol);
|
||||||
replaceChildAtIndexInPlace(0, child0);
|
replaceChildAtIndexInPlace(0, child0);
|
||||||
replaceChildAtIndexInPlace(1, child1);
|
replaceChildAtIndexInPlace(1, child1);
|
||||||
replaceChildAtIndexInPlace(2, child2);
|
replaceChildAtIndexInPlace(2, child2);
|
||||||
|
|||||||
@@ -33,11 +33,18 @@ class Product final : public Expression {
|
|||||||
friend class ProductNode;
|
friend class ProductNode;
|
||||||
public:
|
public:
|
||||||
Product(const ProductNode * n) : Expression(n) {}
|
Product(const ProductNode * n) : Expression(n) {}
|
||||||
static Product Builder(Expression child0, Expression child1, Expression child2, Expression child3) { return Product(child0, child1, child2, child3); }
|
static Product Builder(Expression child0, Symbol 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 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);
|
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("product", 4, &UntypedBuilder);
|
||||||
private:
|
private:
|
||||||
Product(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode<ProductNode>()) {
|
Product(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode<ProductNode>()) {
|
||||||
|
assert(child1.type() == ExpressionNode::Type::Symbol);
|
||||||
replaceChildAtIndexInPlace(0, child0);
|
replaceChildAtIndexInPlace(0, child0);
|
||||||
replaceChildAtIndexInPlace(1, child1);
|
replaceChildAtIndexInPlace(1, child1);
|
||||||
replaceChildAtIndexInPlace(2, child2);
|
replaceChildAtIndexInPlace(2, child2);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define POINCARE_SEQUENCE_H
|
#define POINCARE_SEQUENCE_H
|
||||||
|
|
||||||
#include <poincare/expression.h>
|
#include <poincare/expression.h>
|
||||||
|
#include <poincare/symbol.h>
|
||||||
#include <poincare/approximation_helper.h>
|
#include <poincare/approximation_helper.h>
|
||||||
|
|
||||||
namespace Poincare {
|
namespace Poincare {
|
||||||
|
|||||||
@@ -33,11 +33,18 @@ class Sum final : public Expression {
|
|||||||
friend class SumNode;
|
friend class SumNode;
|
||||||
public:
|
public:
|
||||||
Sum(const SumNode * n) : Expression(n) {}
|
Sum(const SumNode * n) : Expression(n) {}
|
||||||
static Sum Builder(Expression child0, Expression child1, Expression child2, Expression child3) { return Sum(child0, child1, child2, child3); }
|
static Sum Builder(Expression child0, Symbol 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 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);
|
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sum", 4, &UntypedBuilder);
|
||||||
private:
|
private:
|
||||||
Sum(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode<SumNode>()) {
|
Sum(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode<SumNode>()) {
|
||||||
|
assert(child1.type() == ExpressionNode::Type::Symbol);
|
||||||
replaceChildAtIndexInPlace(0, child0);
|
replaceChildAtIndexInPlace(0, child0);
|
||||||
replaceChildAtIndexInPlace(1, child1);
|
replaceChildAtIndexInPlace(1, child1);
|
||||||
replaceChildAtIndexInPlace(2, child2);
|
replaceChildAtIndexInPlace(2, child2);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include <poincare/sequence.h>
|
#include <poincare/sequence.h>
|
||||||
#include <poincare/decimal.h>
|
#include <poincare/decimal.h>
|
||||||
#include <poincare/symbol.h>
|
|
||||||
#include <poincare/undefined.h>
|
#include <poincare/undefined.h>
|
||||||
#include <poincare/variable_context.h>
|
#include <poincare/variable_context.h>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
Reference in New Issue
Block a user