agda

In Agda is it possible to define a datatype that has equations?

百般思念 提交于 2019-12-10 20:45:03
问题 I want to describe the integers: data Integer : Set where Z : Integer Succ : Integer -> Integer Pred : Integer -> Integer ?? what else The above does not define the Integers. We need Succ (Pred x) = x and Pred (Succ x) = x. However, spReduce : (m : Integer) -> Succ (Pred m) = m psReduce : (m : Integer) -> Pred (Succ m) = m Can't be added to the data type. A better definition of the integers is most certainly, data Integers : Set where Pos : Nat -> Integers Neg : Nat -> Integers But I am

How to choose the design for a well-founded inductive type?

柔情痞子 提交于 2019-12-10 19:22:37
问题 While studying well-foundedness, I wanted to see how different designs behave. For example, for a type: data _<_ (x : Nat) : Nat -> Set where <-b : x < (suc x) <-s : (y : Nat) -> x < y -> x < (suc y) well-foundedness is easy to demonstrate. But if a similar type is defined differently: data _<_ : Nat -> Nat -> Set where z-< : (m : Nat) -> zero < (suc m) s<s : (m n : Nat) -> m < n -> (suc m) < (suc n) It is obvious that in both cases the descending chain is not infinite, but in the second case

how to interpret REL in agda

爷,独闯天下 提交于 2019-12-10 18:23:38
问题 I'm trying to understand some parts of the standard library of Agda, and I can't seem to figure out the definition of REL . FWIW here's the definition of REL : -- Binary relations -- Heterogeneous binary relations REL : ∀ {a b} → Set a → Set b → (ℓ : Level) → Set (a ⊔ b ⊔ suc ℓ) REL A B ℓ = A → B → Set ℓ I can't find any documentation online explaining this, which is why I'm asking here. How does this define a binary relation? 回答1: @RodrigoRibeiro's answer explains the Level bits, but once

Agda and Binary Search Trees

隐身守侯 提交于 2019-12-10 17:18:16
问题 Just a note, this is for an assignment, so probably best not to post complete solutions, rather, I'm just stuck and need some hints as to what I should be looking at next. module BST where open import Data.Nat open import Relation.Binary.PropositionalEquality open import Relation.Binary open DecTotalOrder decTotalOrder using () renaming (refl to ≤-refl; trans to ≤-trans) data Ord (n m : ℕ) : Set where smaller : n < m -> Ord n m equal : n ≡ m -> Ord n m greater : n > m -> Ord n m cmp : (n m :

Eliminating subst to prove equality

邮差的信 提交于 2019-12-10 17:15:13
问题 I'm trying to representat mod-n counters as a cut of the interval [0, ..., n-1] into two parts: data Counter : ℕ → Set where cut : (i j : ℕ) → Counter (suc (i + j)) Using this, defining the two crucial operations is straightforward (some proofs omitted for brevity): _+1 : ∀ {n} → Counter n → Counter n cut i zero +1 = subst Counter {!!} (cut zero i) cut i (suc j) +1 = subst Counter {!!} (cut (suc i) j) _-1 : ∀ {n} → Counter n → Counter n cut zero j -1 = subst Counter {!!} (cut j zero) cut (suc

Constructing squares with constraints in an isSet type

烂漫一生 提交于 2019-12-10 16:50:52
问题 This is in continuation of this question, based on this answer. Using the technique explained by Saizan, and factoring my fromList-toList proof a bit to avoid the problematic recursion, I managed to fill in all but one cases of fromList-toList . I think it's easiest if I just show everything I have: {-# OPTIONS --cubical #-} module _ where open import Cubical.Core.Everything open import Cubical.Foundations.Everything hiding (assoc) data FreeMonoid {ℓ} (A : Type ℓ) : Type ℓ where [_] : A →

Lexicographic ordering of pairs/lists in Agda using the standard library

心已入冬 提交于 2019-12-10 15:18:25
问题 The Agda standard library contains some modules Relation.Binary.*.(Non)StrictLex (currently only for Product and List ). We can use these modules to easily construct an instance of, for example, IsStrictTotalOrder for pairs of natural numbers (i.e. ℕ × ℕ ). open import Data.Nat as ℕ using (ℕ; _<_) open import Data.Nat.Properties as ℕ open import Relation.Binary using (module StrictTotalOrder; IsStrictTotalOrder) open import Relation.Binary.PropositionalEquality using (_≡_) open import

Termination of structural induction

邮差的信 提交于 2019-12-10 13:37:11
问题 I can't get Agda's termination checker to accept functions defined using structural induction. I created the following as the, I think, simplest example exhibiting this problem. The following definition of size is rejected, even though it always recurses on strictly smaller components. module Tree where open import Data.Nat open import Data.List data Tree : Set where leaf : Tree branch : (ts : List Tree) → Tree size : Tree → ℕ size leaf = 1 size (branch ts) = suc (sum (map size ts)) Is there

Equality testing without explicit proof that data constructors are injective

夙愿已清 提交于 2019-12-10 02:26:35
问题 Is it possible to define a simple syntactic notion of equality (similar to what GHC might automatically derive as the Eq instance for a Haskell 98 type), without either explicitly proving that each data constructor is injective, or doing something analogous, such as defining the retraction of each constructor and using cong ? In other words, is it possible to exploit the injectivity of data constructors more directly, rather than having to introduce one auxiliary function per constructor? The

refl in agda : explaining congruence property

不想你离开。 提交于 2019-12-09 19:21:35
问题 With the following definition of equality, we have refl as constructor data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x and we can prove that function are congruent on equality cong : ∀ { a b} { A : Set a } { B : Set b } (f : A → B ) {m n} → m ≡ n → f m ≡ f n cong f refl = refl I am not sure I can parse what is going on exactly here. I think we are pattern matching refl on hidden parameters : if we replace the first occurence by refl by another identifier, we get a type error.