------------------------------------------------------------------------ -- The Agda standard library -- -- Well-founded induction ------------------------------------------------------------------------ {-# OPTIONS --cubical-compatible --safe #-} module Induction.WellFounded where open import Data.Product.Base using (Σ; _,_; proj₁; proj₂) open import Function.Base using (_∘_; flip; _on_) open import Induction using (RecStruct; RecursorBuilder; Recursor; build ; SubsetRecursorBuilder; SubsetRecursor; subsetBuild) open import Level using (Level; _⊔_) open import Relation.Binary.Core using (Rel) open import Relation.Binary.Definitions using (Symmetric; Asymmetric; Irreflexive ; _Respects₂_; _Respectsʳ_; _Respects_) open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl) open import Relation.Binary.Consequences using (asym⇒irr) open import Relation.Unary using (Pred; _⊆′_; _⊆_; _⇒_; Universal; IUniversal; Stable; Empty) open import Relation.Nullary.Negation.Core using (¬_) private variable a b ℓ ℓ₁ ℓ₂ r : Level A : Set a B : Set b ------------------------------------------------------------------------ -- Definitions -- When using well-founded recursion you can recurse arbitrarily, as -- long as the arguments become smaller, and "smaller" is -- well-founded. WfRec : Rel A r → ∀ {ℓ} → RecStruct A ℓ _ WfRec _<_ P x = ∀ {y} → y < x → P y -- The accessibility predicate: x is accessible if everything which is -- smaller than x is also accessible (inductively). data Acc {A : Set a} (_<_ : Rel A ℓ) (x : A) : Set (a ⊔ ℓ) where acc : (rs : WfRec _<_ (Acc _<_) x) → Acc _<_ x -- The accessibility predicate encodes what it means to be -- well-founded; if all elements are accessible, then _<_ is -- well-founded. WellFounded : Rel A ℓ → Set _ WellFounded _<_ = ∀ x → Acc _<_ x ------------------------------------------------------------------------ -- Basic properties acc-inverse : ∀ {_<_ : Rel A ℓ} {x : A} (q : Acc _<_ x) → WfRec _<_ (Acc _<_) x acc-inverse (acc rs) y