(** It may seem strange that the general excluded middle is not available by default in Coq; after all, any given claim must be either true or false.  Nonetheless, there is an advantage in not assuming the excluded middle: statements in Coq can make stronger claims than the analogous statements in standard mathematics. Notably, if there is a Coq proof of [exists x, P x], it is possible to explicitly exhibit a value of [x] for which we can prove [P x] -- in other words, every proof of existence is necessarily _constructive_. *)
(** Logics like Coq's, which do not assume the excluded middle, are referred to as _constructive logics_.  More conventional logical systems such as ZFC, in which the excluded middle does hold for arbitrary propositions, are referred to as _classical_. *)
(** The following example illustrates why assuming the excluded middle may lead to non-constructive proofs:  _Claim_: There exist irrational numbers [a] and [b] such that [a ^ b] is rational.  _Proof_: It is not difficult to show that [sqrt 2] is irrational. If [sqrt 2 ^ sqrt 2] is rational, it suffices to take [a = b = sqrt 2] and we are done.  Otherwise, [sqrt 2 ^ sqrt 2] is irrational.  In this case, we can take [a = sqrt 2 ^ sqrt 2] and [b = sqrt 2], since [a ^ b = sqrt 2 ^ (sqrt 2 * sqrt 2) = sqrt 2 ^ 2 = 2].  []  Do you see what happened here?  We used the excluded middle to consider separately the cases where [sqrt 2 ^ sqrt 2] is rational and where it is not, without knowing which one actually holds! Because of that, we wind up knowing that such [a] and [b] exist but we cannot determine what their actual values are (at least, using this line of argument).  As useful as constructive logic is, it does have its limitations: There are many statements that can easily be proven in classical logic but that have much more complicated constructive proofs, and there are some that are known to have no constructive proof at all!  Fortunately, like functional extensionality, the excluded middle is known to be compatible with Coq's logic, allowing us to add it safely as an axiom.  However, we will not need to do so in this book: the results that we cover can be developed entirely within constructive logic at negligible extra cost.  It takes some practice to understand which proof techniques must be avoided in constructive reasoning, but arguments by contradiction, in particular, are infamous for leading to non-constructive proofs.  Here's a typical example: suppose that we want to show that there exists [x] with some property [P], i.e., such that [P x].  We start by assuming that our conclusion is false; that is, [~ exists x, P x]. From this premise, it is not hard to derive [forall x, ~ P x].  If we manage to show that this intermediate fact results in a contradiction, we arrive at an existence proof without ever exhibiting a value of [x] for which [P x] holds!  The technical flaw here, from a constructive standpoint, is that we claimed to prove [exists x, P x] using a proof of [~ ~ (exists x, P x)].  Allowing ourselves to remove double negations from arbitrary statements is equivalent to assuming the excluded middle, as shown in one of the exercises below.  Thus, this line of reasoning cannot be encoded in Coq without assuming additional axioms. *)
(** **** Exercise: 3 stars (excluded_middle_irrefutable)  *)
(** The consistency of Coq with the general excluded middle axiom requires complicated reasoning that cannot be carried out within Coq itself.  However, the following theorem implies that it is always safe to assume a decidability axiom (i.e., an instance of excluded middle) for any _particular_ Prop [P].  Why? Because we cannot prove the negation of such an axiom; if we could, we would have both [~ (P \/ ~P)] and [~ ~ (P \/ ~P)], a contradiction. *)

(* Specifications: *)
Theorem excluded_middle_irrefutable:  forall (P:Prop),
~ ~ (P \/ ~ P).