mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-24 00:00:44 +01:00
[poincare] Fix BinomialCoefficient::shallowReduce
Change-Id: Iafc84162427db910e0c208297efe9904ce768313
This commit is contained in:
@@ -17,7 +17,7 @@ public:
|
||||
Rational(Integer::native_int_t i, Integer::native_int_t j) : Rational(Integer(i), Integer(j)) {}
|
||||
|
||||
Rational(const Rational & other);
|
||||
|
||||
Rational & operator=(const Rational & other);
|
||||
// Getter
|
||||
const Integer numerator() const;
|
||||
const Integer denominator() const;
|
||||
|
||||
@@ -55,7 +55,7 @@ Expression * BinomialCoefficient::shallowReduce(Context& context, AngleUnit angl
|
||||
if (n.isLowerThan(k)) {
|
||||
return replaceWith(new Undefined(), true);
|
||||
}
|
||||
Integer result(1);
|
||||
Rational result(1);
|
||||
Integer kBis = Integer::Subtraction(n, k);
|
||||
k = kBis.isLowerThan(k) ? kBis : k;
|
||||
// Out of bounds
|
||||
@@ -64,8 +64,8 @@ Expression * BinomialCoefficient::shallowReduce(Context& context, AngleUnit angl
|
||||
}
|
||||
int clippedK = k.extractedInt(); // Authorized because k < k_maxNumberOfSteps
|
||||
for (int i = 0; i < clippedK; i++) {
|
||||
Integer factor = Integer::Division(Integer::Subtraction(n, Integer(i)), Integer::Subtraction(k, Integer(i))).quotient;
|
||||
result = Integer::Multiplication(result, factor);
|
||||
Rational factor = Rational(Integer::Subtraction(n, Integer(i)), Integer::Subtraction(k, Integer(i)));
|
||||
result = Rational::Multiplication(result, factor);
|
||||
}
|
||||
return replaceWith(new Rational(result), true);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,13 @@ Rational::Rational(const Rational & other) {
|
||||
m_denominator = other.m_denominator;
|
||||
}
|
||||
|
||||
Rational & Rational::operator=(const Rational & other) {
|
||||
m_numerator = other.m_numerator;
|
||||
m_numerator = other.m_numerator;
|
||||
m_denominator = other.m_denominator;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Getter
|
||||
const Integer Rational::numerator() const {
|
||||
return m_numerator;
|
||||
|
||||
@@ -61,6 +61,9 @@ QUIZ_CASE(poincare_simplify_easy) {
|
||||
assert_parsed_expression_simplify_to("asin([[1/R(2),1/2][1,-1]])", "[[P/4,P/6][P/2,-P/2]]");
|
||||
assert_parsed_expression_simplify_to("atan([[R(3),1][1/R(3),-1]])", "[[P/3,P/4][P/6,-P/4]]");
|
||||
assert_parsed_expression_simplify_to("acos([[1/R(2),1/2][1,-1]])", "[[P/4,P/3][0,P]]");
|
||||
assert_parsed_expression_simplify_to("binomial([[1,-2][3,4]], 2)", "undef");
|
||||
assert_parsed_expression_simplify_to("binomial(20,3)", "1140");
|
||||
assert_parsed_expression_simplify_to("binomial(20,10)", "184756");
|
||||
|
||||
assert_parsed_expression_simplify_to("1*tan(2)*tan(5)", "tan(2)*tan(5)");
|
||||
assert_parsed_expression_simplify_to("P+(3R(2)-2R(3))/25", "(3R(2)-2R(3)+25P)/25");
|
||||
|
||||
Reference in New Issue
Block a user