coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: "Rui Baptista" <rui.baptista AT mail.com>
- To: coq-club AT inria.fr
- Cc: "coq-club AT inria.fr" <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] Partial functions in Coq
- Date: Fri, 26 Sep 2014 17:23:15 +0200
- Importance: normal
- Sensitivity: Normal
(* You can also work instead with the predicate behind the function. *)
Conjecture Z : Set.
Conjecture sub : Z -> Z -> Z.
Conjecture leq : Z -> Z -> Prop.
Conjecture sub : Z -> Z -> Z.
Conjecture leq : Z -> Z -> Prop.
Infix "-" := sub : Z_scope.
Infix "<=" := leq : Z_scope.
Infix "<=" := leq : Z_scope.
Delimit Scope Z_scope with Z.
Require Import Coq.Setoids.Setoid.
Conjecture C1 : forall P, True /\ P <-> P.
Conjecture C2 : forall P, P /\ True <-> P.
Conjecture C3 : forall A (x : A), x = x <-> True.
Conjecture C4 : forall i j, (i <= j)%Z \/ (j <= i)%Z <-> True.
Conjecture C2 : forall P, P /\ True <-> P.
Conjecture C3 : forall A (x : A), x = x <-> True.
Conjecture C4 : forall i j, (i <= j)%Z \/ (j <= i)%Z <-> True.
Hint Rewrite C1 C2 C3 C4 : Hints.
Definition diff : Z -> Z -> Z -> Prop := fun i j k => (i <= j)%Z /\ (i - j)%Z = k.
Goal forall i j, diff i j (i - j)%Z \/ diff j i (j - i)%Z.
unfold diff; repeat (firstorder; autorewrite with Hints in *).
unfold diff; repeat (firstorder; autorewrite with Hints in *).
Qed.
(* If you want to compose your partial functions, you can refactor them to not just return predicates but also take them as input. If they are undefined for a certain input, they return the empty predicate, if they are defined, they return a singleton predicate, and if you want to, you can also return multiple values. *)
Definition singleton : forall {A}, A -> (A -> Prop) := @eq.
Definition equal : forall {A}, (A -> Prop) -> (A -> Prop) -> Prop := fun A P Q => forall x, P x <-> Q x.
Notation "{{ x }}" := (singleton x) (at level 0).
Infix "==" := equal (at level 70).
Definition diff2 : (Z -> Prop) -> (Z -> Prop) -> (Z -> Prop) := fun P Q i => exists j k, P j /\ Q k /\ diff j k i.
Goal forall i j, diff2 {{i}} {{j}} == {{(i - j)%Z}} \/ diff2 {{j}} {{i}} == {{(j - i)%Z}}.
Admitted.
Admitted.
(* Regards, Rui *)
- [Coq-Club] Partial functions in Coq, Iain Whiteside, 09/25/2014
- Re: [Coq-Club] Partial functions in Coq, Pierre Courtieu, 09/25/2014
- Re: [Coq-Club] Partial functions in Coq, Rui Baptista, 09/26/2014
Archive powered by MHonArc 2.6.18.