Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ are as they were. With `Simplify`, the case `y = 0` of:
| `integral(1/(t^2+y^2), t, -oo, +oo)` | `0 provided (y = 0)` | `+oo provided (y = 0)` |
| `integral(1/(t^2+y^2), t, 1, 2)` | `(1/2) provided (y = 0)` | unchanged |

### `factorization(n)` and `primefactors(n)` are functions

**Not silent: what was a product is now a node.** `factorization(n)` and `primefactors(n)` were read as the products
`factorization * n` and `primefactors * n`. `factorization(n)` is now the prime factorisation of `n`, the map from each
prime to its exponent (mathlib's `Nat.factorization`): a node that keeps the map, printed `factorization(360)` and
`2^{3} \cdot 3^{2} \cdot 5` in LaTeX, and not the number, so `factorization(360) = 360` is left undecided.
`primefactors(n)` is its support, the set of the primes dividing `n`. Both are defined on the positive integers and
`NaN` at any other number, as `primenu` is: 0 has no factorisation and a negative integer is `-1` times one. With
`valuation(n, p)` and the product over a set, `product(p ^ valuation(n, p), p in primefactors(n))` is `n`
([#2449](https://github.com/asc-community/AngouriMath/issues/2449)). `factorize(360)` is still refused, and its message
now names `factorization(n)`.

| Input | Was (2.7.0) | Now |
|---|---|---|
| `"factorization(360)".ToEntity().Evaled` | `factorization * 360` | `factorization(360)`, holding `2 ↦ 3, 3 ↦ 2, 5 ↦ 1` |
| `"factorization(0)".ToEntity().Evaled` | `0` | `NaN` |
| `"primefactors(360)".ToEntity().Evaled` | `primefactors * 360` | `{ 2, 3, 5 }` |
| `"product(p ^ valuation(360, p), p in primefactors(360))".ToEntity().Evaled` | throws `FunctionArgumentCountException` | `360` |

### `factorize`, `nextprime`, `divisors`, `gradient`, `divergence` and `φ` are refused by name

**Not silent: these names followed by a bracket now throw `UnrecognizedFunctionParseException` where they were read as
Expand Down
3 changes: 3 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1129,3 +1129,6 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed

[Tests/UnitTests/Convenience/ShadersTest.cs]
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

[Tests/UnitTests/Convenience/PrimeFactorizationNodeTest.cs]
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
38 changes: 38 additions & 0 deletions Sources/AngouriMath/Convenience/MathS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,44 @@ public static class NumberTheory
/// </example>
public static Entity Valuation(Entity argument, Entity prime) => new Valuationf(argument, prime);

/// <summary>
/// The prime factorisation of a positive integer, <c>factorization(n)</c>: the map from
/// each prime to its exponent in <c>n</c>, mathlib's <c>Nat.factorization</c>. A node of
/// its own, which holds the map in <see cref="Entity.PrimeFactorizationf.Factors"/> and
/// is not the number <c>n</c>; <c>NaN</c> at any other number. For the list of pairs
/// alone, <see cref="Factorize(Integer)"/>.
/// https://github.com/asc-community/AngouriMath/issues/2449
/// </summary>
/// <example>
/// <code>
/// var factorization = (Entity.PrimeFactorizationf)MathS.NumberTheory.Factorization(360).Evaled;
/// Console.WriteLine(factorization);
/// Console.WriteLine(factorization.Latexize());
/// </code>
/// Prints
/// <code>
/// factorization(360)
/// 2^{3} \cdot 3^{2} \cdot 5
/// </code>
/// </example>
public static Entity Factorization(Entity integer) => new PrimeFactorizationf(integer);

/// <summary>
/// The set of the primes dividing a positive integer, <c>primefactors(n)</c>, the support
/// of <see cref="Factorization(Entity)"/>; <c>NaN</c> at any other number.
/// https://github.com/asc-community/AngouriMath/issues/2449
/// </summary>
/// <example>
/// <code>
/// Console.WriteLine(MathS.NumberTheory.PrimeFactors(360).Evaled);
/// </code>
/// Prints
/// <code>
/// { 2, 3, 5 }
/// </code>
/// </example>
public static Set PrimeFactors(Entity integer) => new Set.PrimeFactorsf(integer);

/// <summary>
/// The statement that <paramref name="divisor"/> divides <paramref name="dividend"/>,
/// written <c>a divides b</c>: for integers, that <c>b mod a = 0</c>.
Expand Down
4 changes: 3 additions & 1 deletion Sources/AngouriMath/Core/Antlr/AngouriMath.g
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ atom returns[Entity value]
| 'phi(' args = function_arguments ')' { Assert("phi", 1, $args.list.Count); $value = MathS.NumberTheory.Phi($args.list[0]); }
| 'prime(' args = function_arguments ')' { Assert("prime", 1, $args.list.Count); $value = MathS.NumberTheory.Prime($args.list[0]); }
| 'valuation(' args = function_arguments ')' { Assert("valuation", 2, $args.list.Count); $value = MathS.NumberTheory.Valuation($args.list[0], $args.list[1]); }
| 'factorization(' args = function_arguments ')' { Assert("factorization", 1, $args.list.Count); $value = MathS.NumberTheory.Factorization($args.list[0]); }
| 'primefactors(' args = function_arguments ')' { Assert("primefactors", 1, $args.list.Count); $value = MathS.NumberTheory.PrimeFactors($args.list[0]); }
| 'mobius(' args = function_arguments ')' { Assert("mobius", 1, $args.list.Count); $value = MathS.NumberTheory.Mobius($args.list[0]); }
| 'moebiusmu(' args = function_arguments ')' { Assert("moebiusmu", 1, $args.list.Count); $value = MathS.NumberTheory.Mobius($args.list[0]); }
| 'divisorsigma(' args = function_arguments ')' { Assert("divisorsigma", 2, $args.list.Count); $value = MathS.NumberTheory.DivisorSigma($args.list[0], $args.list[1]); }
Expand Down Expand Up @@ -743,7 +745,7 @@ atom returns[Entity value]
with what can be written today: factorize(360) was factorize * 360, and φ(10) was φ * 10.
factorize, nextprime and divisors: https://github.com/asc-community/AngouriMath/issues/2449.
gradient and divergence: https://github.com/asc-community/AngouriMath/issues/2182 */
| 'factorize(' args = function_arguments ')' { $value = NotImplementedFunction("factorize", "factorization node yet; in C#, MathS.NumberTheory.Factorize(n) gives the prime factors of an integer and Factorize() factors an expression"); }
| 'factorize(' args = function_arguments ')' { $value = NotAFunctionHere("factorize", "the prime factorisation of an integer is factorization(n), and in C# Factorize() factors an expression"); }
| 'nextprime(' args = function_arguments ')' { $value = NotImplementedFunction("nextprime", "nextprime yet; prime(primepi(n) + 1) is the least prime greater than n"); }
| 'divisors(' args = function_arguments ')' { $value = NotImplementedFunction("divisors", "set of divisors yet; divisorsigma(0, n) counts them and divisorsigma(1, n) is their sum"); }
| 'gradient(' args = function_arguments ')' { $value = NotImplementedFunction("gradient", "gradient yet; jacobian([f], [x, y]) is the row of partial derivatives of f"); }
Expand Down
6 changes: 5 additions & 1 deletion Sources/AngouriMath/Core/Antlr/AngouriMath.interp

Large diffs are not rendered by default.

200 changes: 102 additions & 98 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,18 @@ T__233=234
T__234=235
T__235=236
T__236=237
NEWLINE=238
NUMBER=239
SPECIALSET=240
BOOLEAN=241
NAN=242
UNICODE_SYNONYM=243
SUPERSCRIPT=244
VARIABLE=245
COMMENT=246
WS=247
T__237=238
T__238=239
NEWLINE=240
NUMBER=241
SPECIALSET=242
BOOLEAN=243
NAN=244
UNICODE_SYNONYM=245
SUPERSCRIPT=246
VARIABLE=247
COMMENT=248
WS=249
'['=1
']'=2
'!'=3
Expand Down Expand Up @@ -395,91 +397,93 @@ WS=247
'phi('=148
'prime('=149
'valuation('=150
'mobius('=151
'moebiusmu('=152
'divisorsigma('=153
'primenu('=154
'primeomega('=155
'primepi('=156
'card('=157
'powerset('=158
'union('=159
'intersection('=160
'complement('=161
'image('=162
'preimage('=163
'floor('=164
'ceil('=165
'ceiling('=166
'round('=167
'min('=168
'max('=169
'argmax('=170
'argmin('=171
'gcd('=172
'lcm('=173
'binomial('=174
'multinomial('=175
'catalannumber('=176
'harmonicnumber('=177
'fallingfactorial('=178
'factorialpower('=179
'risingfactorial('=180
'iverson('=181
'aleph('=182
'erf('=183
'erfc('=184
'erfi('=185
'Ei('=186
'li('=187
'lambertw('=188
'productlog('=189
'polygamma('=190
'digamma('=191
'Si('=192
'Ci('=193
'Shi('=194
'Chi('=195
'det('=196
'transpose('=197
'trace('=198
'dot('=199
'cross('=200
'laplacian('=201
'forwarddifference('=202
'jacobian('=203
'hessian('=204
'resultant('=205
'conjugate('=206
'conj('=207
'arg('=208
'Re('=209
'Im('=210
're('=211
'real('=212
'im('=213
'imag('=214
'trunc('=215
'zeta('=216
'riemannzeta('=217
'hurwitzzeta('=218
'heaviside('=219
'unitstep('=220
'isprime('=221
'pochhammer('=222
'doublefactorial('=223
'factorial2('=224
'fractionalpart('=225
'quotient('=226
'factorize('=227
'nextprime('=228
'divisors('=229
'gradient('=230
'divergence('=231
'φ('=232
'ϕ('=233
'domain('=234
'piecewise('=235
'apply('=236
'lambda('=237
'NaN'=242
'factorization('=151
'primefactors('=152
'mobius('=153
'moebiusmu('=154
'divisorsigma('=155
'primenu('=156
'primeomega('=157
'primepi('=158
'card('=159
'powerset('=160
'union('=161
'intersection('=162
'complement('=163
'image('=164
'preimage('=165
'floor('=166
'ceil('=167
'ceiling('=168
'round('=169
'min('=170
'max('=171
'argmax('=172
'argmin('=173
'gcd('=174
'lcm('=175
'binomial('=176
'multinomial('=177
'catalannumber('=178
'harmonicnumber('=179
'fallingfactorial('=180
'factorialpower('=181
'risingfactorial('=182
'iverson('=183
'aleph('=184
'erf('=185
'erfc('=186
'erfi('=187
'Ei('=188
'li('=189
'lambertw('=190
'productlog('=191
'polygamma('=192
'digamma('=193
'Si('=194
'Ci('=195
'Shi('=196
'Chi('=197
'det('=198
'transpose('=199
'trace('=200
'dot('=201
'cross('=202
'laplacian('=203
'forwarddifference('=204
'jacobian('=205
'hessian('=206
'resultant('=207
'conjugate('=208
'conj('=209
'arg('=210
'Re('=211
'Im('=212
're('=213
'real('=214
'im('=215
'imag('=216
'trunc('=217
'zeta('=218
'riemannzeta('=219
'hurwitzzeta('=220
'heaviside('=221
'unitstep('=222
'isprime('=223
'pochhammer('=224
'doublefactorial('=225
'factorial2('=226
'fractionalpart('=227
'quotient('=228
'factorize('=229
'nextprime('=230
'divisors('=231
'gradient('=232
'divergence('=233
'φ('=234
'ϕ('=235
'domain('=236
'piecewise('=237
'apply('=238
'lambda('=239
'NaN'=244
Loading
Loading