agda

Induction principle for `le`

我怕爱的太早我们不能终老 提交于 2019-12-25 02:24:06
问题 For the inductive type nat , the generated induction principle uses the constructors O and S in its statement: Inductive nat : Set := O : nat | S : nat -> nat nat_ind : forall P : nat -> Prop, P 0 -> (forall n : nat, P n -> P (S n)) -> forall n : nat, P n But for le , the generated statement does not uses the constructors le_n and le_S : Inductive le (n : nat) : nat -> Prop := le_n : n <= n | le_S : forall m : nat, n <= m -> n <= S m le_ind : forall (n : nat) (P : nat -> Prop), P n -> (forall

Functor instance for Data.AVL

≡放荡痞女 提交于 2019-12-24 13:13:15
问题 I would like to define a functor instance for Data.AVL.Indexed.Tree . This seems to be tricky because of the way the type Key⁺ of the indices storing the upper and lower bounds of the tree "depend on" the type (or family of types) of the values in the tree. What I want to do is implement fmap below: open import Relation.Binary open import Relation.Binary.PropositionalEquality module Temp {k ℓ} {Key : Set k} {_<_ : Rel Key ℓ} (isStrictTotalOrder : IsStrictTotalOrder _≡_ _<_) where open import

Showing (head . init ) = head in Agda

一个人想着一个人 提交于 2019-12-23 07:56:21
问题 I'm trying to prove a simple lemma in Agda, which I think is true. If a vector has more than two elements, taking its head following taking the init is the same as taking its head immediately. I have formulated it as follows: lem-headInit : ∀{l} (xs : Vec ℕ (suc (suc l))) -> head (init xs) ≡ head xs lem-headInit (x ∷ xs) = ? Which gives me; .l : ℕ x : ℕ xs : Vec ℕ (suc .l) ------------------------------ Goal: head (init (x ∷ xs) | (initLast (x ∷ xs) | initLast xs)) ≡ x as a response. I do not

Membership proofs for AVL trees

北战南征 提交于 2019-12-23 03:44:09
问题 I'm struggling a little to come up with a notion of membership proof for Data.AVL trees. I would like to be able to pass around a value of type n ∈ m , to mean that n appears as a key in in the AVL tree, so that given such a proof, get n m can always successfully yield a value associated with n. You can assume my AVL trees always contain values drawn from a join semilattice (A, ∨, ⊥) over a setoid (A, ≈), although below the idempotence is left implicit. module Temp where open import Algebra

Merge of sorted lists with sized types

我们两清 提交于 2019-12-23 02:52:31
问题 Suppose we have a datatype of sorted lists, with proof-irrelevant sorting witnesses. We'll use Agda's experimental sized types feature, so that we can hopefully get some recursive functions over the datatype to pass Agda's termination checker. {-# OPTIONS --sized-types #-} open import Relation.Binary open import Relation.Binary.PropositionalEquality as P module ListMerge {𝒂 ℓ} (A : Set 𝒂) {_<_ : Rel A ℓ} (isStrictTotalOrder : IsStrictTotalOrder _≡_ _<_) where open import Level open import

How can i change working of forall in agda?

自作多情 提交于 2019-12-22 13:01:25
问题 I am working with pair of Stream of rationals, Lets say (L,R) Where L and R are Stream of rationals. There are 3 conditions which L and R both have to satisfy to say it is valid. I have written the code as.. isCut_ : cut → Set isCut x = (p q : pair ) → if((((p mem (getLC x)) ∨ (p mem (getRC x)))) ∧ ((not (p mem getLC x)) ∨ (not (p mem getRC x))) ∧ (not (p <pair q) ∨ ((p mem getLC x) ∨ (q mem getRC x))))then ⊤ else ⊥ I really wanted to change the return type of this function to Bool. Here cut

Problems with instance arguments in Agda

蓝咒 提交于 2019-12-22 11:29:21
问题 I'm trying to follow the code for McBride's How to Keep Your Neighbours in Order, and can't understand why Agda (I'm using Agda 2.4.2.2) gives the following error message: Instance search can only be used to find elements in a named type when checking that the expression t has type .T for function _:-_ . The code is given bellow data Zero : Set where record One : Set where constructor <> data Two : Set where tt ff : Two So : Two -> Set So tt = One So ff = Zero record <<_>> (P : Set) : Set

Termination-checking substitution via (monadic) join and fmap

故事扮演 提交于 2019-12-22 11:14:09
问题 I'm using sized types, and have a substitution function for typed terms which termination-checks if I give a definition directly, but not if I factor it via (monadic) join and fmap. {-# OPTIONS --sized-types #-} module Subst where open import Size To show the problem, it's enough to have unit and sums. I have data types of Trie and Term , and I use tries with a codomain of Term inside Term , as part of the elimination form for sums. data Type : Set where 𝟏 : Type _+_ : Type → Type → Type

Using the value of a computed function for a proof in agda

跟風遠走 提交于 2019-12-22 08:24:44
问题 I'm still trying to wrap my head around agda, so I wrote a little tic-tac-toe game Type data Game : Player -> Vec Square 9 -> Set where start : Game x ( - ∷ - ∷ - ∷ - ∷ - ∷ - ∷ - ∷ - ∷ - ∷ [] ) xturn : {gs : Vec Square 9} -> (n : ℕ) -> Game x gs -> n < (#ofMoves gs) -> Game o (makeMove gs x n ) oturn : {gs : Vec Square 9} -> (n : ℕ) -> Game o gs -> n < (#ofMoves gs) -> Game x (makeMove gs o n ) Which will hold a valid game path. Here #ofMoves gs would return the number of empty Square s, n <

Agda functions, function matching on types

人盡茶涼 提交于 2019-12-21 22:11:31
问题 I want to create a helper function, that will take a term from a an indexed or parametrized type and return that type parameter. showLen : {len : ℕ} {A : Set} -> Vec A len -> ℕ showLen ? = len showType : {len : ℕ} {A : Set} -> Vec A len -> Set showType ? = A Is this possible? (I can see how showType [] might have issues, but what about when the Type is indexed?) 回答1: If you get rid of the implicit arguments, you can implement this quite easily: showLen : (len : ℕ) (A : Set) → Vec A len → ℕ