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
2 changes: 2 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,8 @@ prime, `17` ([#1450](https://github.com/asc-community/AngouriMath/issues/1450)).
| `"PP intersect [1; 30]".ToEntity().Evaled` | as written | `{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }` |
| `"min(ZZ+)".ToEntity().Evaled` | `ZZ+` | `1` |
| `"max(x, x in PP and x < 14)".ToEntity().Evaled` | as written | `13` |
| `"prime(25)".ToEntity().Evaled` | `prime * 25` — juxtaposition of a variable `prime` | `97`; `prime(n)` is the `n`-th prime, `NaN` off the positive whole numbers |
| `"valuation(12, 2)".ToEntity().Evaled` | `UnrecognizedFunctionParseException` | `2`; `valuation(n, p)` is the `p`-adic valuation, `+oo` at `0` and `NaN` off the primes |

### `binomial(n, k)` is a function

Expand Down
34 changes: 34 additions & 0 deletions Sources/AngouriMath/Convenience/MathS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,40 @@ public static class NumberTheory
/// </example>
public static Entity Phi(Entity integer) => new Phif(integer);

/// <summary>
/// The <c>n</c>-th prime, <c>prime(n)</c>: <c>prime(1)</c> is <c>2</c> and
/// <c>prime(25)</c> is <c>97</c>. Defined on the positive whole numbers, and a
/// function rather than an operation on the set <c>PP</c>, which carries no order.
/// https://github.com/asc-community/AngouriMath/issues/1450
/// </summary>
/// <example>
/// <code>
/// Console.WriteLine(MathS.NumberTheory.Prime(25).Evaled);
/// </code>
/// Prints
/// <code>
/// 97
/// </code>
/// </example>
public static Entity Prime(Entity index) => new Primef(index);

/// <summary>
/// The <c>p</c>-adic valuation of a whole number, <c>valuation(n, p)</c>: the exponent
/// of the prime <c>p</c> in <c>n</c>. <c>valuation(12, 2)</c> is <c>2</c>,
/// <c>valuation(12, 5)</c> is <c>0</c>, and at <c>n = 0</c> it is <c>+oo</c>.
/// https://github.com/asc-community/AngouriMath/issues/1450
/// </summary>
/// <example>
/// <code>
/// Console.WriteLine(MathS.NumberTheory.Valuation(12, 2).Evaled);
/// </code>
/// Prints
/// <code>
/// 2
/// </code>
/// </example>
public static Entity Valuation(Entity argument, Entity prime) => new Valuationf(argument, prime);

/// <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
2 changes: 2 additions & 0 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.g
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ atom returns[Entity value]
| 'sign(' args = function_arguments ')' { Assert("sign", 1, $args.list.Count); $value = MathS.Signum($args.list[0]); }
| 'abs(' args = function_arguments ')' { Assert("abs", 1, $args.list.Count); $value = MathS.Abs($args.list[0]); }
| '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]); }
| 'card(' args = function_arguments ')' { Assert("card", 1, $args.list.Count); $value = MathS.Sets.Card($args.list[0]); }
| 'powerset(' args = function_arguments ')' { Assert("powerset", 1, $args.list.Count); $value = MathS.Sets.PowerSet($args.list[0]); }
| 'union(' args = function_arguments ')' { Assert("union", 2, $args.list.Count); $value = $args.list[1] is Entity.Set.Inf { Element: Variable } unionRange ? MathS.Sets.IndexedUnion($args.list[0], unionRange.Element, unionRange.SupSet) : throw new InvalidArgumentParseException("union expects its second argument to say which name ranges over which set, as in union(A_i, i in I)"); }
Expand Down
6 changes: 5 additions & 1 deletion Sources/AngouriMath/Core/Antlr/AngouriMath.interp

Large diffs are not rendered by default.

72 changes: 38 additions & 34 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,16 @@ T__167=168
T__168=169
T__169=170
T__170=171
NEWLINE=172
NUMBER=173
SPECIALSET=174
BOOLEAN=175
NAN=176
VARIABLE=177
COMMENT=178
WS=179
T__171=172
T__172=173
NEWLINE=174
NUMBER=175
SPECIALSET=176
BOOLEAN=177
NAN=178
VARIABLE=179
COMMENT=180
WS=181
'!'=1
'^'=2
'-'=3
Expand Down Expand Up @@ -323,29 +325,31 @@ WS=179
'sign('=144
'abs('=145
'phi('=146
'card('=147
'powerset('=148
'union('=149
'intersection('=150
'complement('=151
'image('=152
'preimage('=153
'floor('=154
'ceil('=155
'ceiling('=156
'round('=157
'min('=158
'max('=159
'argmax('=160
'argmin('=161
'gcd('=162
'lcm('=163
'binomial('=164
'trunc('=165
'erf('=166
'conjugate('=167
'domain('=168
'piecewise('=169
'apply('=170
'lambda('=171
'NaN'=176
'prime('=147
'valuation('=148
'card('=149
'powerset('=150
'union('=151
'intersection('=152
'complement('=153
'image('=154
'preimage('=155
'floor('=156
'ceil('=157
'ceiling('=158
'round('=159
'min('=160
'max('=161
'argmax('=162
'argmin('=163
'gcd('=164
'lcm('=165
'binomial('=166
'trunc('=167
'erf('=168
'conjugate('=169
'domain('=170
'piecewise('=171
'apply('=172
'lambda('=173
'NaN'=178
Loading
Loading