mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
Derivation now propagates to powers as expected, whether the base, the exponent, or both are functions of the variable. This also makes division derive as intended. Change-Id: I51cbd5f7ec9f6aaa1df068625bbda1437941fa08
40 lines
1.7 KiB
C++
40 lines
1.7 KiB
C++
#include <poincare/derivative.h>
|
|
#include <poincare/init.h>
|
|
#include <poincare/src/parsing/parser.h>
|
|
#include <poincare_nodes.h>
|
|
#include <apps/shared/global_context.h>
|
|
#include "helper.h"
|
|
|
|
using namespace Poincare;
|
|
|
|
void assert_parses_and_reduces_as(const char * expression, const char * derivative) {
|
|
Shared::GlobalContext globalContext;
|
|
Expression e = parse_expression(expression, &globalContext, false);
|
|
Expression eReduced = e.reduce(ExpressionNode::ReductionContext(&globalContext, Cartesian, Radian, User));
|
|
Expression d = parse_expression(derivative, &globalContext, false).reduce(ExpressionNode::ReductionContext(&globalContext, Cartesian, Radian, User));
|
|
quiz_assert_print_if_failure(eReduced.isIdenticalTo(d), expression);
|
|
}
|
|
|
|
QUIZ_CASE(poincare_differential_addition) {
|
|
assert_parses_and_reduces_as("diff(1,x,1)", "0");
|
|
assert_parses_and_reduces_as("diff(x,x,1)", "1");
|
|
assert_parses_and_reduces_as("diff(1+2,x,1)", "0");
|
|
assert_parses_and_reduces_as("diff(a,x,1)", "0");
|
|
|
|
assert_parses_and_reduces_as("diff(1+x,x,1)", "1");
|
|
assert_parses_and_reduces_as("diff(undef,x,1)", "undef");
|
|
|
|
assert_parses_and_reduces_as("diff(x+x,x,4)", "2");
|
|
assert_parses_and_reduces_as("diff(2*x,x,1)", "2");
|
|
assert_parses_and_reduces_as("diff(-x,x,1)", "-1");
|
|
assert_parses_and_reduces_as("diff(3-x,x,1)", "-1");
|
|
assert_parses_and_reduces_as("diff(a*x,x,2)", "a");
|
|
assert_parses_and_reduces_as("diff(a*x+b,x,x)", "a");
|
|
|
|
assert_parses_and_reduces_as("diff(x*x,x,3)", "6");
|
|
assert_parses_and_reduces_as("diff(x^2,x,2)", "4");
|
|
assert_parses_and_reduces_as("diff(2^x,x,0)", "ln(2)");
|
|
assert_parses_and_reduces_as("diff(x^2,x,x)", "2*x");
|
|
assert_parses_and_reduces_as("diff(a*x^2+b*x+c,x,x)", "2*a*x+b");
|
|
assert_parses_and_reduces_as("diff(1/x,x,1)", "-1");
|
|
} |