How do you solve this small Boolean Algebra problem? - boolean-algebra

Boolean algebra:
a + ~a.b
This is as far as I got:
= a + ~a.b + a.~a
= a + ~a(b + a)
I know that the answer is a + b however I can't seem to prove it.
I would be very grateful if someone could show the steps to proving it.

The way to solve this is to break it down.
I prefer to use & and | and !.
1. A & (!A | B)
2. (A & !A) | (A & B) Distributive property
3. 0 | (A & B) (A & !A) just like True and False can never be True
4. A & B
You may also want to look at De Morgan's Laws

One way to do this easily is:
= a + ~a.b
= a.(1+b) + ~a.b
= a + a.b + ~a.b
= a+ b.(a + ~a)
= a + b
Thanks!

Related

Boolean algebra simplification exercise

So I have been given the following expression, but I cannot seem to solve it, can anyone do this and show the steps please?
Prove XY'Z + XYZ' + XYZ = XY + XZ
XY'Z + XYZ' + XYZ = XY + XZ
Notice X and Z are common factors between XY'Z and XYZ.
XZ(Y' + Y) + XYZ' =
Y' + Y is equal to 1 (if Y=0 then Y'=1 and so 0 + 1 = 1, that is 0 or 1 = 1. Similarly, if Y=1 then Y'=0 and so 1 + 0 = 1). Therefore, what you get is:
XZ·1 + XYZ' =
XZ·1 = XZ since A·1 = A (if A=0 then 0·1 is 0 and if A=1 then 1·1 = 1). Now the function is simplified to:
XZ + XYZ' =
Notice once again X is a common factor between XZ and XYZ'.
X(Z + YZ') =
Notice this time that Z + YZ' is a special case of the distributive law, which is A + A'B = A + B. This is because if we apply the general distributive law A + BC = (A + B)·(A + C) then we get A + A'B = (A + A')·(A + B) = 1·(A + B) = A + B. Following this reasoning we get to simplify the function even further:
X(Z + Y) =
All that's left is for us to use the distributive law and we finally arrive to the final result:
XY + XZ
Please note that nothing is written between variables, an AND operator (or "·" symbol) is assumed. It's just a way to save space.

Maxima: How to factor out a finite sum?

This question is about humane representation of Maxima output.
In short, how do I make
b*d4 + b*d3 + b*d2 + b*d1 + a*sin(c4 + alpha) + a*sin(c3 + alpha) + a*sin(c2 + alpha) + a*sin(c1 + alpha)
look like
b*sum_{i=1}^{4} d_i + a*sum_{j=1}^{4}sin(c_i + \alpha)
where sum_{*}^{*}* is a summation sign and an expression with subscripts ?
Or deeper, how to properly model a finite set of items here ?
Consider a finite set of entities $x_i$ (trying to speak tex here) that are numbered from 1 to n where n is known. Let a function $F$ depend on several characteristics of those entities $c_ji = c_j(x_i), j = 1..k$ (k - also known) so that $F = F(c_11,...,c_kn)$.
Now when I try to implement that in Maxima and do things with it, it would yield sums and products of all kinds, where the numbered items are represented something like $c_1*a + c_2*a + c_3*a + c_4*a + d_1*b + d_2*b + d_3*b + d_4*b$ which you would write down on paper as $a*\sum_{i=1}^{4}c_i + b*sum_{i=1}^{4}d_i$.
So how can I make Maxima do that sort of expression contraction ?
To be more specific, here is an actual code example:
(Maxima output marked as ">>>")
/* let's have 4 entities: */
n: 4 $
/* F is a sum of similar components corresponding to each entity F = F_1 + F_2 + F_3 + F_4 */
F_i: a*sin(alpha + c_i) + b*d_i;
>>> b*d_i + a*sin(c_i + alpha)
/* defining the characteristics */
c(i) := concat(c, i) $
d(i) := concat(d, i) $
/* now let's see what F looks like */
/* first, we should model the fact that we have 4 entities somehow: */
F_i(i) := subst(c(i), c_i, subst(d(i), d_i, F_i)) $
/* now we can evaluate F: */
F: sum(F_i(i), i, 1, 4);
>>> b*d4 + b*d3 + b*d2 + b*d1 + a*sin(c4 + alpha) + a*sin(c3 + alpha) + a*sin(c2 + alpha) + a*sin(c1 + alpha)
/* at this point it would be nice to do something like: */
/* pretty(F); */
/* and get an output of: */
/* $b*\sum_{i=1}^{4}d_i + a*\sum_{j=1}^4 sin(c_j + \alpha)$ */
/* not to mention having Maxima write things in the same order as I do */
So, to sum up, there are three quetions here:
How do I factor out a sum from an expression like the one on top of this post ?
How do I properly let Maxima know what I'm speaking about here ?
How to make Maxima preserve my order of things in output ?
Thanks in advance.
Here's a way to go about what I think you want.
(%i1) n: 4 $
(%i2) F(i) := a*sin(alpha + c[i]) + b*d[i];
(%o2) F(i) := a sin(alpha + c ) + b d
i i
(%i3) 'sum(F(i), i,1,4);
4
====
\
(%o3) > (a sin(c + alpha) + b d )
/ i i
====
i = 1
(%i4) declare (nounify(sum), linear);
(%o4) done
(%i5) 'sum(F(i), i,1,4);
4 4
==== ====
\ \
(%o5) a > sin(c + alpha) + b > d
/ i / i
==== ====
i = 1 i = 1
(%i6)
The most important thing here is that I've written what we would call "c sub i" and "d sub i" as c[i] and d[i] respectively. These are indexed variables named c and d, and i is the index. It's not necessary for there to actually exist arrays or lists named c or d, and i might or might not have a specific value.
I have written F as an ordinary function. I've avoided the construction of variable names via concat and avoided the substitution of those names into an expression. I would like to emphasize that such operations are almost certainly not the best way to go about it.
In %i3 note that I wrote the summation as 'sum(...) which makes it a so-called noun expression, which means it is maintained in a symbolic form and not evaluated.
By default, summations are not treated as linear, so in %i4 I declared summations as linear so that the result in %o5 is as expected.
Maxima doesn't have a way to collect expressions such as a1 + a2 + a3 back into a symbolic summation, but perhaps you don't need such an operation.

Not understanding the recurrence formula of n nodes with a height h in an AVL tree to show h <= 2 log n

I know the formula is: n(h) = n(h-1) + n(h-2) + 1
And I know it can be reduced as:
n(h) = n(h-1) + n(h-2) + 1
>= n(h-2) + n(h-2) + 1
>= 2n(h-2) + 1
>= 2n(h-2)
After this step I don't understand the recurrence that would come here. I was reading a proof online and they did this:
>= 2n(h-2)
>= 2(2n(h-4))
>= 2(2(2n(h-6)))
I'm not understanding that block. Why is each step multiplied by 2 and why is 2 more subtracted each time from the height? I'm having trouble visualizing it or something. Then the rest of the proof shows:
>=(2^i)n(h-2i)
I understand how they got that answer based on the pattern, and I can solve the rest of the proof, but I don't understand how that recursive pattern was chosen. I hope I'm making sense. If anyone can clarify this for me, I would appreciate it very much!
Given that n(h) >= 2n(h-2) for all h, we can apply this very same inequality for h-2 as well. This would give us:
n(h-2) >= 2n(h-2-2)
which is the same as
n(h-2) >= 2n(h-4).
If we now apply it again for h-4 (as we did for h-2) we get
n(h-4) >= 2n(h-4-2) = 2n(h-6).
Now we can replace these two last inequalities into the first one:
n(h) >= 2n(h-2) >= 2(2n(h-4)) >= 2(2(2n(h-6)))
and so on...

how to find cryptarithmetic letter value?

Cross + roads = danger ==> the answer is ==> 96233 + 62513=158746
I'm looking for a instruction to find the answer easier for another example. one of my teacher said that we can using tree to find it. but sometimes using tree to find the answer is impossible.
How do you usually find you're cryptarithmetic solution?
One simple way :
Define the variables (just for convenience) :
vars = Symbol[#] & /# ("abc" <> ToString[#] & /# Range[26]) ;
Associate a variable to each letter of the alphabet :
alphabet = Transpose[{CharacterRange["a", "z"], vars}];
Write a helper function to translate a string into an expression :
formDigits[astring_] := FromDigits[alphabet[[alphabet[[#, 2]] & /#
Position[alphabet[[All, 1]], #][[1, 1]] & /# Characters[astring], 2]]]
Example :
formDigits["cross"]
(* abc19 + 10 (abc19 + 10 (abc15 + 10 (abc18 + 10 abc3))) *)
Write the system of equations corresponding to "Cross + roads = danger" :
equation = formDigits["cross"] + formDigits["roads"] == formDigits["danger"]
Finally solve the system with the obvious additional constraints :
sol = First#FindInstance[{equation, Sequence ## Thread[Thread[0 <= vars <= 9]],
Not[Apply[And, Thread[vars == 0]]]}, alphabet[[All, 2]], Integers] ;
Check :
formDigits["cross"] /. sol
formDigits["roads"] /. sol
formDigits["danger"] /. sol
(* 78644
86614
165258 *)
This is naturally solved, in Prolog. See also Faster implementation of verbal arithmetic in Prolog :
%% unique selection from narrowing domain
selectM([A|As],S,Z):- select(A,S,S1),selectM(As,S1,Z).
selectM([],Z,Z).
%% a puzzle
cryp([[C,R,O,S,S]+[R,O,A,D,S]=[D,A,N,G,E,R]]):-
Dom=[0,1,2,3,4,5,6,7,8,9],
selectM([S],Dom,D0),
N1 is S+S, R is N1 mod 10, R=\=0,
selectM([R,D],D0,D1), D=\=0,
N2 is (N1//10)+S+D, E is N2 mod 10,
selectM([E,O,A,G],D1,D2),
N3 is (N2//10)+O+A, G is N3 mod 10,
N4 is (N3//10)+R+O, N is N4 mod 10,
selectM([N,C],D2,_), C=\=0,
N5 is (N4//10)+C+R, A is N5 mod 10,
D is N5//10.
The key to efficiency is to choose the instantiations of digits progressively, one by one, testing right away to scrap the invalid choices as soon as possible. I'm sure this can be translated to Mathematica.
The other problem like this sum is
CROSS + ROADS = DENGER
The solution for this problem is
68244 + 82714 = 150958

How to proceed with spoj LGIC?

I am trying to solve this problem http://www.spoj.pl/problems/LGIC/. I just can't figure out how is this sequence advancing.
By lagarange's it is too complex to solve for such a great range.
The farthest I could get was with factorials
1! = 1 & a1=2
2! = 2 & a2=4
3! = 6 & a3=11
4! = 24 & a4=36
5! = 120 & a5=147
6! = 720 & a6=778
Please guide me someone..
Perhaps the sequence is: An = n! + 2^n - n.
You can gat the Nth term using
T(n) = n! + pow(2,n) - n

Resources