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

  Program to calculate area of two-dimensional shape

Implement the Shape hierarchy shown in following figure. Each TwoDimensionalShape should contain method getArea to calculate the area of the two-dimensional shape.

  Program asks for number of shares-whole dollar portion price

Program asks for number of shares held, whole dollar portion of price, and fraction portion. fraction portion is to be input as two integer values, one for numerator and one for the denominator.

  Compares lisp with either prolog java c-cpp or python

Write a short paper (800-1000 words) that compares and contrasts Lisp with either Prolog, Java, C/C++, or Python.

  Program to permit company-s clerks to enter employee-s name

Temp Employers wants program which will permit company's clerks to enter employee's name and number of hours employee worked during month.

  Write client-server program and perform popularity checking

For project you are required to write a client/server program and perform popularity checking - Your management has interest in finding out

  Write program to bounce blue ball inside jpanel

Write a program which bounces the blue ball inside JPanel. Ball must begin moving with the mousePressed event. When ball hits edge of JPanel, it must bounce off edge.

  Write a loop that finds the longest name on the list

Write a loop that finds the longest name on the following list, and prints it out: [Doc, Grumpy, Happy, Sleepy, Bashful, Sneezy, Dopey]. Write a loop that.

  Characteristics used for biometric user authentication

You have just been promoted to manager of computer security for large enterprise (XYZ Corporation). Your first project as security manager is to estimate principal physical characteristics used for biometric user authentication.

  Prompt the user for the number of darts to throw

After informing the user what the program does, prompt the user for the number of darts to throw. Also, prompt for a number of simulations (why not have the program simulate this dart throwing more than once).

  Create a text-based program for storing data on hotel room

ITECH5403 – Comparative Programming Languages-Federation University- Australia-You are tasked with creating a text-based program for storing data on Hotel Room.

  Create the application class using appropriate application

Test the class by placing the hard coded data into the driver class, which then instantiates your class and calls its instance method. Pass the hard coded data into the constructor and/or method.

  Write a script in perl

Write separate Perl scripts for each of the given requirements. Mentioned input data files are attached with this posting. In each case command to run the script from the command line should look like:

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