changeset 88:accd3d99cc86

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 31 Oct 2021 16:25:46 +0900
parents 908ed82e33c6
children c2bc4ee841af
files whileTestGears1.agda
diffstat 1 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/whileTestGears1.agda	Fri Oct 29 20:09:19 2021 +0900
+++ b/whileTestGears1.agda	Sun Oct 31 16:25:46 2021 +0900
@@ -2,7 +2,7 @@
 
 open import Function
 open import Data.Nat
-open import Data.Bool hiding ( _≟_ ;  _≤?_ ; _≤_)
+open import Data.Bool hiding ( _≟_ ;  _≤?_ ; _≤_ ; _<_ )
 open import Level renaming ( suc to succ ; zero to Zero )
 open import Relation.Nullary using (¬_; Dec; yes; no)
 open import Relation.Binary.PropositionalEquality
@@ -103,7 +103,7 @@
 
 --                                                                      ↓PreCondition(Invaliant)
 whileLoopSeg : {l : Level} {t : Set l} → {c10 :  ℕ } → (env : Env) → ((varn env) + (vari env) ≡ c10)
-   → (next : (e1 : Env )→ varn e1 + vari e1 ≡ c10 → t) 
+   → (next : (e1 : Env )→ varn e1 + vari e1 ≡ c10 → varn e1 < varn env → t) 
    → (exit : (e1 : Env )→ vari e1 ≡ c10 → t) → t
 whileLoopSeg env proof next exit with  ( suc zero  ≤? (varn  env) )
 whileLoopSeg {_} {_} {c10} env proof next exit | no p = exit env ( begin
@@ -111,10 +111,12 @@
        0 + vari env        ≡⟨ cong (λ k → k + vari env) (sym (lemma1 p )) ⟩
        varn env + vari env ≡⟨ proof ⟩
        c10 ∎ ) where open ≡-Reasoning  
-whileLoopSeg {_} {_} {c10} env proof next exit | yes p = next env1 (proof3 p ) where
+whileLoopSeg {_} {_} {c10} env proof next exit | yes p = next env1 (proof3 p ) proof4 where
       env1 = record {varn = (varn  env) - 1 ; vari = (vari env) + 1}
       1<0 : 1 ≤ zero → ⊥
       1<0 ()
+      proof4 : varn env1 < varn env
+      proof4 = {!!}
       proof3 : (suc zero  ≤ (varn  env))  → varn env1 + vari env1 ≡ c10
       proof3 (s≤s lt) with varn  env
       proof3 (s≤s z≤n) | zero = ⊥-elim (1<0 p)
@@ -127,12 +129,26 @@
              c10

 
+open import Relation.Binary.Definitions
+
+nat-≤> : { x y : ℕ } → x ≤ y → y < x → ⊥
+nat-≤>  (s≤s x<y) (s≤s y<x) = nat-≤> x<y y<x
+
 TerminatingLoop : {l : Level} {t : Set l} {c10 :  ℕ } → (i : ℕ) → (env : Env) → i ≡ varn env
    →  varn env + vari env ≡ c10 
    →  (exit : (e1 : Env )→ vari e1 ≡ c10 → t) → t
-TerminatingLoop {_} {_} {c10} zero env refl p exit = 
-     exit env p
-TerminatingLoop {_} {_} {c10} (suc i) env eq p exit = 
-     whileLoopSeg {_} {_} {c10} env p (λ e1 p1 → TerminatingLoop {_} {_} {c10} i e1 (lemma2 e1 p1 eq) p1 exit) exit where
-         lemma2 :  (e1 : Env) → varn e1 + vari e1 ≡ c10 →  suc i ≡ varn env → i ≡ varn e1
-         lemma2 = {!!}
+TerminatingLoop {_} {t} {c10} i env refl p exit with <-cmp 0 i
+... | tri≈ ¬a b ¬c = whileLoopSeg {_} {t} {c10} env p (λ e1 eq lt → ⊥-elim (lemma3 e1 b lt) ) exit where
+    lemma3 : (e1 : Env) → 0 ≡ varn env → varn e1 < varn env → ⊥
+    lemma3 e refl ()
+... | tri< a ¬b ¬c = whileLoopSeg {_} {t} {c10} env p (TerminatingLoop1 i) exit where
+    TerminatingLoop1 : (j : ℕ) → (e1 : Env) → varn e1 + vari e1 ≡ c10 → varn e1 < varn env → t
+    TerminatingLoop1 zero e1 eq lt = whileLoopSeg {_} {t} {c10} env p {!!} exit 
+    TerminatingLoop1 (suc j) e1 eq lt with <-cmp j (varn e1)
+    ... | tri< (s≤s a) ¬b ¬c = TerminatingLoop1 j e1 {!!} {!!}
+    ... | tri≈ ¬a b ¬c = whileLoopSeg {_} {t} {c10} e1 {!!} lemma4 exit where
+       lemma4 : (e2 : Env) → varn e2 + vari e2 ≡ c10 → varn e2 < varn e1 → t
+       lemma4 e2 eq lt = TerminatingLoop1 j {!!} {!!} {!!}
+    ... | tri> ¬a ¬b c =  ⊥-elim ( nat-≤> lt {!!} )
+
+