Module mathcomp.classical.contra

From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq.
From mathcomp Require Import boolp.

Unset SsrOldRewriteGoalsOrder.  
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.

# Contraposition This file provides tactics to reason by contraposition and contradiction. ## Tactics ``` assume_not == add a goal negation assumption. The tactic also works for goals in Type, simplifies the added assumption, and exposes its top-level constructive content. absurd_not == proof by contradiction. Same as assume_not, but the goal is erased and replaced by False. Caveat: absurd_not cannot be used as a move/ view because its conclusion is indeterminate. The more general notP can be used instead. contra == proof by contraposition. Change a goal of the form assumption -> conclusion to ~ conclusion -> ~ assumption. As with assume_not, contra allows both assumption and conclusion to be in Type, simplifies the negation of both assumption and conclusion, and exposes the constructive contents of the negated conclusion. The contra tactic also supports a limited form of the ':' discharge pseudo tactical, whereby contra: <d-items> means move: <d-items>; contra. The only <d-items> allowed are one term, possibly preceded by a clear switch. absurd == proof by contradiction. The defective form of the tactic simply replaces the entire goal with False (just as the Ltac exfalso), leaving the user to derive a contradiction from the assumptions. The ':' form absurd: <d-items> replaces the goal with the negation of the (single) <d-item> (as with contra:, a clear switch is also allowed. Finally the Ltac absurd term form is also supported. ```

Hiding module for the internal definitions and lemmas used by the tactics defined here.
Module InternalsSource code.

A wrapper for view lemmas with an indeterminate conclusion (of the form forall ... T ..., pattern -> T), and for which the intended view pattern may fail to match some assumptions. This wrapper ensures that such views are only used in the forward direction (as in move/), and only with the appropriate move_viewP hint, preventing its application to an arbitrary assumption A by the instatiation to A -> T' of its indeterminate conclusion T. This is similar to the implies wrapper, except move_viewP is *NOT* declared as a coercion---it must be used explicitly to apply the view manually to an assumption (as in, move_viewP my_view some_assumption).

Variant move_viewSource code SSource code TSource code := MoveViewSource code of S -> T.
Definition move_viewP
Source code
{SSource code TSource code} mvSource code : S -> T := let: MoveView v := mv in v.
Hint View for move/ move_viewP|2.

## Type-level equivalence

Variant equivTSource code SSource code TSource code := EquivTSource code of S -> T & T -> S.

Definition equivT_refl
Source code
SSource code : equivT S S := EquivT id id.
Definition equivT_transl
Source code
{SSource code TSource code USource code} : equivT S T -> equivT S U -> equivT T U :=
  fun (stSource code : equivT S T) (suSource code : equivT S U) =>
    let: EquivT S_T T_S := st in
    let: EquivT S_U U_S := su in
    EquivT (S_U \o T_S) (S_T \o U_S).
Definition equivT_sym
Source code
{SSource code TSource code} : equivT S T -> equivT T S :=
   equivT_transl^~ (equivT_refl S).
Definition equivT_trans
Source code
{SSource code TSource code USource code} : equivT S T -> equivT T U -> equivT S U :=
   equivT_transl \o equivT_sym.
Definition equivT_transr
Source code
{SSource code TSource code USource code} eqSTSource code : equivT U S -> equivT U T :=
   equivT_trans^~ eqST.
Definition equivT_Prop
Source code
 (PSource code QSource code : Prop) : (equivT P Q) <-> (equivT P Q).
Proof.
split; destruct 1; split; assumption. Defined.
Definition equivT_LR
Source code
{SSource code TSource code} (eqSource code : equivT S T) : S -> T :=
  let: EquivT S_T _ := eq in S_T.
Definition equivT_RL
Source code
{SSource code TSource code} (eqSource code : equivT S T) : T -> S :=
  let: EquivT _ T_S := eq in T_S.

Hint View for move/ equivT_LR|2 equivT_RL|2.
Hint View for apply/ equivT_RL|2 equivT_LR|2.

A generic Forall "constructor" for the Gallina forall quantifier, i.e., ``` \Forall x, P := Forall (fun x => P) := forall x, P. ``` The main use of Forall is to apply congruence to a forall equality: ``` congr1 Forall : forall P Q, P = Q -> Forall P = Forall Q. ``` in particular in a classical setting with function extensionality, where we can have (forall x, P x = Q x) -> (forall x, P x) = (forall x, Q x). We use a forallSort structure to factor the ad hoc PTS product formation rules; forallSort is keyed on the type of the entire forall expression, or (up to subsumption) the type of the forall body---this is always a sort. This implementation has two important limitations: 1. It cannot handle the SProp sort and its typing rules. However, its main application is extensionality, which is not compatible with SProp because an (A : SProp) -> B "function" is not a generic (A : Type) -> B function as SProp is not included in Type. 2. The Forall constructor can't be inserted by a straightforward unfold (as in, rewrite -[forall x, _]/(Forall _)) because of the way Coq unification handles Type constraints. The ForallI tactic mitigates this issue, but there are additional issues with its implementation---see below.

Structure forallSortSource code ASource code :=
  ForallSort {forall_sortSource code :> Type; _ : (A -> forall_sort) -> forall_sort}.

Notation mkForallSortSource code A S := (@ForallSort A S (fun TSource code => forall xSource code, T x)).
Polymorphic Definition TypeForall
Source code
 (SSource code := Type) (ASource code : S) := mkForallSort A S.
Canonical TypeForall.

Canonical PropForall
Source code
ASource code := mkForallSort A Prop.

Canonical SetForall
Source code
 (ASource code : Set) := mkForallSort A Set.

Definition Forall
Source code
{ASource code} {SSource code : forallSort A} :=
  let: ForallSort _ F := S return (A -> S) -> S in F.

Notation "\Forall x .. z , T"Source code :=
   (Forall (fun xSource code => .. (Forall (fun zSource code => T)) ..))
  (at level 200, x binder, z binder, T at level 200,
   format "'[hv' '\Forall' '[' x .. z , ']' '/ ' T ']'") : type_scope.

Tactic Notation "ForallI" ssrpatternarg(pat) :=
  let F := fresh "F" in ssrmatching.ssrpattern pat => F;
  case: F / (@erefl _ F : Forall _ = _).
Tactic Notation "ForallI" := ForallI (forall xSource code, _).

We define specialized copies of the wrapped structure of ssrfun for Prop and Type, as we need more than two alternative rules (indeed, 3 for Prop and 4 for Type). We need separate copies for Prop and Type as universe polymorphism cannot instantiate Type with Prop.

Structure wrappedPropSource code := WrapProp {unwrap_PropSource code :> Prop}.
Definition wrap4Prop

pinfty_nbhs : forall R : numFieldType, set_system R pinfty_nbhs is not universe polymorphic Arguments pinfty_nbhs R _ pinfty_nbhs is transparent Expands to: Constant mathcomp.analysis.normedtype_theory.num_normedtype.pinfty_nbhs Declared in library mathcomp.analysis.normedtype_theory.num_normedtype, line 222, characters 11-22


Source code
:= WrapProp.
Definition wrap3Prop

