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.
Equations
- One or more equations did not get rendered due to their size.
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.
Equations
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.
Equations
Instances For
ExSum BaseType sα e stores the structure of a normalized polynomial expression e, which is
a sum of monomials.
Equations
Instances For
Evaluates a numeric literal in the algebra A by lifting it through the base ring R.
Equations
- One or more equations did not get rendered due to their size.
- Mathlib.Tactic.Algebra.evalCast sAlg cR cA x✝ = none
Instances For
Push algebraMaps into sums and products and convert algebraMaps from ℕ, ℤ and ℚ
into casts.
Equations
- One or more equations did not get rendered due to their size.
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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluate the sum of two normalized expressions in R using ring.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluate the product of two normalized expressions in R using ring.
Equations
- One or more equations did not get rendered due to their size.
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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluate the product of two normalized expressions in R using ring.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Raise a normalized expression in R to the power of a normalized natural number expression
using ring.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluate the inverse of two normalized expressions in R using ring.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluate constants in A using norm_num.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Decide if a coefficient is 1.
Equations
- One or more equations did not get rendered due to their size.
- Mathlib.Tactic.Algebra.RingCompute.isOne sAlg cR (Mathlib.Tactic.Algebra.BaseType.mk q(0) Mathlib.Tactic.Ring.Common.ExSum.zero) = none
- Mathlib.Tactic.Algebra.RingCompute.isOne sAlg cR (Mathlib.Tactic.Algebra.BaseType.mk s vs) = none
Instances For
The data used by the algebra tactic to normalize the constant coefficients, which are
expressions in R normalized by ring.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The data used by the algebra tactic to normalize the constant coefficients, which are
expressions in R normalized by ring.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Remove some nonstandard spellings of algebraMap such as Nat.cast
Equations
- One or more equations did not get rendered due to their size.
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.
Equations
- One or more equations did not get rendered due to their size.
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.
Equations
- One or more equations did not get rendered due to their size.
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.
Equations
- Mathlib.Tactic.Algebra.collectScalarRings e = do let __discr ← (Mathlib.Tactic.Algebra.collectScalarRingsAux e).run [] match __discr with | (fst, l) => pure l
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.
Equations
- One or more equations did not get rendered due to their size.
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.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Frontend of algebra: attempt to close a goal g, assuming it is an equation of semirings.
Equations
- One or more equations did not get rendered due to their size.
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.
Equations
- Mathlib.Tactic.Algebra.algebra = Lean.ParserDescr.node `Mathlib.Tactic.Algebra.algebra 1024 (Lean.ParserDescr.nonReservedSymbol "algebra" false)
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.
Equations
- One or more equations did not get rendered due to their size.