Skip to content

Commit ea3e0c6

Browse files
committed
Undo most changes, just add exclamations to all converts
1 parent 0f5e8c5 commit ea3e0c6

3 files changed

Lines changed: 16 additions & 85 deletions

File tree

Mathlib/Tactic/CongrExclamation.lean

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ to right-hand sides of goals. Here is an exhaustive list of things it can try:
6363
6464
- It can try to close goals using a few strategies, including checking
6565
definitional equality, trying to apply `Subsingleton.elim` or `proof_irrel_heq`, and using the
66-
`assumption` tactic. Discharging is done at default transparency (but this will be changed
67-
to reducible transparency in the future).
66+
`assumption` tactic.
6867
6968
The optional parameter is the depth of the recursive applications.
7069
This is useful when `congr!` is too aggressive in breaking down the goal.
@@ -107,8 +106,7 @@ structure Congr!.Config where
107106
closePre : Bool := true
108107
/-- If `closePost := true`, then try to close goals that remain after no more congruence
109108
lemmas can be applied, using the same tactics as `closePre`. These tactics are applied
110-
with the transparency level specified by `postTransparency`, which is currently set to
111-
`.default` but will soon become `.reducible`. -/
109+
with current tactic transparency level. -/
112110
closePost : Bool := true
113111
/-- The transparency level to use when applying a congruence theorem.
114112
By default this is `.reducible`, which prevents unfolding of most definitions. -/
@@ -117,11 +115,6 @@ structure Congr!.Config where
117115
This includes trying to prove the goal by `rfl` and using the `assumption` tactic.
118116
By default this is `.reducible`, which prevents unfolding of most definitions. -/
119117
preTransparency : TransparencyMode := TransparencyMode.reducible
120-
/-- The transparency level to use when trying to close goals after no more congruence lemmas can
121-
be applied. This includes trying to prove the goal by `rfl` and using the `assumption` tactic.
122-
For backwards compatibility this is set to `.default`, which will be changed soon to `.reducible`.
123-
-/
124-
postTransparency : TransparencyMode := TransparencyMode.default
125118
/-- For passes that synthesize a congruence lemma using one side of the equality,
126119
we run the pass both for the left-hand side and the right-hand side. If `preferLHS` is `true`
127120
then we start with the left-hand side.
@@ -197,7 +190,6 @@ def Congr!.Config.unfoldSameFun : Congr!.Config where
197190
sameFun := true
198191
transparency := .default
199192
preTransparency := .default
200-
postTransparency := .default
201193

202194
/-- Whether the given number of arguments is allowed to be considered. -/
203195
def Congr!.Config.numArgsOk (config : Config) (numArgs : Nat) : Bool :=
@@ -684,8 +676,7 @@ def Lean.MVarId.congrCore! (config : Congr!.Config) (mvarId : MVarId) :
684676
return none
685677

686678
/-- A pass to clean up after `Lean.MVarId.preCongr!` and `Lean.MVarId.congrCore!`. -/
687-
def Lean.MVarId.postCongr! (config : Congr!.Config) (mvarId : MVarId) : MetaM (Option MVarId) :=
688-
withTransparency config.postTransparency do
679+
def Lean.MVarId.postCongr! (config : Congr!.Config) (mvarId : MVarId) : MetaM (Option MVarId) := do
689680
let some mvarId ← mvarId.preCongr! config.closePost | return none
690681
-- Convert `p = q` to `p ↔ q`, which is likely the more useful form:
691682
let mvarId ← mvarId.propext

Mathlib/Tactic/Convert.lean

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,6 @@ public meta section
7777

7878
open Lean Meta Elab Tactic
7979

