Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change AngouriMath reference to use NuGet package instead of git submodule #149

Merged
merged 31 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
60920b3
Waiting for AngouriMath to fix bugs
Happypig375 Jun 7, 2020
591a699
More interval tests
Happypig375 Jun 7, 2020
736fc30
Parse -> Visualize
Happypig375 Jun 8, 2020
e42ca86
Updated but more failing tests
Happypig375 Jun 8, 2020
057e1da
Merge master
Happypig375 Jun 14, 2020
9d2e9ff
Include Visual Studio automatic updates
Happypig375 Jun 14, 2020
e22eb64
A lot less failing tests now
Happypig375 Jun 14, 2020
2b48411
Fix intervals with same boundaries
Happypig375 Jun 15, 2020
712a902
Update simplification of fractions
Happypig375 Jun 19, 2020
b85bf32
Update
Happypig375 Jun 24, 2020
4a99531
Update!
Happypig375 Jun 24, 2020
85f1cce
Merge master
Happypig375 Jul 2, 2020
c3175e1
Make buildable
Happypig375 Jul 2, 2020
3094269
Fix typo
Happypig375 Jul 2, 2020
e361a00
Update
Happypig375 Jul 8, 2020
b6a5a12
Update
Happypig375 Jul 8, 2020
bfa4bce
Update
Happypig375 Jul 17, 2020
d714390
Use = instead of ->
Happypig375 Jul 19, 2020
a81feee
Merge branch 'master' into AngouriUpdate
Happypig375 Jul 20, 2020
81f315e
Add a calculator to Avalonia Example
Happypig375 Jul 20, 2020
2d7e835
Merge branch 'master' into AngouriUpdate
Happypig375 Jul 28, 2020
5674705
Update
Happypig375 Jul 28, 2020
388dfd2
Preparing to remove AngouriMath submodule
Happypig375 Jul 28, 2020
402c507
Use AngouriMath package
Happypig375 Jul 28, 2020
b8a5ab0
Allow matrices in square brackets
Happypig375 Jul 28, 2020
9122671
Maybe not exponentiations for ordinary matrix environments
Happypig375 Jul 28, 2020
43ed05c
Simplify reference
Happypig375 Jul 28, 2020
78d8348
Resolve the new possible test into QuarticSolution
Happypig375 Jul 28, 2020
993cbbd
Fix blurry MathButtons & Update Avalonia to 0.10.0-preview2
Happypig375 Jul 29, 2020
632747c
Fix test
Happypig375 Jul 29, 2020
d8b5f6b
Fix test (actually)
Happypig375 Jul 29, 2020
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
1 change: 0 additions & 1 deletion .github/workflows/Test all projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
"CSharpMath.Rendering.Text.Tests"\
"CSharpMath.Xaml.Tests"\
"CSharpMath.Xaml.Tests.NuGet"\
"AngouriMath/Tests/UnitTests"\
"Typography/Typography.TextBreak/Typography.TextBreak.UnitTests"
do
dotnet add "$p" package Microsoft.NET.Test.Sdk # Update is required for GitHubActionsTestLogger to print anything
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "Wiki"]
path = CSharpMath.Wiki
url = https://github.com/verybadcat/CSharpMath.wiki.git
[submodule "AngouriMath"]
path = AngouriMath
url = https://github.com/asc-community/AngouriMath
1 change: 0 additions & 1 deletion AngouriMath
Submodule AngouriMath deleted from 4bfbd5
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="Avalonia.Desktop" Version="0.10.0-preview1" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.0-preview1" />
<ProjectReference Include="..\CSharpMath.Avalonia\CSharpMath.Avalonia.csproj" />
<ProjectReference Include="..\CSharpMath.Evaluation\CSharpMath.Evaluation.csproj" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions CSharpMath.Avalonia.Example/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<TabItem Header="MathButton">
<pages:MathButtonPage />
</TabItem>
<TabItem Header="Calculator">
<pages:CalculatorPage />
</TabItem>
</TabControl>

</DockPanel>
Expand Down
30 changes: 30 additions & 0 deletions CSharpMath.Avalonia.Example/Pages/CalculatorPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:csmath="clr-namespace:CSharpMath.Avalonia;assembly=CSharpMath.Avalonia"
xmlns:local="clr-namespace:CSharpMath.Avalonia.Example.Pages"
x:Class="CSharpMath.Avalonia.Example.Pages.CalculatorPage">

<ScrollViewer Margin="0, 8" HorizontalScrollBarVisibility="Auto">

<StackPanel Spacing="24">

<StackPanel Spacing="4">

