Skip to content

Instantly share code, notes, and snippets.

@kbuzzard
Created August 23, 2018 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbuzzard/53712d672a894d7b158a512f7aa5f836 to your computer and use it in GitHub Desktop.
Save kbuzzard/53712d672a894d7b158a512f7aa5f836 to your computer and use it in GitHub Desktop.
modelling a level of the game "undead"
import data.set.basic tactic.interactive
import data.list.basic
-- todo -- there's some way of deriving decidable eq here I think
inductive square
| vampire : square
| ghost : square
| zombie : square
namespace square
definition nomirror : square β†’ β„•
| vampire := 1
| ghost := 0
| zombie := 1
definition mirror : square β†’ β„•
| vampire := 0
| ghost := 1
| zombie := 1
end square
open square
instance XXX : decidable_eq square
| vampire vampire := is_true rfl
| vampire ghost := is_false (Ξ» h,square.no_confusion h)
| vampire zombie := is_false (Ξ» h,square.no_confusion h)
| ghost vampire := is_false (Ξ» h,square.no_confusion h)
| ghost ghost := is_true rfl
| ghost zombie := is_false (Ξ» h,square.no_confusion h)
| zombie vampire := is_false (Ξ» h,square.no_confusion h)
| zombie ghost := is_false (Ξ» h,square.no_confusion h)
| zombie zombie := is_true rfl
variables a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ : square
/- the 16 equations -/
definition e₁ := a₁.nomirror + a₃.nomirror + a₆.nomirror + aβ‚ˆ.nomirror = 3
definition eβ‚‚ := a₁.mirror = 0
definition e₃ := aβ‚‚.nomirror + aβ‚„.nomirror + aβ‚„.mirror + aβ‚….mirror = 2
definition eβ‚„ := 0 = 0
definition eβ‚… := 0 = 0
definition e₆ := aβ‚….nomirror + aβ‚„.nomirror + aβ‚„.mirror + aβ‚‚.mirror = 3
definition e₇ := a₇.nomirror + a₇.mirror + aβ‚….mirror + aβ‚‚.mirror + a₃.mirror = 3
definition eβ‚ˆ := 0 = 0
definition e₉ := 0 = 0
definition e₁₀ := a₉.mirror + aβ‚ˆ.mirror = 1
definition e₁₁ := a₉.nomirror + a₆.mirror = 2
definition e₁₂ := aβ‚ˆ.nomirror + a₆.nomirror + a₃.nomirror + a₁.nomirror = 3
definition e₁₃ := aβ‚ˆ.nomirror + a₉.nomirror = 2
definition e₁₄ := a₆.nomirror + a₉.mirror = 1
definition e₁₅ := a₃.nomirror + aβ‚‚.mirror + aβ‚….mirror + a₇.mirror + a₇.mirror = 3
definition e₁₆ := a₁.nomirror = 1
definition is_solved := (e₁ a₁ a₃ a₆ aβ‚ˆ) ∧ (eβ‚‚ a₁) ∧ (e₃ aβ‚‚ aβ‚„ aβ‚…) ∧ (eβ‚„) ∧ (eβ‚…) ∧ (e₆ aβ‚‚ aβ‚„ aβ‚…) ∧ (e₇ aβ‚‚ a₃ aβ‚… a₇)
∧ (eβ‚ˆ) ∧ (e₉) ∧ (e₁₀ aβ‚ˆ a₉) ∧ (e₁₁ a₆ a₉) ∧ (e₁₂ a₁ a₃ a₆ aβ‚ˆ)
∧ (e₁₃ aβ‚ˆ a₉) ∧ (e₁₄ a₆ a₉) ∧ (e₁₅ aβ‚‚ a₃ aβ‚… a₇) ∧ (e₁₆ a₁)
∧ list.length (list.filter (Ξ» a, a = vampire) [a₁,aβ‚‚,a₃,aβ‚„,aβ‚…,a₆,a₇,aβ‚ˆ,a₉]) = 3
∧ list.length (list.filter (Ξ» a, a = ghost) [a₁,aβ‚‚,a₃,aβ‚„,aβ‚…,a₆,a₇,aβ‚ˆ,a₉]) = 3
∧ list.length (list.filter (Ξ» a, a = zombie) [a₁,aβ‚‚,a₃,aβ‚„,aβ‚…,a₆,a₇,aβ‚ˆ,a₉]) = 3
lemma not_vampire (a : square) : Β¬ (a = vampire) β†’ a.mirror = 1 :=
begin
intro H,
cases a,exfalso,apply H,refl,refl,refl
end
lemma not_ghost (a : square) : Β¬ (a = ghost) β†’ a.nomirror = 1 :=
begin
intro H,
cases a,refl,exfalso,apply H,refl,refl
end
lemma not_zombie (a : square) : Β¬ (a = zombie) β†’ a.mirror + a.nomirror = 1 :=
begin
intro H,
cases a,refl,refl,exfalso,apply H,refl,
end
lemma square_1_is_vampire (Hsolved : is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉) : a₁ = vampire :=
begin
rcases Hsolved with ⟨h₁,hβ‚‚,h₃,hβ‚„,hβ‚…,h₆,h₇,hβ‚ˆ,h₉,h₁₀,h₁₁,h₁₂,h₁₃,h₁₄,h₁₅,h₁₆,HV,HG,HZ⟩,
cases a₁,
refl,
cases hβ‚‚,
cases hβ‚‚
end
lemma square_2_not_vampire (Hsolved : is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉) : Β¬ aβ‚‚ = vampire :=
begin
rcases Hsolved with ⟨h₁,hβ‚‚,h₃,hβ‚„,hβ‚…,h₆,h₇,hβ‚ˆ,h₉,h₁₀,h₁₁,h₁₂,h₁₃,h₁₄,h₁₅,h₁₆,HV,HG,HZ⟩,
intro H2,
rw H2 at h₃,
rw H2 at h₆,
cases aβ‚„;cases aβ‚…;cases h₃;cases h₆
end
lemma square_4_not_zombie (Hsolved : is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉) : Β¬ aβ‚„ = zombie :=
begin
rcases Hsolved with ⟨h₁,hβ‚‚,h₃,hβ‚„,hβ‚…,h₆,h₇,hβ‚ˆ,h₉,h₁₀,h₁₁,h₁₂,h₁₃,h₁₄,h₁₅,h₁₆,HV,HG,HZ⟩,
intro H4,
rw H4 at h₃,
rw H4 at h₆,
cases aβ‚‚;cases aβ‚…;cases h₃;cases h₆,
end
lemma square_5_not_ghost (Hsolved : is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉) : Β¬ aβ‚… = ghost :=
begin
rcases Hsolved with ⟨h₁,hβ‚‚,h₃,hβ‚„,hβ‚…,h₆,h₇,hβ‚ˆ,h₉,h₁₀,h₁₁,h₁₂,h₁₃,h₁₄,h₁₅,h₁₆,HV,HG,HZ⟩,
intro H5,
rw H5 at h₃,
rw H5 at h₆,
cases aβ‚‚;cases aβ‚„;cases h₃;cases h₆,
end
lemma square_6_not_vampire (Hsolved : is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉) : Β¬ a₆ = vampire :=
begin
rcases Hsolved with ⟨h₁,hβ‚‚,h₃,hβ‚„,hβ‚…,h₆,h₇,hβ‚ˆ,h₉,h₁₀,h₁₁,h₁₂,h₁₃,h₁₄,h₁₅,h₁₆,HV,HG,HZ⟩,
intro H6,
rw H6 at h₁₁,
cases a₉;cases h₁₁,
end
lemma square_8_not_ghost (Hsolved : is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉) : Β¬ aβ‚ˆ = ghost :=
begin
rcases Hsolved with ⟨h₁,hβ‚‚,h₃,hβ‚„,hβ‚…,h₆,h₇,hβ‚ˆ,h₉,h₁₀,h₁₁,h₁₂,h₁₃,h₁₄,h₁₅,h₁₆,HV,HG,HZ⟩,
intro H8,
rw H8 at h₁₃,
cases a₉;cases h₁₃,
end
lemma square_9_not_ghost (Hsolved : is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉) : Β¬ a₉ = ghost :=
begin
rcases Hsolved with ⟨h₁,hβ‚‚,h₃,hβ‚„,hβ‚…,h₆,h₇,hβ‚ˆ,h₉,h₁₀,h₁₁,h₁₂,h₁₃,h₁₄,h₁₅,h₁₆,HV,HG,HZ⟩,
intro H9,
rw H9 at h₁₁,
cases a₆;cases h₁₁,
end
lemma what_i_know (Hsolved : is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉) :
a₁ = vampire
∧ mirror aβ‚‚ = 1
∧ mirror aβ‚„ + nomirror aβ‚„ = 1
∧ nomirror aβ‚… = 1
∧ mirror a₆ = 1
∧ nomirror aβ‚ˆ = 1
∧ nomirror a₉ = 1
:=
begin
have H1 : a₁ = vampire := square_1_is_vampire a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ Hsolved,
have H2 : Β¬ aβ‚‚ = vampire := square_2_not_vampire a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ Hsolved,
have H4 : Β¬ aβ‚„ = zombie := square_4_not_zombie a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ Hsolved,
have H5 : Β¬ aβ‚… = ghost := square_5_not_ghost a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ Hsolved,
have H6 : Β¬ a₆ = vampire := square_6_not_vampire a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ Hsolved,
have H8 : Β¬ aβ‚ˆ = ghost := square_8_not_ghost a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ Hsolved,
have H9 : Β¬ a₉ = ghost := square_9_not_ghost a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ Hsolved,
have H2m : aβ‚‚.mirror = 1 := not_vampire aβ‚‚ H2,
have H4z : aβ‚„.mirror + aβ‚„.nomirror = 1 := not_zombie aβ‚„ H4,
have H5g : aβ‚….nomirror = 1 := not_ghost aβ‚… H5,
have H6v : a₆.mirror = 1 := not_vampire a₆ H6,
have H8g : aβ‚ˆ.nomirror = 1 := not_ghost aβ‚ˆ H8,
have H9g : a₉.nomirror = 1 := not_ghost a₉ H9,
clear H2,clear H4,clear H5,clear H6,clear H8,clear H9,
exact ⟨H1,H2m,H4z,H5g,H6v,H8g,H9g⟩
end
-- I want to finish the job now doing some slicker version of this case by case analysis
lemma square_7_not_zombie (Hsolved : is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉) : Β¬ a₇ = zombie :=
begin
have H := what_i_know a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ Hsolved,
rcases (what_i_know a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ Hsolved) with ⟨H1,H2m,H4z,H5g,H6v,H8g,H9g⟩,
rcases Hsolved with ⟨h₁,hβ‚‚,h₃,hβ‚„,hβ‚…,h₆,h₇,hβ‚ˆ,h₉,h₁₀,h₁₁,h₁₂,h₁₃,h₁₄,h₁₅,h₁₆,HV,HG,HZ⟩,
rw H1 at *,clear H1,
rw H2m at *,clear H2m,
rw H5g at *,clear H5g,
clear hβ‚‚, clear h₁₆,
intro H7,
rw H7 at *,clear H7,
cases aβ‚‚;cases a₃;cases aβ‚…;cases h₇;cases h₁₅,
cases aβ‚„;cases a₆;cases aβ‚ˆ;cases a₉;revert HV;try {exact dec_trivial};cases h₁₀;cases h₁₁;
cases h₁₃,
end
lemma equations_so_far (a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ : square)
(H1 : a₁ = vampire)
(H2 : Β¬ aβ‚‚ = vampire)
(H4 : Β¬ aβ‚„ = zombie)
(H5 : Β¬ aβ‚… = ghost)
(H6 : Β¬ a₆ = vampire)
(H7 : Β¬ a₇ = zombie)
(H8 : Β¬ aβ‚ˆ = ghost)
(H9 : Β¬ a₉ = ghost) :
is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ :=
begin
unfold is_solved,
unfold e₁,unfold eβ‚‚,unfold e₃,unfold eβ‚„,unfold eβ‚…,unfold e₆,unfold e₇,unfold eβ‚ˆ,
unfold e₉,unfold e₁₀,unfold e₁₁,unfold e₁₂,unfold e₁₃,unfold e₁₄,unfold e₁₅,unfold e₁₆,
rw H1,
have H2v : aβ‚‚.mirror = 1,
cases aβ‚‚,exfalso,apply H2,refl,refl,refl,
rw H2v,clear H2v,
have H4z : aβ‚„.mirror + aβ‚„.nomirror = 1,
cases aβ‚„,refl,refl,exfalso,apply H4,refl,
-- unused
have H5g : aβ‚….nomirror = 1,
cases aβ‚…,refl,exfalso,apply H5,refl,refl,
rw H5g,clear H5g,
have H6v : a₆.mirror = 1,
cases a₆,exfalso,apply H6,refl,refl,refl,
rw H6v,clear H6v,
have H8g : aβ‚ˆ.nomirror = 1,
cases aβ‚ˆ,refl,exfalso,apply H8,refl,refl,
rw H8g,clear H8g,
have H9g : a₉.nomirror = 1,
cases a₉,refl,exfalso,apply H9,refl,refl,
rw H9g,clear H9g,
unfold mirror,unfold nomirror,simp,
split,swap,
split,swap,
split,rw ←add_assoc,rw H4z,
split,swap,
split,swap,
split,swap,
split,swap,
split,swap,
split,swap,
split,swap,
repeat {sorry},
end
-- final boss
theorem unique_solution : βˆƒ! (a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ : square),
is_solved a₁ aβ‚‚ a₃ aβ‚„ aβ‚… a₆ a₇ aβ‚ˆ a₉ := begin
sorry
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment