Questions tagged [proof]

A mathematical proof is any mathematical argument which demonstrates the truth of a mathematical statement. Informal proofs are typically rendered in natural language and are held true by consensus; formal proofs are typically rendered symbolically and can be checked mechanically. "Proofs" can be valid or invalid; only the former kind constitutes actual proof, whereas the latter kind usually refers to a flawed attempt at proof.

828 questions
16
votes
4 answers

Proof that Fowler's money allocation algorithm is correct

Martin Fowler has a Money class that has a money allocation routine. This routine allocates money according to a given list of ratios without losing any value through rounding. It spreads any remainder value over the results. For example, $100…
dan-gph
  • 16,301
  • 12
  • 61
  • 79
16
votes
3 answers

Number of binary search trees over n distinct elements

How many binary search trees can be constructed from n distinct elements? And how can we find a mathematically proved formula for it? Example: If we have 3 distinct elements, say 1, 2, 3, there are 5 binary search trees.
siddstuff
  • 1,215
  • 4
  • 16
  • 37
16
votes
3 answers

I need help proving that if f(n) = O(g(n)) implies 2^(f(n)) = O(2^g(n)))

In a previous problem, I showed (hopefully correctly) that f(n) = O(g(n)) implies lg(f(n)) = O(lg(g(n))) with sufficient conditions (e.g., lg(g(n)) >= 1, f(n) >= 1, and sufficiently large n). Now, I need to prove OR disprove that f(n) = O(g(n))…
norman
  • 5,128
  • 13
  • 44
  • 75
15
votes
19 answers

Should code be short/concise?

When writing a mathematical proof, one goal is to continue compressing the proof. The proof gets more elegant but not necessarily more readable. Compression translates to better understanding, as you weed out unnecessary characters and…
4thSpace
  • 43,672
  • 97
  • 296
  • 475
15
votes
4 answers

I can't prove (n - 0) = n with Idris

I am trying to prove, what to my mind is a reasonable theorem: theorem1 : (n : Nat) -> (m : Nat) -> (n + (m - n)) = m Proof by induction gets to the point where me need to prove this: lemma1 : (n : Nat) -> (n - 0) = n This is what happens when I…
Vic Smith
  • 3,477
  • 1
  • 18
  • 29
15
votes
5 answers

Find subset with elements that are furthest apart from eachother

I have an interview question that I can't seem to figure out. Given an array of size N, find the subset of size k such that the elements in the subset are the furthest apart from each other. In other words, maximize the minimum pairwise distance…
citysushi
  • 183
  • 1
  • 7
14
votes
1 answer

Is this always true: fmap (foldr f z) . sequenceA = foldr (liftA2 f) (pure z)

import Prelude hiding (foldr) import Control.Applicative import Data.Foldable import Data.Traversable left, right :: (Applicative f, Traversable t) => (a -> b -> b) -> b -> t (f a) -> f b left f z = fmap (foldr f z) . sequenceA right f z = foldr…
Sjoerd Visscher
  • 11,840
  • 2
  • 47
  • 59
14
votes
1 answer

How do you prove that a function is unique for its type?

id is the only function of type a -> a, and fst the only function of type (a,b) -> a. In these simple cases, this is fairly straightforward to see. But in general, how would you go about proving this? What if there are multiple possible…
Mike Izbicki
  • 6,286
  • 1
  • 23
  • 53
13
votes
2 answers

Is there a proof that runST is indeed pure?

The ST monad, originally devised by Launchbury and Peyton Jones, allows Haskell programmers to write imperative code (with mutable variables, arrays, etc.) while obtaining a pure interface to that code. More concretely, the polymorphic type of the…
Joachim Breitner
  • 25,395
  • 6
  • 78
  • 139
13
votes
1 answer

Proving associativity of natural number addition using Scala shapeless

The following code is Idris: natAssociative : (a : Nat) -> (b : Nat) -> (c : Nat) -> (a + b) + c = a + (b + c) natAssociative Z b c = the (b + c = b + c) refl natAssociative (S k) b c = replace {P=\x => S (k + b) + c = S x} (natAssociative k b c)…
Brian McKenna
  • 45,528
  • 6
  • 61
  • 60
13
votes
5 answers

How to determine the height of a recursion tree from a recurrence relation?

How does one go about determining the height of a recursion tree, built when dealing with recurrence run-times? How does it differ from determining the height of a regular tree? alt text…
Chris
  • 21,549
  • 25
  • 71
  • 99
12
votes
3 answers

General proof strategies to show correctness of recursive functions?

I'm wondering if there exists any rule/scheme of proceeding with proving algorithm correctness? For example we have a function $F$ defined on the natural numbers and defined below: function F(n,k) begin if k=0 then return 1 else if (n mod 2 = 0)…
xan
  • 1,053
  • 1
  • 10
  • 29
12
votes
6 answers

Proving correctness of multithread algorithms

Multithread algorithms are notably hard to design/debug/prove. Dekker's algorithm is a prime example of how hard it can be to design a correct synchronized algorithm. Tanenbaum's Modern operating systems is filled with examples in its IPC section.…
Leandro
  • 151
  • 1
  • 8
12
votes
1 answer

Using the type system to check length of output vs. input list

Suppose a list L, with length n, is interleaved in list J, with length n + 1. We'd like to know, for each element of J, which of its neighbors from L is the greater. The following function takes L as its input, and produces a list K, also of…
Levi Roth
  • 123
  • 5
12
votes
6 answers

Writing a proof for an algorithm

I am trying to compare 2 algorithms. I thought I may try and write a proof for them. (My math sucks, so hence the question.) Normally in our math lesson last year we would be given a question like . Prove:…
sonny
  • 229
  • 2
  • 4
  • 6
1
2
3
55 56