Membership with decidable equality exercise

Assignment Help Programming Languages
Reference no: EM133170102

Assignment: Properties and logic

Exercise 1: Membership with decidable equality

(** Recall the type [sumbool] from ProSeSu22.v*)
(** An alternate way to characterize decision procedures, widely used in Coq, is via the inductive type [sumbool].

Suppose [Q] is a proposition, that is, [Q: Prop].
- We say [Q] is _decidable_ if there is an algorithm for computing a proof of [Q] or [~Q].
- More generally, when [P] is a predicate (a function from some type [T] to [Prop]), we say [P] is decidable when [forall x:T, decidable(P)].

We represent this concept in Coq by an inductive datatype: *)

(** Locate sumbool. =>

Inductive Coq.Init.Specif.sumbool

Print sumbool. =>

Inductive sumbool (A B : Prop) : Set := left : A -> {A} + {B} | right : B -> {A} + {B} you can find more about sumbool in ProSeSu22.v (in the course material folder) *)

Definition deceq (X: Type) := forall (x y : X), {x = y} + {x <> y}.

(** Now let us generalize what we did for lists natural numbers. Recall that [sumbool]s can be treated as "fancy bools"... *)

Fixpoint inb {X:Type} (d: deceq X) (a: X) (l : list X) : bool (* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.

(** The [sumboolP] view can prove quite useful below. *) Print sumboolP.

Theorem inbP {X:Type} (d: deceq X) n l : reflect (In n l) (inb d n l).
Proof. (* FILL IN HERE *) Admitted.

(** Let us now return to [nat]s, but in a somewhat roundabout way. *)

(** Here is yet another way of stating that a type has decidable equality. *)

Inductive booleq {X : Type} (d: X -> X -> bool) :=
Beq : (forall x : X, d x x = true) ->
(forall x y : X, d x y = true -> x = y) -> booleq d.

Theorem refbool {X: Type} {d: X -> X -> bool} (be: booleq d) : deceq X.
Proof. (* FILL IN HERE *) Admitted.

(** Now you might search a bit for theorems about [eqb], or prove the following fact directly. *)

Theorem eqb_wrap : booleq eqb.
Proof. (* FILL IN HERE *) Admitted.

Corollary innatP {X:Type} n l : reflect (In n l) (inb (refbool eqb_wrap) n l).
Proof. (* FILL IN HERE *) Admitted.

(** The last result should be just an application of [inbP]. *)

(** Of course, there is a still quicker route to show inhabitation of [deceq nat]: standard library... *)

Check eq_dec.

Definition exact_deceq : (deceq nat). exact (eq_dec). Defined.

Exercise 2: Reflection for predicates on lists

(** The standard library offers an inductive predicate for comparing lists wrt to a given binary relation *)

Print Forall2.

(**

Inductive Forall2 (A B : Type) (R : A -> B -> Prop) : list A -> list B -> Prop :=
Forall2_nil : Forall2 R [] []
| Forall2_cons : forall (x : A) (y : B) (l : list A) (l' : list B),
R x y -> Forall2 R l l' -> Forall2 R (x :: l) (y :: l')
*)

(** First, let us recall what it means for a relation to be reflected by a binary function. *)

Definition Rreflected {A B : Type} (R : A -> B -> Prop) (f: A -> B -> bool) :=
forall a b, reflect (R a b) (f a b).

(** Define its boolean counterpart. It might be a good idea to do pattern matching on two arguments at the same time. *)

Fixpoint forall2 {A B : Type} (R : A -> B -> Prop) (f: A -> B -> bool) (P: Rreflected R f) (la: list A) (lb : list B) : bool (* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.

(** In the following proof, you might:
- want to think whether you do induction first, or rather apply some trivial reflection view first to split the goal
- recall you can handle boolean conjunctions with [move => /andP ...]
- realize that (instantiated) premises can be also used as reflection views.
*)

Theorem forall2P {A B : Type} (R : A -> B -> Prop) (f: A -> B -> bool) : forall (P: Rreflected R f), Rreflected (Forall2 R) (forall2 R f P).
Proof.
(* FILL IN HERE *) Admitted.

Exercise 3: constructive quantification

(** Many of familiar laws for quantifiers still hold for constructive logic.

Here and everywhere below you can actually provide a normal tactic proof if writing down proof term provides too difficult. *)

Definition notexists_forallnot : forall (X:Type) (P : X -> Prop),
~ (exists x : X, P x) -> (forall x : X, ~ P x)
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.

Definition forallnot_notexists : forall (X:Type) (P : X -> Prop),
(forall x, ~ P x) -> ~ (exists x, P x)
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.

Definition forallnot_equiv_notexists : forall (X:Type) (P : X -> Prop),
(forall x, ~ P x) <-> ~ (exists x, P x)
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.

Definition forallnotnot_equiv_notexistsnot : forall (X:Type) (P : X -> Prop),
(forall x, ~ ~ P x) <-> ~ (exists x, ~ P x)
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.

Lemma CEpqENpNq : forall P Q, (P <-> Q) -> (~P <-> ~Q).
Proof.
(* FILL IN HERE *) Admitted.

Definition notforallnot_equiv_notnotexists : forall (X:Type) (P : X -> Prop),
~(forall x, ~ P x) <-> ~ ~ (exists x, P x)
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.

Definition existsnot_notforall : forall (X:Type) (P : X -> Prop),
(exists x, ~ P x) -> ~ (forall x, P x)
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.

Definition forall_notexistsnot : forall (X:Type) (P : X -> Prop),
(forall x, P x) -> ~ (exists x, ~ P x)
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.

(** How about the converse of the last one? As it turns out, it requires classical logic, see below ... *)

(** [] *)

Attachment:- Assignment3_exercises.rar

Reference no: EM133170102

Questions Cloud

Compare and contrast the following labor laws : Compare and contrast the following labor laws. Wagner Act, Taft Hartley Act and Landrum Griffin Act. Describe important provisions of each of these laws.
Explain the interplay between ehtics value and law : Explain the interplay between ehtics value and law, highlight at least ten Kenyan legislative provision that guide the conduct of business and commercial activ
Ecotourism management discussions : 1. Drawing on your own experience and the reading do you think that there is an ecotourism myth? Is it viewed as being inherently more sustainable than other to
Find a concept restaurant in vietnam and share a photo : Find a concept restaurant in Vietnam and share a photo (you can take the photo yourself or use one, properly cited, from the restaurant's website or social medi
Membership with decidable equality exercise : Membership with decidable equality Exercise - The standard library offers an inductive predicate for comparing lists wrt to a given binary relation
What is the expected dividend payout for this budget year : roject B is a $450,000 project with an estimated IRR of 14%. The company follows a residual dividend policy. What is the expected dividend payout
Discuss the impact of the pandemic on trade protectionism : 1. Analyse how the covid-19 pandemic, climate change, and geopolitics fuel the latest retreat from globalization.
Expertise in the field of career planning : Your task is to showcase your expertise in the field of career planning.
Prepare journal entries to record the foregoing transactions : Prepare journal entries to record the foregoing transactions assuming the university is a private, not-for-profit institution in an Excel spreadsheet

Reviews

len3170102

6/24/2022 10:03:56 PM

I''ve already requested this functional programming assigment (Coq). therefore now instead of the 5 exercises (full assigment) I would like only the first 3 exercises (now it’s 187 lines of code instead of 328) and without the more difficult parts of them. I mean, only the 70-80% of the first 3 exercises, omitting the harder tasks. The deadline is also extended till 29 10am. (I’m uploading a new zip) The concrete assignment is here: HAssignment3_exercises3 I''ve also included the course material. It would be nice if you could use mostly Vanilla Ltac tactics instead of SSReflect. Also would be nice if you could use those tactics and styles of proving/defining which are used in the course material too.

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd