| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Properties of digits and digit expansions |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
open import Data.Digit using (digitChars; Digit; showDigit; toDigits) |
| 10 |
import Data.Char.Properties as Char |
| 11 |
open import Data.Nat.Base using (ℕ) |
| 12 |
open import Data.Nat.Properties using (_≤?_) |
| 13 |
open import Data.Fin.Properties using (inject≤-injective) |
| 14 |
open import Data.Product.Base using (_,_; proj₁) |
| 15 |
open import Data.Vec.Relation.Unary.Unique.Propositional using (Unique) |
| 16 |
import Data.Vec.Relation.Unary.Unique.Propositional.Properties as Unique |
| 17 |
open import Data.Vec.Relation.Unary.AllPairs using (allPairs?) |
| 18 |
open import Relation.Nullary.Decidable.Core using (True; from-yes; ¬?) |
| 19 |
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl) |
| 20 |
open import Function.Base using (_∘_) |
| 21 |
|
| 22 |
module Data.Digit.Properties where |
| 23 |
|
| 24 |
digitCharsUnique : Unique digitChars |
| 25 |
digitCharsUnique = from-yes (allPairs? (λ x y → ¬? (x Char.≟ y)) digitChars) |
| 26 |
|
| 27 |
module _ (base : ℕ) where |
| 28 |
module _ {base≥2 base≥2′ : True (2 ≤? base)} where |
| 29 |
toDigits-injective : ∀ n m → proj₁ (toDigits base {base≥2} n) ≡ proj₁ (toDigits base {base≥2′} m) → n ≡ m |
| 30 |
toDigits-injective n m eq with toDigits base {base≥2} n | toDigits base {base≥2′} m |
| 31 |
toDigits-injective ._ ._ refl | _ , refl | ._ , refl = refl |
| 32 |
|
| 33 |
module _ {base≤16 base≤16′ : True (base ≤? 16)} where |
| 34 |
showDigit-injective : (n m : Digit base) → showDigit {base} {base≤16} n ≡ showDigit {base} {base≤16′} m → n ≡ m |
| 35 |
showDigit-injective n m = inject≤-injective _ _ n m ∘ Unique.lookup-injective digitCharsUnique _ _ |