Formal Ledger Specification
PositiveNat
Initializing search
    GitHub
    • Navigation
    GitHub
      • Home
      • Guide for Contributors
        • Notation
      • Ledger
        • Introduction
        • Prelude
          • Base
          • Instances
        • Conway
          • Abstract
          • Address
          • BaseTypes
          • Certs
            • Properties
              • PoV
              • PoVLemmas
              • VoteDelegsVDeleg
          • Chain
            • Properties
              • CredDepsEqualDomRwds
              • EpochStep
              • GovDepsMatch
              • PParamsWellFormed
          • Crypto
          • Enact
            • Properties
          • Epoch
            • Properties
              • ConstRwds
              • GovDepsMatch
              • NoPropSameDReps
          • Fees
          • Gov
            • Base
            • Actions
            • Properties
              • ChangePPGroup
          • Ledger.Ledger
            • Properties
              • GovDepsMatch
              • PoV
          • PParams
          • Properties
          • Ratify
            • Properties
          • Rewards
          • Script
            • Base
            • Timelock
            • Validation
            • Base
            • Coin
            • ValueSet
            • ValueVector
          • Transaction
            • Epoch
            • Numeric
              • UnitInterval
              • PositiveNat
          • Utxo
            • Properties
              • MinSpend
              • PoV
          • Utxow
            • Properties
            • ExternalFunctions
            • HSLedger
              • Address
              • BaseTypes
              • Cert
              • Certs
              • Chain
              • Core
              • Enact
              • Epoch
              • ExternalStructures
              • Gov
                • Core
                • Actions
              • Ledger
              • NewEpoch
              • PParams
              • Ratify
              • Transaction
              • Utxo
            • HSTypes
            • Util
            • Certs
              • Properties
            • Chain
              • Properties
            • Epoch
              • Properties
            • Equivalence
              • Bisimilarity
              • Certs
              • Convert
              • Deposits
              • Map
              • Utxo
            • Gov
            • Ledger
              • Properties
            • Properties
            • Script
            • Utxo
              • Properties
            • Utxow
              • Properties
            • Examples
              • HelloWorld
              • SucceedIfNumber
            • LedgerImplementation
            • Lib
            • Prelude
            • StructuredContracts
        • ConwaySafe
          • HasCoin
        • PreConway
            • NewPP
              • Properties
            • PPUp
              • Properties
          • NewPP
            • Properties
          • PPUp
            • Properties
        • Convertible
          • Deriving
          • DerivingTest
        • HaskellTypes
          • Deriving
        • EssentialAgda
        • Agda Prelude
            • ComputationalRelation
            • HasSubset
            • HasSubtract
              • Instance
            • Hashable
            • STS
          • MyDebugOptions

    PositiveNat

    {-# OPTIONS --safe #-}
    module Ledger.Conway.Types.Numeric.PositiveNat where
    
    open import Prelude
      hiding ([_,_]; [_]; _*_)
    
    open import Class.Show using (Show; show)
    
    open import Agda.Builtin.FromNat
    open import Data.Nat using (ℕ; NonZero; _>_)
    open import Data.Refinement using (Refinement-syntax; value; _,_)
    open import Data.Irrelevant
    
    -- PosNat: Non zero natural number.
    PosNat : Type
    PosNat = [ x ∈ ℕ ∣ NonZero x ]
    
    instance
      Show-PosNat : Show PosNat
      Show-PosNat .show (n , _) = show n
    
    fromPosNat : PosNat → ℕ
    fromPosNat = value
    
    toPosNat : ℕ → Maybe PosNat
    toPosNat n with nonZero? n
    ... | yes p = just (n , [ p ])
    ... | no ¬p = nothing
    
    mkPosNat : ∀ (n : ℕ) → {T (does (nonZero? n))} → PosNat
    mkPosNat n {evidence}
      with nonZero? n in eq
    ... | no  _ = ⊥-elim evidence
    ... | yes p = n , [ p ]
    
    PosNat-IsNonZero : (n : PosNat) → NonZero (fromPosNat n)
    PosNat-IsNonZero (suc n , n>0) .NonZero.nonZero = tt
    
    PosNat-Is>0 : (n : PosNat) → fromPosNat n > 0
    PosNat-Is>0 (suc n , n>0) = s≤s z≤n
    
    Number-PosNat : Number PosNat
    Number-PosNat = record
      { Constraint = NonZero
      ; fromNat = λ n ⦃ p ⦄ → n , [ p ]
      }
    
    Previous
    UnitInterval
    Next
    Utxo
    Made with Material for MkDocs