coq

Coq: how to apply one hypothesis to another

这一生的挚爱 提交于 2019-12-30 08:09:11
问题 Assume I have two hypotheses in the context, a_b : A -> B and a : A . I should be able to apply a_b to a to gain a further hypothesis, b : B . That is, given the following state: 1 subgoal A : Prop B : Prop C : Prop a_b : A -> B a : A ______________________________________(1/1) C There should be some tactic, foo (a_b a) , to transform this into the following state: 1 subgoal A : Prop B : Prop C : Prop a_b : A -> B a : A b : B ______________________________________(1/1) C But I don't know what

Proving f (f bool) = bool

核能气质少年 提交于 2019-12-30 06:00:25
问题 How can I in coq, prove that a function f that accepts a bool true|false and returns a bool true|false (shown below), when applied twice to a single bool true|false would always return that same value true|false : (f:bool -> bool) For example the function f can only do 4 things, lets call the input of the function b : Always return true Always return false Return b (i.e. returns true if b is true vice versa) Return not b (i.e. returns false if b is true and vice vera) So if the function

How do I prove that two Fibonacci implementations are equal in Coq?

╄→гoц情女王★ 提交于 2019-12-30 05:27:22
问题 I've two Fibonacci implementations, seen below, that I want to prove are functionally equivalent. I've already proved properties about natural numbers, but this exercise requires another approach that I cannot figure out. The textbook I'm using have introduced the following syntax of Coq, so it should be possible to prove equality using this notation: <definition> ::= <keyword> <identifier> : <statement> <proof> <keyword> ::= Proposition | Lemma | Theorem | Corollary <statement> ::= {

Nested recursion and `Program Fixpoint` or `Function`

我与影子孤独终老i 提交于 2019-12-30 04:49:05
问题 I’d like to define the following function using Program Fixpoint or Function in Coq: Require Import Coq.Lists.List. Import ListNotations. Require Import Coq.Program.Wf. Require Import Recdef. Inductive Tree := Node : nat -> list Tree -> Tree. Fixpoint height (t : Tree) : nat := match t with | Node x ts => S (fold_right Nat.max 0 (map height ts)) end. Program Fixpoint mapTree (f : nat -> nat) (t : Tree) {measure (height t)} : Tree := match t with Node x ts => Node (f x) (map (fun t => mapTree

How to call proof asistant Coq from external software

可紊 提交于 2019-12-30 02:26:04
问题 How to call proof assistant Coq from external software? Does Coq have some API? Is Coq command line interface rich enough to pass arguments in file and receive response in file? I am interested in Java or C++ bridges. This is legitimate question. Coq is not the usual business software from which one can expect the developer friendly API. I had similary question about Isabelle/HOL and it was legitimate question with non-trivial answer. 回答1: As of today, there are three ways to interact with

How or is that possible to prove or falsify `forall (P Q : Prop), (P -> Q) -> (Q -> P) -> P = Q.` in Coq?

眉间皱痕 提交于 2019-12-28 18:04:06
问题 I want to prove or falsify forall (P Q : Prop), (P -> Q) -> (Q -> P) -> P = Q. in Coq. Here is my approach. Inductive True2 : Prop := | One : True2 | Two : True2. Lemma True_has_one : forall (t0 t1 : True), t0 = t1. Proof. intros. destruct t0. destruct t1. reflexivity. Qed. Lemma not_True2_has_one : (forall (t0 t1 : True2), t0 = t1) -> False. Proof. intros. specialize (H One Two). inversion H. But, inversion H does nothing. I think maybe it's because the coq's proof independence (I'm not a

Why are logical connectives and booleans separate in Coq?

感情迁移 提交于 2019-12-28 04:14:30
问题 I come from a JavaScript/Ruby programming background and am used to this being how true/false works (in JS): !true // false !false // true Then you can use those true/false values with && like var a = true, b = false; a && !b; So and and not (and other logical/boolean operators) are part of a single system; it seems like the "logical" system and the "boolean" system are one and the same. However, in Coq, logics and booleans are two separate things. Why is this? The quote/link below

Using reflexivity in Coq

倖福魔咒の 提交于 2019-12-25 07:54:03
问题 I was trying out the examples from the Coq documentation Software Foundations (http://www.cis.upenn.edu/~bcpierce/sf/current/Induction.html#lab40) when I noticed that to solve the example give in the link: Theorem andb_true_elim1 : ∀b c : bool, andb b c = true → b = true. Proof. intros b c H. destruct b. Case "b = true". (* <----- here *) reflexivity. Case "b = false". (* <---- and here *) rewrite ← H. reflexivity. Qed. we are destructing b which appears on the left of c for "andb". However

Induction principle for `le`

我怕爱的太早我们不能终老 提交于 2019-12-25 02:24:06
问题 For the inductive type nat , the generated induction principle uses the constructors O and S in its statement: Inductive nat : Set := O : nat | S : nat -> nat nat_ind : forall P : nat -> Prop, P 0 -> (forall n : nat, P n -> P (S n)) -> forall n : nat, P n But for le , the generated statement does not uses the constructors le_n and le_S : Inductive le (n : nat) : nat -> Prop := le_n : n <= n | le_S : forall m : nat, n <= m -> n <= S m le_ind : forall (n : nat) (P : nat -> Prop), P n -> (forall

applying a function with different field

我与影子孤独终老i 提交于 2019-12-25 01:31:36
问题 Is there a way, to apply an hypotesis to our goal in Coq ? For example: Hypothesis: 1 subgoal a : nat l1 : list nat l2 : list nat H : Prefix (a :: l1) l2 IHl1 : Prefix l1 l2 -> sum l1 <= sum l2 Goal ______________________________________(1/1) sum (a :: l1) <= sum l2 I know that if i could do : apply IHl1 , i could have a result like Prefix (a::l1) l2 and after i will be able to do an assumption ! But i can't do the apply because it's giving me this error : Error: Impossible to unify "sum l1 <