ninfty_nbhs : forall R : numFieldType, set_system R ninfty_nbhs is not universe polymorphic Arguments ninfty_nbhs R _ ninfty_nbhs is transparent Expands to: Constant mathcomp.analysis.normedtype_theory.num_normedtype.ninfty_nbhs Declared in library mathcomp.analysis.normedtype_theory.num_normedtype, line 225, characters 11-22


Source code
:= wrap4Prop.
Definition wrap2Prop

is_interval : forall {R : numDomainType}, set R -> Prop is_interval is not universe polymorphic Arguments is_interval {R} E%_classical_set_scope is_interval is transparent Expands to: Constant mathcomp.analysis.normedtype_theory.num_normedtype.is_interval Declared in library mathcomp.analysis.normedtype_theory.num_normedtype, line 812, characters 11-22


Source code
:= wrap3Prop.
Canonical wrap1Prop

itvoo_basis : forall {R : realFieldType}, set_system R itvoo_basis is not universe polymorphic Arguments itvoo_basis {R} _ itvoo_basis is transparent Expands to: Constant mathcomp.analysis.normedtype_theory.num_normedtype.itvoo_basis Declared in library mathcomp.analysis.normedtype_theory.num_normedtype, line 846, characters 11-22


Source code
PSource code := wrap2Prop P.

Polymorphic Structure wrappedTypeSource code@{i} := WrapType {unwrap_TypeSource code :> Type@{i}}.
Polymorphic Definition wrap4Type

bigcup_ointsub : forall {R : realType}, set R -> rat -> set R bigcup_ointsub is not universe polymorphic Arguments bigcup_ointsub {R} U%_classical_set_scope q%_ring_scope _ bigcup_ointsub is transparent Expands to: Constant mathcomp.analysis.normedtype_theory.num_normedtype.bigcup_ointsub Declared in library mathcomp.analysis.normedtype_theory.num_normedtype, line 871, characters 11-25


Source code
@{i} := WrapType@{i}.
Polymorphic Definition wrap3Type

