/- To compile:
alectryon corner_cases.lean3 -o corner_cases.lean3.html
# Lean β HTML; produces βcorner_cases.lean3.htmlβ -/
example : true := begin
trivial
--- asda
end
example : true := begin
skip, exact by trivial, done
end
example : true :=
begin
exact by {
skip,
by_contra,
apply h,
exact trivial
},
skip
end
#check 1
#check (1 +
1 +
1 )
theorem t0 : true -> true :=
by { intro, exact true.intro }
theorem t1 : true -> true :=
begin
-- β’ true β true
intro,
-- αΎ° : true β’ true
exact true.intro
end
-- theorem x : "a" = 1.
theorem t2 : true -> true -> true :=
begin
repeat { intro } ,
sorry
end
theorem t3 : true -> true -> true :=
begin
exact by { repeat { intro }, assumption }
end
theorem t4 : true -> true -> true :=
by { repeat { intro }, admit }
example : true := by exact true.intro
example : true := by trivial
example (a b c : β) (H1 : a = b + 1 ) (H2 : b = c) : a = c + 1 :=
calc a = b + 1 : by a, b, c : β H1 : a = b + 1 H2 : b = c
a = b + 1
exact H1
... = c + 1 : by a, b, c : β H1 : a = b + 1 H2 : b = c
b + 1 = c + 1
rw [ by exact H2 ]
example (a b c : β) : a * (b * c) = a * (c * b) :=
begin a, b, c : β
a * (b * c) = a * (c * b)
conv
begin -- | a * (b * c) = a * (c * b)
to_lhs, -- | a * (b * c)
congr, -- 2 goals : | a and | b * c
skip, -- | b * c
rw nat.mul_comm -- | c * b
end
end
example : true := begin
skip <|> skip, /- Second skip not executed -/
done <|> skip,
trivial
end
example (n : β) : n = n := by {
induction n,
simp, n_n : β n_ih : n_n = n_n
nat.succ n_n.succ = n_n.succ
simp
}
example (n : β) : n = n :=
begin
induction n,
simp, n_n : β n_ih : n_n = n_n
nat.succ n_n.succ = n_n.succ
simp
end
example (n : β) : n = n := by induction n ; simp
-- grouped as (((skip ; skip) ; induction n) ; skip) ; simp
example (n : β) : n = n :=
by skip ; skip ; induction n ; skip ; simp
example (n : β) : n = n := begin
induction n, { simp },
simp
end
example : β (n a : β), n = n := begin β (n : β), β β n = n
repeat { intro }, simp
end
example : true := begin
try { done }, try { trivial }
end
example (p q r : Prop ) : p β§ (q β¨ r) β (p β§ q) β¨ (p β§ r) :=
begin p, q, r : Prop
p β§ (q β¨ r) β p β§ q β¨ p β§ r
intro h, p, q, r : Prop h : p β§ (q β¨ r)
p β§ q β¨ p β§ r
cases h with hp hqr, p, q, r : Prop hp : p hqr : q β¨ r
p β§ q β¨ p β§ r
show (p β§ q) β¨ (p β§ r),p, q, r : Prop hp : p hqr : q β¨ r
p β§ q β¨ p β§ r
cases hqr with hq hr, p, q, r : Prop hp : p hq : q
or.inl p β§ q β¨ p β§ r
{ p, q, r : Prop hp : p hq : q
or.inl p β§ q β¨ p β§ r
have hpq : p β§ q,p, q, r : Prop hp : p hq : q
p β§ q
split ; assumption , p, q, r : Prop hp : p hq : q hpq : p β§ q
p β§ q β¨ p β§ r
left, p, q, r : Prop hp : p hq : q hpq : p β§ q
p β§ q
exact hpq },
have hpr : p β§ r,p, q, r : Prop hp : p hr : r
p β§ r
split ; assumption, p, q, r : Prop hp : p hr : r hpr : p β§ r
p β§ q β¨ p β§ r
right, p, q, r : Prop hp : p hr : r hpr : p β§ r
p β§ r
exact hpr
end
example (p q r : Prop ) (hp : p) (hq : q) (hr : r) :
p β§ q β§ r :=
begin p, q, r : Prop hp : p hq : q hr : r
p β§ q β§ r
split, p, q, r : Prop hp : p hq : q hr : r
p
all_goals { try { split } }, p, q, r : Prop hp : p hq : q hr : r
p
all_goals { assumption }
end
example (p q r : Prop ) (hp : p) (hq : q) (hr : r) :
p β§ q β§ r :=
begin p, q, r : Prop hp : p hq : q hr : r
p β§ q β§ r
repeat { all_goals { split <|> assumption } }
end
example :true := begin
skip, skip; trivial
end
example (n m k : β) (h1 : n = m) (h2 : m = k): (n = k) :=
begin n, m, k : β h1 : n = m h2 : m = k
n = k
rw [show n = m, by assumption, show m = k, by assumption]
end
theorem sub_le_sub_left {n m : β} (k) (h : n β€ m) : k - m β€ k - n :=
begin n, m, k : β h : n β€ m
k - m β€ k - n
induction h; [refl, exact le_trans (nat.pred_le _) h_ih]
end
example : true := by {
try { trivial }
}
example : true := by begin
try begin trivial end
end
-- grouped as done <|> (done <|> trivial)
example : true := by done <|> done <|> trivial
-- unexecuted tactic at end
example : true := by { trivial ; done }
-- special notation
example (n : nat) : true :=
by induction n ; [skip, skip]; [trivial, trivial]
example : true := begin
skip,
trivial, -- trailing comma
end
-- trailing comma
example : true := by { skip ; trivial, }
example : true := by { { skip ; [skip, skip] } <|> trivial }
example : true := by { {{{{ skip ; [skip, skip] }}}} <|> trivial }
-- { } block with no executed children
-- there is no first goal to focus on
example : true := begin { trivial , { skip, skip } } <|> trivial end
-- trailing comma
example : true := begin { skip ; trivial, } end
example : true := begin { { skip ; [skip, skip] } <|> trivial } end
example : true := begin { {{{{ skip ; [skip, skip] }}}} <|> trivial } end