agda

Agda Type-Checking and Commutativity / Associativity of +

 ̄綄美尐妖づ 提交于 2019-11-29 06:14:46
问题 Since the _+_ -Operation for Nat is usually defined recursively in the first argument, its obviously non-trivial for the type-checker to know that i + 0 == i . However, I frequently run into this issue when I write functions on fixed-size Vectors. One example: How can I define an Agda-function swap : {A : Set}{m n : Nat} -> Vec A (n + m) -> Vec A (m + n) which puts the first n values at the end of the vector? Since a simple solution in Haskell would be swap 0 xs = xs swap n (x:xs) = swap (n-1

proofs about regular expressions

北战南征 提交于 2019-11-28 21:11:12
问题 Does anyone know any examples of the following? Proof developments about regular expressions (possibly extended with backreferences) in proof assistants (such as Coq). Programs in dependently-typed languages (such as Agda) about regular expressions. 回答1: Certified Programming with Dependent Types has a section on creating a verified regular expression matcher. Coq Contribs has an automata contribution that might be useful. Jan-Oliver Kaiser formalized the equivalence between regular

What is Axiom K?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 19:49:16
问题 I've noticed the discussion of "Axiom K" comes up more often since HoTT. I believe it's related to pattern matching. I'm surprised that I cannot find a reference in TAPL, ATTAPL or PFPL. What is Axiom K? Is it used for ML-style pattern matching as in SML (or just dependent pattern matching)? What's an appropriate reference for Axiom K? 回答1: Axiom K is also called the principle of uniqueness of identity proofs , and it is an axiom about the nature of the identity type in Martin-Löf's dependent

Eliminating a Maybe at the type level

淺唱寂寞╮ 提交于 2019-11-28 11:44:12
Is there any way to unwrap a value, which is inside the Maybe monad, at the type level? For example, how to define type-safe tail for Vec s having this variant of pred : pred : ℕ -> Maybe ℕ pred 0 = nothing pred (suc n) = just n ? Something like tail : ∀ {n α} {A : Set α} -> Vec A n -> if isJust (pred n) then Vec A (from-just (pred n)) else ⊤ This example is totally artificial, but it's not always possible to get rid of some precondition, so you can write a correct by construction definition like the tail function from the standard library: tail : ∀ {a n} {A : Set a} → Vec A (1 + n) → Vec A n

Is there a language with constrainable types?

两盒软妹~` 提交于 2019-11-28 09:00:00
Is there a typed programming language where I can constrain types like the following two examples? A Probability is a floating point number with minimum value 0.0 and maximum value 1.0. type Probability subtype of float where max_value = 0.0 min_value = 1.0 A Discrete Probability Distribution is a map, where: the keys should all be the same type, the values are all Probabilities, and the sum of the values = 1.0. type DPD<K> subtype of map<K, Probability> where sum(values) = 1.0 As far as I understand, this is not possible with Haskell or Agda. What you want is called refinement types . It's

Termination-checking of function over a trie

戏子无情 提交于 2019-11-28 08:59:20
问题 I'm having difficulty convincing Agda to termination-check the function fmap below and similar functions defined recursively over the structure of a Trie . A Trie is a trie whose domain is a Type , an object-level type formed from unit, products and fixed points (I've omitted coproducts to keep the code minimal). The problem seems to relate to a type-level substitution I use in the definition of Trie . (The expression const (μₜ τ) * τ means apply the substitution const (μₜ τ) to the type τ .)

Termination check on list merge

雨燕双飞 提交于 2019-11-28 03:59:00
问题 Agda 2.3.2.1 can't see that the following function terminates: open import Data.Nat open import Data.List open import Relation.Nullary merge : List ℕ → List ℕ → List ℕ merge (x ∷ xs) (y ∷ ys) with x ≤? y ... | yes p = x ∷ merge xs (y ∷ ys) ... | _ = y ∷ merge (x ∷ xs) ys merge xs ys = xs ++ ys Agda wiki says that it's OK for the termination checker if the arguments on recursive calls decrease lexicographically. Based on that it seems that this function should also pass. So what am I missing

How to enumerate the elements of a list by `Fin`s in linear time?

China☆狼群 提交于 2019-11-28 01:44:53
问题 We can enumerate the elements of a list like this: -- enumerate-ℕ = zip [0..] enumerate-ℕ : ∀ {α} {A : Set α} -> List A -> List (ℕ × A) enumerate-ℕ = go 0 where go : ∀ {α} {A : Set α} -> ℕ -> List A -> List (ℕ × A) go n [] = [] go n (x ∷ xs) = (n , x) ∷ go (ℕ.suc n) xs E.g. enumerate-ℕ (1 ∷ 3 ∷ 2 ∷ 5 ∷ []) is equal to (0 , 1) ∷ (1 , 3) ∷ (2 , 2) ∷ (3 , 5) ∷ [] . Assuming there is sharing in Agda, the function is linear. However if we try to enumerate the elements of a list by Fin s rather

Assisting Agda's termination checker

情到浓时终转凉″ 提交于 2019-11-27 20:37:22
Suppose we define a function f : N \to N f 0 = 0 f (s n) = f (n/2) -- this / operator is implemented as floored division. Agda will paint f in salmon because it cannot tell if n/2 is smaller than n. I don't know how to tell Agda's termination checker anything. I see in the standard library they have a floored division by 2 and a proof that n/2 < n. However, I still fail to see how to get the termination checker to realize that recursion has been made on a smaller subproblem. Agda's termination checker only checks for structural recursion (i.e. calls that happen on structurally smaller

Types containing with/rewrite clauses in agda, or, how to use rewrite instead of subst?

我怕爱的太早我们不能终老 提交于 2019-11-27 14:44:38
First some boring imports: import Relation.Binary.PropositionalEquality as PE import Relation.Binary.HeterogeneousEquality as HE import Algebra import Data.Nat import Data.Nat.Properties open PE open HE using (_≅_) open CommutativeSemiring commutativeSemiring using (+-commutativeMonoid) open CommutativeMonoid +-commutativeMonoid using () renaming (comm to +-comm) Now suppose that I have a type indexed by, say, the naturals. postulate Foo : ℕ -> Set And that I want to prove some equalities about functions operating on this type Foo . Because agda is not very smart, these will be heterogeneous