Skip to content

Commit ea08214

Browse files
The falling and the rising factorial (#2194)
fallingfactorial(x, n), also factorialpower(x, n), Mathematica's name, and risingfactorial(x, n) were reserved by name in #2184 and are now Entity.FallingFactorialf and Entity.RisingFactorialf, built by MathS.FallingFactorial and MathS.RisingFactorial. For a whole n >= 0 they are x (x - 1) ... (x - n + 1) and x (x + 1) ... (x + n - 1), x to the n falling and rising, computed exactly for any number x. For a negative whole n they are the reciprocals of (x + 1) ... (x - n) and (x - 1) ... (x + n), (2.52) in Graham, Knuth and Patashnik's Concrete Mathematics, with no value where a factor vanishes. For any other n they are Gamma(x + 1)/Gamma(x - n + 1) and Gamma(x + n)/Gamma(x), as Mathematica's FactorialPower and Pochhammer are, evaluated numerically: no value at a pole of the numerator, and 0 at one of the denominator. fallingfactorial(5, 1/2) agrees with mpmath to 1e-20. risingfactorial(x, n) is fallingfactorial(x + n - 1, n), and binomial(n, k) is fallingfactorial(n, k)/k!. They draw with Knuth's bars, x^{\underline{n}} and x^{\overline{n}}, and export to SymPy's ff and rf. A conjugate as the whole exponent of a power is drawn in brackets, x^{\left(\overline{n}\right)}, since x^{\overline{n}} is the rising factorial. pochhammer stays refused, (x)_n being the rising factorial to some authors and the falling one to others. Part of #2182. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
1 parent e7b7fd0 commit ea08214

29 files changed

Lines changed: 841 additions & 392 deletions

‎BREAKING-CHANGES.md‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ were read as products or refused.** A name the parser does not know, followed by
339339
`Entity.Conjugatef`, carried through sums, differences, products, quotients and whole powers and not through a root or
340340
a logarithm; `arg(z)` is `Entity.Argf`, in `(-pi, pi]`, with no value at `0`
341341
([#2136](https://github.com/asc-community/AngouriMath/issues/2136),
342-
[#2145](https://github.com/asc-community/AngouriMath/issues/2145)). `re` and `im` are still read as products.
342+
[#2145](https://github.com/asc-community/AngouriMath/issues/2145)). The conjugate is drawn as `\overline{z}`, and as
343+
the whole exponent of a power in brackets, `x^{\left(\overline{n}\right)}`, since `x^{\overline{n}}` is the rising
344+
factorial ([#2182](https://github.com/asc-community/AngouriMath/issues/2182)).
343345

344346
| Input | Was (2.6.0) | Now |
345347
|---|---|---|
@@ -452,8 +454,8 @@ the right shape, written out or once its operations are carried out, throws `Inv
452454
**Not silent: these names followed by a bracket now throw `UnrecognizedFunctionParseException` where they were read as
453455
products.** An unknown name followed by a bracket is a product, so `zeta(2)` was `zeta * 2` and simplified to
454456
`2 * zeta`. The long names of the functions the library is to have are refused until each is implemented, as `trunc`
455-
is: `zeta`, `riemannzeta`, `hurwitzzeta`, `lambertw`, `productlog`, `harmonicnumber`, `catalannumber`, `multinomial`, `fallingfactorial`, `factorialpower`,
456-
`risingfactorial` and `forwarddifference`. Names that will not be functions,
457+
is: `zeta`, `riemannzeta`, `hurwitzzeta`, `lambertw`, `productlog`, `harmonicnumber`, `catalannumber`, `multinomial` and
458+
`forwarddifference`. Names that will not be functions,
457459
because what they mean differs between sources or is already written exactly, are refused with the spelling to use:
458460
`heaviside`, `unitstep`, `isprime`, `pochhammer`, `doublefactorial`, `factorial2`, `fractionalpart` and `quotient`.
459461
Each name without a bracket is still a variable, and short names such as `beta` and `norm` are still read as products
@@ -501,6 +503,20 @@ is ([#2182](https://github.com/asc-community/AngouriMath/issues/2182)).
501503
| `"hessian(x^3 y^2, [x, y])".ToEntity().Simplify()` | throws `UnhandledParseException` | `[[6 * x * y ^ 2, 6 * x ^ 2 * y], [6 * x ^ 2 * y, 2 * x ^ 3]]` |
502504
| `"jacobian(x y, {x, y})".ToEntity()` | throws `UnhandledParseException` | throws `InvalidArgumentParseException`: a set has no order for the columns |
503505

506+
### The falling and the rising factorial
507+
508+
**Not silent: `fallingfactorial(x, n)`, also `factorialpower(x, n)`, and `risingfactorial(x, n)` are functions, where
509+
they were a parse error.** For a whole `n >= 0` they are `x (x - 1) ... (x - n + 1)` and `x (x + 1) ... (x + n - 1)`. For a
510+
negative whole `n` they are reciprocals of products, and for any other `n` they are the gamma ratios `Γ(x + 1)/Γ(x - n + 1)`
511+
and `Γ(x + n)/Γ(x)`. LaTeX draws them with Knuth's bars, `x^{\underline{n}}` and `x^{\overline{n}}`
512+
([#2182](https://github.com/asc-community/AngouriMath/issues/2182)).
513+
514+
| Input | Was (2.6.0) | Now |
515+
|---|---|---|
516+
| `"fallingfactorial(5, 2)".ToEntity().Simplify()` | throws `UnhandledParseException` | `20` |
517+
| `"risingfactorial(3, 2)".ToEntity().Simplify()` | throws `UnhandledParseException` | `12` |
518+
| `"fallingfactorial(5, 1/2)".ToEntity().EvalNumerical()` | throws `UnhandledParseException` | `2.29257989505120015013822761269...` |
519+
504520
### A subscript may have a subscript
505521

506522
**Not silent: what was a parse error is a name.** A name took at most one `_`, so `x_1_2` and `X_a_beta` were lexer

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,3 +811,6 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
811811

812812
[Tests/UnitTests/Convenience/VectorCalculusTest.cs]
813813
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
814+
815+
[Tests/UnitTests/Convenience/FactorialPowerTest.cs]
816+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n

‎Sources/AngouriMath/Convenience/MathS.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,14 @@ public static Entity VectorLength(Matrix v)
13871387
[MethodImpl(MethodImplOptions.AggressiveInlining)]
13881388
public static Entity Binomial(Entity n, Entity k) => new Binomialf(n, k);
13891389

1390+
/// <summary>The falling factorial <c>x (x - 1) ... (x - n + 1)</c>, <c>x^{\underline{n}}</c></summary>
1391+
/// <remarks>https://github.com/asc-community/AngouriMath/issues/2182</remarks>
1392+
public static Entity FallingFactorial(Entity x, Entity n) => new FallingFactorialf(x, n);
1393+
1394+
/// <summary>The rising factorial <c>x (x + 1) ... (x + n - 1)</c>, <c>x^{\overline{n}}</c></summary>
1395+
/// <remarks>https://github.com/asc-community/AngouriMath/issues/2182</remarks>
1396+
public static Entity RisingFactorial(Entity x, Entity n) => new RisingFactorialf(x, n);
1397+
13901398
/// <summary>The Iverson bracket <c>iverson(P)</c>: <c>1</c> where the statement holds, <c>0</c> where it does not</summary>
13911399
/// <param name="statement">The statement</param>
13921400
/// <returns>The <see cref="Entity.Iversonf"/> node</returns>

‎Sources/AngouriMath/Core/Antlr/AngouriMath.g‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,9 @@ atom returns[Entity value]
625625
| 'gcd(' args = function_arguments ')' { AssertAtLeast("gcd", 1, $args.list.Count); $value = $args.list.Aggregate((a, b) => MathS.Gcd(a, b)); }
626626
| 'lcm(' args = function_arguments ')' { AssertAtLeast("lcm", 1, $args.list.Count); $value = $args.list.Aggregate((a, b) => MathS.Lcm(a, b)); }
627627
| 'binomial(' args = function_arguments ')' { Assert("binomial", 2, $args.list.Count); $value = MathS.Binomial($args.list[0], $args.list[1]); }
628+
| 'fallingfactorial(' args = function_arguments ')' { Assert("fallingfactorial", 2, $args.list.Count); $value = MathS.FallingFactorial($args.list[0], $args.list[1]); }
629+
| 'factorialpower(' args = function_arguments ')' { Assert("factorialpower", 2, $args.list.Count); $value = MathS.FallingFactorial($args.list[0], $args.list[1]); }
630+
| 'risingfactorial(' args = function_arguments ')' { Assert("risingfactorial", 2, $args.list.Count); $value = MathS.RisingFactorial($args.list[0], $args.list[1]); }
628631
/* The Iverson bracket, 1 where a statement holds and 0 where it does not: a count written as
629632
a sum. https://github.com/asc-community/AngouriMath/issues/1478 */
630633
| 'iverson(' args = function_arguments ')' { Assert("iverson", 1, $args.list.Count); $value = MathS.Iverson($args.list[0]); }
@@ -693,9 +696,6 @@ atom returns[Entity value]
693696
| 'harmonicnumber(' args = function_arguments ')' { $value = NotImplementedFunction("harmonicnumber", "harmonic numbers yet"); }
694697
| 'catalannumber(' args = function_arguments ')' { $value = NotImplementedFunction("catalannumber", "Catalan numbers yet"); }
695698
| 'multinomial(' args = function_arguments ')' { $value = NotImplementedFunction("multinomial", "multinomial coefficients yet"); }
696-
| 'fallingfactorial(' args = function_arguments ')' { $value = NotImplementedFunction("fallingfactorial", "falling factorial yet"); }
697-
| 'factorialpower(' args = function_arguments ')' { $value = NotImplementedFunction("factorialpower", "falling factorial yet"); }
698-
| 'risingfactorial(' args = function_arguments ')' { $value = NotImplementedFunction("risingfactorial", "rising factorial yet"); }
699699
| 'forwarddifference(' args = function_arguments ')' { $value = NotImplementedFunction("forwarddifference", "forward difference yet"); }
700700
/* Names that will not be functions, refused with the spelling to use: what they mean is
701701
ambiguous between sources, or is already written exactly another way. */

‎Sources/AngouriMath/Core/Antlr/AngouriMath.interp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ null
174174
'gcd('
175175
'lcm('
176176
'binomial('
177+
'fallingfactorial('
178+
'factorialpower('
179+
'risingfactorial('
177180
'iverson('
178181
'aleph('
179182
'erf('
@@ -213,9 +216,6 @@ null
213216
'harmonicnumber('
214217
'catalannumber('
215218
'multinomial('
216-
'fallingfactorial('
217-
'factorialpower('
218-
'risingfactorial('
219219
'forwarddifference('
220220
'heaviside('
221221
'unitstep('

‎Sources/AngouriMath/Core/Antlr/AngouriMath.tokens‎

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -409,48 +409,48 @@ WS=237
409409
'gcd('=172
410410
'lcm('=173
411411
'binomial('=174
412-
'iverson('=175
413-
'aleph('=176
414-
'erf('=177
415-
'erfc('=178
416-
'erfi('=179
417-
'Ei('=180
418-
'li('=181
419-
'polygamma('=182
420-
'digamma('=183
421-
'Si('=184
422-
'Ci('=185
423-
'Shi('=186
424-
'Chi('=187
425-
'det('=188
426-
'transpose('=189
427-
'dot('=190
428-
'cross('=191
429-
'laplacian('=192
430-
'jacobian('=193
431-
'hessian('=194
432-
'resultant('=195
433-
'conjugate('=196
434-
'conj('=197
435-
'arg('=198
436-
'Re('=199
437-
'Im('=200
438-
're('=201
439-
'real('=202
440-
'im('=203
441-
'imag('=204
442-
'trunc('=205
443-
'zeta('=206
444-
'riemannzeta('=207
445-
'hurwitzzeta('=208
446-
'lambertw('=209
447-
'productlog('=210
448-
'harmonicnumber('=211
449-
'catalannumber('=212
450-
'multinomial('=213
451-
'fallingfactorial('=214
452-
'factorialpower('=215
453-
'risingfactorial('=216
412+
'fallingfactorial('=175
413+
'factorialpower('=176
414+
'risingfactorial('=177
415+
'iverson('=178
416+
'aleph('=179
417+
'erf('=180
418+
'erfc('=181
419+
'erfi('=182
420+
'Ei('=183
421+
'li('=184
422+
'polygamma('=185
423+
'digamma('=186
424+
'Si('=187
425+
'Ci('=188
426+
'Shi('=189
427+
'Chi('=190
428+
'det('=191
429+
'transpose('=192
430+
'dot('=193
431+
'cross('=194
432+
'laplacian('=195
433+
'jacobian('=196
434+
'hessian('=197
435+
'resultant('=198
436+
'conjugate('=199
437+
'conj('=200
438+
'arg('=201
439+
'Re('=202
440+
'Im('=203
441+
're('=204
442+
'real('=205
443+
'im('=206
444+
'imag('=207
445+
'trunc('=208
446+
'zeta('=209
447+
'riemannzeta('=210
448+
'hurwitzzeta('=211
449+
'lambertw('=212
450+
'productlog('=213
451+
'harmonicnumber('=214
452+
'catalannumber('=215
453+
'multinomial('=216
454454
'forwarddifference('=217
455455
'heaviside('=218
456456
'unitstep('=219

0 commit comments

Comments
 (0)