Skip to content

Commit 7c93f86

Browse files
hrmacbetheric-wieserPatrickMassot
committed
feat: match_scalars and module tactics (#16593)
This PR contributes two new tactics `match_scalars` and `module`. Given a goal which is an equality in a type `M` (with `M` an `AddCommMonoid`), the `match_scalars` tactic parses the LHS and RHS of the goal as linear combinations of `M`-atoms over some semiring `R`, and reduces the goal to the respective equalities of the `R`-coefficients of each atom. For example, this produces the goal `⊢ a * 1 + b * 1 = (b + a) * 1`: ```lean example [AddCommMonoid M] [Semiring R] [Module R M] (a b : R) (x : M) : a • x + b • x = (b + a) • x := by match_scalars ``` This produces the two goals `⊢ a * (a * 1) + b * (b * 1) = 1` (from the `x` atom) and `⊢ a * -(b * 1) + b * (a * 1) = 0` (from the `y` atom): ```lean example [AddCommGroup M] [Ring R] [Module R M] (a b : R) (x : M) : a • (a • x - b • y) + (b • a • y + b • b • x) = x := by match_scalars ``` The `module` tactic runs the `match_scalars` tactic and then runs the `ring` tactic on each of the coefficient-wise equalities which are created, failing if this does not resolve them. For example, it solves the following goals: ```lean example [AddCommMonoid M] [CommSemiring R] [Module R M] (a b : R) (x : M) : a • x + b • x = (b + a) • x := by module example [AddCommMonoid M] [Field K] [CharZero K] [Module K M] (x : M) : (2:K)⁻¹ • x + (3:K)⁻¹ • x + (6:K)⁻¹ • x = x := by module example [AddCommGroup M] [CommRing R] [Module R M] (a : R) (v w : M) : (1 + a ^ 2) • (v + w) - a • (a • v - w) = v + (1 + a + a ^ 2) • w := by module ``` The scalar type `R` in these tactics is not pre-determined: instead it starts as `ℕ` (when each atom is initially given a scalar `(1:ℕ)`) and gets bumped up into bigger semirings when such semirings are encountered. However, to permit this, it is assumed that there is a "linear order" on all the semirings which appear in the expression: for any two semirings `R` and `S` which occur, we have either `Algebra R S` or `Algebra S R`). Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Patrick Massot <patrickmassot@free.fr>
1 parent 1fc8e52 commit 7c93f86

File tree

5 files changed

+967
-1
lines changed

5 files changed

+967
-1
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,6 +4288,7 @@ import Mathlib.Tactic.Measurability.Init
42884288
import Mathlib.Tactic.MinImports
42894289
import Mathlib.Tactic.MkIffOfInductiveProp
42904290
import Mathlib.Tactic.ModCases
4291+
import Mathlib.Tactic.Module
42914292
import Mathlib.Tactic.Monotonicity
42924293
import Mathlib.Tactic.Monotonicity.Attr
42934294
import Mathlib.Tactic.Monotonicity.Basic

Mathlib/Tactic.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ import Mathlib.Tactic.Measurability.Init
150150
import Mathlib.Tactic.MinImports
151151
import Mathlib.Tactic.MkIffOfInductiveProp
152152
import Mathlib.Tactic.ModCases
153+
import Mathlib.Tactic.Module
153154
import Mathlib.Tactic.Monotonicity
154155
import Mathlib.Tactic.Monotonicity.Attr
155156
import Mathlib.Tactic.Monotonicity.Basic

0 commit comments

Comments
 (0)