module prob1 where open import Relation.Binary.PropositionalEquality open import Relation.Binary.Core open import Data.Nat open import Data.Nat.Properties open import logic open import nat open import Data.Empty open import Data.Product open import Relation.Nullary -- open import Relation.Binary.Definitions -- All variables are positive integer -- A = -M*n + i +k*M - M -- where n is in range (0,…,k-1) and i is in range(0,…,M-1) -- Goal: Prove that A can take all values of (0,…,k*M-1) -- A1 = -M*n1 + i1 +k*M M, A2 = -M*n2 + i2 +k*M - M -- (1) If n1!=n2 or i1!=i2 then A1!=A2 -- Or its contraposition: (2) if A1=A2 then n1=n2 and i1=i2 -- Proof by contradiction: Suppose A1=A2 and (n1!=n2 or i1!=i2) becomes -- contradiction -- Induction on n and i record Cond1 (A M k : ℕ ) : Set where field n : ℕ i : ℕ range-n : n < k range-i : i < M rule1 : i + k * M ≡ M * (suc n) + A -- A ≡ (i + k * M ) - (M * (suc n)) -- k = 1 → n = 0 → ∀ M → A = i -- k = 2 → n = 1 → -- i + 2 * M = M * (suc n) + A i = suc n → A = 0 record UCond1 (A M k : ℕ ) : Set where field c1 : Cond1 A M k u1 : {j m : ℕ} → j < Cond1.i c1 → m < k → ¬ ( j + k * M ≡ M * (suc m) + A ) u2 : {j m : ℕ} → Cond1.i c1 < j → j < M → m < k → ¬ ( j + k * M ≡ M * (suc m) + A ) -- u3 : {j m : ℕ} → j < M → m < Cond1.n c1 → ¬ ( j + k * M ≡ M * (suc m) + A ) -- u4 : {j m : ℕ} → j < M → Cond1.n c1 < m → m < k → ¬ ( j + k * M ≡ M * (suc m) + A ) problem1-0 : (k A M : ℕ ) → (A A ((k - n) ) * M ) → A - ((k - n) * M) < M → Cond1 A M (suc k) cck n n ((k - n) ) * M ) → A - ((k - n) * M) < M → UCond1 A M (suc k) cck-u n n ¬a ¬b c = ⊥-elim ( nat-<> lt (<-plus {_} {_} {A} (<≤+ (s≤s c) (subst₂ (λ x y → x ≤ y ) (*-comm _ m ) (*-comm _ m ) (*≤ (s≤s (≤to< c))))))) lemma6 : {i j x : ℕ} → M + (j + x ) ≤ i + x → M ≤ i lemma6 {i} {j} {x} lt = ≤-minus {M} {i} {x} (x+y≤z→x≤z ( begin M + x + j ≡⟨ +-assoc M _ _ ⟩ M + (x + j ) ≡⟨ cong (λ k → M + k ) (+-comm x _ ) ⟩ M + (j + x) ≤⟨ lt ⟩ i + x ∎ )) where open ≤-Reasoning i : ℕ i = A - ((k - n) * M) lemma-u1 : {j : ℕ} {m1 : ℕ} → j < i → m1 < suc k → ¬ j + suc k * M ≡ M * suc m1 + A lemma-u1 {j} {m1} j (lemma6 (subst₂ (λ x y → M + x ≤ y) (sym eq) (sym (Cond1.rule1 c1 )) (lemma5 (lemma4 eq (Cond1.rule1 c1) j ¬a ¬b c = ⊥-elim (nat-<> (≤-trans i (lemma6 (subst₂ (λ x y → M + x ≤ y) (sym (Cond1.rule1 c1)) (sym eq) lemma3-2)) j0 n (k - n) * M → UCond1 A M (suc k) cc zero n (k - n) * M lemma1 a=mk = subst (λ x → (k - n) * M < suc x ) (sym (a=mk0 a=mk )) a ¬a ¬b c = cc n (less-1 n M → suc A > (k - n) * M lemma3 mk (k - k) * M start-range zero = s≤s z≤n start-range (suc k) = start-range k