80-
/-- Configuration for the `convert` family of tactics.
81-
This is `Congr!.Config` with different, less aggressive, defaults.
82-
-/
83-
structure Convert.Config extends Congr!.Config where
84-
postTransparency := .default -- Will be set to .reducible in a follow-up PR
85-
86-
/-- Elaborator for `Convert.Config` (which is equivalent to `Congr!.Config`
87-
but with different, less aggressive, defaults). -/
88-
declare_config_elab Convert.elabConfig Convert.Config
89-
90-
/--
91-
A configuration option that makes `convert` do the sorts of aggressive unfoldings that `congr`
92-
does while also similarly preventing `convert` from considering partial applications or congruences
93-
between different functions being applied.
94-
-/
95-
abbrev Convert.Config.unfoldSameFun : Convert.Config :=
96-
{ Congr!.Config.unfoldSameFun with
97-
postTransparency := .default } -- Will be set to .reducible in a follow-up PR
98-
9980
/--
10081
Close the goal `g` using `Eq.mp v e`,
10182
where `v` is a metavariable asserting that the type of `g` and `e` are equal.
@@ -151,7 +132,8 @@ pattern-matched, like `rintro` would, using the `with` keyword.
151132
See also `convert_to t`, where `t` specifies the expected type, instead of a proof term of type `t`.
152133
In other words, `convert_to t` works like `convert (?_ : t)`. Both tactics use the same options.
153134
154-
* `convert! e` uses default transparency, rather than reducible, when solving side goals.
135+
* `convert! e` uses default transparency when solving side goals. This is currently the same
136+
behaviour as `convert`, but `convert` will use reducible transparency in the future.
155137
* `convert ← e` creates equality goals in the opposite direction (with the goal type on the right).
156138
* `convert e using n`, where `n` is a positive numeral, controls the depth with which congruence is
157139
applied. For example, if the main goal is `⊢ Prime (n + n + 1)` and `e : Prime (2 * n + 1)`, then
@@ -174,7 +156,6 @@ example {n : ℕ} (e : Prime (2 * n + 1)) :
174156
ring
175157
176158
-- `convert` can fail where `exact` succeeds.
177-
def p (n : ℕ) := True
178159
example (h : p 0) : p 1 := by
179160
fail_if_success
180161
convert h -- fails, left-over goal 1 = 0
@@ -221,7 +202,7 @@ def elabTermForConvert (term : Syntax) (expectedType? : Option Expr) :
221202
elab_rules : tactic
222203
| `(tactic| convert%$tk $[!%$semireducible]? $cfg $[←%$sym]? $term $[using $n]? $[with $ps?*]?) =>
223204
withMainContext do
224-
let config := { ← Convert.elabConfig cfg with }
205+
let config ← Congr!.elabConfig (mkOptionalNode cfg)
225206
let patterns := (ps?.getD #[]).toList
226207
let expectedType ← mkFreshExprMVar (mkSort (← getLevel (← getMainTarget)))
227208
let (e, gs) ← elabTermForConvert term expectedType
@@ -243,7 +224,8 @@ pattern-matched, like `rintro` would, using the `with` keyword.
243224
`convert e`, where `e` is a term of type `t`, uses `e` to close the new main goal. In other words,
244225
`convert e` works like `convert_to t; refine e`. Both tactics use the same options.
245226
246-
* `convert_to! t` uses default transparency, rather than reducible, when solving side goals.
227+
* `convert_to! t` uses default transparency when solving side goals. This is currently the same
228+
behaviour as `convert_to`, but `convert_to` will use reducible transparency in the future.
247229
* `convert_to ty at h` changes the type of the local hypothesis `h` to `ty`. If later local
248230
hypotheses or the goal depend on `h`, then `convert_to t at h` may leave a copy of `h`.
249231
* `convert_to ← t` creates equality goals in the opposite direction (with the original goal type on
@@ -259,7 +241,7 @@ pattern-matched, like `rintro` would, using the `with` keyword.
259241
* `convert_to (config := cfg) t` uses the configuration options in `cfg` to control the congruence
260242
rules (see `Congr!.Config`).
261243
-/
262-
syntax (name := convertTo) "convert_to" ("!")? Parser.Tactic.optConfig " ←"? ppSpace term
244+
syntax (name := convertTo) "convert_to" Lean.Parser.Tactic.optConfig " ←"? ppSpace term
263245
(" using " num)? (" with" (ppSpace colGt rintroPat)*)? (Parser.Tactic.location)? : tactic
264246

265247
@[tactic_alt convertTo]
@@ -268,20 +250,13 @@ syntax (name := convert_to!) "convert_to!" Lean.Parser.Tactic.optConfig " ←"?
268250

269251
macro_rules
270252
| `(tactic| convert_to! $cfg $[←%$l]? $t $[using $n]? $[with $w]? $[$loc]?) =>
271-
`(tactic| convert_to ! $cfg $[←%$l]? $t:term $[using $n]? $[with $w]? $[$loc]?)
253+
`(tactic| convert_to $cfg $[←%$l]? $t:term $[using $n]? $[with $w]? $[$loc]?)
272254

