Skip to content

Instantly share code, notes, and snippets.

View MikeMKH's full-sized avatar
:shipit:
Learning about logic programming with Prolog

Mike Harris MikeMKH

:shipit:
Learning about logic programming with Prolog
  • Milwaukee, WI
  • 01:07 (UTC -05:00)
View GitHub Profile
@MikeMKH
MikeMKH / ex5_1.v
Created April 28, 2017 11:35
Polymorphic minimal propositional logic in Coq from Coq Art
(* exercise 5.1 from Coq Art *)
Lemma id_P :
forall P : Prop, P -> P.
Proof.
intros P H.
assumption.
Qed.
Lemma id_PP :
@MikeMKH
MikeMKH / ex4_3.v
Created April 27, 2017 10:57
Look at inference rules in Coq from Coq Art
(* exercise 4.3 from Coq Art *)
Lemma all_perm :
forall (A : Type) (P : A -> A -> Prop),
(forall x y : A, P x y) ->
forall x y : A, P y x.
Proof.
intros A P H x y.
apply H.
Qed.
@MikeMKH
MikeMKH / reduction.v
Created April 25, 2017 11:35
Simple reductions in Coq from Coq Art.
Definition ninc (n : nat) : nat := n + 1.
Definition ntwice (f : nat -> nat) (n : nat) : nat := f (f n).
Eval cbv in (ntwice ninc 0).
(* = 2 *)
Eval cbv delta [ninc ntwice] in (ntwice ninc 0).
(* = (fun (f : nat -> nat) (n : nat) => f (f n)) (fun n : nat => n + 1) 1 *)
Eval cbv delta [ninc] in (ntwice ninc 0).
@MikeMKH
MikeMKH / ex3_5.v
Last active April 27, 2017 10:56
Simple example of the cut rule in Coq with and without the using the cut rule from Coq Art
(* exercise 3.5 from Coq Art *)
Section section_for_cut_example.
Variables P Q R T : Prop.
Hypotheses (H : P -> Q)
(H0 : Q -> R)
(H1 : (P -> R) -> T -> Q)
(H2 : (P -> R) -> T).
@MikeMKH
MikeMKH / ex3_2.v
Created April 20, 2017 11:49
Simple Coq proofs using just intro, apply, and assumption from Coq Art
(* exercise 3.2 from Coq Art *)
Variables P Q R T : Prop.
Lemma id_P : P -> P.
Proof.
intro H.
assumption.
Qed.
@MikeMKH
MikeMKH / binarySystem.v
Created April 19, 2017 11:43
Binary system in Coq taken from More Exercises section of https://www.seas.upenn.edu/~cis500/current/sf/Basics.html
(* taken from More Exercies - exercie 3 of https://www.seas.upenn.edu/~cis500/current/sf/Basics.html *)
Inductive bin : Type :=
| Zero : bin
| Twice : bin -> bin
| More : bin -> bin.
Function bin_incr (n : bin) : bin :=
match n with
| Zero => More Zero
@MikeMKH
MikeMKH / more.v
Created April 18, 2017 11:32
Simple proofs in Coq taken from More Exercises section of https://www.seas.upenn.edu/~cis500/current/sf/Basics.html
(* taken from More Exercises sections in https://www.seas.upenn.edu/~cis500/current/sf/Basics.html *)
Theorem identity_fn_applied_twice :
forall (f : bool -> bool),
(forall (x : bool), f x = x)
-> forall (b : bool), f (f b) = b.
Proof.
intros f H b.
rewrite -> H.
rewrite -> H.
@MikeMKH
MikeMKH / caseAnalysis.v
Created April 17, 2017 11:25
Simple proofs using case analysis in Coq taken from By Case Analysis section of https://www.seas.upenn.edu/~cis500/current/sf/Basics.html
(* taken from By Case Analysis section of https://www.seas.upenn.edu/~cis500/current/sf/Basics.html *)
Fixpoint beq_nat (n m : nat) : bool :=
match n, m with
| O, O => true
| O, _ => false
| S _, O => false
| S n', S m' => beq_nat n' m'
end.
@MikeMKH
MikeMKH / rewriting.v
Created April 12, 2017 11:36
Simple proofs using Rewrite in Coq, taken from Proof by Rewriting section of https://www.seas.upenn.edu/~cis500/current/sf/Basics.html
(* taken from the Proof by Rewriting section of https://www.seas.upenn.edu/~cis500/current/sf/Basics.html *)
Theorem plus_id : forall n m : nat,
n = m -> n + n = m + m.
Proof.
intros.
rewrite <- H.
reflexivity.
Qed.
@MikeMKH
MikeMKH / bySimpl.v
Created April 11, 2017 11:42
Simple proofs using Simplification in Coq, taken from Proof by Simplification section of https://www.seas.upenn.edu/~cis500/current/sf/Basics.html
(* taken from https://www.seas.upenn.edu/~cis500/current/sf/Basics.html *)
Theorem plus_0_l : forall n : nat, 0 + n = n.
Proof.
intros.
simpl.
reflexivity.
Qed.
Theorem plus_1_l : forall n : nat, 1 + n = S n.