Tom de Jong, 27 May 2019. Refactored December 2021. * Continuous K and S functions. These will interpret the K and S combinators of PCF in ScottModelOfPCF.lagda. * Continuous ifZero function specific to the lifting of the natural numbers. This will then be used to interpret the ifZero combinator of PCF in ScottModelOfPCF.lagda. \begin{code} {-# OPTIONS --safe --without-K #-} open import MLTT.Spartan open import UF.FunExt open import UF.PropTrunc module PCF.Combinatory.PCFCombinators (pt : propositional-truncations-exist) (fe : Fun-Ext) (π₯ : Universe) where open PropositionalTruncation pt open import UF.Subsingletons open import DomainTheory.Basics.Dcpo pt fe π₯ open import DomainTheory.Basics.Exponential pt fe π₯ open import DomainTheory.Basics.Miscelanea pt fe π₯ open import DomainTheory.Basics.Pointed pt fe π₯ \end{code} We start by defining continuous K and S functions. These will interpret the K and S combinators of PCF in ScottModelOfPCF.lagda. This requires a little (straightforward) work, because S must be continuous in all of its arguments. Therefore, it is not enough to have S of type DCPO[ π , π βΉα΅αΆα΅α΅ π ] β DCPO[ π , π ] β DCPO[ π , π ]. Rather we should have S of type DCPO[π βΉα΅αΆα΅α΅ π βΉα΅αΆα΅α΅ π , (π βΉα΅αΆα΅α΅ π) βΉα΅αΆα΅α΅ (π βΉα΅αΆα΅α΅ π) ]. \begin{code} module _ (π : DCPO {π€} {π£}) (π : DCPO {π€'} {π£'}) where Kα΅αΆα΅α΅ : DCPO[ π , π βΉα΅αΆα΅α΅ π ] Kα΅αΆα΅α΅ = k , c where k : β¨ π β© β DCPO[ π , π ] k x = ((Ξ» _ β x) , constant-functions-are-continuous π π) c : (I : π₯ Μ ) (Ξ± : I β β¨ π β©) (Ξ΄ : is-Directed π Ξ±) β is-sup (underlying-order (π βΉα΅αΆα΅α΅ π)) (k (β π Ξ΄)) (Ξ» (i : I) β k (Ξ± i)) c I Ξ± Ξ΄ = u , v where u : (i : I) (e : β¨ π β©) β Ξ± i ββ¨ π β© (β π Ξ΄) u i e = β-is-upperbound π Ξ΄ i v : (f : DCPO[ π , π ]) β ((i : I) β k (Ξ± i) ββ¨ π βΉα΅αΆα΅α΅ π β© f) β (e : β¨ π β©) β β π Ξ΄ ββ¨ π β© [ π , π ]β¨ f β© e v (f , _) l e = β-is-lowerbound-of-upperbounds π Ξ΄ (f e) (Ξ» (i : I) β (l i) e) module _ (π : DCPO {π¦} {π¦'}) where Sβα΅αΆα΅α΅ : DCPO[ π , π βΉα΅αΆα΅α΅ π ] β DCPO[ π , π ] β DCPO[ π , π ] Sβα΅αΆα΅α΅ (f , cf) (g , cg) = (Ξ» x β [ π , π ]β¨ f x β© (g x)) , c where c : is-continuous π π (Ξ» x β [ π , π ]β¨ f x β© (g x)) c I Ξ± Ξ΄ = u , v where u : (i : I) β [ π , π ]β¨ f (Ξ± i) β© (g (Ξ± i)) ββ¨ π β© [ π , π ]β¨ f (β π Ξ΄) β© (g (β π Ξ΄)) u i = [ π , π ]β¨ f (Ξ± i) β© (g (Ξ± i)) ββ¨ π β©[ β¦ 1β¦ ] [ π , π ]β¨ f (β π Ξ΄) β© (g (Ξ± i)) ββ¨ π β©[ β¦ 2β¦ ] [ π , π ]β¨ f (β π Ξ΄) β© (g (β π Ξ΄)) ββ¨ π β© where β¦ 1β¦ = monotone-if-continuous π (π βΉα΅αΆα΅α΅ π) (f , cf) (Ξ± i) (β π Ξ΄) (β-is-upperbound π Ξ΄ i) (g (Ξ± i)) β¦ 2β¦ = monotone-if-continuous π π (f (β π Ξ΄)) (g (Ξ± i)) (g (β π Ξ΄)) (monotone-if-continuous π π (g , cg) (Ξ± i) (β π Ξ΄) (β-is-upperbound π Ξ΄ i)) v : (y : β¨ π β©) β ((i : I) β ([ π , π ]β¨ f (Ξ± i) β© (g (Ξ± i))) ββ¨ π β© y) β ([ π , π ]β¨ f (β π Ξ΄) β© (g (β π Ξ΄))) ββ¨ π β© y v y ineqs = Ξ³ where Ξ³ : [ π , π ]β¨ f (β π Ξ΄) β© (g (β π Ξ΄)) ββ¨ π β© y Ξ³ = transport (Ξ» - β [ π , π ]β¨ f (β π Ξ΄) β© - ββ¨ π β© y) eβ Ξ³β where eβ : β π (image-is-directed' π π (g , cg) Ξ΄) οΌ g (β π Ξ΄) eβ = (continuous-β-οΌ π π (g , cg) Ξ΄) β»ΒΉ Ξ΅β : is-Directed π (g β Ξ±) Ξ΅β = image-is-directed' π π (g , cg) Ξ΄ Ξ³β : [ π , π ]β¨ f (β π Ξ΄) β© (β π Ξ΅β) ββ¨ π β© y Ξ³β = transport (Ξ» - β - ββ¨ π β© y) eβ Ξ³β where eβ : β π (image-is-directed' π π (f (β π Ξ΄)) Ξ΅β) οΌ [ π , π ]β¨ f (β π Ξ΄) β© (β π Ξ΅β) eβ = (continuous-β-οΌ π π (f (β π Ξ΄)) Ξ΅β) β»ΒΉ Ξ΅β : is-Directed π ([ π , π ]β¨ f (β π Ξ΄) β© β (g β Ξ±)) Ξ΅β = image-is-directed' π π (f (β π Ξ΄)) Ξ΅β Ξ³β : (β π Ξ΅β) ββ¨ π β© y Ξ³β = β-is-lowerbound-of-upperbounds π Ξ΅β y Ξ³β where Ξ³β : (i : I) β [ π , π ]β¨ f (β π Ξ΄) β© (g (Ξ± i)) ββ¨ π β© y Ξ³β i = transport (Ξ» - β [ π , π ]β¨ - β© (g (Ξ± i)) ββ¨ π β© y) eβ Ξ³β where Ξ΅β : is-Directed (π βΉα΅αΆα΅α΅ π) (f β Ξ±) Ξ΅β = image-is-directed' π (π βΉα΅αΆα΅α΅ π) (f , cf) Ξ΄ eβ : β (π βΉα΅αΆα΅α΅ π) {I} {f β Ξ±} Ξ΅β οΌ f (β π Ξ΄) eβ = (continuous-β-οΌ π (π βΉα΅αΆα΅α΅ π) (f , cf) Ξ΄) β»ΒΉ Ξ³β : [ π , π ]β¨ β (π βΉα΅αΆα΅α΅ π) {I} {f β Ξ±} Ξ΅β β© (g (Ξ± i)) ββ¨ π β© y Ξ³β = β-is-lowerbound-of-upperbounds π (pointwise-family-is-directed π π (f β Ξ±) Ξ΅β (g (Ξ± i))) y h where h : (j : I) β [ π , π ]β¨ f (Ξ± j) β© (g (Ξ± i)) ββ¨ π β© y h j = β₯β₯-rec (prop-valuedness π ([ π , π ]β¨ f (Ξ± j) β© (g (Ξ± i))) y) r (semidirected-if-Directed π Ξ± Ξ΄ i j) where r : (Ξ£ k κ I , Ξ± i ββ¨ π β© Ξ± k Γ Ξ± j ββ¨ π β© Ξ± k) β [ π , π ]β¨ f (Ξ± j) β© (g (Ξ± i)) ββ¨ π β© y r (k , l , m ) = [ π , π ]β¨ f (Ξ± j) β© (g (Ξ± i)) ββ¨ π β©[ β¦ 1β¦ ] [ π , π ]β¨ f (Ξ± k) β© (g (Ξ± i)) ββ¨ π β©[ β¦ 2β¦ ] [ π , π ]β¨ f (Ξ± k) β© (g (Ξ± k)) ββ¨ π β©[ β¦ 3β¦ ] y ββ¨ π β© where β¦ 1β¦ = monotone-if-continuous π (π βΉα΅αΆα΅α΅ π) (f , cf) (Ξ± j) (Ξ± k) m (g (Ξ± i)) β¦ 2β¦ = monotone-if-continuous π π (f (Ξ± k)) (g (Ξ± i)) (g (Ξ± k)) (monotone-if-continuous π π (g , cg) (Ξ± i) (Ξ± k) l) β¦ 3β¦ = ineqs k Sβα΅αΆα΅α΅ : DCPO[ π , π βΉα΅αΆα΅α΅ π ] β DCPO[ π βΉα΅αΆα΅α΅ π , π βΉα΅αΆα΅α΅ π ] Sβα΅αΆα΅α΅ (f , cf) = h , c where h : DCPO[ π , π ] β DCPO[ π , π ] h = (Sβα΅αΆα΅α΅ (f , cf)) c : is-continuous (π βΉα΅αΆα΅α΅ π) (π βΉα΅αΆα΅α΅ π) h c I Ξ± Ξ΄ = u , v where u : (i : I) (d : β¨ π β©) β [ π , π ]β¨ h (Ξ± i) β© d ββ¨ π β© [ π , π ]β¨ h (β (π βΉα΅αΆα΅α΅ π) {I} {Ξ±} Ξ΄ )β© d u i d = monotone-if-continuous π π (f d) ([ π , π ]β¨ Ξ± i β© d) ([ π , π ]β¨ β (π βΉα΅αΆα΅α΅ π) {I} {Ξ±} Ξ΄ β© d) (β-is-upperbound π (pointwise-family-is-directed π π Ξ± Ξ΄ d) i) v : (g : DCPO[ π , π ]) β ((i : I) β h (Ξ± i) ββ¨ π βΉα΅αΆα΅α΅ π β© g) β (d : β¨ π β©) β [ π , π ]β¨ h (β (π βΉα΅αΆα΅α΅ π) {I} {Ξ±} Ξ΄) β© d ββ¨ π β© [ π , π ]β¨ g β© d v g l d = transport (Ξ» - β - ββ¨ π β© [ π , π ]β¨ g β© d) e s where Ξ΅ : is-Directed π (pointwise-family π π Ξ± d) Ξ΅ = pointwise-family-is-directed π π Ξ± Ξ΄ d e : β π (image-is-directed' π π (f d) Ξ΅) οΌ [ π , π ]β¨ h (β (π βΉα΅αΆα΅α΅ π) {I} {Ξ±} Ξ΄) β© d e = (continuous-β-οΌ π π (f d) Ξ΅) β»ΒΉ Ο : is-Directed π ([ π , π ]β¨ f d β© β (pointwise-family π π Ξ± d)) Ο = image-is-directed' π π (f d) Ξ΅ s : β π Ο ββ¨ π β© [ π , π ]β¨ g β© d s = β-is-lowerbound-of-upperbounds π Ο ([ π , π ]β¨ g β© d) (Ξ» (i : I) β l i d) Sα΅αΆα΅α΅ : DCPO[ π βΉα΅αΆα΅α΅ π βΉα΅αΆα΅α΅ π , (π βΉα΅αΆα΅α΅ π) βΉα΅αΆα΅α΅ (π βΉα΅αΆα΅α΅ π) ] Sα΅αΆα΅α΅ = Sβα΅αΆα΅α΅ , c where c : is-continuous (π βΉα΅αΆα΅α΅ π βΉα΅αΆα΅α΅ π) ((π βΉα΅αΆα΅α΅ π) βΉα΅αΆα΅α΅ (π βΉα΅αΆα΅α΅ π)) Sβα΅αΆα΅α΅ c I Ξ± Ξ΄ = u , v where u : (i : I) ((g , _) : DCPO[ π , π ]) (d : β¨ π β©) β [ π , π ]β¨ [ π , π βΉα΅αΆα΅α΅ π ]β¨ Ξ± i β© d β© (g d) ββ¨ π β© [ π , π ]β¨ [ π , π βΉα΅αΆα΅α΅ π ]β¨ β (π βΉα΅αΆα΅α΅ (π βΉα΅αΆα΅α΅ π)) {I} {Ξ±} Ξ΄ β© d β© (g d) u i (g , _) d = β-is-upperbound π (pointwise-family-is-directed π π Ξ² Ξ΅ (g d)) i where Ξ² : I β DCPO[ π , π ] Ξ² = pointwise-family π (π βΉα΅αΆα΅α΅ π) Ξ± d Ξ΅ : is-Directed (π βΉα΅αΆα΅α΅ π) Ξ² Ξ΅ = pointwise-family-is-directed π (π βΉα΅αΆα΅α΅ π) Ξ± Ξ΄ d v : (f : DCPO[ π βΉα΅αΆα΅α΅ π , π βΉα΅αΆα΅α΅ π ]) β ((i : I) β Sβα΅αΆα΅α΅ (Ξ± i) ββ¨ (π βΉα΅αΆα΅α΅ π) βΉα΅αΆα΅α΅ (π βΉα΅αΆα΅α΅ π) β© f) β (g : DCPO[ π , π ]) (d : β¨ π β©) β [ π , π ]β¨ [ π , π βΉα΅αΆα΅α΅ π ]β¨ β (π βΉα΅αΆα΅α΅ (π βΉα΅αΆα΅α΅ π)) {I} {Ξ±} Ξ΄ β© d β© ([ π , π ]β¨ g β© d) ββ¨ π β© [ π , π ]β¨ [ π βΉα΅αΆα΅α΅ π , π βΉα΅αΆα΅α΅ π ]β¨ f β© g β© d v (f , _) l g d = β-is-lowerbound-of-upperbounds π Ξ΅ ([ π , π ]β¨ f g β© d) (Ξ» (i : I) β l i g d) where Ξ΅ : is-Directed π (Ξ» i β [ π , π ]β¨ [ π βΉα΅αΆα΅α΅ π , π βΉα΅αΆα΅α΅ π ]β¨ Sβα΅αΆα΅α΅ (Ξ± i) β© g β© d) Ξ΅ = pointwise-family-is-directed π π Ξ² Ο ([ π , π ]β¨ g β© d) where Ξ² : I β DCPO[ π , π ] Ξ² i = [ π , π βΉα΅αΆα΅α΅ π ]β¨ Ξ± i β© d Ο : is-Directed (π βΉα΅αΆα΅α΅ π) Ξ² Ο = pointwise-family-is-directed π (π βΉα΅αΆα΅α΅ π) Ξ± Ξ΄ d module _ (π : DCPOβ₯ {π€} {π£}) (π : DCPOβ₯ {π€'} {π£'}) where Kα΅αΆα΅α΅β₯ : DCPOβ₯[ π , π βΉα΅αΆα΅α΅β₯ π ] Kα΅αΆα΅α΅β₯ = Kα΅αΆα΅α΅ (π β») (π β») Sα΅αΆα΅α΅β₯ : (π : DCPOβ₯ {π¦} {π¦'}) β DCPOβ₯[ π βΉα΅αΆα΅α΅β₯ π βΉα΅αΆα΅α΅β₯ π , (π βΉα΅αΆα΅α΅β₯ π) βΉα΅αΆα΅α΅β₯ (π βΉα΅αΆα΅α΅β₯ π) ] Sα΅αΆα΅α΅β₯ π = Sα΅αΆα΅α΅ (π β») (π β») (π β») \end{code} Finally, we construct the continuous ifZero function, specific to the lifting of β. This will then be used to interpret the ifZero combinator of PCF in ScottModelOfPCF.lagda. \begin{code} module IfZeroDenotationalSemantics (pe : propext π₯) where open import Lifting.Construction π₯ open import Lifting.Miscelanea π₯ open import Lifting.Miscelanea-PropExt-FunExt π₯ pe fe open import Lifting.Monad π₯ open import DomainTheory.Lifting.LiftingSet pt fe π₯ pe open import UF.DiscreteAndSeparated open import Naturals.Properties πα΅β : DCPOβ₯ {π₯ βΊ} {π₯ βΊ} πα΅β = π-DCPOβ₯ β-is-set β¦ ifZeroβ¦β : π β β π β β β β π β β¦ ifZeroβ¦β a b zero = a β¦ ifZeroβ¦β a b (succ n) = b β¦ ifZeroβ¦β : π β β π β β DCPOβ₯[ πα΅β , πα΅β ] β¦ ifZeroβ¦β a b = (β¦ ifZeroβ¦β a b) β― , β―-is-continuous β-is-set β-is-set (β¦ ifZeroβ¦β a b) β¦ ifZeroβ¦β : π β β DCPOβ₯[ πα΅β , πα΅β βΉα΅αΆα΅α΅β₯ πα΅β ] β¦ ifZeroβ¦β a = β¦ ifZeroβ¦β a , c where c : is-continuous (πα΅β β») ((πα΅β βΉα΅αΆα΅α΅β₯ πα΅β) β») (β¦ ifZeroβ¦β a) c I Ξ± Ξ΄ = u , v where u : (i : I) (l : π β) (d : is-defined (((β¦ ifZeroβ¦β a (Ξ± i)) β―) l)) β ((β¦ ifZeroβ¦β a (Ξ± i)) β―) l οΌ ((β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) β―) l u i l d = ((β¦ ifZeroβ¦β a (Ξ± i)) β―) l οΌβ¨ qβ β© β¦ ifZeroβ¦β a (Ξ± i) (value l e) οΌβ¨ qβ β© β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) οΌβ¨ qβ β© ((β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) β―) l β where e : is-defined l e = β―-is-defined (β¦ ifZeroβ¦β a (Ξ± i)) l d qβ = β―-on-total-element (β¦ ifZeroβ¦β a (Ξ± i)) e qβ = (β―-on-total-element (β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) {l} e) β»ΒΉ qβ = β-cases {π₯ βΊ} {Ξ» (n : β) β β¦ ifZeroβ¦β a (Ξ± i) n οΌ β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) n} (value l e) pβ pβ where pβ : value l e οΌ zero β β¦ ifZeroβ¦β a (Ξ± i) (value l e) οΌ β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) pβ q = β¦ ifZeroβ¦β a (Ξ± i) (value l e) οΌβ¨ ap (β¦ ifZeroβ¦β a (Ξ± i)) q β© β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) zero οΌβ¨ ap (β¦ ifZeroβ¦β a _) (q β»ΒΉ) β© β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) β pβ : (n : β) β value l e οΌ succ n β β¦ ifZeroβ¦β a (Ξ± i) (value l e) οΌ β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) pβ n q = β¦ ifZeroβ¦β a (Ξ± i) (value l e) οΌβ¨ β¦ 1β¦ β© β¦ ifZeroβ¦β a (Ξ± i) (succ n) οΌβ¨ refl β© Ξ± i οΌβ¨ β¦ 2β¦ β© β (πα΅β β») Ξ΄ οΌβ¨ refl β© β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (succ n) οΌβ¨ β¦ 3β¦ β© β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) β where β¦ 1β¦ = ap (β¦ ifZeroβ¦β a (Ξ± i)) q β¦ 3β¦ = ap (β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) (q β»ΒΉ) β¦ 2β¦ = family-defined-somewhere-sup-οΌ β-is-set Ξ΄ i eα΅’ where eα΅’ : is-defined (Ξ± i) eα΅’ = οΌ-to-is-defined (ap (β¦ ifZeroβ¦β a (Ξ± i)) q) (οΌ-to-is-defined (β―-on-total-element (β¦ ifZeroβ¦β a (Ξ± i)) {l} e) d) v : (f : DCPOβ₯[ πα΅β , πα΅β ]) β ((i : I) β β¦ ifZeroβ¦β a (Ξ± i) ββͺ πα΅β βΉα΅αΆα΅α΅β₯ πα΅β β« f) β (l : π β) (d : is-defined (((β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) β―) l)) β ((β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) β―) l οΌ [ πα΅β β» , πα΅β β» ]β¨ f β© l v (f , _) ineqs l d = ((β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) β―) l οΌβ¨ qβ β© β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) οΌβ¨ qβ β© f l β where e : is-defined l e = β―-is-defined (β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) l d qβ = β―-on-total-element (β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) {l} e qβ = β-cases {π₯ βΊ} {Ξ» (n : β) β β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) n οΌ f l} (value l e) pβ pβ where pβ : value l e οΌ zero β β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) οΌ f l pβ q = β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) οΌβ¨ β¦ 1β¦ β© β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) zero οΌβ¨ refl β© a οΌβ¨ β¦ 2β¦ β© f l β where β¦ 1β¦ = ap (β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) q β¦ 2β¦ = β₯β₯-rec (lifting-of-set-is-set β-is-set) h (inhabited-if-Directed (πα΅β β») Ξ± Ξ΄) where h : (i : I) β a οΌ f l h i = a οΌβ¨ β¦ 1'β¦ β© β¦ ifZeroβ¦β a (Ξ± i) (value l e) οΌβ¨ β¦ 2'β¦ β© ((β¦ ifZeroβ¦β a (Ξ± i)) β―) l οΌβ¨ β¦ 3'β¦ β© f l β where β¦ 1'β¦ = ap (β¦ ifZeroβ¦β a (Ξ± i)) (q β»ΒΉ) β¦ 2'β¦ = (β―-on-total-element (β¦ ifZeroβ¦β a (Ξ± i)) e) β»ΒΉ β¦ 3'β¦ = ineqs i l (οΌ-to-is-defined r d) where r : ((β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) β―) l οΌ ((β¦ ifZeroβ¦β a (Ξ± i)) β―) l r = qβ β β¦ 1β¦ β β¦ 1'β¦ β β¦ 2'β¦ pβ : (m : β) β value l e οΌ succ m β β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) οΌ f l pβ m q = β₯β₯-rec (lifting-of-set-is-set β-is-set) h e' where β¦ 1β¦ : (β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) β―) l οΌ β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) β¦ 1β¦ = β―-on-total-element (β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) {l} e β¦ 2β¦ : β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) οΌ β (πα΅β β») Ξ΄ β¦ 2β¦ = ap (β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄)) q e' : is-defined (β (πα΅β β») Ξ΄) e' = οΌ-to-is-defined (β¦ 1β¦ β β¦ 2β¦) d h : (Ξ£ i κ I , is-defined (Ξ± i)) β β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) οΌ f l h (i , dα΅’) = β¦ ifZeroβ¦β a (β (πα΅β β») Ξ΄) (value l e) οΌβ¨ β¦ 1'β¦ β© β (πα΅β β») Ξ΄ οΌβ¨ β¦ 2'β¦ β© Ξ± i οΌβ¨ β¦ 3'β¦ β© ((β¦ ifZeroβ¦β a (Ξ± i)) β―) l οΌβ¨ β¦ 4'β¦ β© f l β where β¦ 1'β¦ = β¦ 2β¦ β¦ 2'β¦ = (family-defined-somewhere-sup-οΌ β-is-set Ξ΄ i dα΅’) β»ΒΉ β¦ 3'β¦ = (β―-on-total-element (β¦ ifZeroβ¦β a (Ξ± i)) e β ap (β¦ ifZeroβ¦β a (Ξ± i)) q) β»ΒΉ β¦ 4'β¦ = ineqs i l (οΌ-to-is-defined β¦ 3'β¦ dα΅’) \end{code} We can exploit the fact that ifZero a b 0 οΌ ifZero b a 1, to reduce the proof that ifZero is continuous in its first argument to continuity in its second argument. The "flip"-code below prepares for this. \begin{code} β-flip : β β β β-flip zero = succ zero β-flip (succ n) = zero ifZero-flip-equation : (a b : π β) (n : β) β β¦ ifZeroβ¦β a b n οΌ β¦ ifZeroβ¦β b a (β-flip n) ifZero-flip-equation a b zero = refl ifZero-flip-equation a b (succ n) = refl πβ-flip : π β β π β πβ-flip (P , Ο , Ο) = (P , β-flip β Ο , Ο) ifZeroβ―-flip-equation : (a b : π β) (l : π β) β ((β¦ ifZeroβ¦β a b) β―) l οΌ ((β¦ ifZeroβ¦β b a) β―) (πβ-flip l) ifZeroβ―-flip-equation a b l = β'-is-antisymmetric u v where l' : π β l' = πβ-flip l lemma : (p : is-defined l) β (β¦ ifZeroβ¦β a b β―) l οΌ (β¦ ifZeroβ¦β b a β―) l' lemma p = (β¦ ifZeroβ¦β a b β―) l οΌβ¨ β¦ 1β¦ β© β¦ ifZeroβ¦β a b (value l p) οΌβ¨ β¦ 2β¦ β© β¦ ifZeroβ¦β b a (value l' p) οΌβ¨ β¦ 3β¦ β© (β¦ ifZeroβ¦β b a β―) l' β where β¦ 1β¦ = β―-on-total-element (β¦ ifZeroβ¦β a b) p β¦ 2β¦ = ifZero-flip-equation a b (value l p) β¦ 3β¦ = (β―-on-total-element (β¦ ifZeroβ¦β b a) p) β»ΒΉ u : (β¦ ifZeroβ¦β a b β―) l β' (β¦ ifZeroβ¦β b a β―) l' u q = lemma (β―-is-defined (β¦ ifZeroβ¦β a b) l q) v : (β¦ ifZeroβ¦β b a β―) l' β' (β¦ ifZeroβ¦β a b β―) l v q = (lemma (β―-is-defined (β¦ ifZeroβ¦β b a) l' q)) β»ΒΉ \end{code} We are now ready to give the final continuity proof. \begin{code} β¦ ifZeroβ¦ : DCPOβ₯[ πα΅β , πα΅β βΉα΅αΆα΅α΅β₯ πα΅β βΉα΅αΆα΅α΅β₯ πα΅β ] β¦ ifZeroβ¦ = β¦ ifZeroβ¦β , c where c : is-continuous (πα΅β β») ((πα΅β βΉα΅αΆα΅α΅β₯ πα΅β βΉα΅αΆα΅α΅β₯ πα΅β) β») β¦ ifZeroβ¦β c I Ξ± Ξ΄ = u , v where u : (i : I) (b : π β) (l : π β) β ((β¦ ifZeroβ¦β (Ξ± i) b) β―) l ββͺ πα΅β β« ((β¦ ifZeroβ¦β (β (πα΅β β») Ξ΄) b) β―) l u i b l = ((β¦ ifZeroβ¦β (Ξ± i) b) β―) l ββͺ πα΅β β«[ β¦ 1β¦ ] ((β¦ ifZeroβ¦β b (Ξ± i)) β―) l' ββͺ πα΅β β«[ β¦ 2β¦ ] ((β¦ ifZeroβ¦β b (β (πα΅β β») Ξ΄)) β―) l' ββͺ πα΅β β«[ β¦ 3β¦ ] ((β¦ ifZeroβ¦β (β (πα΅β β») Ξ΄) b) β―) l ββͺ πα΅β β« where l' : π β l' = πβ-flip l β¦ 1β¦ = οΌ-to-β (πα΅β β») (ifZeroβ―-flip-equation (Ξ± i) b l) β¦ 2β¦ = (monotone-if-continuous (πα΅β β») ((πα΅β βΉα΅αΆα΅α΅β₯ πα΅β) β») (β¦ ifZeroβ¦β b) (Ξ± i) (β (πα΅β β») Ξ΄) (β-is-upperbound (πα΅β β») Ξ΄ i)) l' β¦ 3β¦ = οΌ-to-β (πα΅β β») (ifZeroβ―-flip-equation (β (πα΅β β») Ξ΄) b l) v : ((f , _) : DCPOβ₯[ πα΅β , πα΅β βΉα΅αΆα΅α΅β₯ πα΅β ]) β ((i : I) (b : π β) β β¦ ifZeroβ¦β (Ξ± i) b ββͺ πα΅β βΉα΅αΆα΅α΅β₯ πα΅β β« f b) β (b : π β) (l : π β) β ((β¦ ifZeroβ¦β (β (πα΅β β») Ξ΄) b) β―) l ββͺ πα΅β β« [ πα΅β β» , πα΅β β» ]β¨ f b β© l v (f , _) ineqs b l = ((β¦ ifZeroβ¦β (β (πα΅β β») Ξ΄) b) β―) l ββͺ πα΅β β«[ β¦ 1β¦ ] ((β¦ ifZeroβ¦β b (β (πα΅β β») Ξ΄)) β―) l' ββͺ πα΅β β«[ β¦ 2β¦ ] [ πα΅β β» , πα΅β β» ]β¨ β¦ ifZeroβ¦β b (β (πα΅β β») Ξ΄) β© l' ββͺ πα΅β β«[ β¦ 3β¦ ] β (πα΅β β») {I} {Ξ±'} Ξ΄' ββͺ πα΅β β«[ β¦ 4β¦ ] β (πα΅β β») {I} {Ξ±''} Ξ΄'' ββͺ πα΅β β«[ β¦ 5β¦ ] [ πα΅β β» , πα΅β β» ]β¨ f b β© l ββͺ πα΅β β« where l' : π β l' = πβ-flip l Ξ±' : (i : I) β βͺ πα΅β β« Ξ±' i = ((β¦ ifZeroβ¦β b (Ξ± i)) β―) l' Ξ΄' : is-Directed (πα΅β β») Ξ±' Ξ΄' = pointwise-family-is-directed (πα΅β β») (πα΅β β») (β¦ ifZeroβ¦β b β Ξ±) Ξ΅ l' where Ξ΅ : is-Directed ((πα΅β βΉα΅αΆα΅α΅β₯ πα΅β) β») (β¦ ifZeroβ¦β b β Ξ±) Ξ΅ = image-is-directed' (πα΅β β») ((πα΅β βΉα΅αΆα΅α΅β₯ πα΅β) β») (β¦ ifZeroβ¦β b) Ξ΄ Ξ±'' : (i : I) β βͺ πα΅β β« Ξ±'' i = ((β¦ ifZeroβ¦β (Ξ± i) b) β―) l e : Ξ±' οΌ Ξ±'' e = dfunext fe (Ξ» i β (ifZeroβ―-flip-equation (Ξ± i) b l) β»ΒΉ) Ξ΄'' : is-Directed (πα΅β β») Ξ±'' Ξ΄'' = transport (is-Directed (πα΅β β»)) e Ξ΄' β¦ 1β¦ = οΌ-to-β (πα΅β β») (ifZeroβ―-flip-equation (β (πα΅β β») Ξ΄) b l) β¦ 2β¦ = reflexivity (πα΅β β») _ β¦ 3β¦ = οΌ-to-β (πα΅β β») (ap (Ξ» - β [ πα΅β β» , πα΅β β» ]β¨ - β© l') (continuous-β-οΌ (πα΅β β») ((πα΅β βΉα΅αΆα΅α΅β₯ πα΅β) β») (β¦ ifZeroβ¦β b) {I} {Ξ±} Ξ΄)) β¦ 4β¦ = οΌ-to-β (πα΅β β») (β-family-οΌ (πα΅β β») e Ξ΄') β¦ 5β¦ = β-is-lowerbound-of-upperbounds (πα΅β β») Ξ΄'' ([ πα΅β β» , πα΅β β» ]β¨ f b β© l) (Ξ» i β ineqs i b l) \end{code}