interior_itv : forall {R : realType}, (forall (x y : R) (a b : bool), interior [set` Interval (BSide a x) (BSide b y)] = `]x, y[%classic) * (forall (x : R) (b : bool), interior [set` Interval (BSide b x) +oo%O] = `]x, +oo[%classic) * (forall (y : R) (b : bool), interior [set` Interval -oo%O (BSide b y)] = `]-oo, y[%classic) * (interior `]-oo, +oo[ = `]-oo, +oo[%classic) interior_itv is not universe polymorphic Arguments interior_itv {R} interior_itv is transparent Expands to: Constant mathcomp.analysis.normedtype_theory.num_normedtype.interior_itv Declared in library mathcomp.analysis.normedtype_theory.num_normedtype, line 1029, characters 11-23


Source code
@{i} := wrap4Type@{i}.
Polymorphic Definition wrap2Type
Source code
@{i} := wrap3Type@{i}.
Polymorphic Definition wrap1Type
Source code
@{i} (TSource code : Type@{i}) := wrap2Type T.
Canonical wrap1Type.

Lemma generic_forall_extensionalitySource code {ASource code} {SSource code : forallSort A} {PSource code QSource code : A -> S} :
  P =1 Q -> Forall P = Forall Q.
Proof.
by move/funext->. Qed.

A set of tools (tactics, views, and rewrite rules) to facilitate the handling of classical negation. The core functionality of these tools is implemented by three sets of canonical structures that provide for the simplification of negation statements (e.g., using de Morgan laws), the conversion from constructive statements in Type to purely logical ones in Prop (equivalently, expansion rules for the statement inhabited T), and conversely extraction of constructive contents from logical statements. Except for bool predicates and operators, all definitions are treated transparently when matching statements for either simplification or conversion; this is achieved by using the wrapper telescope pattern, first delegating the matching of specific logical connectives, predicates, or type constructors to an auxiliary structure that *FAILS* to match unknown operators, thus triggers the expansion of defined constants. If this ultimately fails then the wrapper is expanded, and the primary structure instance for the expanded wrapper provides an alternative default rule: not simplifying ~ P, not expanding inhabited T, or not extracting any contents from a proposition P, respectively. Additional rules, for intermediate wrapper instances, are used to handle forall statements (for which canonical instances are not yet supported), as well as addiitonal simplifications, such as inhabited P = P :> Prop. Finally various tertiary structures are used to match deeper patterns, such as bounded forall statements of the form forall x, P x -> Q x, or inequalites x != y (i.e., is_true (~~ (x == y))). As mentioned above, tertiary rules for bool subexpressions do not try to expand definitions, as this would lead to the undesirable expansion of some standard definitions. This is simply achieved by *NOT* using the wrapper telescope pattern, and just having a default instance alongside those for specific predicates and connectives.

The negatedProp structure provides simplification of the Prop negation (~ _) for standard connectives and predicates. The instances below cover the pervasive and ssrbool Prop connectives, decidable equality, as well as bool propositions (i.e., the is_true predicate), together with a few bool connectives and predicates: negation ~~, equality ==, and nat <= and <. Others can be added (e.g., Order.le/lt) by declaring appropriate instances of bool_negation and bool_affirmation, while other Prop connectives and predicates can be added by declaring instances of proper_negatedProp.

The implementation follows the wrapper telescope pattern outlined above: negatedProp instances match on the wrappedProp wrapper to try three generic matching rules, in succession: - Rule 1: match a specific connective or predicate with an instance of the properNegatedProp secondary structure, expanding definitions if needed, but failing if no proper match is found. - Rule 2: match a forall statement (including (T : Type) -> P statements). - Rule 3: match any Prop but return the trivial simplification. The simplified proposition is returned as a projection parameter nP rather than a Structure member, so that applying the corresponding views or rewrite rules doesn't expose the inferred structures; properNegatedProp does similarly. Also, negatedProp similarly returns a 'trivial' bool flag that is set when Rule 3 is used, but this is actually used in the reverse direction: views notP and rewrite rule notE force trivial := false, thus excluding trivial instances.

Structure negatedPropSource code (trivialSource code : bool) nPSource code :=
  NegatedProp {negated_PropSource code :> wrappedProp; _ : (~ negated_Prop) = nP}.

Structure properNegatedPropSource code nPSource code := ProperNegatedProp {
  proper_negated_PropSource code :> Prop; _ : (~ proper_negated_Prop) = nP}.

Local Notation nPropSource code t nP P := (unwrap_Prop (@negated_Prop t nP P)).
Local Notation nPredSource code t nP P x := (nProp t (nP x) (P x)).
Local Notation pnPropSource code nP P := (@proper_negated_Prop nP P).

User views and rewrite rules. The plain versions (notP, notE and notI) do not match trivial instances; lax_XXX versions allow them. In addition, the negation introduction rewrite rule notI does not match forall or -> statements---lax_notI must be used for these.

Lemma lax_notESource code {tSource code nPSource code} PSource code : (~ nProp t nP P) = nP
Proof.
by case: P. Qed.
Lemma lax_notPUsed by
  • mathcomp.analysis.topology_theory.metric_structure
  • mathcomp.classical.wochoice

Source code
{tSource code nPSource code PSource code} : ~ nProp t nP P -> nP
Proof.
by rewrite lax_notE. Qed.
Definition lax_notI
Source code
{tSource code nPSource code} PSource code : nProp t nP P = (~ nP) := canRL notK (lax_notE P).

#[warn(note="A different `notE` used to be provided by `boolp.v` before MathComp-Analysis 1.15.0.")]
Definition notE
Source code
{nPSource code} PSource code : (~ nProp false nP P) = nP := lax_notE P.
#[warn(note="A different `notP` used to be provided by `boolp.v` before MathComp-Analysis 1.15.0.")]
Definition notP
Source code
{nPSource code PSource code} := MoveView (@lax_notP false nP P).

Fact proper_nPropPSource code nPSource code PSource code : (~ pnProp nP P) = nP
Proof.
by case: P. Qed.
Definition notI
Source code
{nPSource code} PSource code : pnProp nP P = (~ nP) := canRL notK (proper_nPropP P).

Rule 1: proper negation simplification, delegated to properNegatedProp.
Canonical proper_nProp
Source code
nPSource code PSource code :=
  @NegatedProp false nP (wrap1Prop (pnProp nP P)) (proper_nPropP P).

Rule 2: forall_nProp is defined below as it uses exists_nProp.

Rule 3: trivial negation.
Canonical trivial_nProp
Source code
PSource code := @NegatedProp true (~ P) (wrap3Prop P) erefl.

properNegatedProp instances.

Canonical True_nProp
Source code
:= @ProperNegatedProp False True notB.1.
Canonical False_nProp

mx_norm : forall [K : numDomainType] {m n : nat}, 'M_(m, n) -> K mx_norm is not universe polymorphic Arguments mx_norm [K] {m n}%_nat_scope x%_ring_scope mx_norm is transparent Expands to: Constant mathcomp.analysis.normedtype_theory.matrix_normedtype.mx_norm Declared in library mathcomp.analysis.normedtype_theory.matrix_normedtype, line 115, characters 11-18


Source code
:= @ProperNegatedProp True False notB.2.
Canonical not_nProp

matrix_triangle : forall {K : numDomainType} [m n : nat] (M N : 'M_(m, n)), (`|M + N| <= `|M| + `|N|)%R matrix_triangle is not universe polymorphic Arguments matrix_triangle {K} [m n]%_nat_scope (M N)%_ring_scope matrix_triangle is opaque Expands to: Constant mathcomp.analysis.normedtype_theory.matrix_normedtype.matrix_triangle Declared in library mathcomp.analysis.normedtype_theory.matrix_normedtype, line 205, characters 8-23


Source code
PSource code := @ProperNegatedProp P (~ P) (notK P).

Fact and_nPropPSource code PSource code tQSource code nQSource code QSource code : (~ (P /\ nProp tQ nQ Q)) = (P -> nQ).
Proof.
by rewrite -implypN lax_notE. Qed.
Canonical and_nProp

pair_triangle : forall {K : numDomainType} (x y : K * K), (`|x + y| <= `|x| + `|y|)%R pair_triangle is not universe polymorphic Arguments pair_triangle {K} x y pair_triangle is opaque Expands to: Constant mathcomp.analysis.normedtype_theory.matrix_normedtype.pair_triangle Declared in library mathcomp.analysis.normedtype_theory.matrix_normedtype, line 209, characters 8-21


Source code
PSource code tQSource code nQSource code QSource code :=
  ProperNegatedProp (@and_nPropP P tQ nQ Q).

Fact and3_nPropPSource code PSource code QSource code tRSource code nRSource code RSource code : (~ [/\ P, Q & nProp tR nR R]) = (P -> Q -> nR).
Proof.
#[warnings="-user-warn"] by hnf; rewrite and3E notE. Qed.
Canonical and3_nProp
Source code
PSource code QSource code tRSource code nRSource code RSource code :=
  ProperNegatedProp (@and3_nPropP P Q tR nR R).

Fact and4_nPropPSource code PSource code QSource code RSource code tSSource code nSSource code SSource code :
  (~ [/\ P, Q, R & nProp tS nS S]) = (P -> Q -> R -> nS).
Proof.
#[warnings="-user-warn"] by hnf; rewrite and4E notE. Qed.
Canonical and4_nProp
Source code
PSource code QSource code RSource code tSSource code nSSource code SSource code :=
  ProperNegatedProp (@and4_nPropP P Q R tS nS S).

Fact and5_nPropPSource code PSource code QSource code RSource code SSource code tTSource code nTSource code TSource code :
  (~ [/\ P, Q, R, S & nProp tT nT T]) = (P -> Q -> R -> S -> nT).
Proof.
#[warnings="-user-warn"] by hnf; rewrite and5E notE. Qed.
Canonical and5_nProp
Source code
PSource code QSource code RSource code SSource code tTSource code nTSource code TSource code :=
  ProperNegatedProp (@and5_nPropP P Q R S tT nT T).

Fact or_nPropPSource code tPSource code nPSource code PSource code tQSource code nQSource code QSource code :
  (~ (nProp tP nP P \/ nProp tQ nQ Q)) = (nP /\ nQ).
Proof.
by rewrite not_orE !lax_notE. Qed.
Canonical or_nProp
Source code
tPSource code nPSource code PSource code tQSource code nQSource code QSource code :=
  ProperNegatedProp (@or_nPropP tP nP P tQ nQ Q).

Fact or3_nPropPSource code tPSource code nPSource code PSource code tQSource code nQSource code QSource code tRSource code nRSource code RSource code :
  (~ [\/ nProp tP nP P, nProp tQ nQ Q | nProp tR nR R]) = [/\ nP, nQ & nR].
Proof.
#[warnings="-user-warn"] by rewrite or3E notE and3E. Qed.
Canonical or3_nProp
Source code
tPSource code nPSource code PSource code tQSource code nQSource code QSource code tRSource code nRSource code RSource code :=
  ProperNegatedProp (@or3_nPropP tP nP P tQ nQ Q tR nR R).

Fact or4_nPropPSource code tPSource code nPSource code PSource code tQSource code nQSource code QSource code tRSource code nRSource code RSource code tSSource code nSSource code SSource code :
  (~ [\/ nProp tP nP P, nProp tQ nQ Q, nProp tR nR R | nProp tS nS S])
     = [/\ nP, nQ, nR & nS].
Proof.
#[warnings="-user-warn"] by rewrite or4E notE and4E. Qed.
Canonical or4_nProp
Source code
tPSource code nPSource code PSource code tQSource code nQSource code QSource code tRSource code nRSource code RSource code tSSource code nSSource code SSource code :=
  ProperNegatedProp (@or4_nPropP tP nP P tQ nQ Q tR nR R tS nS S).

The andRHS tertiary structure used to simplify (~ (P -> False)) to P, both here for the imply_nProp instance and for bounded_forall_nProp below. Because the andRHS instances match the Prop RETURNED by negatedProp they do not need to expand definitions, hence do not need to use the wrapper telescope pattern.

Notation and_defSource code binary P Q PQ := (PQ = if binary then P /\ Q else Q)%type.
Structure andRHSSource code binarySource code PSource code QSource code PQSource code :=
  AndRHS {and_RHSSource code :> Prop; _ : (P /\ and_RHS) = PQ; _ : and_def binary P Q PQ}.
Canonical unary_and_rhs
Source code
PSource code := @AndRHS false P P P True (andB.1.2 P) erefl.
Canonical binary_and_rhs
Source code
PSource code QSource code := @AndRHS true P Q (P /\ Q) Q erefl erefl.

Fact imply_nPropPSource code bSource code PSource code nQSource code PnQSource code tRSource code (nRSource code : andRHS b P nQ PnQ) RSource code :
  (~ (P -> nProp tR nR R)) = PnQ.
Proof.
by rewrite -orNp {R}lax_notE; case: nR. Qed.
Canonical imply_nProp
Source code
bSource code PSource code nQSource code PnQSource code tRSource code nRSource code RSource code :=
  ProperNegatedProp (@imply_nPropP b P nQ PnQ tR nR R).

Fact exists_nPropPSource code ASource code tPSource code nPSource code PSource code :
  (~ exists xSource code : A, nPred tP nP P x) = (forall xSource code : A, nP x).
Proof.
eqProp=> [nEP x | AnP [x]]; last by rewrite -/(~ _) lax_notE.
by rewrite -(lax_notE (P x)) => Px; case: nEP; exists x.
Qed.
Canonical exists_nProp
Source code
ASource code tPSource code nPSource code PSource code :=
  ProperNegatedProp (@exists_nPropP A tP nP P).

Fact exists2_nPropPSource code ASource code PSource code tQSource code nQSource code QSource code :
  (~ exists2 xSource code : A, P x & nPred tQ nQ Q x) = (forall xSource code : A, P x -> nQ x).
Proof.
#[warnings="-user-warn"] by rewrite exists2E notE. Qed.
Canonical exists2_nProp
Source code
ASource code PSource code tQSource code nQSource code QSource code :=
  ProperNegatedProp (@exists2_nPropP A P tQ nQ Q).

Fact inhabited_nPropPSource code TSource code : (~ inhabited T) = (T -> False).
Proof.
#[warnings="-user-warn"] by rewrite inhabitedE notE. Qed.
Canonical inhabited_nProp
Source code
TSource code := ProperNegatedProp (inhabited_nPropP T).

Rule 2: forall negation, including (T : Type) -> P statements. We use tertiary structures to recognize bounded foralls and simplify, e.g., ~ forall x, P -> Q to exists2 x, P & ~ Q, or even exists x, P when Q := False (as above for imply). As forall_body_nProp and forall_body_proper_nProp are telescopes over negatedProp and properNegatedProp, respectively, their instances match instances declared above without the need to expand definitions, hence do not need to use the wrapper telescope idiom.

Structure negatedForallBodySource code boundedSource code PSource code nQSource code tRSource code nRSource code := NegatedForallBody {
  negated_forall_bodySource code :> negatedProp tR nR; _ : and_def bounded P nQ nR}.
Structure properNegatedForallBodySource code bSource code PSource code nQSource code nRSource code := ProperNegatedForallBody {
  proper_negated_forall_bodySource code :> properNegatedProp nR; _ : and_def b P nQ nR}.
Notation nBodySource code b P nQ t nR x := (negatedForallBody b (P x) (nQ x) t (nR x)).

The explicit argument to fun_if is a workaround for a bug in the Coq unification code that prevents default instances from ever matching match constructs. Furthermore rewriting with ifE would not work here, because the if_expr definition would be expanded by the eta expansion needed to match the exists_nProp rule.

Fact forall_nPropPSource code ASource code bSource code PSource code nQSource code tRSource code nRSource code (RSource code : forall xSource code, nBody b P nQ tR nR x) :
  (~ forall xSource code : A, R x) = if b then exists2 xSource code, P x & nQ x else exists xSource code, nQ x.
Proof.
rewrite exists2E -(fun_if (fun PSource code => exists xSource code, idfun P x)) notI /=; congr not.
apply/generic_forall_extensionality=> x; rewrite if_arg lax_notI.
by case: (R x) => _ <-.
Qed.
Canonical forall_nProp
Source code
ASource code bSource code PSource code nQSource code tRSource code nRSource code (RSource code : forall xSource code, nBody b P nQ tR nR x) :=
  @NegatedProp false _ (wrap2Prop (forall xSource code : A, R x)) (forall_nPropP R).

Fact proper_nBodyPSource code bSource code PSource code nQSource code nRSource code :
  properNegatedForallBody b P nQ nR -> and_def b P nQ nR.
Proof.
by case. Qed.
Canonical proper_nBody
Source code
bSource code PSource code nQSource code nRSource code RSource code :=
  let def_nRSource code := @proper_nBodyP b P nQ nR R in
  @NegatedForallBody b P nQ false nR (proper_nProp R) def_nR.
Canonical nonproper_nBody
Source code
tPSource code nPSource code PSource code :=
  @NegatedForallBody false True nP tP nP P erefl.

Fact andRHS_defSource code bSource code PSource code QSource code PQSource code : andRHS b P Q PQ -> and_def b P Q PQ.
Proof.
by case. Qed.
Canonical bounded_nBody
Source code
bSource code PSource code nQSource code PnQSource code tRSource code nRSource code RSource code :=
  ProperNegatedForallBody (@imply_nProp b P nQ PnQ tR nR R) (andRHS_def nR).
Canonical unbounded_nBody
Source code
nQSource code QSource code :=
  @ProperNegatedForallBody false True nQ nQ Q erefl.

The properNegatedProp instance that handles boolean statements. We use two tertiary structures to handle positive and negative boolean statements so that the contra tactic below will mostly subsume the collection of contraXX lemmas in ssrbool and eqtype. We only match manifest ~~ connectives, the true and false constants, and the ==, <=%N, and <%N predicates. In particular we do not use de Morgan laws to push boolean negation into connectives, as we did above for Prop connectives. It will be up to the user to use rewriting to put the negated statement in its desired shape.

Structure negatedBoolSource code nPSource code :=
  NegatedBool {negated_boolSource code :> bool; _ : (~ negated_bool) = nP}.
Structure positedBoolSource code PSource code :=
  PositedBool {posited_boolSource code :> bool; _ : is_true posited_bool = P}.

Local Fact is_true_nPropPSource code nPSource code (bSource code : negatedBool nP) : (~ b) = nP.
Proof.
by case: b. Qed.
Canonical is_true_nProp
Source code
nPSource code bSource code := ProperNegatedProp (@is_true_nPropP nP b).

Local Fact true_negPSource code : (~ true) = False
Proof.
by eqProp. Qed.
Local Fact true_posPSource code : (true : Prop) = True
Proof.
by eqProp. Qed.
Local Fact false_negPSource code : (~ false) = True
Proof.
by eqProp. Qed.
Local Fact false_posPSource code : (false : Prop) = False
Proof.
by eqProp. Qed.
Canonical true_neg
Source code
:= NegatedBool true_negP.
Canonical true_pos
Source code
:= PositedBool true_posP.
Canonical false_neg
Source code
:= NegatedBool false_negP.
Canonical false_pos
Source code
:= PositedBool false_posP.

Local Fact id_negPSource code (bSource code : bool) : (~ b) = ~~ b
Proof.
exact/reflect_eq/negP. Qed.
Canonical id_neg
Source code
bSource code := NegatedBool (id_negP b).
Canonical id_pos
Source code
 (bSource code : bool) := @PositedBool b b erefl.

Local Fact negb_negPSource code PSource code (bSource code : positedBool P) : (~ ~~ b) = P.
Proof.
by rewrite (reflect_eq negP) negbK; case: b. Qed.
Canonical negb_neg
Source code
PSource code bSource code := NegatedBool (@negb_negP P b).
Local Fact negb_posPSource code nPSource code (bSource code : negatedBool nP) : (~~ b = nP :> Prop).
Proof.
#[warnings="-user-warn"] by rewrite -(reflect_eq negP) notE. Qed.
Canonical negb_pos
Source code
nPSource code bSource code := PositedBool (@negb_posP nP b).

We use a tertiary structure to handle the negation of nat comparisons, and simplify ~ m <= n to n < m, and ~ m < n to n <= m. As m < n is merely notation for m.+1 <= n, we need to dispatch on the left hand side of the comparison to perform the latter simplification.

Structure negatedLeqLHSSource code nSource code lt_nmSource code :=
  NegatedLeqLHS {negated_leq_LHSSource code :> nat; _ : (n < negated_leq_LHS) = lt_nm}.
Canonical neg_ltn_LHS
Source code
nSource code mSource code := @NegatedLeqLHS n (n <= m) m.+1 erefl.
Canonical neg_leq_LHS
Source code
nSource code mSource code := @NegatedLeqLHS n (n < m) m erefl.

Local Fact leq_negPSource code nSource code lt_nmSource code (mSource code : negatedLeqLHS n lt_nm) : (~ m <= n) = lt_nm.
Proof.
#[warnings="-user-warn"] by rewrite notE -ltnNge; case: m => /= m ->. Qed.
Canonical leq_neg
Source code
nSource code lt_nmSource code mSource code := NegatedBool (@leq_negP n lt_nm m).

We use two tertiary structures to simplify negation of boolean constant and decidable equalities, simplifying b <> true to ~~ b, b <> false to b, x <> y to x != y, and ~ x != y to x = y. We do need to use the wrapper telescope pattern here, as we want to simplify instances of x <> y when y evaluates to true or false. Since we only need two rules (true/false RHS or generic eqType RHS) we can use the generic wrapped type from ssrfun. The actual matching of the true and false RHS is delegated to a fourth level bool_eq_negation_rhs structure. Finally observe that the ~ x != y to x = y simplification can be handled by a bool_affirmation instance.

Structure neqRHSSource code nPSource code TSource code xSource code :=
  NeqRHS {neq_RHSSource code :> wrapped T; _ : (x <> unwrap neq_RHS) = nP}.
Structure boolNeqRHSSource code nPSource code (xSource code : bool) :=
  BoolNeqRHS {bool_neq_RHSSource code; _ : (x <> bool_neq_RHS) = nP}.

Local Fact eq_nPropPSource code nPSource code TSource code xSource code (ySource code : neqRHS nP x) : (x <> unwrap y :> T) = nP.
Proof.
by case: y. Qed.
Canonical eq_nProp
Source code
nPSource code TSource code xSource code ySource code := ProperNegatedProp (@eq_nPropP nP T x y).

Local Fact bool_neqPSource code nPSource code xSource code ySource code : (x <> @bool_neq_RHS nP x y) = nP.
Proof.
by case: y. Qed.
Canonical bool_neq
Source code
nPSource code xSource code ySource code := @NeqRHS nP bool x (wrap _) (@bool_neqP nP x y).
Canonical true_neq
Source code
nPSource code bSource code := BoolNeqRHS (@is_true_nPropP nP b).
Local Fact false_neqPSource code PSource code (bSource code : positedBool P) : (b <> false :> bool) = P.
Proof.
by move: b => [] [] /= <-; exact/propext. Qed.
Canonical false_neq
Source code
PSource code bSource code := BoolNeqRHS (@false_neqP P b).

Local Fact eqType_neqPSource code (TSource code : eqType) (xSource code ySource code : T) : (x <> y) = (x != y).
Proof.
by rewrite [in LHS](reflect_eq eqP) (reflect_eq negP). Qed.
Canonical eqType_neq
Source code
 (TSource code : eqType) xSource code ySource code :=
  @NeqRHS (x != y) T x (Wrap y) (eqType_neqP x y).
Local Fact eq_op_posPSource code (TSource code : eqType) xSource code ySource code : (x == y :> T : Prop) = (x = y).
Proof.
exact/esym/reflect_eq/eqP. Qed.
Canonical eq_op_pos
Source code
TSource code xSource code ySource code := PositedBool (@eq_op_posP T x y).

The witnessedType structure provides conversion between Type and Prop in goals; the conversion is mostly used in the Type-to-Prop direction, e.g., as a preprocessing step preceding proof by contradiction (see absurd_not below), but the Prop-to-Type direction is required for contraposition. Thus witnessedType associates to a type T a "witness" proposition P equivalent to the existence of an x of type T. As in a `{classical_logic} context inhabited T is such a proposition, witnessedType can be understood as providing simplification for inhabited T, much like negatedProp provides simplification for ~ P for standard connectives and predicates.

Similarly to negatedProp, witnessedType returns the witness proposition via a projection argument P, but does not need to signal "trivial" instances as the default value for P is nontrivial (namely, inhabited T), while the "trivial" case where P = T is actually desireable and handled by an extra top-priority rule.

Structure witnessedTypeSource code PSource code := WitnessedType {
 witnessed_TypeSource code :> wrappedType; _ : inhabited witnessed_Type = P}.
Structure properWitnessedTypeSource code PSource code := ProperWitnessedType {
  proper_witnessed_TypeSource code :> Type; _ : inhabited proper_witnessed_Type = P}.
Local Notation wTypeSource code P T := (unwrap_Type (@witnessed_Type P T)).
Local Notation wTyconSource code P T x := (wType (P x) (T x)).


Lemma witnessedType_introSource code {PSource code : Prop} TSource code : P -> wType P T.
Proof.
by case: T => /= T <- /inhabited_witness. Qed.
Local Coercion witnessedType_intro : witnessedType >-> Funclass.

Lemma witnessedType_elimSource code {PSource code} TSource code : wType P T -> P.
Proof.
by case: T => /= T <-. Qed.
Local Notation wTypePSource code := witnessedType_elim.


Local Fact eq_inhabitedSource code TSource code (PSource code : Prop) : (T -> P) -> (P -> T) -> inhabited T = P.
Proof.
by move=> T_P P_T; eqProp=> [[/T_P] | /P_T]. Qed.
Ltac eqInh := apply: eq_inhabited.

Rule 1: Prop goals are left as is.
Canonical Prop_wType
Source code
PSource code :=
  @WitnessedType P (wrap1Type P) (eq_inhabited (@id P) id).

Rule 2: Specific type constructors (sigs, sums, and pairs) are delegated to the secondary properWitnessedType structure.
Lemma proper_wTypePSource code PSource code (TSource code : properWitnessedType P) : inhabited T = P.
Proof.
by case: T. Qed.
Canonical proper_wType
Source code
PSource code TSource code :=
  @WitnessedType P (wrap2Type _) (@proper_wTypeP P T).

Rule 3: Forall (and -> as a special case).
Local Fact forall_wTypePSource code ASource code PSource code TSource code :
  inhabited (forall xSource code : A, wTycon P T x) = (forall xSource code : A, P x) .
Proof.
by do [eqInh=> allP x; have:= allP x] => [/wTypeP | /T]. Qed.
Canonical forall_wType
Source code
ASource code PSource code TSource code :=
  @WitnessedType _ (wrap3Type _) (@forall_wTypeP A P T).

Rule 4: Default to inhabited if all else fails.
Canonical inhabited_wType
Source code
TSource code := @WitnessedType (inhabited T) (wrap4Type T) erefl.

Specific proper_witnessedType instances.

Local Fact void_wTypePSource code : inhabited void = False
Proof.
by eqInh. Qed.
Canonical void_wType
Source code
:= ProperWitnessedType void_wTypeP.

Local Fact unit_wTypePSource code : inhabited unit = True
Proof.
by eqInh. Qed.
Canonical unit_wType
Source code
:= ProperWitnessedType unit_wTypeP.

Local Fact pair_wTypePSource code PSource code QSource code SSource code TSource code : inhabited (wType P S * wType Q T) = (P /\ Q).
Proof.
by eqInh=> [[/wTypeP-isP /wTypeP] | [/S-x /T]]. Qed.
Canonical pair_wType
Source code
PSource code QSource code SSource code TSource code := ProperWitnessedType (@pair_wTypeP P Q S T).

Local Fact sum_wTypePSource code PSource code QSource code SSource code TSource code : inhabited (wType P S + wType Q T) = (P \/ Q).
Proof.
by eqInh=> [[] /wTypeP | /decide_or[/S | /T]]; by [left | right]. Qed.
Canonical sum_wType
Source code
PSource code QSource code SSource code TSource code := ProperWitnessedType (@sum_wTypeP P Q S T).

Local Fact sumbool_wTypePSource code PSource code QSource code : inhabited ({P} + {Q}) = (P \/ Q).
Proof.
by eqInh=> [[] | /decide_or[]]; by [left | right]. Qed.
Canonical sumbool_wType
Source code
PSource code QSource code := ProperWitnessedType (@sumbool_wTypeP P Q).

Local Fact sumor_wTypePSource code PSource code QSource code TSource code : inhabited (wType P T + {Q}) = (P \/ Q).
Proof.
by eqInh=> [[/wTypeP|] | /decide_or[/T|]]; by [left | right]. Qed.
Canonical sumor_wType
Source code
PSource code QSource code TSource code := ProperWitnessedType (@sumor_wTypeP P Q T).

Local Fact sig1_wTypePSource code TSource code PSource code : inhabited {xSource code : T | P x} = (exists xSource code : T, P x).
Proof.
by eqInh=> [[x Px] | /cid//]; exists x. Qed.
Canonical sig1_wType
Source code
TSource code PSource code := ProperWitnessedType (@sig1_wTypeP T P).

Local Fact sig2_wTypePSource code TSource code PSource code QSource code :
  inhabited {xSource code : T | P x & Q x} = exists2 xSource code : T, P x & Q x.
Proof.
by eqInh=> [[x Px Qx] | /cid2//]; exists x. Qed.
Canonical sig2_wType
Source code
TSource code PSource code QSource code := ProperWitnessedType (@sig2_wTypeP T P Q).

Local Fact sigT_wTypePSource code ASource code PSource code TSource code :
  inhabited {xSource code : A & wTycon P T x} = (exists xSource code : A, P x).
Proof.
by eqInh=> [[x /wTypeP] | /cid[x /T]]; exists x. Qed.
Canonical sigT_wType
Source code
ASource code PSource code TSource code := ProperWitnessedType (@sigT_wTypeP A P T).

Local Fact sigT2_wTypePSource code ASource code PSource code QSource code SSource code TSource code :
  inhabited {xSource code : A & wTycon P S x & wTycon Q T x} = (exists2 xSource code : A, P x & Q x).
Proof.
by eqInh=> [[x /wTypeP-Px /wTypeP] | /cid2[x /S-y /T]]; exists x. Qed.
Canonical sigT2_wType
Source code
ASource code PSource code QSource code SSource code TSource code :=
  ProperWitnessedType (@sigT2_wTypeP A P Q S T).

The witnessProp structure provides for conversion of some Prop assumptions to Type values with some constructive contents, e.g., convert a P \/ Q assumption to a {P} + {Q} sumbool value. This is not the same as the forward direction of witnessedType, because instances here match the Prop statement: witness_Prop find a T such that P -> T while witnessedType finds a P such that P -> T (and T -> P for the converse direction).

The implementation follows the wrapper telescope pattern similarly to negatedProp, with three rules, one for Prop constructors with proper constructive contents, one for forall propositions (also with proper constructive contents) and one default rule that just returns P : Prop as is (thus, with no other contents except the provability of P). The witnessProp structure also uses projection parameters to return the inferred Type T together with a bool 'trivial' flag that is set when the trivial rule is used. Here, however, this flag is used in both directions: the 'witness' view forces it to false to prevent trivial instances, but the flag is also used to fine tune the choice of T, selecting between sum, sumor, and sumbool, between sig and sigT, and sig2 and sigT2. This relies on the fact that the tactic engine will eagerly iota reduce the returned type, so that the user will never see the conditionals specified in the proper_witness_Prop instances. However, it would not be possible to construct the specialised types for trivial witnesses (e.g., {P} + {Q}) using the types returned by witnessProp instances, since thes are in Type, and the information that they are actully in Prop has been lost. This is solved by returning an additional Prop P0 that is a copy of the matched Prop P when trivial = true. (We put P0 = True when trivial = false, as we only need to ensure P -> P0.) Caveat: although P0 should in principle be the last parameter of witness_Prop, and we use this order for the wProp and wPred projector local notation, it is important to put P0 _BEFORE_ T, to circumvent an incompleteness in Coq's implementation of higher-order pattern unification that would cause the trivial rule to fail for the body of an exists. In such a case the rule needs to unify (1) ?P0 x ~ ?P and (2) ?T x ~ ?P for some type A some x : A in the context of ?P, but not ?P0 nor ?T. This succeeds easily if (1) is performed before (2), setting ?P := ?P0 x and ?T := ?P0, but if (2) is attempted first Coq tries to perform ?P := ?T x, which fails Type/Prop universe constraints, and then fails outright, instead of using pattern unification to solve (2) as ?P := ?Q x, ?T := ?Q for a fresh ?Q : A -> Prop.

Structure witnessPropSource code (trivialSource code : bool) (P0Source code : Prop) (TSource code : Type) :=
  WitnessProp {witness_PropSource code :> wrappedProp; _ : witness_Prop -> T * P0}.
Structure properWitnessPropSource code TSource code :=
  ProperWitnessProp {proper_witness_PropSource code :> Prop; _ : proper_witness_Prop -> T}.

Local Notation wPropSource code t T P0 P := (unwrap_Prop (@witness_Prop t P0 T P)).
Local Notation wPredSource code t T P0 P x := (wProp t (T x) (P0 x) (P x)).

Local Fact wPropPSource code tSource code TSource code P0Source code PSource code : wProp t T P0 P -> T * P0
Proof.
by case: P. Qed.
Lemma lax_witnessUsed by
  • mathcomp.reals.reals
  • mathcomp.analysis.topology_theory.num_topology
  • mathcomp.analysis.topology_theory.topology_structure
  • mathcomp.analysis.topology_theory.metric_structure
  • mathcomp.analysis.derive.derive_matrix
  • mathcomp.analysis.normedtype_theory.pseudometric_normed_Zmodule
  • mathcomp.analysis.normedtype_theory.tvs
  • mathcomp.analysis.functional_analysis.hahn_banach_theorem
  • mathcomp.analysis.sequences
  • mathcomp.classical.wochoice

Source code
{tSource code TSource code P0Source code PSource code} : move_view (wProp t T P0 P) T.
Proof.
by split=> /wPropP[]. Qed.
Definition witness
Source code
{TSource code P0Source code PSource code} := @lax_witness false T P0 P.

Rule 1: proper instances (except forall), delegated to an auxiliary structures.
Local Fact proper_wPropPSource code TSource code PSource code : wrap1Prop (@proper_witness_Prop T P) -> T * True.
Proof.
by case: P => _ P_T {}/P_T. Qed.
Canonical proper_wProp

limf_esup : forall {d : filter_display} {T : choiceType} {X : filteredType d T} {R : realFieldType}, (X -> \bar R) -> set_system X -> \bar R limf_esup is not universe polymorphic Arguments limf_esup {d}%_fdisp_scope {T X R} f%_function_scope F limf_esup is transparent Expands to: Constant mathcomp.analysis.normedtype_theory.ereal_normedtype.limf_esup Declared in library mathcomp.analysis.normedtype_theory.ereal_normedtype, line 47, characters 11-20


Source code
TSource code PSource code := WitnessProp false (@proper_wPropP T P).

Rule 2: forall types (including implication); as only proper instances are allowed, we set trivial = false for the recursive body instance.
Local Fact forall_wPropPSource code ASource code TSource code P0Source code PSource code :
  wrap2Prop (forall xSource code : A, wPred false T P0 P x) -> (forall xSource code, T x) * True.
Proof.
by move=> P_A; split=> // x; have /witness := P_A x. Qed.
Canonical forall_wProp

limf_einf : forall {d : filter_display} {T : choiceType} {X : filteredType d T} {R : realFieldType}, (X -> \bar R) -> set_system X -> \bar R limf_einf is not universe polymorphic Arguments limf_einf {d}%_fdisp_scope {T X R} f%_function_scope F limf_einf is transparent Expands to: Constant mathcomp.analysis.normedtype_theory.ereal_normedtype.limf_einf Declared in library mathcomp.analysis.normedtype_theory.ereal_normedtype, line 49, characters 11-20


Source code
ASource code TSource code P0Source code PSource code := WitnessProp false (@forall_wPropP A T P0 P).

Rule 3: trivial (proof) self-witness.
Canonical trivial_wProp

lower_semicontinuous : forall {d : filter_display} {X : topologicalType d} {R : numFieldType}, (X -> \bar R) -> Prop lower_semicontinuous is not universe polymorphic Arguments lower_semicontinuous {d}%_fdisp_scope {X R} f%_function_scope lower_semicontinuous is transparent Expands to: Constant mathcomp.analysis.normedtype_theory.ereal_normedtype.lower_semicontinuous Declared in library mathcomp.analysis.normedtype_theory.ereal_normedtype, line 91, characters 11-31


Source code
PSource code :=
  WitnessProp true (fun pSource code : wrap3Prop P => (p, p) : P * P).

Specific proper_witnesss_Prop instances.

Canonical inhabited_wProp
Source code
TSource code := ProperWitnessProp (@inhabited_witness T).

Conjunctions P /\ Q are a little delicate to handle, as we should not produce a proper instance (and thus fail) if neither P nor Q is proper. We use a tertiary structure for this : nand_bool b, which has instances only for booleans b0 such that ~~ (b0 && b). We allow the witness_Prop instance for P to return an arbitrary 'trivial' flag s, but then force the 'trivial' flag for Q to be an instance of nand_bool s.

Structure nandBoolSource code bSource code := NandBool {nand_boolSource code :> bool; _ : ~~ (nand_bool && b)}.
Canonical nand_false_bool
Source code
bSource code := @NandBool b false isT.
Canonical nand_true_bool

gauss_fun : forall {R : realType}, R -> R gauss_fun is not universe polymorphic Arguments gauss_fun {R} x%_ring_scope gauss_fun is transparent Expands to: Constant mathcomp.analysis.gauss_integral.gauss_fun Declared in library mathcomp.analysis.gauss_integral, line 29, characters 11-20


Source code
:= @NandBool false true isT.

Local Fact and_wPropPSource code sSource code SSource code P0Source code PSource code (tSource code : nandBool s) TSource code Q0Source code QSource code :
  wProp s S P0 P /\ wProp t T Q0 Q -> S * T.
Proof.
by case=> /lax_witness-x /lax_witness. Qed.
Canonical and_wProp

gauss_integral_proof.integral0y_gauss : forall {R : realType}, R gauss_integral_proof.integral0y_gauss is not universe polymorphic Arguments gauss_integral_proof.integral0y_gauss {R} gauss_integral_proof.integral0y_gauss is transparent Expands to: Constant mathcomp.analysis.gauss_integral.gauss_integral_proof.integral0y_gauss Declared in library mathcomp.analysis.gauss_integral, line 66, characters 11-27


Source code
sSource code SSource code P0Source code PSource code tSource code TSource code Q0Source code QSource code :=
  ProperWitnessProp (@and_wPropP s S P0 P t T Q0 Q).

Local Fact or_wPropPSource code sSource code SSource code P0Source code PSource code tSource code TSource code Q0Source code QSource code :
    wProp s S P0 P \/ wProp t T Q0 Q ->
  if t then if s then {P0} + {Q0} : Type else S + {Q0} else S + T : Type.
Proof.
by case: s t => -[] in P Q *; (case/decide_or=> /wPropP[]; [left | right]).
Qed.
Canonical or_wProp

gauss_integral_proof.integral0_gauss : forall {R : realType}, R -> R gauss_integral_proof.integral0_gauss is not universe polymorphic Arguments gauss_integral_proof.integral0_gauss {R} x%_ring_scope gauss_integral_proof.integral0_gauss is transparent Expands to: Constant mathcomp.analysis.gauss_integral.gauss_integral_proof.integral0_gauss Declared in library mathcomp.analysis.gauss_integral, line 71, characters 11-26


Source code
sSource code SSource code P0Source code PSource code tSource code TSource code Q0Source code QSource code :=
  ProperWitnessProp (@or_wPropP s S P0 P t T Q0 Q).

Local Fact exists_wPropPSource code ASource code tSource code TSource code P0Source code PSource code :
  (exists xSource code : A, wPred t T P0 P x) -> if t then {xSource code | P0 x} else {xSource code & T x}.
Proof.
by case/cid => x /wPropP[]; case t; exists x. Qed.
Canonical exists_wProp

gauss_integral_proof.u : forall {R : realType}, R -> R -> R gauss_integral_proof.u is not universe polymorphic Arguments gauss_integral_proof.u {R} (x t)%_ring_scope gauss_integral_proof.u is transparent Expands to: Constant mathcomp.analysis.gauss_integral.gauss_integral_proof.u Declared in library mathcomp.analysis.gauss_integral, line 85, characters 11-12


Source code
ASource code tSource code TSource code P0Source code PSource code :=
  ProperWitnessProp (@exists_wPropP A t T P0 P).

Local Fact exists2_wPropPSource code ASource code sSource code SSource code P0Source code PSource code tSource code TSource code Q0Source code QSource code (stSource code := if s then t else false) :
    (exists2 xSource code : A, wPred s S P0 P x & wPred t T Q0 Q x) ->
  if st then {xSource code | P0 x & Q0 x} else {xSource code : A & S x & T x}.
Proof.
by case/cid2=> x /wPropP[P0x y] /wPropP[]; case: ifP; exists x. Qed.
Canonical exists2_wProp

gauss_integral_proof.integral01_u : forall {R : realType}, R -> R gauss_integral_proof.integral01_u is not universe polymorphic Arguments gauss_integral_proof.integral01_u {R} x%_ring_scope gauss_integral_proof.integral01_u is transparent Expands to: Constant mathcomp.analysis.gauss_integral.gauss_integral_proof.integral01_u Declared in library mathcomp.analysis.gauss_integral, line 136, characters 11-23


Source code
ASource code sSource code SSource code P0Source code PSource code tSource code TSource code Q0Source code QSource code :=
  ProperWitnessProp (@exists2_wPropP A s S P0 P t T Q0 Q).

## User lemmas and tactics for proof by contradiction and contraposition.

Helper lemmas: - push_goal_copy makes a copy of the goal that can then be matched with witnessedType and negatedProp instances to generate a contradiction assuption, without disturbing the original form of the goal. - assume_not_with turns the copy generated by push_identity into an equivalent negative assumption, which can then be simplified using the lax_notP and lax_witness views. - absurd and absurdW replace the goal with False; absurdW does this under an assumption, and is used to weaken proof-by-assuming-negation to proof-by-contradiction. - contra_Type converts an arbitrary function goal (with assumption and conclusion in Type) to an equivalent contrapositive Prop implication. - contra_notP simplifies a contrapositive ~ Q -> ~ P goal using negatedProp instances.

Local Fact push_goal_copySource code {TSource code} : ((T -> T) -> T) -> T
Proof.
exact. Qed.
Local Fact assume_not_withSource code {RSource code PSource code TSource code} : (~ P -> R) -> (wType P T -> R) -> R.
Proof.
by move=> nP_T T_R; have [/T|] := asboolP P. Qed.

Local Fact absurdWSource code {SSource code TSource code} : (S -> False) -> S -> T
Proof.
by []. Qed.

Local Fact contra_TypeSource code {PSource code QSource code SSource code TSource code} : (~ Q -> ~ P) -> wType P S -> wType Q T.
Proof.
by rewrite implyNN => P_Q /wTypeP/P_Q/T. Qed.

Local Fact contra_notPSource code tPSource code tQSource code (nPSource code nQSource code : Prop) PSource code QSource code :
  (nP -> nQ) -> (~ nProp tP nP P -> ~ nProp tQ nQ Q).
Proof.
by rewrite 2!lax_notE. Qed.

End Internals.
Import Internals.
#[warnings="-user-warn"] Definition notP
Used by
  • mathcomp.classical.wochoice

Source code
:= @Internals.notP.
Hint View for move/ move_viewP|2.
Hint View for move/ Internals.equivT_LR|2 Internals.equivT_RL|2.
Hint View for apply/ Internals.equivT_RL|2 Internals.equivT_LR|2.
Export (canonicals) Internals.

Lemma and tactic assume_not: add a goal negation assumption. The tactic also works for goals in Type, simplifies the added assumption, and exposes its top-level constructive content.

Lemma assume_notSource code {PSource code} : (~ P -> P) -> P
Proof.
by rewrite implyNp orB. Qed.
Ltac assume_not :=
  apply: Internals.push_goal_copy; apply: Internals.assume_not_with
    => /Internals.lax_notP-/Internals.lax_witness.

Lemma and tactic absurd_not: proof by contradiction. Same as assume_not, but the goal is erased and replaced by False. Caveat: absurd_not cannot be used as a move/ view because its conclusion is indeterminate. The more general notP defined above can be used instead.
Lemma absurd_notSource code {PSource code} : (~ P -> False) -> P
Proof.
#[warnings="-user-warn"] by move/Internals.notP. Qed.
Ltac absurd_not := assume_not; apply: Internals.absurdW.

Tactic contra: proof by contraposition. Assume the negation of the goal conclusion, and prove the negation of a given assumption. The defective form contra (which can also be written contrapose) expects the assumption to be pushed on the goal which thus has the form assumption -> conclusion. As with assume_not, contra allows both assumption and conclusion to be in Type, simplifies the negation of both assumption and conclusion, and exposes the constructive contents of the negated conclusion. The contra tactic also supports a limited form of the ':' discharge pseudo tactical, whereby contra: <d-items> means move: <d-items>; contra. The only <d-items> allowed are one term, possibly preceded by a clear switch.

Ltac contrapose :=
  apply: Internals.contra_Type;
  apply: Internals.contra_notP => /Internals.lax_witness.
Tactic Notation "contra" := contrapose.
Tactic Notation "contra" ":" constr(H) := move: (H); contra.
Tactic Notation "contra" ":" ident(H) := move: H; contra.
Tactic Notation "contra" ":" "{" hyp_list(Hs) "}" constr(H) :=
  contra: (H); clear Hs.
Tactic Notation "contra" ":" "{" hyp_list(Hs) "}" ident(H) :=
  contra: H; clear Hs.
Tactic Notation "contra" ":" "{" "-" "}" constr(H) := contra: (H).

Lemma and tactic absurd: proof by contradiction. The defective form of the lemma simply replaces the entire goal with False (just as the Ltac exfalso), leaving the user to derive a contradiction from the assumptions. The ':' form absurd: <d-items> replaces the goal with the negation of the (single) <d-item> (as with contra:, a clear switch is also allowed. Finally the Ltac absurd term form is also supported.

Lemma absurdSource code TSource code : False -> T
Proof.
by []. Qed.
Tactic Notation (at level 0) "absurd" := apply absurd.
Tactic Notation (at level 0) "absurd" constr(P) := have []: ~ P.
Tactic Notation "absurd" ":" constr(H) := absurd; contra: (H) => _.
Tactic Notation "absurd" ":" ident(H) := absurd; contra: H => _.
Tactic Notation "absurd" ":" "{" hyp_list(Hs) "}" constr(H) :=
  absurd: (H) => _; clear Hs.
Tactic Notation "absurd" ":" "{" hyp_list(Hs) "}" ident(H) :=
  absurd: H => _; clear Hs.