mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare/cosine] Implemented didDerivate and unaryFunctionDifferential for Cosine
Derivation now propagates as expected on cosines. Change-Id: I6f5af48ac7462c5b8e77ff1a6428a65bf6c0c7de
This commit is contained in:
committed by
Émilie Feral
parent
5cf85368ea
commit
407d4bce6e
@@ -34,6 +34,10 @@ private:
|
||||
LayoutShape leftLayoutShape() const override { return LayoutShape::MoreLetters; };
|
||||
LayoutShape rightLayoutShape() const override { return LayoutShape::BoundaryPunctuation; }
|
||||
|
||||
// Derivation
|
||||
bool didDerivate(ReductionContext reductionContext, Expression symbol, Expression symbolValue) override;
|
||||
Expression unaryFunctionDifferential() override;
|
||||
|
||||
// Evaluation
|
||||
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>);
|
||||
@@ -51,6 +55,9 @@ public:
|
||||
static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("cos", 1, &UntypedBuilderOneChild<Cosine>);
|
||||
|
||||
Expression shallowReduce(ExpressionNode::ReductionContext reductionContext);
|
||||
|
||||
bool didDerivate(ExpressionNode::ReductionContext reductionContext, Expression symbol, Expression symbolValue);
|
||||
Expression unaryFunctionDifferential();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
#include <poincare/cosine.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/derivative.h>
|
||||
#include <poincare/layout_helper.h>
|
||||
#include <poincare/multiplication.h>
|
||||
#include <poincare/rational.h>
|
||||
#include <poincare/serialization_helper.h>
|
||||
#include <poincare/sine.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@@ -34,6 +38,14 @@ Expression CosineNode::shallowReduce(ReductionContext reductionContext) {
|
||||
return Cosine(this).shallowReduce(reductionContext);
|
||||
}
|
||||
|
||||
bool CosineNode::didDerivate(ReductionContext reductionContext, Expression symbol, Expression symbolValue) {
|
||||
return Cosine(this).didDerivate(reductionContext, symbol, symbolValue);
|
||||
}
|
||||
|
||||
Expression CosineNode::unaryFunctionDifferential() {
|
||||
return Cosine(this).unaryFunctionDifferential();
|
||||
}
|
||||
|
||||
Expression Cosine::shallowReduce(ExpressionNode::ReductionContext reductionContext) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
@@ -45,5 +57,13 @@ Expression Cosine::shallowReduce(ExpressionNode::ReductionContext reductionConte
|
||||
return Trigonometry::shallowReduceDirectFunction(*this, reductionContext);
|
||||
}
|
||||
|
||||
bool Cosine::didDerivate(ExpressionNode::ReductionContext reductionContext, Expression symbol, Expression symbolValue) {
|
||||
Derivative::DerivateUnaryFunction(*this, symbol, symbolValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
Expression Cosine::unaryFunctionDifferential() {
|
||||
return Multiplication::Builder(Rational::Builder(-1), Sine::Builder(childAtIndex(0).clone()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,4 +44,6 @@ QUIZ_CASE(poicare_differential_unary_functions) {
|
||||
assert_parses_and_reduces_as("diff(sin(x),x,π)","-1");
|
||||
assert_parses_and_reduces_as("diff(sin(2y),y,π/12)","√(3)");
|
||||
assert_parses_and_reduces_as("diff(sin(2x)+sin(3x),x,π/6)","1");
|
||||
|
||||
assert_parses_and_reduces_as("diff(cos(x),x,π/2)","-1");
|
||||
}
|
||||
Reference in New Issue
Block a user