273255
elab_rules : tactic
274-
| `(tactic| convert_to $[!%$semireducible]? $cfg $[←%$sym]? $newType $[using $n]?
256+
| `(tactic| convert_to $cfg $[←%$sym]? $newType $[using $n]?
275257
$[with $ps?*]? $[$loc?:location]?) => do
276258
let n : ℕ := n |>.map (·.getNat) |>.getD 1
277-
let mut config := { ← Convert.elabConfig cfg with }
278-
if semireducible.isSome then
279-
config := { config with
280-
-- TODO: also enable this in the future? (Not right now, for backwards compatibility).
281-
-- transparency := default,
282-
-- preTransparency := default,
283-
-- postTransparency := default -- Disabled while the port to `convert!` happens.
284-
}
259+
let config ← Congr!.elabConfig cfg
285260
let patterns := (ps?.getD #[]).toList
286261
withLocation (expandOptLocation (mkOptionalNode loc?))
287262
(atLocal := fun fvarId ↦ do
@@ -307,7 +282,8 @@ into new goals, using the hole's name, if any, as the goal case name.
307282
Like `congr!`, `convert_to` introduces variables while applying congruence rules. These can be
308283
pattern-matched, like `rintro` would, using the `with` keyword.
309284
310-
* `ac_change! t` uses default transparency, rather than reducible, when solving side goals.
285+
* `ac_change! t` uses default transparency when solving side goals. This is currently the same
286+
behaviour as `ac_change`, but `ac_change` will use reducible transparency in the future.
311287
* `ac_change t using n`, where `n` is a positive numeral, controls the depth with which congruence
312288
is applied. For example, if the main goal is `⊢ Prime ((a * b + 1) + c)`,
313289
then `ac_change Prime ((1 + a * b) + c) using 2` solves the side goals, and
@@ -332,4 +308,5 @@ macro_rules
332308
| `(tactic| ac_change! $t $[using $n]?) =>
333309
`(tactic| convert_to! $t:term $[using $n]? <;> try ac_rfl)
334310

311+
335312
end Mathlib.Tactic

MathlibTest/convert.lean

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ example (prime : Nat → Prop) (n : Nat) (h : prime (2 * n + 1)) :
7575

7676
example (p q : Nat → Prop) (h : ∀ ε > 0, p ε) :
7777
∀ ε > 0, q ε := by
78-
convert! h using 2 with ε hε
78+
convert h using 2 with ε hε
7979
guard_hyp hε : ε > 0
8080
guard_target = q ε ↔ p ε
8181
exact test_sorry
@@ -128,41 +128,4 @@ example (x y z : Nat) (h : x + y = z) : y + x = z := by
128128
· rw [Nat.add_comm]
129129
exact h
130130

131-
/-! Check that we don't unfold at semireducible transparency: although `congr!` (which
132-
`convert` relies on) applies lemmas at reducible transparency, it used to call
133-
`assumption`/`rfl` at default transparency and solve too much.
134-
135-
`convert!` uses default transparency throughout, and solves the goals all at once.
136-
-/
137-
138-
/-- An identity function at default transparency, to test that we don't unfold too much. -/
139-
def semireducibleId {α : Type*} (a : α) := a
140-
141-
/-
142-
-- These examples can be uncommented when `convert` is reducible by default.
143-
example (P : ℕ → Prop) {a b : ℕ} (h : P a) : P (semireducibleId a) := by
144-
convert h
145-
guard_target =ₛ semireducibleId a = a
146-
rfl
147-
148-
example (P : ℕ → Prop) {a b : ℕ} (h : P a) : P (semireducibleId a) := by
149-
convert! h
150-
151-
example (P : ℕ → Prop) {a b : ℕ} (hab : b = a) (h : P a) : P (semireducibleId b) := by
152-
convert h
153-
guard_target =ₛ semireducibleId b = a
154-
exact hab
155-
156-
example (P : ℕ → Prop) {a b : ℕ} (hab : b = a) (h : P (semireducibleId a)) : P b := by
157-
convert! h
158-
159-
example (P : ℕ → Prop) {a b : ℕ} (hab : b = a) (h : P a) : P (semireducibleId b) := by
160-
convert h
161-
guard_target =ₛ semireducibleId b = a
162-
exact hab
163-
164-
example (P : ℕ → Prop) {a b : ℕ} (hab : b = a) (h : P (semireducibleId a)) : P b := by
165-
convert! h
166-
-/
167-
168131
end Tests

0 commit comments

Comments
 (0)