<TextBlock Classes="h1"
Text="CSharpMath.Evaluation.Evaluate" />

<TextBlock Classes="h2"
Text="Evaluates a MathList that can be constructed from LaTeX" />

</StackPanel>

<TextBox Name="input" AcceptsReturn="True" TextWrapping="Wrap" Text="x^4+4x^3+16x^2+4x+1=y" />

<csmath:MathView LaTeX="{Binding #input.Text, Converter={x:Static local:CalculatorPageConverter.Singleton}}" />

</StackPanel>

</ScrollViewer>

</UserControl>
22 changes: 22 additions & 0 deletions CSharpMath.Avalonia.Example/Pages/CalculatorPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Globalization;
using Avalonia.Controls;
using Avalonia.Data.Converters;
using Avalonia.Markup.Xaml;

namespace CSharpMath.Avalonia.Example.Pages {
public class CalculatorPage : UserControl {
public CalculatorPage() => AvaloniaXamlLoader.Load(this);
}
class CalculatorPageConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
value is string latex
? Atom.LaTeXParser.MathListFromLaTeX(latex)
.Bind(list => Evaluation.Interpret(list))
.Match(success => success, error => latex)
: value;
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
throw new NotImplementedException();
public static CalculatorPageConverter Singleton { get; } = new CalculatorPageConverter();
}
}
1 change: 1 addition & 0 deletions CSharpMath.Avalonia/CSharpMath.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
<AvaloniaResource Include="**\*.xaml" />
<PackageReference Include="Avalonia" Version="0.10.0-preview1" />
<ProjectReference Include="..\CSharpMath.Evaluation\CSharpMath.Evaluation.csproj" />
<ProjectReference Include="..\CSharpMath.Rendering\CSharpMath.Rendering.csproj" />
</ItemGroup>

Expand Down
283 changes: 186 additions & 97 deletions CSharpMath.Evaluation.Tests/EvaluationTests.cs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions CSharpMath.Evaluation/CSharpMath.Evaluation.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CSharpMath.Editor\CSharpMath.Editor.csproj" />
<ProjectReference Include="..\AngouriMath\AngouriMath\AngouriMath.csproj" />
<ProjectReference Include="..\CSharpMath\CSharpMath.csproj" />
<PackageReference Include="AngouriMath" Version="1.1.0.3-beta" />
</ItemGroup>

</Project>
</Project>
159 changes: 89 additions & 70 deletions CSharpMath.Evaluation/Evaluation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace CSharpMath {
using Atom;
using Atoms = Atom.Atoms;
using Structures;

public static partial class Evaluation {
enum Precedence {
DefaultContext,
Expand Down Expand Up @@ -63,9 +64,9 @@ public sealed class Set : MathItem {
public override string Latexise() => Content.Latexise();
}
}
public static MathList Parse(MathItem entity) =>
public static MathList Visualize(MathItem entity) =>
LaTeXParser.MathListFromLaTeX(entity.Latexise())
// CSharpMath must handle all LaTeX coming from MathS or a bug is present!
// CSharpMath must handle all LaTeX coming from AngouriMath or a bug is present!
.Match(list => list, e => throw new InvalidCodePathException(e));
public static Result<MathItem> Evaluate(MathList mathList) {
MathS.pi.ToString(); // Call into MathS's static initializer to ensure Entity methods work
Expand Down Expand Up @@ -125,9 +126,17 @@ static Result<MathItem> ExpectNotNull(this Result<MathItem?> result, string item
static Result<MathItem> TryMakeSet(MathItem.Comma c, bool leftClosed, bool rightClosed) =>
c switch {
{ Content: var l, Next: { Content: var r, Next: null } } =>
l.AsEntity("left interval boundary")
.Bind(left => r.AsEntity("right interval boundary")
.Bind(right => (MathItem)new Set(MathS.Sets.Interval(left, right).SetLeftClosed(leftClosed, leftClosed).SetRightClosed(rightClosed, rightClosed)))),
l.AsEntity("left interval boundary")
.Bind(left => r.AsEntity("right interval boundary")
.Bind(right =>
(MathItem)(
left == right // MathS.Sets.Interval throws when both edges are equal
? leftClosed && rightClosed
? new Set(MathS.Sets.Element(left))
: MathS.Sets.Empty()
: new Set(MathS.Sets.Interval(left, right).SetLeftClosed(leftClosed).SetRightClosed(rightClosed))
)
)),
_ => "Unrecognized comma-delimited collection of " + c.Count() + " items"
};
static readonly Dictionary<Precedence, (string KnownOpening, string InferredClosing)> ContextInfo =
Expand Down Expand Up @@ -202,7 +211,7 @@ Result HandleSuperscript(ref MathItem? @this, MathList superscript) {
case Atoms.Placeholder _:
return "Placeholders should be filled";
case Atoms.Number n:
if (Number.TryParse(n.Nucleus, out var number)) {
if (AngouriMath.Core.Numerix.ComplexNumber.TryParse(n.Nucleus, out var number)) {
@this = new NumberEntity(number);
goto handleThis;
} else return "Invalid number: " + n.Nucleus;
Expand Down Expand Up @@ -239,7 +248,7 @@ _ when LaTeXSettings.CommandForAtom(atom) is string s => MathS.Var(s + subscript
v.Subscript.Clear();
goto handleThis;
case Atoms.Ordinary { Nucleus: "∞" }:
@this = new NumberEntity(MathS.Num(double.PositiveInfinity));
@this = new NumberEntity(AngouriMath.Core.Numerix.RealNumber.PositiveInfinity);
goto handleThis;
case Atoms.Ordinary { Nucleus: "∅" }:
@this = MathS.Sets.Empty();
Expand All @@ -261,56 +270,6 @@ _ when LaTeXSettings.CommandForAtom(atom) is string s => MathS.Var(s + subscript
if (error != null) return error;
@this = MathS.Pow(radicand, degree);
goto handleThis;
case Atoms.Open { Nucleus: var opening }:
if (!OpenBracketInfo.TryGetValue(opening, out var bracketInfo))
return "Unsupported opening bracket " + opening;
i++;
(@this, error) = Transform(mathList, ref i, bracketInfo.KnownPrecedence);
if (error != null) return error;
if (@this == null) return "Missing " + bracketInfo.InferredClosing;
goto handleThis;
case Atoms.Close { Nucleus: var rightBracket, Superscript: var super, Subscript: var sub }:
if (sub.Count > 0) return "Subscripts are unsupported for Close " + rightBracket;
if (!ContextInfo.TryGetValue(prec, out var contextInfo))
switch (prec) {
case Precedence.DefaultContext:
string leftBracket;
switch (rightBracket) {
case ")":
leftBracket = "(";
break;
case "]":
leftBracket = "[";
break;
case "}":
leftBracket = "{";
break;
default:
return "Unsupported closing bracket " + rightBracket;
}
return "Missing " + leftBracket;
default:
i--;
return prev;
}
return
BracketHandlers.TryGetValue((contextInfo.KnownOpening, rightBracket), out var handler)
? handler(prev).Bind(handled => {
MathItem? nullable = handled;
if (HandleSuperscript(ref nullable, super).Error is { } error)
return Result.Err(error);
return Result.Ok(nullable);
})
: $"Unrecognized bracket pair {contextInfo.KnownOpening} {rightBracket}";
case Atoms.Inner { LeftBoundary: { Nucleus: var left }, InnerList: var inner, RightBoundary: { Nucleus: var right } }:
(@this, error) = Transform(inner);
if (error != null) return error;
(@this, error) =
BracketHandlers.TryGetValue((left, right), out handler)
? handler(@this)
: $"Unrecognized bracket pair {left ?? "(empty)"} {right ?? "(empty)"}";
if (error != null) return error;
goto handleThis;
case Atoms.UnaryOperator { Nucleus: "+" }:
handlePrecendence = Precedence.UnaryPlusMinus;
handlePrefix = e => +e;
Expand Down Expand Up @@ -370,10 +329,10 @@ _ when LaTeXSettings.CommandForAtom(atom) is string s => MathS.Var(s + subscript
case Atoms.LargeOperator { Nucleus: "log", Subscript: var @base }:
Entity? logBase;
(logBase, error) = Transform(@base).ExpectEntityOrNull(nameof(logBase));
@base.Clear();
if (error != null) return error;
@base.Clear();
logBase ??= new NumberEntity(10);
handleFunction = arg => MathS.Log(arg, logBase);
handleFunction = arg => MathS.Log(logBase, arg);
handleFunctionInverse = arg => MathS.Pow(logBase, arg);
goto handleFunction;
case Atoms.LargeOperator { Nucleus: "ln" }:
Expand Down Expand Up @@ -407,17 +366,6 @@ _ when LaTeXSettings.CommandForAtom(atom) is string s => MathS.Var(s + subscript
handlePrecendence = Precedence.PercentDegree;
handlePostfix = x => x * MathS.pi / 180;
goto handlePostfix;
case Atoms.Table { Environment:"matrix", NRows:var rows, NColumns:var cols, Cells:var cells }:
var matrixElements = new Entity[rows * cols];
for (var row = 0; row < rows; row++)
for (var col = 0; col < cols; col++) {
if (cells[row].Count <= col)
return $"There are empty slots in the {rows}×{cols} matrix";
(matrixElements[row * cols + col], error) = Transform(cells[row][col]).ExpectEntity("matrix element");
if (error != null) return error;
}
@this = MathS.Matrices.Matrix(rows, cols, matrixElements);
goto handleThis;
case Atoms.Punctuation { Nucleus: "," }:
if (prec <= Precedence.Comma) {
if (prev is null) return "Missing left operand for comma";
Expand All @@ -444,8 +392,67 @@ _ when LaTeXSettings.CommandForAtom(atom) is string s => MathS.Var(s + subscript
handlePrecendence = Precedence.SetOperation;
handleBinarySet = (l, r) => l - r;
goto handleBinarySet;
// Until C# allows declaring variables under "or pattern"s...
case Atoms.Inner { LeftBoundary:{ Nucleus:"[" }, InnerList:{ Count:1 } inner, RightBoundary:{ Nucleus:"]" } }
when inner[0] is Atoms.Table { Environment: "matrix" } table:
var matrix = table;
goto handleMatrix;
case Atoms.Table { Environment: "matrix" } table:
matrix = table;
goto handleMatrix;
case Atoms.Open { Nucleus: var opening }:
if (!OpenBracketInfo.TryGetValue(opening, out var bracketInfo))
return "Unsupported opening bracket " + opening;
i++;
(@this, error) = Transform(mathList, ref i, bracketInfo.KnownPrecedence);
if (error != null) return error;
if (@this == null) return "Missing " + bracketInfo.InferredClosing;
goto handleThis;
case Atoms.Close { Nucleus: var rightBracket, Superscript: var super, Subscript: var sub }:
if (sub.Count > 0) return "Subscripts are unsupported for Close " + rightBracket;
if (!ContextInfo.TryGetValue(prec, out var contextInfo))
switch (prec) {
case Precedence.DefaultContext:
string leftBracket;
switch (rightBracket) {
case ")":
leftBracket = "(";
break;
case "]":
leftBracket = "[";
break;
case "}":
leftBracket = "{";
break;
default:
return "Unsupported closing bracket " + rightBracket;
}
return "Missing " + leftBracket;
default:
i--;
return prev;
}
return
BracketHandlers.TryGetValue((contextInfo.KnownOpening, rightBracket), out var handler)
? handler(prev).Bind(handled => {
MathItem? nullable = handled;
if (HandleSuperscript(ref nullable, super).Error is { } error)
return Result.Err(error);
return Result.Ok(nullable);
})
: $"Unrecognized bracket pair {contextInfo.KnownOpening} {rightBracket}";
case Atoms.Inner { LeftBoundary: { Nucleus: var left }, InnerList: var inner, RightBoundary: { Nucleus: var right } }:
(@this, error) = Transform(inner);
if (error != null) return error;
(@this, error) =
BracketHandlers.TryGetValue((left, right), out handler)
? handler(@this)
: $"Unrecognized bracket pair {left ?? "(empty)"} {right ?? "(empty)"}";
if (error != null) return error;
goto handleThis;
case Atoms.Space _:
case Atoms.Style _:
case Atoms.Comment _:
case Atoms.Ordinary { Nucleus: var nucleus } when string.IsNullOrWhiteSpace(nucleus):
if (atom.Superscript.Count > 0)
return $"Exponentiation is unsupported for {atom.TypeName}";
Expand All @@ -457,6 +464,18 @@ _ when LaTeXSettings.CommandForAtom(atom) is string s => MathS.Var(s + subscript
default:
return $"Unsupported {atom.TypeName} {atom.Nucleus}";

handleMatrix:
var (rows, cols, cells) = (matrix.NRows, matrix.NColumns, matrix.Cells);
var matrixElements = new Entity[rows * cols];
for (var row = 0; row < rows; row++)
for (var col = 0; col < cols; col++) {
if (cells[row].Count <= col)
return $"There are empty slots in the {rows}×{cols} matrix";
(matrixElements[row * cols + col], error) = Transform(cells[row][col]).ExpectEntity("matrix element");
if (error != null) return error;
}
@this = MathS.Matrices.Matrix(rows, cols, matrixElements);
goto handleThis;
#pragma warning disable CS0162 // Unreachable code detected
#pragma warning disable CS0164 // This label has not been referenced
handleFunction:
Expand Down
Loading