Documentation

Mathlib.Tactic.Algebra.Basic

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

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.

structure Mathlib.Tactic.Algebra.Cache {u : Lean.Level} {A : Q(Type u)} (sA : Q(CommSemiring «$A»)) extends Mathlib.Tactic.Ring.Common.Cache sA :

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.

Instances For
    def Mathlib.Tactic.Algebra.mkCache {u : Lean.Level} {A : Q(Type u)} (sA : Q(CommSemiring «$A»)) :

    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
      inductive Mathlib.Tactic.Algebra.BaseType {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»)) (a : Q(«$A»)) :

      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!

      Instances For
        def Mathlib.Tactic.Algebra.ExBase {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»)) (e : Q(«$A»)) :

        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
          def Mathlib.Tactic.Algebra.ExProd {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»)) (e : Q(«$A»)) :

          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
            def Mathlib.Tactic.Algebra.ExSum {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»)) (e : Q(«$A»)) :

            ExSum BaseType sα e stores the structure of a normalized polynomial expression e, which is a sum of monomials.

            Equations
            Instances For
              def Mathlib.Tactic.Algebra.evalCast {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»)) {a : Q(«$A»)} (cR : Cache q(«$sR»)) (cA : Cache q(«$sA»)) :

              Evaluates a numeric literal in the algebra A by lifting it through the base ring R.

              Equations
              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
                  def Mathlib.Tactic.Algebra.evalSMulCast {u u' v : Lean.Level} {R : Q(Type u)} {R' : Q(Type u')} {A : Q(Type v)} {sR : Q(CommSemiring «$R»)} {sA : Q(CommSemiring «$A»)} (sAlg : Q(Algebra «$R» «$A»)) (smul : Q(SMul «$R'» «$A»)) (r' : Q(«$R'»)) :
                  Lean.MetaM ((r : Q(«$R»)) × Q(∀ (a : «$A»), «$r» a = «$r'» a))

                  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
                    def Mathlib.Tactic.Algebra.RingCompute.add {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»)) (cR : Ring.Common.Cache sR) {a b : Q(«$A»)} (za : BaseType sAlg a) (zb : BaseType sAlg b) :
                    Lean.MetaM (Ring.Common.Result (BaseType sAlg) q(«$a» + «$b») × Option Q(Meta.NormNum.IsNat («$a» + «$b») 0))

                    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
                      def Mathlib.Tactic.Algebra.RingCompute.mul {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»)) (cR : Ring.Common.Cache sR) {a b : Q(«$A»)} (za : BaseType sAlg a) (zb : BaseType sAlg b) :
                      Lean.MetaM (Ring.Common.Result (BaseType sAlg) q(«$a» * «$b»))

                      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
                        def Mathlib.Tactic.Algebra.RingCompute.cast {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»)) (cR : Cache sR) (u' : Lean.Level) (R' : Q(Type u')) :
                        Q(CommSemiring «$R'»)(_smul : Q(SMul «$R'» «$A»)) → (r' : Q(«$R'»)) → AtomM ((y : Q(«$A»)) × Ring.Common.ExSum (BaseType sAlg) sA q(«$y») × Q(∀ (a : «$A»), «$r'» a = «$y» * a))

                        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
                          def Mathlib.Tactic.Algebra.RingCompute.neg {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»)) (cR : Cache sR) {a : Q(«$A»)} (_rA : Q(CommRing «$A»)) (za : BaseType sAlg a) :

                          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
                            def Mathlib.Tactic.Algebra.RingCompute.pow {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»)) (cR : Ring.Common.Cache sR) {a : Q(«$A»)} {b : Q()} (za : BaseType sAlg a) (vb : Ring.Common.ExProdNat q(«$b»)) :
                            OptionT Lean.MetaM (Ring.Common.Result (BaseType sAlg) q(«$a» ^ «$b»))

                            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
                              def Mathlib.Tactic.Algebra.RingCompute.inv {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»)) (cR : Cache sR) {a : Q(«$A»)} :
                              Option Q(CharZero «$A»)(fA : Q(Semifield «$A»)) → (za : BaseType sAlg a) → AtomM (Option (Ring.Common.Result (BaseType sAlg) q(«$a»⁻¹)))

                              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
                                def Mathlib.Tactic.Algebra.RingCompute.derive {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»)) (cR : Cache sR) (cA : Cache sA) (x : Q(«$A»)) :

                                Evaluate constants in A using norm_num.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  def Mathlib.Tactic.Algebra.RingCompute.isOne {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»)) (cR : Ring.Common.Cache sR) {x : Q(«$A»)} (zx : BaseType sAlg x) :

                                  Decide if a coefficient is 1.

                                  Equations
                                  Instances For
                                    def Mathlib.Tactic.Algebra.ringCompare {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»)) :

                                    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
                                      def Mathlib.Tactic.Algebra.ringCompute {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»)) (cR : Cache sR) (cA : Cache sA) :

                                      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
                                              Instances For
                                                def Mathlib.Tactic.Algebra.pickLargerRing (r1 r2 : (u : Lean.Level) × Q(Type u)) :
                                                Lean.MetaM ((u : Lean.Level) × Q(Type u))

                                                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
                                                  def Mathlib.Tactic.Algebra.inferBase {v : Lean.Level} {A : Q(Type v)} {sA : Q(CommSemiring «$A»)} (ca : Cache q(«$sA»)) (e : Lean.Expr) :
                                                  Lean.MetaM ((u : Lean.Level) × Q(Type u))

                                                  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 R uses the term R as the scalar ring, instead of attempting to infer it automatically.
                                                      Equations
                                                      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 R uses the term R as the scalar ring, instead of attempting to infer it automatically.
                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For