Simplifying the boolean expression: A ^ B * C - boolean

I've been trying to simplify the
Boolean expression: A ^ B * C for some time now. I'm able to first simplify it down to: A * ~B + ~A * B * C but after that I can't seem to simplify it further. Using an online simplifies, it says that it simplifies to (A + B) * (A + C) * (~A + ~B) but why is that? And what laws are used to simplify it to that?

It depends on the precedence of the operators. Normally AND comes before XOR and it is A XOR (B AND C). Some programming languages evaluate expressions strictly from left to right when not using parentheses, resulting in (A XOR B) AND C, assuming you are using ^ for XOR and * for AND.
Your simplification seems to be going for the latter variant but normally in boolean algebra you'd evaluate the AND first:
A * ~(B*C) + ~A * B * C
= A * (~B + ~C) + ~A * B * C
= A * ~B + A * ~C + ~A * B * C
It's been a while that I've worked with boolean expressions like this, so I don't know if there can be made any further simplifications (or even if mine are correct).
And are you sure, you wrote down the result of the online simplifier correctly? Because the term (A + B) * (~A * ~B) evaluates to A * ~A * ~B + B * ~A * ~B = 0 + 0 and therefore the whole term evaluates to false. This is all assuming that there is the following precedence of operators: NOT > AND > OR. If the last term in their solution is (~A + ~B) it would make more sense and evaluate to your term A * ~B + ~A * B * C, it just is its conjunctive normal form.

Related

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).

Can't use PeanoNat.Nat.add_assoc in proof

Require Import PeanoNat.
Check PeanoNat.Nat.add_assoc.
Output:
Nat.add_assoc
: forall n m p : nat, n + (m + p) = n + m + p
So, the theorem is defined.
But when I create a theorem and try to use it, it gives an error:
Theorem a : forall a b c d e f,
a + b + c + d + e = f.
Proof.
intros.
PeanoNat.Nat.add_assoc a (b + c) d.
Error: The reference PeanoNat.Nat.add_assoc was not found in the
current environment.
Why can't it find the theorem?
What comes after Proof. is not the proof itself. It's a series of instructions, called tactics, that tells Coq how to build a proof. add_assoc is a proof, not a tactic that builds a proof. You would use the tactic rewrite (Nat.add_assoc a (b + c) d) to rewrite (any part of) the goal according to the equality
Nat.add_assoc a (b + c) d
: a + (b + c + d) = a + (b + c) + d
However, your goal a + b + c + d + e = f does not contain either of those terms—+ is left associative and your goal is actually (((a + b) + c) + d) + e = f—so this tactic will fail. In fact, your goal is unprovable, but I assume that it's just for example. You may also be interested in the tactic apply [prf]. It takes the conclusion (thing on the right side of all the ->s and foralls) of prf, matches it against the goal, and gives you subgoals for all of its hypotheses. See also: the Coq tactic reference.

Reordering parentheses using associative property in Racket

I am having trouble implementing a function that given something like this:
'((+(d + e) + f) + (a + (a + c))
Returns this:
'(d + (e + (f + (a + (a + c)))))
Now the catch is that I have to use associativity to get the answer so I only want to use this property:
'((a + b) + c) = '(a + (b + c))
To get the correct output. I know how to implement the function for this case:
'((a + b) + c) -> '(a + (b + c))
However I cannot seem to figure out how to implement it for the first case above (or any other case larger than three items). I am not looking for answers only some guidance. If you would like to see code snippets let me know and I can post some. Also, I created a function that stripped the '+ from the list to make it easier to process.
I think this defines the grammar:
var ::= a | b | c | d | e | f | g
fpip ::= var | (fpip + fpip)
Where a valid fpip can be:
fpip = '((a + b) + c)
or
fpip = '((a + b) + (c + d))
and at it's most atomic level:
fpip = '(a + b)
edit: yes the initial '+ should be erased. Regardless of how many plus signs there are in the initial input there should only be (amount-of-vars - 1) '+ in the output. For example:
'(+ + + + (a + b) + + c) -> '(a + (b + c)
I think these are the cases to consider. Let's call the the recursive rewriter REWRITE.
var -> var
(var + var) -> (var + var)
(var + (fip1 + fpip2)) -> (var + (REWRITE (fip1 + fpip2))
((fip1 + fpip2) + var) -> (REWRITE (fip1 + (fip2 + var))
((fip1 + fpip2) + (fip3 + fpip4)) -> (REWRITE (fip1 + (fip2 + (fip3 + fip4))))

Converting a query to CNF

I've recently been trying to learn logic, but I've come across a query that I can't do and I'm not quite sure where I'm going wrong. When converting a query to CNF, what do you do when you come to this particular situation?
(a AND NOT(b AND c)) AND (d OR e)
= (a AND NOT b) OR (a AND NOT c) AND (d OR e)
=
How would i re-arrange this to get it into CNF form? Am I doing something completely wrong?
Thanks for your help,
Sean
I use the symbols:
^ for AND
v for OR
~ for NOT
and here is how you can transform your formula in CNF:
(a ^ ~(b ^ c)) ^ (d v e)
= (a ^ (~b v ~c)) ^ (d v e) // DeMorgan: ~(A ^ B) <=> (~A v ~B)
= a ^ (~b v ~c) ^ (d v e)
= CNF
Every clauses are separated by AND and contain only OR. With your syntax it gives:
a AND (NOT b OR NOT c) AND (d OR e)
I hope it helps :)

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

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.