{-# OPTIONS --cubical-compatible --safe #-} open import Data.Product.Base using (Σ; _,_) open import Data.Sum.Base using (_⊎_; inj₁; inj₂) open import Level using (Level) module WG21-Vihula84-final where {- Harrop formulae Definitional proof-irrelevance and Making `Irrelevant` a proper `Monad` based on: https://github.com/agda/agda-stdlib/pull/2977 ... back as far as https://github.com/agda/agda-stdlib/pull/2243 (long history of progressive refactoring of these ideas over the last 2+ years) -} {- Harrop (1956): "Disjunction and Existence Properties in Intuitionistic Logic" Preamble: (look at the normal forms of proofs) * if ⊢ A ∨ B, then either ⊢ A or ⊢ B * if ⊢ ∃ xᴬ. P, then there exists ⊢ t : A st ⊢ P [ t / x ] Question: what about under hypotheses? Harrop: say * a formula (type; set) is `Harrop` if... * a context Γ of assumptions is `Harrop` if ⋀ Γ is Harrop Theorem: if Γ is Harrop, then * if Γ ⊢ A ∨ B, then either Γ ⊢ A or Γ ⊢ B * if Γ ⊢ ∃ xᴬ. P, then there exists Γ ⊢ t : A st Γ ⊢ P [ t / x ] -} {- Definitional proof Irrelevance in Agda (cf. Nisse's `Erased` talk) * `f : A → B` is a function, taking arguments `a : A`, returning `f a : B` given by `f a = e`, `e` is allowed to 'use' `a` * `f : .A → B`, given by `f a = e`, now `e` is *not* allowed to use `a`: - can't pattern match on `a` - can't use `a` as an argument to some other function `g` which uses `a` - BUT: can use `a` in a sub-term position which is 'computationally irrelevant' -} {- So: * *operationally*, `.A` is a set, as above * *denotationally*, `.A` is a set, when `A` is a set, such that - inhabitants `a : A` are inhabitants of `.A` - ' all such inhabitants are definitionally equal' (according to the typechecker) -} {- Application: `Data.Refinement`, based on `Data.Irrelevant` https://github.com/agda/agda-stdlib/blob/master/src/Data/Refinement/Base.agda -} open import Data.Refinement.Base {- Idea: Relation.Nullary.Recomputable` types * in the air for a long time: for `A : Set`, (a proof of) the property `.A → A` reflects the idea that `A` isn't 'interesting', because *any* proof/inhabitant of `.A` can be 'promoted'/'recomputed' into a fully-fledged inhabitant of `A`, eg. one which we can do pattern-matching on etc. * define `Recomputable A = .A → A`, as a 'type class', with single method `recompute` * for `Recomputable A` - `recompute` is a *constant* function - if `A` is `Irrelevant` (for every `a , b : A`, `a ≡ b` is provable), then for all `a : A` we have `recompute a ≡ a` https://github.com/agda/agda-stdlib/blob/master/src/Relation/Nullary/Recomputable/Base.agda https://github.com/agda/agda-stdlib/blob/master/src/Relation/Nullary/Recomputable.agda -} {- Back in 1956: Harrop working relative to Heyting Arithmetic HA * Atomic formulae are *decidable*: take all these as `Harrop` * `⊥` is `Harrop` (so too is `⊤‵, but if need be define that as `⊥ → ⊥`) * if `A` and `B` are `Harrop`, then `A ∧ B` is `Harrop` * if `B` is Harrop, and `A` is any formula, then `A → B` is Harrop * if `P[ a / x ]` is `Harrop` for every `a : A`, then `∀x ᴬ.P` is `Harrop` (NB. only consider `A = ℕ`, ...) Proof of Theorem: * induction on cut-free proof of `Γ ⊢ A`, invert hypothesis that `⋀ Γ` is `Harrop` * consider the (main connective in the) last inference rule * use the `Harrop` inversion hypotheses in the 'interesting' cases (NB. `A ∨ B` and `∃xᴬ.P` follow immediately by induction!) -} {- 70 years later * `Recomputable` types satisfy the `Harrop` closure properties (2024!) * for *atomic formulas*: - need to either hypothesise that they are `Recomputable` - else: `Decidable A → Recomputable A` * new: `Irrelevant A` is `Recomputable` for any `A`! * hence: `Irrelevant` has a 'real' definable `_>>=_` https://github.com/agda/agda-stdlib/blob/master/src/Data/Irrelevant.agda -} open import Data.Irrelevant {- Conjecture: Harrop revisited -} open import Relation.Nullary.Decidable.Core renaming (Dec to Decidable) open import Relation.Nullary.Negation.Core open import Relation.Nullary.Recomputable private variable a b c : Level A : Set a B : Set b C : Set c harropDP₀ : Decidable C → (C → A ⊎ B) → (C → A) ⊎ (C → B) harropDP₀ d c⇒a⊎b with d ... | no ¬c = inj₁ λ c → contradiction c ¬c ... | yes c with c⇒a⊎b c ... | inj₁ a = inj₁ λ _ → a ... | inj₂ b = inj₂ λ _ → b -- we'd then to lift this up to: harropDP₁ : Recomputable C → (C → A ⊎ B) → (C → A) ⊎ (C → B) harropDP₁ r c⇒a⊎b = {!!} {- Problem: * can't do induction over `Recomputable` * need to introduce a *universe* with constructors the Harrop conditions * do induction over the universe * NB. TODO! -}