The algebra tactic #
A suite of three tactics for solving equations in commutative algebras over commutative (semi)rings, where the exponents can also contain variables.
Based largely on the implementation of ring. The algebra normal form mirrors that of ring
except that the constants are expressions in the base ring that are kept in ring normal form.
Organization #
This tactic is implemented using the machinery of Ring.Common
- Normalized expressions are stored as an
Common.ExSum, with a custom type for representing coefficients inR. - While
ringstores coefficients as rational numbers normalized bynorm_num,algebrastores coefficients as experssions in the base ringR, normalized byring. - These coefficients are sums, not products. The normal form of
a • x + b • xis(a + b) • x.
This tactic is used internally to implement the polynomial tactic.
Limitations #
The main limitation of the current implementation is that it does not handle rational constants
when the algebra A is a field but the base ring R is not. This is never an issue when working
with polynomials, but would be an issue when working with a number field over its ring of integers.
When inferring the base ring, we assum that any two rings R and S that appear are comparable,
in the sense that either R is an S-algebra or S is an R-algebra.
This cache contains typeclasses required during algebra's execution. These assumptions
are stronger than ring because algebra occasionally requires commutativity to move between
the base ring and the algebra.
A Field instance on
A, if available.
Instances For
Create a new cache for A by doing the necessary instance searches.
Instances For
The type used to store the coefficients of the algebra tactic, which are expressions in R
kept in ring normal form and mapped into A by the algebraMap.
Note that these are sums, not products!
- mk {u v : Lean.Level} {R : Q(Type u)} {A : Q(Type v)} {sR : Q(CommSemiring «$R»)} {sA : Q(CommSemiring «$A»)} {sAlg : Q(Algebra «$R» «$A»)} (r : Q(«$R»)) : Ring.ExSum q(«$sR») r → BaseType sAlg q((algebraMap «$R» «$A») «$r»)
Instances For
ExBase BaseType sα e stores the structure of a normalized expression e, which appears
as the base of an exponent expression e^n. The sum constructor is only used when the exponent
n is not a constant.
Instances For
ExProd BaseType sα e stores the structure of a normalized monomial expression e.
A monomial here is a product of powers of ExBase expressions, terminated by a (nonzero) constant
coefficient. The data of the constant coefficient is stored in the BaseType.
Instances For
ExSum BaseType sα e stores the structure of a normalized polynomial expression e, which is
a sum of monomials.
Instances For
Evaluates a numeric literal in the algebra A by lifting it through the base ring R.
Instances For
Push algebraMaps into sums and products and convert algebraMaps from ℕ, ℤ and ℚ
into casts.
Instances For
Handle scalar multiplication when the scalar ring R' doesn't match the base ring R.
Assumes R is an R'-algebra (i.e., R' is smaller), and casts the scalar using algebraMap.
Instances For
Evaluate the sum of two normalized expressions in R using ring.
Instances For
Evaluate the product of two normalized expressions in R using ring.
Instances For
Take an expression r' in a ring R' such that R is an R'-algebra and cast r' to R
using algebraMap R' R, so that the scalar multiplication action on A is preserved.
Instances For
Evaluate the product of two normalized expressions in R using ring.
Instances For
Raise a normalized expression in R to the power of a normalized natural number expression
using ring.
Instances For
Evaluate the inverse of two normalized expressions in R using ring.
Instances For
Evaluate constants in A using norm_num.
Instances For
Decide if a coefficient is 1.
Instances For
The data used by the algebra tactic to normalize the constant coefficients, which are
expressions in R normalized by ring.
Instances For
The data used by the algebra tactic to normalize the constant coefficients, which are
expressions in R normalized by ring.
Instances For
Remove some nonstandard spellings of algebraMap such as Nat.cast
Instances For
Clean up the normal form into a more human-friendly format. This does everything
RingNF.cleanup does and also pulls the scalar multiplication from the end of of each term to
the start. i.e. x * y * (r • 1) → r • (x * y)
Used by cleanup.
Instances For
Turn scalar multiplication by an explicit constant in R into multiplication in A.
e.g. (4 : ℚ) • x becomes 4 * x but ↑n • x stays ↑n • x.
Instances For
Collect all scalar rings from scalar multiplications using a state monad for performance.
Note: The match in this definition should be kept up to date with the Common.eval function.
Collect all scalar rings from scalar multiplications and algebraMap applications in the
expression.
Instances For
Given two rings, determine which is 'larger' in the sense that the larger is an algebra over the smaller. Returns the first ring if they're the same or incompatible.
Instances For
Infer from the expression what base ring the normalization should use. Finds all scalar rings in the expression and picks the 'larger' one in the sense that it is an algebra over the smaller rings.
Instances For
Frontend of algebra: attempt to close a goal g, assuming it is an equation of semirings.
Instances For
algebra solves equalities in the language of algebras: ring operations and scalar
multiplications.
Given a goal which is an equality in a commutative R-algebra A, algebra parses the LHS and
RHS of the goal as polynomial expressions of A-atoms with coefficients in some semiring R, and
closes the goal if the two expressions are the same. The R-coefficients are put into ring normal
form.
By default, the scalar ring R is inferred automatically by looking for scalar multiplications and
algebraMaps present in the expressions. The inference procedure assumes that any two rings R
and S that appear are comparable, in the sense that either R is an S-algebra or S is an
R-algebra.
algebra with Ruses the termRas the scalar ring, instead of attempting to infer it automatically.
Instances For
algebra solves equalities in the language of algebras: ring operations and scalar
multiplications.
Given a goal which is an equality in a commutative R-algebra A, algebra parses the LHS and
RHS of the goal as polynomial expressions of A-atoms with coefficients in some semiring R, and
closes the goal if the two expressions are the same. The R-coefficients are put into ring normal
form.
By default, the scalar ring R is inferred automatically by looking for scalar multiplications and
algebraMaps present in the expressions. The inference procedure assumes that any two rings R
and S that appear are comparable, in the sense that either R is an S-algebra or S is an
R-algebra.
algebra with Ruses the termRas the scalar ring, instead of attempting to infer it automatically.