Logical equivalence - equivalent

I have a question about the use of formal language. Could someone please explain me why this statement is logically equivalent?
f ∨ g ∧ h ≡ (f ∨ g) ∧ (f ∨ h).
I made two truth tables (see the pictures below), but this statement doesn´t hold (it isn't logically equivalent). However, according to the exercise it is.
I hope someone can help me out (maybe I made a mistake).
My truth tables:
f ∨ g ∧ h:
(f ∨ g) ∧ (f ∨ h):
Thanks in advance.

Have a close look at the way the equivalence is denoted:
no parenthesis on the left side, two on the right specifying the disjunctions to be evaluated first.
If this was the conventional logical operator precedence, both pairs of parentheses were dispensable.
If left to right evaluation was conventional, the first pair was redundant: the convention actually is conjunction before disjunction (and the equivalence is denoted correctly as well as irredundant).
So, the f ∨ g column in your first table is immaterial, if correct.
The f ∨ g ∧ h column is inconsistent: the label with explicit parentheses would need to be f ∨ (g ∧ h), the values tabulated are for (f ∨ g) ∧ h.

Related

How can I replace a variable by another in coq

When I was trying to prove if two functions are equivalent and come to the step:
I : f(S a') b = S (f a' b)
f (S a') (S b) = S (f a' (S b))
I am wondering whether it's possible to use exact(I) to prove it, namely, to replace (S b) by b, since that's the only difference.
The inference from the premise to the conclusion is generally false for an arbitrary function f: consider the function f a b such that f a 0 := a and f a (S b) := S b, you can prove the premise and contradict the conclusion.
You could substitute b in I only if it was quantified universally in that hypotesis: I : forall b, f (S a') b = S (f a' b) ; in that case substituting would amount to application of I to S b.
If it's not possible to strenghten your hypothesis, you need to use something specific to the function f to conclude.

How do I prove an existential goal that asks for a certain function in Coq?

Completely new to coq here.
I know about the exists tactic to prove an existential goal, but in this case it wants a function mapping from two sets. What is the syntax for demonstrating such a function?
And if there is no such function how would I disprove this? (I would suppose through a contradiction, but then how would I pose a contradictory hypothesis?)
Context: Trying to work out the proof that all surjective functions have a right inverse.
1 subgoal
A, B : Set
f : A → B
H : ∀ b : B, ∃ a : A, f a = b
______________________________________(1/1)
∃ g : B → A, ∀ b : B, f (g b) = b
Of course, whether or not a function g exists depends on accepting axiom of choice, so where does that come into coq?
I did find this solution:
https://gist.github.com/pedrominicz/0d9004b82713d9244b762eb250b9c808
and the associated reddit post
https://www.reddit.com/r/logic/comments/fxjypn/what_is_not_constructive_in_this_proof/
But I didn't understand it/didn't work for me.
So, what I want to know is:
How do you specify axiom of choice in coq (to prove/disprove this)?
In general, how would I construct a function to provide witness to an existential goal? (I also want to show that all injective functions have a left inverse)
There are several variants of the axiom of choice in the Coq type theory. You can look at the Coq.Logic.ChoiceFacts module for a reasonably comprehensive list of the various formulations and their relative power.
As far as I can tell, your example is equivalent to the axiom of functional choice. One elegant way to phrase and assume it is the following.
Axiom functional_choice : forall (A : Type) (B : A -> Type),
(forall x : A, inhabited (B x)) -> inhabited (forall x : A, B x).
The inhabited type is an inductive box that hides the computational content of a proof in Type into a Prop value that can only be inspected to produce more Prop values. In particular, This axiom is pretty innocuous from the point of view of computation since it only produces values in Prop. There are much more violently non-computational examples of choice like global choice which can be stated as:
Axiom global_choice : forall (A : Type), inhabited A -> A.
This one allows to extract computational content out of thin air.
Here is an answer that is a complete script (tested with coq 8.13.2). Coq by default does not have the axiom of choice loaded, so you need to say explicitly that you are going to work with it.
Require Import ClassicalChoice.
Lemma question (A B : Set) (f : A -> B) :
(forall b, exists a, f a = b) -> exists g, forall b, f (g b) = b.
Proof.
intros H.
apply (choice (fun y x => f x = y)).
exact H.
Qed.

Casting from a to b then b to a is identity?

Given the definition:
Definition cast (a b:Type) (p:a = b) (x:a) : b :=
match p with
| eq_refl _ => x
end.
I was hoping that the following lemma would be provable:
Lemma cast_cast_is_id : forall (a b:Type) (x:a) (p:a = b) (q:b = a),
cast b a q (cast a b p x) = x.
However, I do not seem to be able to carry out a proof for this. I can destruct p successfully, but cannot destruct q after that. Replacing the lemma's statement with eq_sym p instead of arbitrary q does not help me either it seems.
I fear I have unwittingly stumbled into some subtle point of HoTT.
Can anyone prove this lemma or is it known to be unprovable without further axioms?
I am not completely sure, but it seems to me that what you are trying to prove is no different from forall a (p:a=a), p = eq_refl. If so, you cannot prove it in Coq, unless you know something about a, e.g., decidable equality. In that case, you can use the results on UIP (unicity of identity proofs) from the standard library.

Provide example in Coq where (A B: Prop), P: Prop -> Type, such that A <-> B, but one cannot replace P A with P B

As the title asks, I wish for an example where:
Section Question:
Definition A: Prop := <whatever you like>.
Definition B:Prop := <whatever you like>.
Definition/Inductive/Fixpoint P: Prop -> Type := <whatever you like>.
Theorem AEquivB: A <-> B.
Proof. <supply proof here>. Qed.
(* Question 1. can we pick a P, A, B to prove this? *)
Theorem PA_not_equals_Pb: P A <> P B.
Proof. <supply proof here>. Qed.
(* Question 1.5. can we pick a P, A, B to prove this? *)
Theorem PA_not_equiv_PB: ~(P A <-> P B)
Proof. <supply proof here>. Qed.
In general, I am interested to understand whether "proof equivalence" is "good enough" to be used as "equality" in a sense, or whether there are situations where we can have P A, and A <-> B, but not P B.
It is consistent with Coq that forall A B : Prop, (A <-> B) -> A = B. (That is, you can add this as an axiom and the theory won't collapse.) This axiom is called propositional extensionality. As A = B quickly gives forall P : Prop -> Prop, P A <-> P B, there are no terms P, A, B such that (A <-> B) /\ ~(P A <-> P B), since this would contradict the axiom, but we know it is consistent. Similarly, we also quickly get P A = P B, which means we cannot also get P A <> P B. Note that even though such P, A, B that violate propositional extensionality do not exist, we still cannot prove propositional extensionality. Coq simply doesn't have the strength to talk about itself like that (which is good, since that means you can customize it), which is why propositional extensionality needs to be added as an axiom if you want it.

example for introduction pattern (p1 & ... & pn) does not work

I am reading the Coq (8.5p1) reference manual,
introduction via (p1 & ... & pn) is a shortcut for introduction via
(p1,(...,(...,pn)...)); it expects the hypothesis to be a sequence of
right-associative binary inductive constructors such as conj or
ex_intro; for instance, an hypothesis with type A/(exists x, B/\C/\D)
can be introduced via pattern (a & x & b & c & d);
Trying to test this out, I did:
Goal forall A B C D: Prop, A/\(exists x:nat, B/\C/\D) -> D.
intros (a & x & b & c & d).
But Coq is telling me:
Error: Not an inductive product.
And I got the same error for a few other variants, such as one without the -> D.
Can some one please explain what's the correct usage (in a hopefully useful example)?
Since your goal starts with forall A B C D: Prop, you need to introduce A B C D first:
intros A B C D (a & x & b & c & d).
I think this syntax was introduced to get rid of nested square brackets, which can be used to destructure during the introduction phase. Compare the following two proofs:
Goal forall A B C D: Prop,
A /\ (exists x:nat, B /\ C /\ D) -> D.
intros A B C D (_ & _ & _ & _ & d). assumption. Qed.
Goal forall A B C D: Prop,
A /\ (exists x:nat, B /\ C /\ D) -> D.
intros A B C D [_ [_ [_ [_ d]]]]. assumption. Qed.
I think the first one is easier on eyes.