Show that ~(A XOR B) is the same as (~A XOR B) using Boolean algebra [closed] - boolean-expression

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I need to show that the expression:
~(A XOR B)
is equivilant to
(~A XOR B)
using boolean algebra.
I really have no idea how to start, any help would be appreciated.

In order to show that two logical expressions are equivalent, you may proceed in two different ways.
Write a truth table for each of the expressions and then, if the resulting functional truth values are the same, then the expressions are equivalent;
Equivalence is the same as implication in both directions;
A <=> B is equivalent to (A => B) AND (B => A)
So, what you need is try to get (~A xor B) from ~(A xor B) and vice versa.
~(A xor B) =
by definition of xor + negation = ~ ( (~A and B) or (A and ~B) ) =
by De Morgan law = ~ (~A and B) and ~(A and ~B) =
by De Morgan law again = (A or ~B) and (~A or B) =
by applying distributive law = (A and ~A) or (A and B) or (~B and ~A) or (~B and B) =
ignore contradictions = (A and B) or (~B and ~A) =
apply definition of xor in another direction = ~A xor B.
the end
The same procedure must be done in the other direction ( get ~(A xor B) from (~A xor B) ). Then the proof will be complete.

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.

Teach Coq that associative law of natural numbers holds

I have a simple question.
I want to teach Coq that there is vec_assoc.
Require Import Coq.Vectors.Vector.
Lemma vec_assoc (A:Type)(a b c:nat): t A ((a+b)+c) = t A (a+(b+c)).
Proof.
f_equal. symmetry. apply Nat.add_assoc. Qed.
Variable a b c:nat.
Variable A B:Type.
Variable I : (t A ((a+b)+c) -> B).
Variable p:t A (a+(b+c)).
Coq returns an error
`The term "p" has type "vector A (a + (b + c))"
while it is expected to have type "vector A (a + b + c)".`
When I execute Compute I p.
How do I teach Coq that associative law of natural number holds?
Well, associativity does not hold with respect to convertibility of Coq terms, it only holds propositionally. What that means is that in a context where a, b c : nat you can build a term pf : a + (b + c) = (a + b) + c but it is not the case that the specific proof eq_refl can be given the type a + (b + c) = (a + b) + c.
In your case, since you already have a proof that t A (a + (b + c)) = t A ((a + b) + c) you could do the application by first transporting p along this equality using eq_rect or the rew vec_assoc A a b c in p syntax from the module EqNotations of the standard library (just add Import EqNotations.).
In any case nothing will compute since both I and p are variables (and the proof vec_assoc is opaque thanks to Qed).

Coq: How to rewrite inside a lambda?

Basically, I want to prove the following lemma, but I'm having trouble since I can't seem to directly rewrite inside of the lambdas.
However I feel like this should be possible, because if I were "inside" the lambda, I could easily prove it for any given x.
Lemma lemma :
forall {A B : Type} (f : A -> B) (g : A -> B),
(forall (x : A), f x = g x) -> (fun x => f x) = (fun x => g x).
The statement you're trying to prove is (essentially) functional extentionality, which is well-known to not be provable in Coq without extra axioms. Basically, the idea is that f and g can be intentionally very different (their definitions can look different), but still take on the same values. Equality of functions (fun x => f x) = (fun x => g x) would (without any additional axioms) imply that the two functions are syntactically the same.
For example, take f(n) = 0 and g(n) = 1 if x^(3 + n) + y^(3 + n) = z^(3 + n) has a non-trivial solution in integers, otherwise 0 (both functions from natural numbers to natural numbers). Then f and g are intentionally different - one doesn't syntactically reduce to the other. However, thanks to Andrew Wiles, we know that f and g are extentionally the same since g(n) = 0 for all n.
You can freely add your lemma (or various strengthenings) as an axiom to Coq without worrying about inconsistency.

Boolean expression with four operands

How can I write a boolean expression which will be true if and only if there is one out of four operands is true? I need the most succinct possible way to write it.
Here's how I'd do it:
((A XOR B) XOR (C XOR D)) AND (NOT (A AND B)) AND (NOT (C AND D))
The first part
((A XOR B) XOR (C XOR D))
Works for all cases except three inputs being true, hence the second part.

Convert function with only AND Boolean operations

I have some function like
(A and ( B or c)) or (D and E and (F or H or R or P )))
and I want to convert that function to function with only and operations (of course if possible)
I find that with DeMorgan's Laws can be done some kind of transformations but I didn't manage to conver this function any ideas ?
I know that function
!(A or B) is equal to function !A and !B
but I could not find the equal function to the one above
The function you mentioned:
!(A or B) = !A and !B
is the same as:
A or B = !(!A and !B)
So let's start by splitting your problem into two parts of ABC and DEFHRP.
(A and (B or C)) = (A and !(!B and !C))
(D and E and (F or H or R or P)) = (D and E and !(!F and !H and !R and !P))
Since these two parts are joined by an 'or', we can apply the equivalence again to get:
!(!(A and !(!B and !C)) and !(D and E and !(!F and !H and !R and !P)))
The key substitution you're looking for is A OR B => !(!A AND !B). Using this you can expand the expression.
a and (b or c)
is the same as
a and not (not b and not c)
You can test it here
And for the more complex one:
d and e and (f or h or r)
is the same as
d and e and not(not f and not h and not r)
which is tested here