{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Program.Division.ConversionRules where
open import Common.FOL.Relation.Binary.EqReasoning
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat
open import LTC-PCF.Data.Nat.Inequalities
open import LTC-PCF.Program.Division.Division
private
div-s₁ : D → D → D
div-s₁ i j = divh (fix divh) · i · j
div-s₂ : D → D → D
div-s₂ i j = fun · j
where
fun : D
fun = lam (λ j → if (lt i j)
then zero
else succ₁ (fix divh · (i ∸ j) · j))
div-s₃ : D → D → D
div-s₃ i j = if (lt i j) then zero else succ₁ (fix divh · (i ∸ j) · j)
div-s₄ : D → D → D
div-s₄ i j = if true then zero else succ₁ (fix divh · (i ∸ j) · j)
div-s₅ : D → D → D
div-s₅ i j = if false then zero else succ₁ (fix divh · (i ∸ j) · j)
div-s₆ : D
div-s₆ = zero
div-s₇ : D → D → D
div-s₇ i j = succ₁ (fix divh · (i ∸ j) · j)
proof₀₋₁ : ∀ i j → fix divh · i · j ≡ div-s₁ i j
proof₀₋₁ i j = subst (λ t → t · i · j ≡ divh (fix divh) · i · j)
(sym (fix-eq divh))
refl
proof₁₋₂ : ∀ i j → div-s₁ i j ≡ div-s₂ i j
proof₁₋₂ i j =
subst (λ t → t · j ≡ fun i · j)
(sym (beta fun i))
refl
where
fun : D → D
fun y = lam (λ j → if (lt y j)
then zero
else succ₁ (fix divh · (y ∸ j) · j))
proof₂₋₃ : ∀ i j → div-s₂ i j ≡ div-s₃ i j
proof₂₋₃ i j = beta fun j
where
fun : D → D
fun y = if (lt i y) then zero else succ₁ ((fix divh) · (i ∸ y) · y)
proof₃_₄ : ∀ i j → i < j → div-s₃ i j ≡ div-s₄ i j
proof₃_₄ i j i<j =
subst (λ t → (if t then zero else succ₁ ((fix divh) · (i ∸ j) · j)) ≡
(if true then zero else succ₁ ((fix divh) · (i ∸ j) · j)))
(sym i<j)
refl
proof₃₋₅ : ∀ i j → i ≮ j → div-s₃ i j ≡ div-s₅ i j
proof₃₋₅ i j i≮j =
subst (λ t → (if t then zero else succ₁ ((fix divh) · (i ∸ j) · j)) ≡
(if false then zero else succ₁ ((fix divh) · (i ∸ j) · j)))
(sym i≮j)
refl
proof₄₋₆ : ∀ i j → div-s₄ i j ≡ div-s₆
proof₄₋₆ i j = if-true zero
proof₅₋₇ : ∀ i j → div-s₅ i j ≡ div-s₇ i j
proof₅₋₇ i j = if-false (succ₁ (fix divh · (i ∸ j) · j))
div-x<y : ∀ {i j} → i < j → div i j ≡ zero
div-x<y {i} {j} i<j =
div i j ≡⟨ proof₀₋₁ i j ⟩
div-s₁ i j ≡⟨ proof₁₋₂ i j ⟩
div-s₂ i j ≡⟨ proof₂₋₃ i j ⟩
div-s₃ i j ≡⟨ proof₃_₄ i j i<j ⟩
div-s₄ i j ≡⟨ proof₄₋₆ i j ⟩
div-s₆ ∎
div-x≮y : ∀ {i j} → i ≮ j → div i j ≡ succ₁ (div (i ∸ j) j)
div-x≮y {i} {j} i≮j =
div i j ≡⟨ proof₀₋₁ i j ⟩
div-s₁ i j ≡⟨ proof₁₋₂ i j ⟩
div-s₂ i j ≡⟨ proof₂₋₃ i j ⟩
div-s₃ i j ≡⟨ proof₃₋₅ i j i≮j ⟩
div-s₅ i j ≡⟨ proof₅₋₇ i j ⟩
div-s₇ i j ∎