induction

Wellfounded induction in CoQ

冷暖自知 提交于 2019-12-10 20:04:49
问题 Let's say that I know certain natural numbers are good . I know 1 is good, if n is good then 3n is, and if n is good then n+5 is, and those are only ways of constructing good numbers. It seems to me that the adequate formalization of this in Coq is Inductive good : nat -> Prop := | g1 : good 1 | g3 : forall n, good n -> good (n * 3) | g5 : forall n, good n -> good (n + 5). However, despite being obvious, the fact that 0 is not good seems not being provable using this definition (because when

Why must coq mutually inductive types have the same parameters?

十年热恋 提交于 2019-12-10 15:31:32
问题 Following Arthur's suggestion, I changed my Fixpoint relation to a mutual Inductive relation which "builds up" the different comparisons between games rather than "drilling down". But now I am receiving an entirely new error message: Error: Parameters should be syntactically the same for each inductive type. I think the error message is saying that I need the same exact parameters for all of these mutual inductive definitions. I realize there are simple hacks to get around this (unused dummy

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

Proof of induction on pseudocode

不问归期 提交于 2019-12-10 12:08:36
问题 Given the pseudocode MUL(a,b) x=a y=0 WHILE x>=b DO x=x-b y=y+1 IF x=0 THEN RETURN(true) ELSE RETURN(false) Let x(n) and y(n) denote the value of x and y after the while loop has run n times. I have to show by the proof of induction that x(n) + b*y(n) = a What I've done: P(n): x(n) + by(n) = a Let a and b be arbitrary numbers then the first loop will give x(1) = a - b and y(1) = 0 + 1 = 1 P(1): x(1) + by(1) = a <=> a = a so P(1) is true. Assume P(n) is true. We want to show that P(n+1) is

How do I apply inductive reasoning to `GHC.TypeLits.Nat`?

让人想犯罪 __ 提交于 2019-12-09 13:04:53
问题 Consider this definition of zip for the usual vectors length indexed by Peano numerals: {-# language DataKinds #-} {-# language KindSignatures #-} {-# language GADTs #-} {-# language TypeOperators #-} {-# language StandaloneDeriving #-} {-# language FlexibleInstances #-} {-# language FlexibleContexts #-} module Vector where import Prelude hiding (zip) data N where Z :: N S :: N -> N data Vector (n :: N) a where VZ :: Vector Z a (:::) :: a -> Vector n a -> Vector (S n) a infixr 1 ::: deriving

Coq - Induction over functions without losing information

北战南征 提交于 2019-12-07 09:59:39
问题 I'm having some troubles in Coq when trying to perform case analysis on the result of a function (which returns an inductive type). When using the usual tactics, like elim , induction , destroy , etc, the information gets lost. I'll put an example: We first have a function like so: Definition f(n:nat): bool := (* definition *) Now, imagine we are at this step in the proof of a specific theorem: n: nat H: f n = other_stuff ------ P (f n ) When I apply a tactic, like let's say, induction (f n)

Coq induction start at specific nat

故事扮演 提交于 2019-12-07 09:13:34
问题 I'm trying to learn coq so please assume I know nothing about it. If I have a lemma in coq that starts forall n m:nat, n>=1 -> m>=1 ... And I want to proceed by induction on n. How do I start the induction at 1? Currently when I use the "induction n." tactic it starts at zero and this makes the base statement false which makes it hard to proceed. Any hints? 回答1: The following is a proof that every proposition P is true forall n>=1 , if P is true for 1 and if P is inductively true. Require

Coq - Induction over functions without losing information

丶灬走出姿态 提交于 2019-12-05 18:12:24
I'm having some troubles in Coq when trying to perform case analysis on the result of a function (which returns an inductive type). When using the usual tactics, like elim , induction , destroy , etc, the information gets lost. I'll put an example: We first have a function like so: Definition f(n:nat): bool := (* definition *) Now, imagine we are at this step in the proof of a specific theorem: n: nat H: f n = other_stuff ------ P (f n ) When I apply a tactic, like let's say, induction (f n) , this happens: Subgoal 1 n:nat H: true = other_stuff ------ P true Subgoal 2 n:nat H: false = other

How do I apply inductive reasoning to `GHC.TypeLits.Nat`?

江枫思渺然 提交于 2019-12-03 15:36:02
Consider this definition of zip for the usual vectors length indexed by Peano numerals: {-# language DataKinds #-} {-# language KindSignatures #-} {-# language GADTs #-} {-# language TypeOperators #-} {-# language StandaloneDeriving #-} {-# language FlexibleInstances #-} {-# language FlexibleContexts #-} module Vector where import Prelude hiding (zip) data N where Z :: N S :: N -> N data Vector (n :: N) a where VZ :: Vector Z a (:::) :: a -> Vector n a -> Vector (S n) a infixr 1 ::: deriving instance Show a => Show (Vector n a) class Zip z where zip :: z a -> z b -> z (a, b) instance Zip

Proof by Induction of Pseudo Code

帅比萌擦擦* 提交于 2019-12-03 04:35:04
问题 I don't really understand how one uses proof by induction on psuedocode. It doesn't seem to work the same way as using it on mathematical equations. I'm trying to count the number of integers that are divisible by k in an array. Algorithm: divisibleByK (a, k) Input: array a of n size, number to be divisible by k Output: number of numbers divisible by k int count = 0; for i <- 0 to n do if (check(a[i],k) = true) count = count + 1 return count; Algorithm: Check (a[i], k) Input: specific number