Menu
  • HOME
  • TAGS

Proving an algorithm correct by induction

algorithm,correctness,induction,eiffel,proof-of-correctness

Use the fact that 3n-1 = 3.3n-2 and 2n-1 = 2.2n-2 : 5(3n-1 - 2n-1) - 6(3n-2 - 2n-2) = 15(3n-2) - 10(2n-2) - 6(3n-2) + 6(2n-2) = 9.3n-2 - 4.2n-2 = 3n - 2n...

Open Type Level Proofs in Haskell/Idris

haskell,proof,category-theory,correctness,idris

I believe that McBride has answered that question (for Type Theory) in his ornament paper (pdf). The concept you are looking for is the one of an algebraic ornament (emphasis mine): An algebra φ describes a structural method to interpret data, giving rise to a fold φ oper- ation, applying...

Const variable declaration

c++,const,correctness

Well, first of all, it's neither necessary nor best practice - it's insufficient. You need a type too. Once you fill that in, the const is still not necessary, unless you try to take it by non-const reference. We have three choices that could compile: Foo qwerty = asdf.getFoo(); //...

Add integers safely, and prove the safety

c++,c,standards,verification,correctness

OP's approach is optimally portably staying within type int as well as safe - no undefined behavior (UB) with any combination of int. It is independent of a particular int format (2's complement, 2's complement, sign-magnitude). In C, int overflow/(underflow) is undefined behavior. So code, if staying with int, must...

Correctness and Logic of algorithm: minimum steps to one

c++,algorithm,logic,correctness

The "general solution" is incorrect. Sometime's it's optimal to divide by 2 and then subtract 1, and the general solution code doesn't allow for that. The "general solution" produces incorrect results for 642. 642 -> 214 -> 107 -> 106 -> 53 -> 52 -> 26 -> 13 -> 12...