Skip to content

Commit 7aaf21d

Browse files
An integer range is listed, and a family of sets has a union and an intersection (#1435)
Item 4 of the reference's docket (#1409), second half. ZZ /\ [1; 10] lists its members: an integer set cut by a numeric interval with at most 4096 members in it is the finite set of them -- the reference's [n] = {1, ..., n} is ZZ+ /\ [1; n], and its indexed unions run over such ranges; the reals and the complex numbers cut by an interval are the interval, and the rationals stay as written. union(A_k, k in I) and intersection(A_k, k in I), the ⋃ and ⋂ over a family, are Entity.Set.IndexedUnionf and IndexedIntersectionf: binders like sum, with the capture-avoiding substitution a quantifier has, folded to the binary operators over a listed index set, and over any other an object whose membership goes through the quantifiers -- x in union(A_n, n in I) is exists n in I : x in A_n -- so that the reference's limit cases read at their members: 0 in intersection([0; 1/n), n in ZZ+) is True and 0.1 is not, 1 is in every [n] and 2 is not. complement(A, U) is U \ A, a complement being relative to a universe. The reference's rows are the tests (IndexedSetOperationTest): Ex 3.6.1, Ex 3.6.6 over two index sets, Ex 3.5.11, Problem 3.11.20, §3.9.5 Try 8. An index is k or n where the book writes i, which is the imaginary unit here. #1409 Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent f66b5c3 commit 7aaf21d

24 files changed

Lines changed: 1330 additions & 803 deletions

‎BREAKING-CHANGES.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,25 @@ too ([#1409](https://github.com/asc-community/AngouriMath/issues/1409)). `subset
621621
| `{1, 3} in powerset(ZZ)` | `UnrecognizedFunctionParseException` | `True` |
622622
| `card({1, {}})` | `#{ 1, { } }` — left as written | `2` |
623623

624+
### An integer range is listed, and a family of sets has a union and an intersection
625+
626+
`ZZ /\ [1; 10]` lists its members now — an integer set cut by a numeric interval with at most
627+
4096 members in it is the finite set of them, the `[n] = {1, …, n}` of combinatorics being
628+
`ZZ+ /\ [1; n]`; the reals and the complex numbers cut by an interval are the interval, and the
629+
rationals stay as written. `union(A_k, k in I)` and `intersection(A_k, k in I)` are
630+
`Entity.Set.IndexedUnionf` and `Entity.Set.IndexedIntersectionf`, binders like `sum`: folded over
631+
a listed index set, and over any other an object whose membership is decided by the quantifiers
632+
(`0 in intersection([0; 1/n), n in ZZ+)` is `True`). `complement(A, U)` is `U \ A`
633+
([#1409](https://github.com/asc-community/AngouriMath/issues/1409)). `union`, `intersection` and
634+
`complement` are keywords now, and were names.
635+
636+
| Input | Was (2.5.0) | Now |
637+
|---|---|---|
638+
| `ZZ /\ [1; 10]` | `ZZ /\ [1; 10]` — left as written | `{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }` |
639+
| `RR /\ [0; 1]` | `RR /\ [0; 1]` — left as written | `[0; 1]` |
640+
| `union({k, 2 k}, k in {1, 2, 3})` | `UnhandledParseException` — `union` was a name, and `union(` a juxtaposition that does not parse | `{ 1, 2, 4, 3, 6 }` |
641+
| `0.1 in intersection([0; 1/n), n in ZZ+)` | `UnhandledParseException` | `False` |
642+
| `complement({1, 2}, {1, 2, 3})` | `UnhandledParseException` | `{ 3 }` |
624643
### An exponential of a multiple of a logarithm is integrated as the power it is
625644

626645
`e^(k ln(q))` is `q^k` — the definition of the principal power, for every complex `q` other than

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
291291
[AngouriMath/Functions/NumberTheory/ResidueClasses.cs]
292292
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
293293

294+
[Tests/UnitTests/Core/Sets/IndexedSetOperationTest.cs]
295+
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
296+
294297
[Tests/UnitTests/Calculus/ExponentialOfALogarithmIntegralTest.cs]
295298
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
296299

‎Sources/AngouriMath/Convenience/MathS.cs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6262,6 +6262,36 @@ public static class Sets
62626262
/// </example>
62636263
public static Entity Subset(Entity sub, Entity super) => new Subsetf(sub, super);
62646264

6265+
/// <summary>
6266+
/// The union of a family of sets indexed by <paramref name="var"/> ranging over
6267+
/// <paramref name="over"/>: <c>union(A_i, i in I)</c>, the set of what is in some
6268+
/// <c>A_i</c>. Folded over a listed index set; a membership object otherwise.
6269+
/// </summary>
6270+
/// <example>
6271+
/// <code>
6272+
/// Console.WriteLine("union({k, 2 k}, k in {1, 2, 3})".ToEntity().Evaled);
6273+
/// </code>
6274+
/// Prints
6275+
/// <code>
6276+
/// { 1, 2, 4, 3, 6 }
6277+
/// </code>
6278+
/// </example>
6279+
public static Set IndexedUnion(Entity body, Entity var, Entity over) => new IndexedUnionf(var, over, body);
6280+
6281+
/// <summary>
6282+
/// The intersection of a family of sets indexed by <paramref name="var"/> ranging
6283+
/// over <paramref name="over"/>: <c>intersection(A_i, i in I)</c>, the set of what
6284+
/// is in every <c>A_i</c>.
6285+
/// </summary>
6286+
public static Set IndexedIntersection(Entity body, Entity var, Entity over) => new IndexedIntersectionf(var, over, body);
6287+
6288+
/// <summary>
6289+
/// The complement of <paramref name="set"/> relative to the universe
6290+
/// <paramref name="universe"/>, which is <c>universe \ set</c>: a complement is
6291+
/// always relative to a universe, there being no set of everything.
6292+
/// </summary>
6293+
public static Set Complement(Entity set, Entity universe) => universe.SetSubtract(set);
6294+
62656295
/// <returns>A set of all Complexes/>s</returns>
62666296
public static Set C => SpecialSet.Create(Domain.Complex);
62676297

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ atom returns[Entity value]
550550
| 'phi(' args = function_arguments ')' { Assert("phi", 1, $args.list.Count); $value = MathS.NumberTheory.Phi($args.list[0]); }
551551
| 'card(' args = function_arguments ')' { Assert("card", 1, $args.list.Count); $value = MathS.Sets.Card($args.list[0]); }
552552
| 'powerset(' args = function_arguments ')' { Assert("powerset", 1, $args.list.Count); $value = MathS.Sets.PowerSet($args.list[0]); }
553+
| '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)"); }
554+
| 'intersection(' args = function_arguments ')' { Assert("intersection", 2, $args.list.Count); $value = $args.list[1] is Entity.Set.Inf { Element: Variable } intersectionRange ? MathS.Sets.IndexedIntersection($args.list[0], intersectionRange.Element, intersectionRange.SupSet) : throw new InvalidArgumentParseException("intersection expects its second argument to say which name ranges over which set, as in intersection(A_i, i in I)"); }
555+
| 'complement(' args = function_arguments ')' { Assert("complement", 2, $args.list.Count); $value = MathS.Sets.Complement($args.list[0], $args.list[1]); }
553556
| 'floor(' args = function_arguments ')' { Assert("floor", 1, $args.list.Count); $value = MathS.Floor($args.list[0]); }
554557
| 'ceil(' args = function_arguments ')' { Assert("ceil", 1, $args.list.Count); $value = MathS.Ceil($args.list[0]); }
555558
/* SymPy's spelling, accepted so that an expression copied from there parses. Stringize

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

Lines changed: 7 additions & 1 deletion
Large diffs are not rendered by default.

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

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,17 @@ T__160=161
162162
T__161=162
163163
T__162=163
164164
T__163=164
165-
NEWLINE=165
166-
NUMBER=166
167-
SPECIALSET=167
168-
BOOLEAN=168
169-
NAN=169
170-
VARIABLE=170
171-
COMMENT=171
172-
WS=172
165+
T__164=165
166+
T__165=166
167+
T__166=167
168+
NEWLINE=168
169+
NUMBER=169
170+
SPECIALSET=170
171+
BOOLEAN=171
172+
NAN=172
173+
VARIABLE=173
174+
COMMENT=174
175+
WS=175
173176
'!'=1
174177
'^'=2
175178
'-'=3
@@ -316,22 +319,25 @@ WS=172
316319
'phi('=144
317320
'card('=145
318321
'powerset('=146
319-
'floor('=147
320-
'ceil('=148
321-
'ceiling('=149
322-
'round('=150
323-
'min('=151
324-
'max('=152
325-
'argmax('=153
326-
'argmin('=154
327-
'gcd('=155
328-
'lcm('=156
329-
'binomial('=157
330-
'trunc('=158
331-
'erf('=159
332-
'conjugate('=160
333-
'domain('=161
334-
'piecewise('=162
335-
'apply('=163
336-
'lambda('=164
337-
'NaN'=169
322+
'union('=147
323+
'intersection('=148
324+
'complement('=149
325+
'floor('=150
326+
'ceil('=151
327+
'ceiling('=152
328+
'round('=153
329+
'min('=154
330+
'max('=155
331+
'argmax('=156
332+
'argmin('=157
333+
'gcd('=158
334+
'lcm('=159
335+
'binomial('=160
336+
'trunc('=161
337+
'erf('=162
338+
'conjugate('=163
339+
'domain('=164
340+
'piecewise('=165
341+
'apply('=166
342+
'lambda('=167
343+
'NaN'=172

0 commit comments

Comments
 (0)