{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.Division.CorrectnessProofI where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesI
open import FOTC.Data.Nat.PropertiesI
import FOTC.Data.Nat.Induction.NonAcc.WF-I
open module WFInd = FOTC.Data.Nat.Induction.NonAcc.WF-I.WFInd
open import FOTC.Program.Division.Division
open import FOTC.Program.Division.ResultI
open import FOTC.Program.Division.Specification
open import FOTC.Program.Division.TotalityI
div-x<y-correct : ∀ {i j} → N i → N j → i < j → divSpec i j (div i j)
div-x<y-correct Ni Nj i<j = div-x<y-N i<j , div-x<y-resultCorrect Ni Nj i<j
div-x≮y-correct : ∀ {i j} → N i → N j →
(∀ {i'} → N i' → i' < i → divSpec i' j (div i' j)) →
j > zero →
i ≮ j →
divSpec i j (div i j)
div-x≮y-correct {i} {j} Ni Nj ah j>0 i≮j =
div-x≮y-N ih i≮j , div-x≮y-resultCorrect Ni Nj ih i≮j
where
ih : divSpec (i ∸ j) j (div (i ∸ j) j)
ih = ah {i ∸ j}
(∸-N Ni Nj)
(x≥y→y>0→x∸y<x Ni Nj (x≮y→x≥y Ni Nj i≮j) j>0)
divCorrect : ∀ {i j} → N i → N j → j > zero → divSpec i j (div i j)
divCorrect {j = j} Ni Nj j>0 = <-wfind A ih Ni
where
A : D → Set
A d = divSpec d j (div d j)
ih : ∀ {n} → N n → (∀ {m} → N m → m < n → A m) → A n
ih {n} Nn ah =
case (div-x<y-correct Nn Nj) (div-x≮y-correct Nn Nj ah j>0) (x<y∨x≮y Nn Nj)