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
4 changes: 3 additions & 1 deletion Sources/AngouriMath/Core/Antlr/AngouriMath.g
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*

Remember to run the "antlr_rerun.bat" file located at "Sources/Utils/antlr_rerun.bat" (relative to the repository root)
every time you modify this file so that the generated source files under the Antlr folder are updated and changes are
Expand Down Expand Up @@ -219,6 +219,8 @@ Keyword nodes
provided_expression returns[Entity value]
: expr = implies_expression { $value = $expr.value; }
('provided' pred = provided_expression { $value = $value.Provided($pred.value); })?
// note: even though Provided is associative, we parse it right-to-left matching natural language
// "I'll go, provided you go, provided it's sunny" - Natural reading: I'll go ← (you go ← sunny)
;

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public override string Latexise()
partial record Providedf
{
/// <inheritdoc/>
public override string Latexise() => $@"{Expression.Latexise(Expression.LatexPriority < LatexPriority)} \quad \text{{for}} \quad {Predicate.Latexise(Predicate.LatexPriority <= LatexPriority)}";
public override string Latexise() => $@"{Expression.Latexise(Expression.LatexPriority < LatexPriority)} \quad \text{{for}} \quad {Predicate.Latexise(Predicate.LatexPriority < LatexPriority)}";
}

partial record Piecewise
{
/// <inheritdoc/>
public override string Latexise() => $@"\begin{{cases}}" +
public override string Latexise() => @"\begin{cases}" +
string.Join(@"\\",
Cases.Select(c =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public override string Stringize()
partial record Providedf
{
/// <inheritdoc/>
public override string Stringize() => $@"{Expression.Stringize(Expression.Priority <= Priority.Provided)} provided {Predicate.Stringize(Predicate.Priority < Priority.Provided)}";
public override string Stringize() => $@"{Expression.Stringize(Expression.Priority < Priority.Provided)} provided {Predicate.Stringize(Predicate.Priority < Priority.Provided)}";
/// <inheritdoc/>
public override string ToString() => Stringize();
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Tests/UnitTests/Convenience/FromStringTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public void TestFormula8()
[Fact] public void TestProvided1() => Assert.Equal(MathS.Provided("a", "b"), FromString("a provided b"));
[Fact] public void TestProvided2() => Assert.Equal(MathS.Provided("a", MathS.Provided("b", "c")), FromString("a provided b provided c"));
[Fact] public void TestProvided3() => Assert.Equal(MathS.Provided(MathS.Provided("a", "b"), "c"), FromString("(a provided b) provided c"));
[Fact] public void TestProvided4() => Assert.Equal(FromString("a provided (b provided c)").Stringize(), FromString("(a provided b) provided c").Stringize());

[Theory]
[InlineData("sh", "Sinh")]
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tests/UnitTests/Convenience/LatexTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ [Fact] public void Provided2()
[Fact] public void Provided3()
=> Test(@"a \quad \text{for} \quad b \quad \text{for} \quad c", MathS.Provided(MathS.Provided("a", "b"), "c"));
[Fact] public void Provided4()
=> Test(@"\left(a \quad \text{for} \quad b \quad \text{for} \quad \left(c \quad \text{for} \quad d\right)\right) \to \top ", MathS.Provided(MathS.Provided("a", "b"), MathS.Provided("c", "d")).Implies(Entity.Boolean.True));
=> Test(@"\left(a \quad \text{for} \quad b \quad \text{for} \quad c \quad \text{for} \quad d\right) \to \top ", MathS.Provided(MathS.Provided("a", "b"), MathS.Provided("c", "d")).Implies(Entity.Boolean.True));
// Juxtaposition tests
[Fact] public void M1InTheMiddle() => Test(@"x \left(-1\right) \cdot x", (x * (-1)) * x);
[Fact] public void MultiplyNumberWithPower() => Test(@"2 \cdot {3}^{4}", 2 * ((Entity)3).Pow(4));
Expand Down
1 change: 0 additions & 1 deletion Sources/Tests/UnitTests/Convenience/PriorityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class PriorityTest
[InlineData("not a or not b implies not c or not d", "((not a) or (not b)) implies ((not c) or (not d))")]
[InlineData("a = b and b > c and d", "a = b > c and d")]
[InlineData("a provided b", "a provided b")]
[InlineData("(a provided b) provided c", "(a provided b) provided c")]
[InlineData("a provided b provided c", "a provided (b provided c)")]
[InlineData("a provided b and c", "a provided (b and c)")]
[InlineData("a provided b + c > 0", "a provided (b + c > 0)")]
Expand Down
Loading