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
21 changes: 21 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,27 @@ with the multiplier gathered from the whole product in the exponent
| `"e^(2*acoth(2*x))*(3 - 12*x^2)^2".Integrate("x")` | `integral(…)` — left unevaluated | `(144 * x ^ 5 / 5 + 144 * x ^ 4 / 4 + (-36) * x ^ 2 / 2 + (-9) * x provided not 2 * x + -1 = 0) + C` |
| `"e^(1/3*acoth(x))*x^2".Integrate("x")` | `integral(…)` — left unevaluated | an antiderivative in `((x + 1)/(x - 1))^(1/6)` |

### `...` is the pattern operator

`{1, 2, ..., n}`, `{2, 4, ..., 2 n}`, `{5, 10, 15, ...}`, `{..., -1, 0}`, `1 + 2 + ... + n` and
`1 * 2 * ... * n` parse — also with `…` — as the arithmetic progression of whole numbers the shown
terms determine, up to the term after the dots: a set is `ZZ /\ [a; z]` for step one and a residue
class cut by the interval otherwise, listed when the ends are numbers; a sum is `sum(k, k, 1, n)`
and a product `product(k, k, 1, n)`, with `a + d k` as the term for another step. Shown terms with
no common step, a progression that is not of whole numbers, and dots with nothing to determine
them are refused with a message saying which. The smaller half of
[#1437](https://github.com/asc-community/AngouriMath/issues/1437); the general term with an index
shown and the argument list of symbolic length wait for v3. Every one of these was a parse error.

| Input | Was (2.5.0) | Now |
|---|---|---|
| `{1, 2, ..., 10}` | `UnhandledParseException` | `{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }` |
| `{1, 2, ..., n}` | `UnhandledParseException` | `ZZ /\ [1; n]` |
| `7 in {1, 3, 5, ...}` | `UnhandledParseException` | `True` |
| `1 + 2 + ... + 100` | `UnhandledParseException` | `5050` |
| `1 * 2 * ... * n` | `UnhandledParseException` | `product(k, k, 1, n)`, which is `n!` for `n >= 1` |
| `{1, 4, 9, ..., n}` | `UnhandledParseException` | `InvalidArgumentParseException`, naming the term off the progression |

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

**Addition, not silent.** The binomial coefficient is a node, `Entity.Binomialf`, spelled
Expand Down
6 changes: 6 additions & 0 deletions Sources/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
[AngouriMath/Functions/NumberTheory/ResidueClasses.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

[AngouriMath/Core/PatternOperator.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/Core/PatternOperatorTest.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/Core/Sets/IndexedSetOperationTest.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

Expand Down
38 changes: 30 additions & 8 deletions Sources/AngouriMath/Core/Antlr/AngouriMath.g
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,29 @@ unary_expression returns[Entity value]
| p = power_expression { $value = $p.value; }
;

/* `1 * 2 * ... * n` is the product of the progression the shown factors determine: the
factors are collected, and where dots stood among them the pattern operator builds the
product. Without dots the fold is the same as it was. https://github.com/asc-community/AngouriMath/issues/1437 */
mult_expression returns[Entity value]
: u1 = unary_expression { $value = $u1.value; }
('*' u2 = unary_expression { $value = $value * $u2.value; } |
'/' u2 = unary_expression { $value = $value / $u2.value; } |
'mod' u2 = unary_expression { $value = $value % $u2.value; })*
@init { Entity beforeDots = null; Entity afterDots = null; bool mixed = false; }
: u1 = unary_expression { $value = $u1.value; }
('*' ( ('...' | '…') { if (beforeDots is not null) throw new InvalidArgumentParseException("A product written with dots has one ... in it"); beforeDots = $value; }
| u2 = unary_expression { if (beforeDots is null) $value = $value * $u2.value; else if (afterDots is null) afterDots = $u2.value; else throw new InvalidArgumentParseException("A product written with dots ends with the one factor after them, as 1 * 2 * ... * n"); } ) |
'/' u2 = unary_expression { $value = $value / $u2.value; mixed = true; } |
'mod' u2 = unary_expression { $value = $value % $u2.value; mixed = true; })*
{ if (beforeDots is not null) $value = AngouriMath.Core.PatternOperator.SumOrProduct(mixed ? null : Mulf.LinearChildren(beforeDots), afterDots, product: true); }
;


/* `1 + 2 + ... + n` is the sum of the progression the shown terms determine, the same way. The
terms before the dots are read off the folded sum, so that a sum without dots allocates
nothing it did not. */
sum_expression returns[Entity value]
@init { Entity beforeDots = null; Entity afterDots = null; }
: m1 = mult_expression { $value = $m1.value; }
('+' m2 = mult_expression { $value = $value + $m2.value; } |
'-' m2 = mult_expression { $value = $value - $m2.value; })*
('+' ( ('...' | '…') { if (beforeDots is not null) throw new InvalidArgumentParseException("A sum written with dots has one ... in it"); beforeDots = $value; }
| m2 = mult_expression { if (beforeDots is null) $value = $value + $m2.value; else if (afterDots is null) afterDots = $m2.value; else throw new InvalidArgumentParseException("A sum written with dots ends with the one term after them, as 1 + 2 + ... + n"); } ) |
'-' m2 = mult_expression { if (beforeDots is null) $value = $value - $m2.value; else throw new InvalidArgumentParseException("A sum written with dots ends with the one term after them, as 1 + 2 + ... + n"); })*
{ if (beforeDots is not null) $value = AngouriMath.Core.PatternOperator.SumOrProduct(Sumf.LinearChildren(beforeDots), afterDots, product: false); }
;

/*
Expand Down Expand Up @@ -380,6 +392,16 @@ function_arguments returns[List<Entity> list]
: (e = expression { $list.Add($e.value); } (',' e = expression { $list.Add($e.value); })*)?
;

/* The items of a set literal, with `...` (or `…`) allowed among them: a listed set as it
was, or a pattern -- {1, 2, ..., n}, {2, 4, 6, ...}, {..., -1, 0} -- which the pattern
operator reads as the progression the shown terms determine. A null stands for the dots.
https://github.com/asc-community/AngouriMath/issues/1437 */
set_items returns[List<Entity> list]
@init { $list = new List<Entity>(); }
: ( ( e = expression { $list.Add($e.value); } | ('...' | '…') { $list.Add(null); } )
(',' ( e = expression { $list.Add($e.value); } | ('...' | '…') { $list.Add(null); } ))* )?
;

interval_arguments returns[(Entity from, Entity to) couple]
: from = expression { $couple.from = $from.value; } ';' to = expression { $couple.to = $to.value; }
;
Expand Down Expand Up @@ -418,7 +440,7 @@ atom returns[Entity value]
| '(' interval_arguments ']' { $value = new Entity.Set.Interval($interval_arguments.couple.from, false, $interval_arguments.couple.to, true); }
| '(' expression ')' { $value = $expression.value; }
| '{' cset_args = cset_arguments '}' { $value = new ConditionalSet($cset_args.couple.variable, $cset_args.couple.predicate); }
| '{' args = function_arguments '}' { $value = new FiniteSet((IEnumerable<Entity>)$args.list); }
| '{' items = set_items '}' { $value = $items.list.Contains(null) ? AngouriMath.Core.PatternOperator.Set($items.list) : new FiniteSet($items.list.Cast<Entity>()); }
| 'log(' args = function_arguments ')' { $value = Assert("log", (1, 2), $args.list.Count) ? MathS.Log(10, $args.list[0]) : MathS.Log($args.list[0], $args.list[1]); }
| 'log10(' args = function_arguments ')' { Assert("log10", 1, $args.list.Count); $value = MathS.Log(10, $args.list[0]); }
| 'log2(' args = function_arguments ')' { Assert("log2", 1, $args.list.Count); $value = MathS.Log(2, $args.list[0]); }
Expand Down
7 changes: 6 additions & 1 deletion Sources/AngouriMath/Core/Antlr/AngouriMath.interp

Large diffs are not rendered by default.

Loading
Loading