Questions tagged [induction]

Anything related to mathematical induction principle and techniques applied to computing. Please DO NOT USE this tag for math-only questions since they are off-topic on SO. This tag may be used for math-related questions only if it involves some programming activity or software tools (e.g. automatic theorem proving, etc.).

Anything related to mathematical induction principle and techniques applied to computing. Please DO NOT USE this tag for math-only questions since they are off-topic on SO. This tag may be used for math-related questions only if it involves some programming activity or software tools (e.g. automatic theorem proving, etc.).

236 questions
31
votes
3 answers

Are Lists Inductive or Coinductive in Haskell?

So I've been reading about coinduction a bit lately, and now I'm wondering: are Haskell lists inductive or coinductive? I've also heard that Haskell doesn't distinguish the two, but if so, how do they do so formally? Lists are defined inductively,…
Crazycolorz5
  • 757
  • 5
  • 12
15
votes
5 answers

Showing two different fibonacci functions are equivalent

I'm trying to learn exactly what it means to prove a program correct. I'm starting from scratch and getting hung up on the first steps/the introduction to the topic. In this paper on total functional programming, two definitions of the fibonacci…
15
votes
1 answer

How do I convert an inductive type into a coinductive type efficiently (without recursion)?

> {-# LANGUAGE DeriveFunctor, Rank2Types, ExistentialQuantification #-} Any inductive type is defined like so > newtype Ind f = Ind {flipinduct :: forall r. (f r -> r) -> r} > induction = flip flipinduct induction has type (f a -> a) -> Ind f ->…
PyRulez
  • 9,505
  • 9
  • 37
  • 82
12
votes
1 answer

What is the relationship between recursion and proof by induction?

What is the relationship between recursion and proof by induction? Let's say fn(n), recursion is fn(n) calls itself until meet base condition; induction is when base condition is meet, try to prove (base case + 1) is also correct. It seems…
Timeless
  • 6,444
  • 8
  • 54
  • 90
11
votes
2 answers

Can I tell Coq to do induction from n to n+2?

I'm trying to see if it's possible to prove evenb n = true <-> exists k, n = double k from https://softwarefoundations.cis.upenn.edu/lf-current/Logic.html without involving odd numbers at all. I tried something like the following: Theorem…
Max Ng
  • 379
  • 3
  • 10
11
votes
1 answer

What are sized types in Agda?

What are sized types in Agda? I've tried to read the paper about MiniAgda, but failed to proceed due to the following points: Why are data types generic over their size? As far as I know the size is the depth of the tree of induction. Why are data…
盛安安
  • 768
  • 1
  • 6
  • 19
10
votes
2 answers

Proof by Induction of Pseudo Code

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:…
John Smith
  • 617
  • 1
  • 10
  • 19
8
votes
2 answers

How to use a custom induction principle in Coq?

I read that the induction principle for a type is just a theorem about a proposition P. So I constructed an induction principle for List based on the right (or reverse) list constructor . Definition rcons {X:Type} (l:list X) (x:X) : list X := l…
tinlyx
  • 18,900
  • 26
  • 81
  • 148
7
votes
1 answer

Structural induction in Haskell

Is the following a definition of structural induction? foldr f a (xs::ys) = foldr f (foldr f a ys) xs Can someone give me an example of structural induction in Haskell?
user1913592
  • 165
  • 1
  • 8
6
votes
1 answer

Termination of structural induction

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…
Cactus
  • 25,576
  • 9
  • 60
  • 130
6
votes
3 answers

How to do induction on the length of a list in Coq?

When reasoning on paper, I often use arguments by induction on the length of some list. I want to formalized these arguments in Coq, but there doesn't seem to be any built in way to do induction on the length of a list. How should I perform such an…
kainwen
  • 326
  • 1
  • 11
6
votes
1 answer

Proof that a binary tree with n leaves has a height of at least log n

I've been able to create a proof that shows the maximum total nodes in a tree is equal to n = 2^(h+1) - 1 and logically I know that the height of a binary tree is log n (can draw it out to see) but I'm having trouble constructing a formal proof to…
MandyLB
  • 197
  • 2
  • 14
6
votes
1 answer

What is the intuition behind the checkerboard covering recursive algorithm and how does one get better at formulating such an algorithm?

You may have heard of the classic checkerboard covering puzzle. How do you cover a checkerboard that has one corner square missing, using L-shaped tiles? There is a recursive approach to this as explained in the book "Python Algorithms Mastering…
6
votes
4 answers

Understanding recursion in Python

I'm really trying to wrap my brain around how recursion works and understand recursive algorithms. For example, the code below returns 120 when I enter 5, excuse my ignorance, and I'm just not seeing why? def fact(n): if n == 0: return…
suffa
  • 3,178
  • 7
  • 41
  • 62
5
votes
3 answers

Inductive Specification: Top-down vs Bottom-up vs Rules of Inference?

Please bear with me on this one. I am first going to describe an example from the book, and then ask my question at the end. According to the text on Programming Language Paradigms: Inductive specification is a powerful method of specifying a set…
Sahat Yalkabov
  • 29,198
  • 40
  • 103
  • 171
1
2 3
15 16