Skip to content

Commit 449ee75

Browse files
committed
TEsts
1 parent 1d87606 commit 449ee75

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

src/Lean/Elab/PreDefinition/Eqns.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ partial def splitMatch? (mvarId : MVarId) (declNames : Array Name) : MetaM (Opti
101101
target declNames badCases then
102102
try
103103
Meta.Split.splitMatch mvarId e
104-
catch _ =>
104+
catch ex =>
105+
trace[Elab.definition.eqns] "cannot split {e}\n{ex.toMessageData}"
105106
go (badCases.insert e)
106107
else
107-
trace[Meta.Tactic.split] "did not find term to split\n{MessageData.ofGoal mvarId}"
108+
trace[Elab.definition.eqns] "did not find term to split\n{MessageData.ofGoal mvarId}"
108109
return none
109110
go {}
110111

tests/lean/run/structuralEqn6.lean

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,70 @@
1-
/-- The number of trailing zeros in the binary representation of `i`. -/
21
def trailingZeros (i : Int) : Nat :=
32
if h : i = 0 then 0 else aux i.natAbs i h (Nat.le_refl _) 0
43
where
54
aux (k : Nat) (i : Int) (hi : i ≠ 0) (hk : i.natAbs ≤ k) (acc : Nat) : Nat :=
6-
match k, (by omega : k ≠ 0) with
7-
| k + 1, _ =>
5+
match k with
6+
| k + 1 =>
87
if h : i % 2 = 0 then aux k (i / 2) (by omega) (by omega) (acc + 1)
98
else acc
9+
| 0 => by omega
1010
termination_by structural k
1111

1212
/--
1313
info: equations:
1414
@[defeq] theorem trailingZeros.aux.eq_1 : ∀ (i : Int) (hi : i ≠ 0) (acc k_2 : Nat) (hk_2 : i.natAbs ≤ k_2 + 1),
1515
trailingZeros.aux k_2.succ i hi hk_2 acc = if h : i % 2 = 0 then trailingZeros.aux k_2 (i / 2) ⋯ ⋯ (acc + 1) else acc
16+
@[defeq] theorem trailingZeros.aux.eq_2 : ∀ (i : Int) (hi : i ≠ 0) (acc : Nat) (hk_2 : i.natAbs ≤ 0),
17+
trailingZeros.aux 0 i hi hk_2 acc = acc
1618
-/
17-
#guard_msgs in
19+
#guard_msgs(pass trace, all) in
1820
#print equations trailingZeros.aux
21+
22+
23+
-- set_option trace.Elab.definition.eqns true
24+
-- set_option trace.split.debug true
25+
-- set_option trace.Meta.Match.unify true
26+
27+
def trailingZeros' (i : Int) : Nat :=
28+
if h : i = 0 then 0 else aux i.natAbs i h (Nat.le_refl _) 0
29+
where
30+
aux (k : Nat) (i : Int) (hi : i ≠ 0) (hk : i.natAbs ≤ k) (acc : Nat) : Nat :=
31+
match k, (by omega : k ≠ 0) with
32+
| k + 1, _ =>
33+
if h : i % 2 = 0 then aux k (i / 2) (by omega) (by omega) (acc + 1)
34+
else acc
35+
termination_by k
36+
37+
/--
38+
info: equations:
39+
theorem trailingZeros'.aux.eq_1 : ∀ (i : Int) (hi : i ≠ 0) (acc k_2 : Nat) (x_1 : k_2 + 1 ≠ 0)
40+
(hk_2 : i.natAbs ≤ k_2 + 1),
41+
trailingZeros'.aux k_2.succ i hi hk_2 acc =
42+
if h : i % 2 = 0 then trailingZeros'.aux k_2 (i / 2) ⋯ ⋯ (acc + 1) else acc
43+
-/
44+
#guard_msgs(pass trace, all) in
45+
#print equations trailingZeros'.aux
46+
47+
48+
49+
/-- The number of trailing zeros in the binary representation of `i`. -/
50+
def trailingZeros2 (i : Int) : Nat :=
51+
if h : i = 0 then 0 else aux i.natAbs i h (Nat.le_refl _) 0
52+
where
53+
aux (k : Nat) (i : Int) (hi : i ≠ 0) (hk : i.natAbs ≤ k) (acc : Nat) : Nat :=
54+
match k with
55+
| k + 1 =>
56+
if h : i % 2 = 0 then aux k (i / 2) (by omega) (by omega) (acc + 1)
57+
else acc
58+
| 0 => by omega
59+
termination_by structural k
60+
61+
/--
62+
info: equations:
63+
@[defeq] theorem trailingZeros2.aux.eq_1 : ∀ (i : Int) (hi : i ≠ 0) (acc k_2 : Nat) (hk_2 : i.natAbs ≤ k_2 + 1),
64+
trailingZeros2.aux k_2.succ i hi hk_2 acc =
65+
if h : i % 2 = 0 then trailingZeros2.aux k_2 (i / 2) ⋯ ⋯ (acc + 1) else acc
66+
@[defeq] theorem trailingZeros2.aux.eq_2 : ∀ (i : Int) (hi : i ≠ 0) (acc : Nat) (hk_2 : i.natAbs ≤ 0),
67+
trailingZeros2.aux 0 i hi hk_2 acc = acc
68+
-/
69+
#guard_msgs(pass trace, all) in
70+
#print equations trailingZeros2.aux

0 commit comments

Comments
 (0)