![](/img/trans.png)
[英]Haskell error: Couldn't match expected type `Bool' against inferred type `IO b'
[英]How to solve ∀ a : bool → bool, ∀ b : bool, a (a (a b)) = a b in Lean
我試過解決這個問題,但不能,有什么幫助嗎? 到目前為止我的解決方案:
example : ∀ a : bool → bool, ∀ b : bool, a (a (a b)) = a b :=
begin
assume a b,
cases a:b,
cases b,
cases a,
have c : tt ≠ ff,
contradiction,
sorry,
end
這對我來說是一個非常不尋常的問題(我是一個數學家,所以bool
對我來說不存在),所以我可能會錯過有效的方法,但是你當然可以對a tt
所有可能性進行抨擊, a ff
和b
。
example : ∀ a : bool → bool, ∀ b : bool, a (a (a b)) = a b :=
begin
assume a b,
cases h₁ : a tt ;
cases h₂ : a ff ;
cases b,
repeat { rw h₁ <|> rw h₂ },
end
(在編輯中略有簡化)
不要猶豫,詢問是否有部分語法不清楚(或者更好,來問Zulip )。
我不確定你在嘗試中做了什么。 但是您的行cases a:b
在您的上下文中創建了一個名為a
的新事物,這很可能會引起混淆。 而contradiction
戰術成功的事實是一個不幸的意外,在這里使用trivial
會更清楚。
使用你的戰術風格:
example : ∀ a : bool → bool, ∀ b : bool, a (a (a b)) = a b :=
begin
assume a b,
-- split reasoning into b as ff or tt
cases hb : b,
{ -- in this case, all b is now ff
-- so let's split what (a ff) is into ff and tt
-- since we have two (a ff) expressions in our goal
cases hf : a ff,
{ -- this case is where (a ff) = ff,
-- so we use it directly twice
exact hf.symm ▸ hf },
{ -- in this case, (a ff) = tt, so now we have
-- the expression (a tt) in our goal
-- we split it into the cases ff and tt
cases ht : a tt,
{ -- in this case, we already have the goal, use it
exact hf },
{ -- in this case, we already have the goal, use it
exact ht } } },
{ -- in this case, all b is now ff
-- so let's split what (a tt) is into ff and tt
-- since we have two (a tt) expressions in our goal
cases ht : a tt,
{ -- in this case, (a tt) = ff, so now we have
-- the expression (a ff) in our goal
-- we split it into the cases ff and tt
cases hf : a ff,
{ -- in this case, we already have the goal, use it
exact hf },
{ -- in this case, we already have the goal, use it
exact ht } },
{ -- this case is where (a tt) = tt,
-- so we use it directly twice
exact ht.symm ▸ ht } },
end
在 case-bash 變體中,仍然沒有策略:
example : ∀ a : bool → bool, ∀ b : bool, a (a (a b)) = a b :=
begin
intros a b,
-- split reasoning into b as ff or tt
cases hb : b;
-- and for all cases, split reasoning of the (a ff) expression
cases hf : a ff;
-- and for all cases, split reasoning of the (a tt) expression
cases ht : a tt,
-- now deal with all cases
{ exact hf.symm ▸ hf },
{ exact hf.symm ▸ hf },
{ exact hf },
{ exact ht },
{ exact hf.symm ▸ hf },
{ exact ht.symm ▸ ht },
{ exact hf.symm ▸ ht },
{ exact ht.symm ▸ ht },
end
最后,使用簡單的策略:
example : ∀ a : bool → bool, ∀ b : bool, a (a (a b)) = a b :=
begin
intros a b,
-- split reasoning into b as ff or tt
cases hb : b;
-- and for all cases, split reasoning of the (a ff) expression
cases hf : a ff;
-- and for all cases, split reasoning of the (a tt) expression
cases ht : a tt;
-- now deal with all cases using tactics
all_goals {
-- we can try rewriting either (a ff) or (a tt) which must occur
-- in the goal expression because of the original (a b) expression
-- and only one of those is present, so we use the
-- <|> syntax to try the second tactic (rw) if the first one fails
rw ht <|> rw hf,
-- now, either we've formed a reflexive equality and we're done
-- or the equality we're left with is of the form (a tt = ff)
-- which we'll have as an assumption
-- if tactic we tried to use here was a plain "assumption",
-- that would fail in the cases where we had already solved the goal
-- so we wrap it in a "try"
try { assumption } },
end
這是作弊的解決方案:
import tactic.fin_cases
example : ∀ a : bool → bool, ∀ b : bool, a (a (a b)) = a b :=
begin
intros a b,
fin_cases a; fin_cases b; refl
end
這里fin_cases
是來自mathlib
一種策略。 如果它可以找到一個可計算的[fintype α]
它就會對a : α
案例分析a : α
。 因此,從數學上講,解決方案說:考慮所有情況,驗證在每種情況下我們都有定義的相等性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.