------------------------------------------------------------------------ -- The Agda standard library -- -- Various forms of induction for natural numbers ------------------------------------------------------------------------ {-# OPTIONS --cubical-compatible --safe #-} module Data.Nat.Induction where open import Data.Nat.Base open import Data.Nat.Properties using (<⇒<′) open import Data.Product.Base using (_×_; _,_) open import Data.Unit.Polymorphic.Base using (⊤) open import Induction using (RecStruct; RecursorBuilder; Recursor; build) open import Induction.WellFounded as WF open import Level using (Level) private variable ℓ : Level ------------------------------------------------------------------------ -- Re-export accessability open WF public using (Acc; acc) ------------------------------------------------------------------------ -- Ordinary induction Rec : ∀ ℓ → RecStruct ℕ ℓ ℓ Rec ℓ P zero = ⊤ Rec ℓ P (suc n) = P n recBuilder : RecursorBuilder (Rec ℓ) recBuilder P f zero = _ recBuilder P f (suc n) = f n (recBuilder P f n) rec : Recursor (Rec ℓ) rec = build recBuilder ------------------------------------------------------------------------ -- Complete induction CRec : ∀ ℓ → RecStruct ℕ ℓ ℓ CRec ℓ P zero = ⊤ CRec ℓ P (suc n) = P n × CRec ℓ P n cRecBuilder : RecursorBuilder (CRec ℓ) cRecBuilder P f zero = _ cRecBuilder P f (suc n) = f n ih , ih where ih = cRecBuilder P f n cRec : Recursor (CRec ℓ) cRec = build cRecBuilder ------------------------------------------------------------------------ -- Complete induction based on _<′_ <′-Rec : RecStruct ℕ ℓ ℓ <′-Rec = WfRec _<′_ -- mutual definition <′-wellFounded : WellFounded _<′_ <′-wellFounded′ : ∀ n → <′-Rec (Acc _<′_) n <′-wellFounded n = acc (<′-wellFounded′ n) <′-wellFounded′ (suc n) <′-base = <′-wellFounded n <′-wellFounded′ (suc n) (<′-step m