proof

Functional proofs (Haskell)

放肆的年华 提交于 2019-12-10 00:42:46
问题 I failed at reading RWH; and not one to quit, I ordered Haskell: The Craft of Functional Programming . Now I'm curious about these functional proofs on page 146. Specifically I'm trying to prove 8.5.1 sum (reverse xs) = sum xs . I can do some of the induction proof but then I get stuck.. HYP: sum ( reverse xs ) = sum xs BASE: sum ( reverse [] ) = sum [] Left = sum ( [] ) (reverse.1) = 0 (sum.1) Right = 0 (sum.1) INDUCTION: sum ( reverse (x:xs) ) = sum (x:xs) Left = sum ( reverse xs ++ [x] )

Proof by case analysis in Coq

扶醉桌前 提交于 2019-12-07 10:05:38
问题 I am trying to prove a Proposition about the following function: Program Fixpoint division (m:nat) (n:nat) {measure m} : nat := match lt_nat 0 n with | false => 0 | true => match leq_nat n m with | false => 0 | true => S (division (menos m n) n) end end. menos is natural subtraction. I am trying to prove some fact involving division. I wrote down an informal proof were I first consider a case analysis in lt_nat 0 n and then in the case when lt_nat is true a further case analysis in leq_nat n

Is there a way to prove a program has no bug?

蓝咒 提交于 2019-12-07 05:33:18
问题 I was thinking about the fact that we can prove a program has bugs. We can test it to assess that it is more or less bug resistant. But is there a way (even theoretically) to prove that a program has no bug ? For simple programs, such as a "Hello World", I guess we should be able to do it. But what about larger programs ? 回答1: There are nowadays many different formalisms that can be used to prove programs correct (e.g., formalizations in proof assistants, dependently typed programming

Handling let in hypothesis

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 01:24:38
问题 As an exercise in Coq, I'm trying to prove that the following function returns a pair of lists of equal length. Require Import List. Fixpoint split (A B:Set)(x:list (A*B)) : (list A)*(list B) := match x with |nil => (nil, nil) |cons (a,b) x1 => let (ta, tb) := split A B x1 in (a::ta, b::tb) end. Theorem split_eq_len : forall (A B:Set)(x:list (A*B))(y:list A)(z:list B),(split A B x)=(y,z) -> length y = length z. Proof. intros A B x. elim x. simpl. intros y z. intros H. injection H. intros H1

Proving correctness of multithread algorithms

这一生的挚爱 提交于 2019-12-06 19:15:23
问题 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. Does anyone have a good reference (books, articles) for this? Thanks! 回答1: It is impossible to prove anything without building upon guarentees, so the first thing you want to do is to get familiar with the memory model of your target platform; Java

Can a red node have just 1 black child in a red-black tree?

二次信任 提交于 2019-12-06 07:45:23
The rules for a Red-Black Tree: Every node is either red or black. The root is black. Every leaf (NIL) is black. If a node is red, then both its children are black. For each node, all simple paths from the node to descendant leaves contain the same number of black nodes. Rule 4 mentions that red nodes need both black childs but what if there is just one child to begin with? Is there an argument to prove or disprove this? No,a red node cannot have one child,consider the following cases:- 1.If the single child it has is red...this cannot happen because no two consecutive nodes can be red. 2.If

How to implement `forall` (mathematics) in a procedural or OO language

安稳与你 提交于 2019-12-06 05:24:39
I am trying to understand how to implement forall in a procedural or OO language like Ruby or JavaScript. For example (this is Coq): Axiom point : Type. Axiom line : Type. Axiom lies_in : point -> line -> Prop. Axiom ax : forall (p1 p2 : point), p1 <> p2 -> exists! l : line, lies_in p1 l /\ lies_in p2 l. My attempt at doing this is just defining a class such as this (call MainAxiom == ax ). class MainAxiom attr :p1 attr :p2 def initialize raise 'Invalid' if @p1 == @p2 l = Line.new check_lies_in(l, @p1) check_lies_in(l, @p2) end def check_lies_in(line, point) ... end end This has all kinds of

Proof of associativity law for type-level set

我的未来我决定 提交于 2019-12-06 02:48:27
I'm trying to prove that type-level function Union is associative, but I'm not sure how it should be done. I proved right identity and associativity laws for type-level append function and right identity for union: data SList (i :: [k]) where SNil :: SList '[] SSucc :: SList t -> SList (h ': t) appRightId :: SList xs -> xs :~: (xs :++ '[]) appRightId SNil = Refl appRightId (SSucc xs) = case appRightId xs of Refl -> Refl appAssoc :: SList xs -> Proxy ys -> Proxy zs -> (xs :++ (ys :++ zs)) :~: ((xs :++ ys) :++ zs) appAssoc SNil _ _ = Refl appAssoc (SSucc xs) ys zs = case appAssoc xs ys zs of

In Coq, which tactic to change the goal from `S x = S y` to `x = y`

可紊 提交于 2019-12-06 01:52:26
I want to change the goal from S x = S y to x = y . It's like inversion , but for the goal instead of a hypothesis. Such a tactic seems legit, because when we have x = y , we can simply use rewrite and reflexivity to prove the goal. Currently I always find myself using assert (x = y) to introduce a new subgoal, but it's tedious to write when x and y are complex expression. The tactic apply f_equal. will do what you want, for any constructor or function. The lema f_equal shows that for any function f , you always have x = y -> f x = f y . This allows you to reduce the goal from f x = f y to x =

Well founded recursion in Coq

*爱你&永不变心* 提交于 2019-12-05 20:03:45
I am trying to write a function for computing natural division in Coq and I am having some trouble defining it since it is not structural recursion. My code is: Inductive N : Set := | O : N | S : N -> N. Inductive Bool : Set := | True : Bool | False : Bool. Fixpoint sum (m :N) (n : N) : N := match m with | O => n | S x => S ( sum x n) end. Notation "m + n" := (sum m n) (at level 50, left associativity). Fixpoint mult (m :N) (n : N) : N := match m with | O => O | S x => n + (mult x n) end. Notation "m * n" := (mult m n) (at level 40, left associativity). Fixpoint pred (m : N) : N := match m