AngouriMath
AngouriMath.Core
Classes within the AngouriMath.Core namespace
AddressableRulesAttribute
Summary
Marks a rewrite ruleswitch whose arms are to be generated as individually
addressable RewriteRule values, in a field named after the
method withArms appended.
Remarks
The method must be expression-bodied with a body of the formparameter switch { ... } ;
anything else is a build error rather than an empty list, since a rule set that silently
has no rules reads exactly like one that has been checked.
ApproachFrom
Summary
Where to tend to the given number in limits
Binding
Summary
The name a binder is handed, and what that name means inside it.
Remarks
Two kinds of name need reading rather than taking as they arrive, and they arrive from
opposite directions.i is the imaginary unit and that is decided in the lexer —
NUMBER: ... | 'i' — so it never reaches the rule that makes variables and is a
number in the name position.e andpi are Constants,
which are Variables by inheritance and separate objects by identity, so the
name position holds a constant and what is bound must be the variable of that name.
Either way the answer is the same: the binder decides what its name means, once, here.
#976,
#984Naming i as the bound name says something about the whole binder, so it is
honoured throughout it — through the summand and the bounds, not only in the name
position. Doing it in the name position alone would be worse than not doing it at all:
the index would become a variable while everyi beside it stayed the imaginary
unit, nothing would substitute, andsum(i, i, 1, 10) would answer10i instead of 55 — a wrong answer in place of an unevaluated one.
Only inside the binder that declares it. sum(i * k, k, 1, 3) is6i , and the
i outside the sum insum(i, i, 1, 3) + i is still the imaginary unit.
This is a struct holding two fields and it is the whole cost of the
feature where nothing is shadowed: Of(AngouriMath.Entity) is two type tests that both
fail, and In(AngouriMath.Entity) hands the expression straight back without walking it.
ConcurrentFieldAttribute
Summary
Use this attribute on those static fields that are already synchronized
internally or explicitly
ConstantFieldAttribute
Summary
Use this attribute on those static fields that do not require thread static attribute
because they are constant
CostModel
Summary
What "simpler" means, as a named value rather than as an anonymous function.
Remarks
ComplexityCriteria has always accepted any
Func`2, so the cost of an expression was already the caller's
to choose. What it could not do is be named: two callers wanting "the smallest tree"
each wrote the same lambda, neither could say which one they used, and nothing could list
what the alternatives are. #746 v2.0 asks for a cost model that is data for exactly that reason, and names the examples —
smallest tree, fewest radicals — that All now holds.
A model counts one of two things, and which one decides what it may read.SmallestTree and Default count how the expression is
written:y ^ (1 * (-1)) * x really is a bigger tree thanx / y , so
reading the node as written is not an approximation, it is the question. The others count a
mathematical feature — is there a division here, is there a radical — which is a
property of the value and not of the spelling, so they ask what an exponent
Evaled to rather than what it was typed as.
The distinction is worth stating because getting it wrong is silent and backwards:
FewestDivisions used to test the exponent's node, so
y ^ (1 * (-1)) * x — a division written where the test could not see it — scored
cheaper thanx / y , under the one criterion whose whole job is to remove
divisions. That is
#950. A caller
writing their own model wants to decide which of the two kinds it is, because nothing
here can decide it for them: an expression handed to a cost model has not necessarily been
evaluated, and on an e-graph — where every writing of a value is a member of one class at
once — it certainly has not.
Every model here counts nodes a little, even the ones that are about something else. A criterion that counts only its own feature ties constantly, and a tie is settled by
whichever candidate the search happened to generate first — which is an accident rather
than a preference. The node term is small enough not to overturn the feature it is added to
and large enough to decide between candidates the feature cannot separate.
Example
using var _ = MathS.Settings.ComplexityCriteria.Set(CostModel.FewestDivisions.Cost); Console.WriteLine("a / b + b / c".ToEntity().Simplify()); // (a * c + b ^ 2) / (b * c)Parameter "Name"
A short name, so a report can say which model produced an answer.Parameter "Description"
What this model prefers, in a sentence.Parameter "Cost"
Domain
Summary
Remarks
A member of this enum is a constraint on a node, not a mathematical object. Seven of
them also name a set — Create(AngouriMath.Core.Domain) maps those seven
toBB ,ZZ+ ,ZZ* ,ZZ ,QQ ,RR andCC — and Any does not,
because "no constraint" is not a collection of values. Sets are
Sets and are reasoned about with membership, union and difference;
a domain is not, and the two are deliberately different types.
The members are ordered from narrowest to widest and are compared as such — evaluation
asksCodomain < Domain.Complex to mean "narrower than the complex plane", and
DomainConditionIn(AngouriMath.Core.Domain) narrows a node whose codomain is
wider than the reading it is asked in. Any is the top of that order,
which is what makes it the identity for narrowing rather than a set of everything.
Distinct from Codomain, which is the ambient reading a
question is asked in and applies to nodes that do not constrain themselves. A node's own
codomain says what that node is declared over; the ambient one says what the library
should take an unconstrained node to be.
DomainsFunctional
EquationSystem
Summary
A class for systems of equations. Is not part of AM's ecosystem,
that is, it is not an Entity, just an intermediate class.
It is a system of arbitrary equations, not only those linear. However,
it is not a system of Statements.
FastExpression
Summary
Compiled function (not to a delegate, but to AM's VM readable format)
FiniteSetBuilder
Summary
Use this class for solvers and other places when a set needs to be built
and you want to avoid using lists. It builds an instance of FiniteSet.
IBinaryNode
Summary
From this interface all double-argument nodes are inherited
ILatexizeable
Summary
Any class that supports converting to LaTeX format should implement this interface
Example
using System; using AngouriMath; using static AngouriMath.MathS; Entity expr = "sqrt(a) + integral(sin(x), x)"; Console.WriteLine(expr); Console.WriteLine(expr.Latexize()); Entity expr2 = "a / b ^ limit(sin(x) - cosh(y), x, +oo)"; Console.WriteLine(expr2); Console.WriteLine(expr2.Latexize());
Prints
sqrt(a) + integral(sin(x), x) \sqrt{a}+\int \left[\sin\left(x\right)\right] dx a / b ^ limit(sin(x) - (e ^ y + e ^ (-y)) / 2, x, +oo) \frac{a}{{b}^{\lim_{x\to \infty } \left[\sin\left(x\right)-\frac{{e}^{y}+{e}^{-y}}{2}\right]}}IUnaryNode
Summary
From this interface all single-argument nodes are inherited
MatrixBuilder
Summary
Use this class for solvers and other places when a matrix needs to be built without
recreating an instance multiple times. It builds an instance of Matrix.
It enables to build a tensor row-by-row.
Example
using System; using AngouriMath; using AngouriMath.Core; var mb = new MatrixBuilder(3); Console.WriteLine(mb.ToMatrix() is null); Console.WriteLine("-------------------------"); mb.Add(new Entity[] { 1, 2, 3 } ); mb.Add(new Entity[] { "x", "sqrt(y)", 5 } ); Console.WriteLine(mb.ToMatrix().ToString(multilineFormat: true)); Console.WriteLine("-------------------------"); mb.Add(new Entity[] { 1 } ); // throws
Prints
True ------------------------- Matrix[2 x 3] 1 2 3 x sqrt(y) 5 ------------------------- Unhandled exception. AngouriMath.Core.Exceptions.InvalidMatrixOperationException: Incorrect usage of MatrixBuilderParser
PatternOperator
Summary
The pattern operator,... (or… ): between shown terms it names the
progression the shown terms determine, and the term after it names where the
progression stops.{1, 2, ..., n} is the integers from 1 ton ,
{2, 4, ..., 2 n} the even ones,{5, 10, 15, ...} every positive multiple of
five,{..., -1, 0} the non-positive integers;1 + 2 + ... + n is
sum(k, k, 1, n) and1 * 2 * ... * n isproduct(k, k, 1, n) .
Remarks
What is read, and what is refused. An arithmetic progression of whole numbers,
from at least two shown terms on one side of the dots: the step is the difference of the
first two, and every further shown term has to be on the progression, or the input is
refused with the term that is not. Three shown terms with no step in common,
{1, 4, 9, ...} , are a guess about the writer's rule and are refused rather than
answered with the smallest polynomial through them. A progression of anything but whole
numbers,{1/2, 1, 3/2, ..., n} , is refused too: a set of those is the image of a
range, which has no node yet.
What is built. Nothing new: a set is ZZ /\ [a; z] for step one and a residue
class cut by the interval,{ x in ZZ : x = a (mod d) } /\ [a; z] , otherwise -- both
list their members when the ends are numbers, and stay written over a symbolic end; a
one-sided pattern is the class cut by a ray. A sum issum(a + d k, k, 0, (z - a)/d) and a product the same underproduct , with the index namedk , ork_1 where the terms mentionk . The general term with an index shown,a_1 + ... + a_n ,
and the list of names of symbolic length,f(x_1, ..., x_n) , are the larger half of
#1437 and wait for
v3's design of a family of names.
Priority
ReasonOfFailureWhileParsing
Summary
Nesting class for reasons of why parsing could fail. The type union for it
is
Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 4405 pages online