[poincare/constant] Constants differentiate to 0

This commit is contained in:
Gabriel Ozouf
2020-12-02 11:31:05 +01:00
committed by LeaNumworks
parent a178c88e54
commit 764d14fed1
2 changed files with 13 additions and 0 deletions

View File

@@ -50,6 +50,9 @@ public:
Expression shallowReduce(ReductionContext reductionContext) override;
LayoutShape leftLayoutShape() const override { return LayoutShape::OneLetter; };
/* Derivation */
bool derivate(ReductionContext reductionContext, Expression symbol, Expression symbolValue) override;
private:
char m_name[0]; // MUST be the last member variable
@@ -70,6 +73,7 @@ public:
// Simplification
Expression shallowReduce(ExpressionNode::ReductionContext reductionContext);
bool derivate(ExpressionNode::ReductionContext reductionContext, Expression symbol, Expression symbolValue);
private:
ConstantNode * node() const { return static_cast<ConstantNode *>(Expression::node()); }

View File

@@ -78,6 +78,10 @@ Expression ConstantNode::shallowReduce(ReductionContext reductionContext) {
return Constant(this).shallowReduce(reductionContext);
}
bool ConstantNode::derivate(ReductionContext reductionContext, Expression symbol, Expression symbolValue) {
return Constant(this).derivate(reductionContext, symbol, symbolValue);
}
bool ConstantNode::isConstantCodePoint(CodePoint c) const {
UTF8Decoder decoder(m_name);
bool result = (decoder.nextCodePoint() == c);
@@ -106,4 +110,9 @@ Expression Constant::shallowReduce(ExpressionNode::ReductionContext reductionCon
return result;
}
bool Constant::derivate(ExpressionNode::ReductionContext reductionContext, Expression symbol, Expression symbolValue) {
replaceWithInPlace(Rational::Builder(0));
return true;
}
}