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
24 changes: 24 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,30 @@ returned as all of them. `MathS.Equations("y^2 - 2", "x^2 + (P - Q y) * x - 3").

---

### An indexed union or intersection binds its index

**Silent: a bound name is no longer reported free.** `FreeVariables` of `union(A_k, k in I)` and `intersection(A_k, k in I)`
listed `k`, though the family binds it as a quantifier does and `Substitute` already left it alone. `DomainCondition` left
the family's condition on `k` free beside it; it now holds over the index set, as a sum's does over its range. The same
condition of a set builder mentioned the name its predicate is renamed to for traversal, `%1`, and of a lambda its
parameter; both are where the set's members or the function's arguments lie, not where the expression is defined, and are
dropped ([#2458](https://github.com/asc-community/AngouriMath/issues/2458)).

| Input | Was (2.7.0) | Now |
|---|---|---|
| `"union({2*pi*k + y}, k in ZZ)".ToEntity().FreeVariables` | `k, pi, y` | `pi, y` |
| `"intersection({k, y}, k in ZZ)".ToEntity().FreeVariables` | `k, y` | `y` |
| `"union({k*y}, k in {k, n})".ToEntity().FreeVariables` | `k, n, y` | `y, n` |
| `"union({1/k}, k in ZZ)".ToEntity().DomainCondition` | `not k = 0` | `False` |
| `"union({1/k}, k in ZZ+)".ToEntity().DomainCondition` | `not k = 0` | `True` |
| `"{ k : 1/k > y }".ToEntity().DomainCondition` | `1 / %1 in RR and y in RR and not %1 = 0` | `y in RR` |
| `"x in { k : k > y }".ToEntity().DomainCondition` | `%1 in RR and y in RR` | `y in RR` |
| `"lambda(k, 1/(k - y))".ToEntity().DomainCondition` | `not k - y = 0` | `True` |

`Vars` and `VarsAndConsts` still list the index, which occurs.

---

### A system row that is not a solution declines the system

**Silent: a wrong row is now no answer.** With `P + Q sqrt(2) = (1 + sqrt(2))^70`, the coefficient `P - Q y` is
Expand Down
6 changes: 6 additions & 0 deletions Sources/AngouriMath/Core/Entity/Entity.Definition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@ Limitf limit
// https://github.com/asc-community/AngouriMath/issues/1409
Quantifier quantifier
=> BoundBy(quantifier.Var, quantifier.Body, quantifier.Over),
// An indexed union or intersection binds its index as a quantifier does, and
// for the reason its membership is one: x in union(A_k, k in I) is
// exists k in I : x in A_k. union({ 2 pi k + y }, k in ZZ) is a function of y.
// https://github.com/asc-community/AngouriMath/issues/2458
Set.IndexedSetOperation indexed
=> BoundBy(indexed.Var, indexed.Body, indexed.Over),
_ => new HashSet<Variable>(@this.DirectChildren.SelectMany(c => c.FreeVariables))
}
,
Expand Down
9 changes: 8 additions & 1 deletion Sources/AngouriMath/Core/Entity/Omni/Entity.Omni.Classes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,14 @@ internal Entity New(Entity var, Entity predicate)
// https://github.com/asc-community/AngouriMath/issues/891
/// <inheritdoc/>
protected override Entity[] InitDirectChildren() =>
new[] { Predicate.Substitute(Var, Variable.CreateTemp(Predicate.Vars)) };
new[] { Predicate.Substitute(Var, Placeholder) };

/// <summary>
/// The name <see cref="Var"/> is renamed to in the predicate this set builder
/// publishes as its child, which is what a question asked of that child mentions
/// in place of <see cref="Var"/>.
/// </summary>
internal Variable Placeholder => Variable.CreateTemp(Predicate.Vars);

/// <summary>
/// The written parts, which is what a pattern has to be able to say. The rename
Expand Down
17 changes: 13 additions & 4 deletions Sources/AngouriMath/Functions/Evaluation/Evaluation.Definition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ private static Entity WhereTheCaseItTakesIsDefined(Piecewise piecewise, System.F
/// coefficient is a number that is not zero. A finite range of numbers is the conjunction
/// over it. Anything else is kept as <c>forall</c> over the range: the set, the whole
/// numbers from the lower bound to the upper, the interval between a definite integral's
/// limits. A set builder admits the members its predicate is defined at, so its own
/// condition on its name is part of whom it admits rather than of where the set is defined.
/// A limit does not need its body defined throughout anything, and is left as it was.
/// limits, the index set of an indexed union or intersection. A set builder admits the
/// members its predicate is defined at, so its own condition on its name is part of whom it
/// admits rather than of where the set is defined; a lambda's condition on its parameter is
/// where the function it denotes is defined, and both are dropped. A limit does not need its
/// body defined throughout anything, and is left as it was.
/// https://github.com/asc-community/AngouriMath/issues/1632
/// https://github.com/asc-community/AngouriMath/issues/2458
/// </para>
/// <para>
/// For a definite integral this is sufficient for a value and not necessary: an integral
Expand All @@ -135,10 +138,16 @@ private static Entity ScopedToItsBinder(Entity binder, Entity condition)
Argmaxf(_, var name, var over) => (name, over),
Argminf(_, var name, var over) => (name, over),
Quantifier quantifier => (quantifier.Var, quantifier.Over),
Set.IndexedSetOperation indexed => (indexed.Var, indexed.Over),
Summationf(_, var index, var from, var to) => (index, WholeNumbersBetween(index, from, to)),
Productf(_, var index, var from, var to) => (index, WholeNumbersBetween(index, from, to)),
Integralf { Range: { } limits } integral => (integral.Var, Between(integral.Var, limits.from, limits.to)),
Set.ConditionalSet(var name, _) => (name, null),
// The condition is of the child the set builder publishes, in which its name is
// renamed: that placeholder is the name the conjuncts mention.
Set.ConditionalSet set => (set.Placeholder, null),
// A lambda, like a set builder, binds its parameter over no range: a condition on
// the parameter is where the function is defined, not where the lambda is.
Lambda(var parameter, _) => (parameter, null),
_ => null
};
if (scope is not var (bound, range))
Expand Down
25 changes: 25 additions & 0 deletions Sources/Tests/UnitTests/Common/FreeVariablesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,30 @@ public void AnIndexOutsideItsBinderIsStillFree()
=> Assert.Equal(
SeqVar("k", "n").OrderBy(v => v.Name),
"sum(k, k, 1, n) + k".ToEntity().FreeVariables.OrderBy(v => v.Name));

/// <summary>
/// An indexed union or intersection binds its index as a quantifier does, throughout the
/// family and the index set: <c>x in union(A_k, k in I)</c> is <c>exists k in I : x in A_k</c>.
/// <a href="https://github.com/asc-community/AngouriMath/issues/2458">#2458</a>
/// </summary>
[Theory]
[InlineData("union({ 2*pi*k + y }, k in ZZ)", "pi y")]
[InlineData("intersection({ k, y }, k in ZZ)", "y")]
[InlineData("union([k; y], k in [0; n])", "n y")]
[InlineData("union({ k*y }, k in { k, n })", "n y")]
[InlineData("union({ 1/k }, k in ZZ)", "")]
public void Issue2458_AnIndexedFamilyBindsItsIndex(string exprRaw, string free)
=> Assert.Equal(
free.Split(' ', System.StringSplitOptions.RemoveEmptyEntries),
exprRaw.ToEntity().FreeVariables.Select(v => v.Name).OrderBy(n => n, System.StringComparer.Ordinal));

/// <summary>Only inside the family that declares it, and it still occurs.</summary>
[Fact]
public void Issue2458_AnIndexOutsideItsFamilyIsStillFree()
{
var expr = "union({ 2*pi*k + y }, k in ZZ) \\/ { k }".ToEntity();
Assert.Equal(new[] { "k", "pi", "y" }, expr.FreeVariables.Select(v => v.Name).OrderBy(n => n, System.StringComparer.Ordinal));
Assert.Equal(new[] { "k", "y" }, "union({ 2*pi*k + y }, k in ZZ)".ToEntity().Vars.Select(v => v.Name).OrderBy(n => n, System.StringComparer.Ordinal));
}
}
}
41 changes: 41 additions & 0 deletions Sources/Tests/UnitTests/Core/BinderConditionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,46 @@ public void AFiniteRangeIsTheConjunctionOverIt(string sum, string at, bool defin
[Fact]
public void ASetBuildersOwnConditionIsMembership()
=> Assert.DoesNotContain("{ w : 1/w > a }".ToEntity().DomainCondition.Vars, v => v.Name == "w");

/// <summary>
/// The set builder's condition is of the predicate it publishes, in which its name is
/// renamed, so the test above held on a condition that mentioned <c>%1</c> instead:
/// <c>1 / %1 in RR and a in RR and not %1 = 0</c>. No name of the builder's, written or
/// invented, is left.
/// <a href="https://github.com/asc-community/AngouriMath/issues/2458">#2458</a>
/// </summary>
[Theory]
[InlineData("{ w : 1/w > a }")]
[InlineData("{ w in ZZ : 1/w > a }")]
[InlineData("x in { w : w > a }")]
public void Issue2458_ASetBuilderLeavesNoPlaceholderInItsCondition(string exprRaw)
=> Assert.Equal(new[] { "a" }, exprRaw.ToEntity().DomainCondition.Vars.Select(v => v.Name).ToArray());

/// <summary>
/// A lambda's condition on its parameter is where the function it denotes is defined,
/// and outside it that name is another one.
/// <a href="https://github.com/asc-community/AngouriMath/issues/2458">#2458</a>
/// </summary>
[Fact]
public void Issue2458_ALambdaLeavesNoParameterInItsCondition()
=> Assert.DoesNotContain("lambda(k, 1/(k - y))".ToEntity().DomainCondition.Vars, v => v.Name == "k");

/// <summary>
/// An indexed union or intersection is defined where every set of the family is, as a
/// sum is where every term is: over the index set, not at a free name of the same spelling.
/// <a href="https://github.com/asc-community/AngouriMath/issues/2458">#2458</a>
/// </summary>
[Theory]
[InlineData("union({ 1/k }, k in ZZ)", "0", false)]
[InlineData("union({ 1/k }, k in ZZ+)", "0", true)]
[InlineData("intersection([-1/k; 1/k], k in ZZ+)", "0", true)]
[InlineData("union({ 1/(k - x) }, k in { 1, 2 })", "1", false)]
[InlineData("union({ 1/(k - x) }, k in { 1, 2 })", "3", true)]
public void Issue2458_AnIndexedFamilysConditionHoldsOverItsIndexSet(string family, string at, bool defined)
{
var condition = family.ToEntity().DomainCondition;
Assert.DoesNotContain(condition.FreeVariables, v => v.Name == "k");
Assert.Equal(defined ? MathS.Boolean.True : MathS.Boolean.False, condition.Substitute("x", at.ToEntity()).Simplify());
}
}
}
Loading