open import Data.Parity.Base
open import Data.Parity.Properties
open import Data.List using (List)
renaming (
_∷_ to _l∷_; [] to l[]; _++_ to _l++_;
map to lmap
)
open import Data.Vec
open import Data.Vec.Properties
open import Data.Nat using (ℕ)
renaming (_<_ to _ℕ<_; _≥_ to _ℕ≥_)
open import Data.Fin using (
Fin; suc; zero;
pred;
fromℕ; fromℕ<;
inject₁
)
open import Data.Fin.Properties
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Data.Empty
_Cups : ℕ → Set
n Cups = Vec Parity n
open Parity
initS : 5 Cups
initS = 0ℙ ∷ 0ℙ ∷ 1ℙ ∷ 1ℙ ∷ 0ℙ ∷ []
target : 5 Cups
target = 1ℙ ∷ 1ℙ ∷ 1ℙ ∷ 1ℙ ∷ 1ℙ ∷ []
module Actions where
{-# TERMINATING #-}
half-actions : ∀ {m} → Fin m → Fin m → List (Fin m × Fin m)
half-actions cnt zero = l[]
half-actions cnt x = ( cnt , pred x ) l∷ (half-actions cnt (pred x))
all-actions : ∀ {n} → n Cups → List (Fin n × Fin n)
all-actions {ℕ.zero} _ = l[]
all-actions {ℕ.suc n'} (_ ∷ cups') =
let cnt = fromℕ n'
as = half-actions cnt cnt
recur = all-actions cups'
in as l++ (lmap (λ (a , b) → ( inject₁ a , inject₁ b)) recur)
χ : ∀ {n} → n Cups → Parity
χ [] = 0ℙ
χ (x ∷ cups) = χ cups + x
lemma₁ : χ initS ≡ 0ℙ
lemma₁ = refl
lemma₂ : χ target ≡ 1ℙ
lemma₂ = refl
module Lemma where
helper : ∀ {p} → p ⁻¹ ≡ p + 1ℙ
helper {0ℙ} = refl
helper {1ℙ} = refl
helper₂ : ∀ {p} → p ≡ p + 0ℙ
helper₂ {0ℙ} = refl
helper₂ {1ℙ} = refl
helper₃ : ∀ {p} → p ≡ p ⁻¹ ⁻¹
helper₃ {0ℙ} = refl
helper₃ {1ℙ} = refl
open ≡-Reasoning
lemma : ∀ {n} → (i : Fin n) → (a : n Cups)
→ χ (a [ i ]%= _⁻¹) ≡ χ a ⁻¹
lemma zero (0ℙ ∷ a') =
begin
χ a' + 1ℙ ≡⟨ sym helper ⟩
χ a' ⁻¹ ≡⟨ cong _⁻¹ helper₂ ⟩
(χ a' + 0ℙ) ⁻¹
∎
lemma zero (1ℙ ∷ a') =
begin
χ a' + 0ℙ ≡⟨ sym helper₂ ⟩
χ a' ≡⟨ helper₃ ⟩
χ a' ⁻¹ ⁻¹ ≡⟨ cong _⁻¹ helper ⟩
(χ a' + 1ℙ) ⁻¹
∎
lemma (suc i') (0ℙ ∷ a') =
begin
χ (updateAt a' i' _⁻¹) + 0ℙ ≡⟨ sym helper₂ ⟩
χ (updateAt a' i' _⁻¹) ≡⟨ lemma i' a' ⟩
χ a' ⁻¹ ≡⟨ cong _⁻¹ helper₂ ⟩
(χ a' + 0ℙ) ⁻¹
∎
lemma (suc i') (1ℙ ∷ a') =
begin
χ (updateAt a' i' _⁻¹) + 1ℙ ≡⟨ sym helper ⟩
χ (updateAt a' i' _⁻¹) ⁻¹ ≡⟨ cong _⁻¹ (lemma i' a') ⟩
χ a' ⁻¹ ⁻¹ ≡⟨ sym (cong _⁻¹ (sym helper)) ⟩
(χ a' + 1ℙ) ⁻¹
∎
theorem : ∀ {n} → (i j : Fin n) → (a : n Cups)
→ χ ((a [ i ]%= _⁻¹) [ j ]%= _⁻¹) ≡ χ a
theorem i j a =
begin
χ (updateAt (updateAt a i _⁻¹) j _⁻¹) ≡⟨ lemma j (a [ i ]%= _⁻¹) ⟩
χ (updateAt a i _⁻¹)⁻¹ ≡⟨ ⁻¹-selfInverse (sym (lemma i a)) ⟩
χ a
∎ where open ≡-Reasoning
open Lemma
_⇒¬_ : ∀ {n} → n Cups → n Cups → Set
a ⇒¬ b = χ a ≡ χ b → ⊥