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
8 changes: 4 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ printed with `if` came back as a product with `if` read as an undeclared variabl
usual notation is not in the grammar, print the function call the parser does have.
`StringizeRoundTripTest` is where that is enforced; add to it when you add a node.

**`Latexise` has a round trip too, and it is enforced in someone else's repository.**
**`Latexize` has a round trip too, and it is enforced in someone else's repository.**
[CSharpMath.Evaluation](https://github.com/verybadcat/CSharpMath/blob/master/CSharpMath.Evaluation/Evaluation.cs)
reads LaTeX back into an `Entity`, and says so in its own source: *"CSharpMath must handle all LaTeX
coming from AngouriMath or a bug is present!"* So a change to what `Latexise` emits — a new node, a
coming from AngouriMath or a bug is present!"* So a change to what `Latexize` emits — a new node, a
different command, a changed bracketing — can break a downstream project, and no test here will say
so.

That is weaker than `Stringize`'s contract, not stronger. `StringizeRoundTripTest` fails in this
repository the moment the printed form stops parsing; the LaTeX contract fails as a bug report from
someone else, months later. When you change `Latexise` output, check it against CSharpMath and open
someone else, months later. When you change `Latexize` output, check it against CSharpMath and open
a PR there as well ([#822](https://github.com/asc-community/AngouriMath/issues/822)).

The syntax the parser accepts is written down in
Expand Down Expand Up @@ -217,7 +217,7 @@ the *basis* is, and it is made differently on purpose:

| | basis | why |
|---|---|---|
| quantum | `Entity`-backed | the state is then an ordinary expression, so `Simplify`, `Substitute`, `Latexise` and the rest work on it without anything being taught about quantum |
| quantum | `Entity`-backed | the state is then an ordinary expression, so `Simplify`, `Substitute`, `Latexize` and the rest work on it without anything being taught about quantum |
| polynomials, series | a generic `TBasis` struct | exponent vectors never enter the expression tree, and the internal layers stay allocation-free and type-safe |

One generic spine, instantiated twice. That is less tidy than picking a single answer, and the
Expand Down
42 changes: 41 additions & 1 deletion BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ read first.
| loud | `floor(x)`, `ceil(x)`, `ceiling(x)` | `UnrecognizedFunctionParseException` | the functions |
| loud | `round(x)`, `min(a, b)`, `max(a, b)`, `gcd(a, b)` | `UnrecognizedFunctionParseException` | the functions |
| loud | 28 members deprecated since 1.x | obsolete but present | removed |
| loud | `Latexise`, `ILatexiseable`, `entity_latexise` | the British spelling | `Latexize`, `ILatexizeable`, `entity_latexize` |
| loud | the target frameworks | `net7.0;netstandard2.0` | `netstandard2.0;net8.0;net10.0` |
| **silent** | `abs(x) = c` for a negative `c` | a set of non-solutions | the empty set |

Expand Down Expand Up @@ -118,6 +119,42 @@ right answer. Code written against the old names was wrong in the same way.
[#632](https://github.com/asc-community/AngouriMath/issues/632), PR
[#664](https://github.com/asc-community/AngouriMath/pull/664).

### `Latexise` is now `Latexize`

The library serialises a node to text two ways, and spelled them in two languages:

| | was | is |
|---|---|---|
| the method | `Latexise()` | `Latexize()` |
| the interface | `ILatexiseable` | `ILatexizeable` |
| the string extension | `"x + 1".Latexise()` | `"x + 1".Latexize()` |
| the C# helper | `MathS.Latex(ILatexiseable)` | `MathS.Latex(ILatexizeable)` |
| the native entry point | `entity_latexise` | `entity_latexize` |
| the C++ method | `Entity::Latexise()` | `Entity::Latexize()` |
| the F# function | `latexise` | `latexize` |

Everything else in the public surface is `-ize` — `Stringize`, `Factorize`, `Serialize`,
`Deserialize` — so `Latexise` and its interface were the only members a caller had to remember the
other spelling for. `Stringize` and `Latexise` do the same kind of thing and sit next to each other
in every file that has either, which is what made the split spelling costly rather than merely
untidy.

**What breaks.** Every call, every override, and every implementation of the interface. There is no
forwarding member: this release is the one that removed 28 members that accumulated as forwarders,
so adding a permanent one here would undo that on the same day. The compiler reports each site, and
the fix is mechanical.

`MathS.Quantum.Factorise` keeps its spelling for now. Renaming it to `Factorize` would give the
library two public `Factorize` methods doing unrelated things — expression factoring on `Entity`,
tensor factorisation on a quantum state — which is a worse outcome than the inconsistency. It wants
a distinguishing name rather than a spelling change, and that is not decided here.

**Downstream.** [`CSharpMath.Evaluation`](https://github.com/verybadcat/CSharpMath) reads LaTeX
produced here back into an `Entity` and calls this method. It is unaffected until it moves to 2.0,
at which point it needs the new name.

[#840](https://github.com/asc-community/AngouriMath/issues/840).

---

## Parsing
Expand Down Expand Up @@ -312,7 +349,10 @@ This one is worth reading twice if you parse printed output, because the misread
ordinary number: every root of a trigonometric equation prints through this path, and
`cos(x)^2 + sin(x) = 0` returns roots that are exact as entities and were not as text.

`Latexise` is under no such obligation, since nothing parses LaTeX, and is unaffected.
`Latexize` is unaffected by this change. Its output is under a weaker obligation, not none:
nothing in this repository parses LaTeX back, but [`CSharpMath.Evaluation`](https://github.com/verybadcat/CSharpMath)
does, so a change to what it emits can break a downstream project with no test here to say so
([#822](https://github.com/asc-community/AngouriMath/issues/822)).

The syntax the parser accepts is now written down in
[`Sources/AngouriMath/Docs/Usage/Syntax.md`](Sources/AngouriMath/Docs/Usage/Syntax.md).
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Console.WriteLine("x^2 + x + a".SolveEquation("x"));
Under developing now and forever (always available)
```cs
Entity expr = "(sin(x)^2 - sin(x) + a)(b - x)((-3) * x + 2 + 3 * x ^ 2 + (x + (-3)) * x ^ 3)";
Console.WriteLine(expr.SolveEquation("x").Latexise());
Console.WriteLine(expr.SolveEquation("x").Latexize());
```
<img src="https://render.githubusercontent.com/render/math?math=\left\{-\left(-\arcsin\left(\frac{1-\sqrt{1-4\times a}}{2}\right)-2\times \pi\times n_{1}\right),-\left(-\pi--\arcsin\left(\frac{1-\sqrt{1-4\times a}}{2}\right)-2\times \pi\times n_{1}\right),-\left(-\arcsin\left(\frac{1%2B\sqrt{1-4\times a}}{2}\right)-2\times \pi\times n_{1}\right),-\left(-\pi--\arcsin\left(\frac{1%2B\sqrt{1-4\times a}}{2}\right)-2\times \pi\times n_{1}\right),\frac{-b}{-1},-i,i,1,2\right\}">

Expand Down Expand Up @@ -297,7 +297,7 @@ var system = MathS.Equations(
"cos(x2 + 1)^2 + 3y",
"y * (-1) + 4cos(x2 + 1)"
);
Console.WriteLine(system.Latexise());
Console.WriteLine(system.Latexize());
var solutions = system.Solve("x", "y");
Console.WriteLine(solutions);
```
Expand Down Expand Up @@ -334,10 +334,10 @@ WriteLine("x^2 + a x".Integrate("x").InnerSimplified);

There are four types of sets:
```cs
WriteLine("{ 1, 2 }".Latexise());
WriteLine("[3; +oo)".Latexise());
WriteLine("RR".Latexise());
WriteLine("{ x : x^8 + a x < 0 }".Latexise());
WriteLine("{ 1, 2 }".Latexize());
WriteLine("[3; +oo)".Latexize());
WriteLine("RR".Latexize());
WriteLine("{ x : x^8 + a x < 0 }".Latexize());
```

<img src="https://render.githubusercontent.com/render/math?math=\left\{ 1, 2 \right\}">
Expand All @@ -347,9 +347,9 @@ WriteLine("{ x : x^8 + a x < 0 }".Latexise());

And there operators:
```cs
WriteLine(@"A \/ B".Latexise());
WriteLine(@"A /\ B".Latexise());
WriteLine(@"A \ B".Latexise());
WriteLine(@"A \/ B".Latexize());
WriteLine(@"A /\ B".Latexize());
WriteLine(@"A \ B".Latexize());
```

<img src="https://render.githubusercontent.com/render/math?math=A\cup B">
Expand All @@ -363,7 +363,7 @@ WriteLine(@"A \ B".Latexise());
You can build LaTeX with AngouriMath:
```cs
var expr = "x ^ y + sqrt(x) + integral(sqrt(x) / a, x, 1) + derive(sqrt(x) / a, x, 1) + limit(sqrt(x) / a, x, +oo)";
Console.WriteLine(expr.Latexise());
Console.WriteLine(expr.Latexize());
>>> {x}^{y}+\sqrt{x}+\int \left[\frac{\sqrt{x}}{a}\right] dx+\frac{d\left[\frac{\sqrt{x}}{a}\right]}{dx}+\lim_{x\to \infty } \left[\frac{\sqrt{x}}{a}\right]
```
<img src="https://render.githubusercontent.com/render/math?math={x}^{y}%2B\sqrt{x}%2B\int\left[\frac{\sqrt{x}}{a}\right]dx%2B\frac{d\left[\frac{\sqrt{x}}{a}\right]}{dx}%2B\lim_{x\to\infty}\left[\frac{\sqrt{x}}{a}\right]">
Expand Down
2 changes: 1 addition & 1 deletion Sources/AngouriMath/Convenience/AngouriMathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public static Complex ToNumber(this NumericsComplex complex)
/// Builds a LaTeX code from an expression
/// </summary>
/// <returns>A <see cref="string"/> which can be rendered into pretty output</returns>
public static string Latexise(this string str) => str.ToEntity().Latexise();
public static string Latexize(this string str) => str.ToEntity().Latexize();

/// <summary>
/// Compiles an expression into a special compiled code that runs via
Expand Down
14 changes: 7 additions & 7 deletions Sources/AngouriMath/Convenience/MathS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3162,7 +3162,7 @@ public static IEnumerable<Entity> TaylorTerms(Entity expr, params (Variable expr
/// var inCyrillic = Var("Абаваола");
/// </code>
/// Underscore "_" allows indexing. Greek letter names (e. g.
/// "alpha") will be latexised as Greek letter (but other than that,
/// "alpha") will be latexized as Greek letter (but other than that,
/// will appear as "alpha" in other places).
/// </example>
public static Variable Var(string name) => name;
Expand All @@ -3184,7 +3184,7 @@ public static IEnumerable<Entity> TaylorTerms(Entity expr, params (Variable expr
/// var inCyrillic = Var("Абаваола");
/// </code>
/// Underscore "_" allows indexing. Greek letter names (e. g.
/// "alpha") will be latexised as Greek letter (but other than that,
/// "alpha") will be latexized as Greek letter (but other than that,
/// will appear as "alpha" in other places).
/// </example>
public static (Variable, Variable) Var(string name1, string name2) => (Var(name1), Var(name2));
Expand All @@ -3206,7 +3206,7 @@ public static IEnumerable<Entity> TaylorTerms(Entity expr, params (Variable expr
/// var inCyrillic = Var("Абаваола");
/// </code>
/// Underscore "_" allows indexing. Greek letter names (e. g.
/// "alpha") will be latexised as Greek letter (but other than that,
/// "alpha") will be latexized as Greek letter (but other than that,
/// will appear as "alpha" in other places).
/// </example>
public static (Variable, Variable, Variable) Var(string name1, string name2, string name3)
Expand All @@ -3231,7 +3231,7 @@ public static (Variable, Variable, Variable) Var(string name1, string name2, str
/// var inCyrillic = Var("Абаваола");
/// </code>
/// Underscore "_" allows indexing. Greek letter names (e. g.
/// "alpha") will be latexised as Greek letter (but other than that,
/// "alpha") will be latexized as Greek letter (but other than that,
/// will appear as "alpha" in other places).
/// </example>
public static (Variable, Variable, Variable, Variable) Var(string name1, string name2, string name3, string name4)
Expand All @@ -3256,7 +3256,7 @@ public static (Variable, Variable, Variable, Variable) Var(string name1, string
/// var inCyrillic = Var("Абаваола");
/// </code>
/// Underscore "_" allows indexing. Greek letter names (e. g.
/// "alpha") will be latexised as Greek letter (but other than that,
/// "alpha") will be latexized as Greek letter (but other than that,
/// will appear as "alpha" in other places).
/// </example>
public static (Variable, Variable, Variable, Variable, Variable) Var(string name1, string name2, string name3, string name4, string name5)
Expand Down Expand Up @@ -3984,7 +3984,7 @@ public static ParsingResult Parse(string source)
/// <returns>
/// The <a href="https://en.wikipedia.org/wiki/LaTeX">LaTeX</a> representation of the argument
/// </returns>
/// <param name="latexiseable">
/// <param name="latexizeable">
/// Any element (<see cref="Entity"/>, <see cref="Set"/>, etc.) that can be represented in LaTeX
/// </param>
/// <example>
Expand All @@ -4008,7 +4008,7 @@ public static ParsingResult Parse(string source)
/// \frac{a}{{b}^{\lim_{x\to \infty } \left[\sin\left(x\right)-\frac{{e}^{y}+{e}^{-y}}{2}\right]}}
/// </code>
/// </example>
public static string Latex(ILatexiseable latexiseable) => latexiseable.Latexise();
public static string Latex(ILatexizeable latexizeable) => latexizeable.Latexize();

/// <summary>
/// <para>All operations for <see cref="Number"/> and its derived classes are available from here.</para>
Expand Down
10 changes: 5 additions & 5 deletions Sources/AngouriMath/Core/Entity/Entity.Definition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ internal enum Priority
///
/// Entity expr = "sqrt(a) + integral(sin(x), x)";
/// Console.WriteLine(expr);
/// Console.WriteLine(expr.Latexise());
/// Console.WriteLine(expr.Latexize());
/// Entity expr2 = "a / b ^ limit(sin(x) - cosh(y), x, +oo)";
/// Console.WriteLine(expr2);
/// Console.WriteLine(expr2.Latexise());
/// Console.WriteLine(expr2.Latexize());
/// </code>
/// Prints
/// <code>
Expand All @@ -83,13 +83,13 @@ internal enum Priority
/// \frac{a}{{b}^{\lim_{x\to \infty } \left[\sin\left(x\right)-\frac{{e}^{y}+{e}^{-y}}{2}\right]}}
/// </code>
/// </example>
public interface ILatexiseable
public interface ILatexizeable
{
/// <summary>
/// Converts the object to the LaTeX format
/// That is, a string that can be later displayed and rendered as LaTeX
/// </summary>
public string Latexise();
public string Latexize();
}
}

Expand All @@ -101,7 +101,7 @@ namespace AngouriMath
/// Every node, expression, or number is an <see cref="Entity"/>.
/// However, you cannot create an instance of this class, look for the nested classes instead.
/// </summary>
public abstract partial record Entity : ILatexiseable
public abstract partial record Entity : ILatexizeable
{
/// <summary>
/// Returns the array of the direct children. Will be
Expand Down
14 changes: 7 additions & 7 deletions Sources/AngouriMath/Core/EquationSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ namespace AngouriMath.Core
/// It is a system of arbitrary equations, not only those linear. However,
/// it is not a system of <see cref="Statement"/>s.
/// </summary>
public sealed class EquationSystem : ILatexiseable
public sealed class EquationSystem : ILatexizeable
{
private readonly IEnumerable<Entity> equations;

/// <summary>
/// The equations you pass should not have an <see cref="MathS.Equality"/> node.
/// After having created a system of equations, you may solve or latexise it.
/// After having created a system of equations, you may solve or latexize it.
/// </summary>
/// <param name="equations">
/// Any <see cref="IEnumerable{T}"/> parameter, such as <see cref="List{T}"/> or <see cref="System.Array"/>.
Expand All @@ -40,7 +40,7 @@ public sealed class EquationSystem : ILatexiseable

/// <summary>
/// The equations you pass should not have an <see cref="MathS.Equality"/> node.
/// After having created a system of equations, you may solve or latexise it.
/// After having created a system of equations, you may solve or latexize it.
/// </summary>
/// <param name="equations">
/// An <see cref="System.Array"/>
Expand Down Expand Up @@ -73,19 +73,19 @@ public sealed class EquationSystem : ILatexiseable
public Matrix? Solve(params Variable[] vars) => EquationSolver.SolveSystem(equations, vars);

/// <returns>
/// Latexised version of the system. It adds
/// Latexized version of the system. It adds
/// zero equality to all the provided expressions
/// </returns>
public string Latexise()
public string Latexize()
{
using var enumerator = equations.GetEnumerator();
if (!enumerator.MoveNext())
return string.Empty;
var firstEquation = enumerator.Current.Latexise() + " = 0";
var firstEquation = enumerator.Current.Latexize() + " = 0";
if (!enumerator.MoveNext())
return firstEquation;
var sb = new StringBuilder(@"\begin{cases}").Append(firstEquation);
do sb.Append(@"\\").Append(enumerator.Current.Latexise()).Append(" = 0");
do sb.Append(@"\\").Append(enumerator.Current.Latexize()).Append(" = 0");
while (enumerator.MoveNext());
sb.Append(@"\end{cases}");
return sb.ToString();
Expand Down
2 changes: 1 addition & 1 deletion Sources/AngouriMath/Docs/Contributing/AddingNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/// 3. A few essential methods
/// a. InnerEval and InnerSimplify (<see cref="AngouriMath.Entity.Sinf.InnerEval"/> for numerical and <see cref="AngouriMath.Entity.Andf.InnerEval"/> for boolean)
/// b. Stringize (<see cref="AngouriMath.Entity.Sinf.Stringize"/>) (and tests to CircleTest.cs)
/// c. Latexise (<see cref="AngouriMath.Entity.Sinf.Latexise"/>) (and tests to LatexTest.cs)
/// c. Latexize (<see cref="AngouriMath.Entity.Sinf.Latexize"/>) (and tests to LatexTest.cs)
/// d. Limit computation (<see cref="AngouriMath.Entity.Sinf.ComputeLimitDivideEtImpera"/>) (and tests to LimitTest.cs)
/// e. Hash for sorting (<see cref="AngouriMath.Entity.Sinf.SortHashName"/>)
/// f. Default domain <see cref="AngouriMath.Entity.Sinf.Codomain"/>
Expand Down
2 changes: 1 addition & 1 deletion Sources/AngouriMath/Docs/Usage/Syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ form would silently come back as something else.
**LaTeX output has a round trip too, and it is checked in someone else's repository.**
[CSharpMath.Evaluation](https://github.com/verybadcat/CSharpMath/blob/master/CSharpMath.Evaluation/Evaluation.cs)
reads LaTeX back into an `Entity` and says so in its own source — *"CSharpMath must handle all
LaTeX coming from AngouriMath or a bug is present!"* — so `Latexise` is free to use `\frac`,
LaTeX coming from AngouriMath or a bug is present!"* — so `Latexize` is free to use `\frac`,
`\bmod` and the rest, but changing what it emits can break a downstream project and no test here
will say so ([#822](https://github.com/asc-community/AngouriMath/issues/822)).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace AngouriMath
{
partial record Entity : ILatexiseable
partial record Entity : ILatexizeable
{
/// <summary>
/// Attempt to find analytical roots of a custom equation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace AngouriMath
{
partial record Entity : ILatexiseable
partial record Entity : ILatexizeable
{
partial record Number
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace AngouriMath
{
partial record Entity : ILatexiseable
partial record Entity : ILatexizeable
{
/// <summary><para>This <see cref="Entity"/> MUST contain exactly ONE occurance of <paramref name="x"/>,
/// otherwise this function won't work correctly.</para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static bool Satisfies(Entity expr, Entity.Variable v, Complex root)

namespace AngouriMath
{
partial record Entity : ILatexiseable
partial record Entity : ILatexizeable
{
/// <summary>
/// Searches for numerical solutions via Newton's method
Expand Down
Loading
Loading