2014-08-01 00:48:51 +00:00
|
|
|
----------------------------------------------------------------------------------------------------
|
2014-07-19 19:09:47 +00:00
|
|
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
-- Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
-- Author: Leonardo de Moura
|
2014-08-01 00:48:51 +00:00
|
|
|
----------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
import logic.classes.decidable tools.tactic
|
2014-08-20 02:32:44 +00:00
|
|
|
using decidable tactic eq_ops
|
2014-07-19 19:09:47 +00:00
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
definition ite (c : Prop) {H : decidable c} {A : Type} (t e : A) : A :=
|
|
|
|
rec_on H (assume Hc, t) (assume Hnc, e)
|
2014-07-19 19:09:47 +00:00
|
|
|
|
|
|
|
notation `if` c `then` t `else` e:45 := ite c t e
|
|
|
|
|
2014-08-28 18:10:04 +00:00
|
|
|
theorem if_pos {c : Prop} {H : decidable c} (Hc : c) {A : Type} {t e : A} : (if c then t else e) = t :=
|
2014-07-29 02:58:57 +00:00
|
|
|
decidable_rec
|
|
|
|
(assume Hc : c, refl (@ite c (inl Hc) A t e))
|
2014-08-28 01:34:09 +00:00
|
|
|
(assume Hnc : ¬c, absurd Hc Hnc)
|
2014-07-29 02:58:57 +00:00
|
|
|
H
|
2014-07-19 19:09:47 +00:00
|
|
|
|
2014-08-28 18:10:04 +00:00
|
|
|
theorem if_neg {c : Prop} {H : decidable c} (Hnc : ¬c) {A : Type} {t e : A} : (if c then t else e) = e :=
|
2014-07-29 02:58:57 +00:00
|
|
|
decidable_rec
|
2014-08-28 01:34:09 +00:00
|
|
|
(assume Hc : c, absurd Hc Hnc)
|
2014-07-29 02:58:57 +00:00
|
|
|
(assume Hnc : ¬c, refl (@ite c (inr Hnc) A t e))
|
|
|
|
H
|
2014-07-19 19:09:47 +00:00
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
theorem if_t_t (c : Prop) {H : decidable c} {A : Type} (t : A) : (if c then t else t) = t :=
|
|
|
|
decidable_rec
|
|
|
|
(assume Hc : c, refl (@ite c (inl Hc) A t t))
|
|
|
|
(assume Hnc : ¬c, refl (@ite c (inr Hnc) A t t))
|
|
|
|
H
|
2014-07-19 19:09:47 +00:00
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
theorem if_true {A : Type} (t e : A) : (if true then t else e) = t :=
|
2014-08-28 18:10:04 +00:00
|
|
|
if_pos trivial
|
2014-07-19 19:09:47 +00:00
|
|
|
|
2014-07-29 02:58:57 +00:00
|
|
|
theorem if_false {A : Type} (t e : A) : (if false then t else e) = e :=
|
2014-08-28 18:10:04 +00:00
|
|
|
if_neg not_false_trivial
|
2014-08-04 04:41:01 +00:00
|
|
|
|
2014-08-04 19:00:46 +00:00
|
|
|
theorem if_cond_congr {c₁ c₂ : Prop} {H₁ : decidable c₁} {H₂ : decidable c₂} (Heq : c₁ ↔ c₂) {A : Type} (t e : A)
|
|
|
|
: (if c₁ then t else e) = (if c₂ then t else e) :=
|
|
|
|
rec_on H₁
|
|
|
|
(assume Hc₁ : c₁, rec_on H₂
|
2014-08-28 18:10:04 +00:00
|
|
|
(assume Hc₂ : c₂, if_pos Hc₁ ⬝ (if_pos Hc₂)⁻¹)
|
2014-08-28 01:34:09 +00:00
|
|
|
(assume Hnc₂ : ¬c₂, absurd (iff_elim_left Heq Hc₁) Hnc₂))
|
2014-08-04 19:00:46 +00:00
|
|
|
(assume Hnc₁ : ¬c₁, rec_on H₂
|
2014-08-28 01:34:09 +00:00
|
|
|
(assume Hc₂ : c₂, absurd (iff_elim_right Heq Hc₂) Hnc₁)
|
2014-08-28 18:10:04 +00:00
|
|
|
(assume Hnc₂ : ¬c₂, if_neg Hnc₁ ⬝ (if_neg Hnc₂)⁻¹))
|
2014-08-04 19:00:46 +00:00
|
|
|
|
2014-08-04 04:41:01 +00:00
|
|
|
theorem if_congr_aux {c₁ c₂ : Prop} {H₁ : decidable c₁} {H₂ : decidable c₂} {A : Type} {t₁ t₂ e₁ e₂ : A}
|
2014-08-04 19:00:46 +00:00
|
|
|
(Hc : c₁ ↔ c₂) (Ht : t₁ = t₂) (He : e₁ = e₂) :
|
2014-08-04 04:41:01 +00:00
|
|
|
(if c₁ then t₁ else e₁) = (if c₂ then t₂ else e₂) :=
|
2014-08-04 20:30:28 +00:00
|
|
|
Ht ▸ He ▸ (if_cond_congr Hc t₁ e₁)
|
2014-08-04 19:00:46 +00:00
|
|
|
|
|
|
|
theorem if_congr {c₁ c₂ : Prop} {H₁ : decidable c₁} {A : Type} {t₁ t₂ e₁ e₂ : A} (Hc : c₁ ↔ c₂) (Ht : t₁ = t₂) (He : e₁ = e₂) :
|
|
|
|
(if c₁ then t₁ else e₁) = (@ite c₂ (decidable_iff_equiv H₁ Hc) A t₂ e₂) :=
|
|
|
|
have H2 [fact] : decidable c₂, from (decidable_iff_equiv H₁ Hc),
|
2014-08-04 04:41:01 +00:00
|
|
|
if_congr_aux Hc Ht He
|