Simplifying 5-var Boolean SOP Expression using the Laws and Properties - math

I have this question that is messing me up because I am not getting that where should I start, which terms should I pick at the beginning? Because this confusing expression does not even let me take the common as it makes no sense. Also, it does not even let me remove compliments (using the Laws) as it also does not make any sense. Please help me in this, at least just guide me what should I do? From where should I start? I would be really grateful.
The Explanation of Symbols I used to write the expression:
! : NOT Gate
+ : OR Gate
. (dot) : AND Gate
Boolean Expression:
A.!B.E + !(B.C).D.!E + !(C.D).E+!A.D.!E + A.!(C.D).E + A.E + A.B.!E + !(A.C) + B.C.!D
I have used an online expression simplifier and that gave me the following answer:
!A + B + !C + D + E
But how the above long expression has been simplified in this short one? I know the Laws and Properties but I am not getting that how should I start simplifying the long one? Which terms should I see first? Kindly anyone please help me.

(This is a direct answer to your comment, and a side-ways answer to your main question. In short, use a different method to get the desired simplified expression.)
You have a complicated expression, but one that uses only 5 logical variables. In this problem it would be much easier to build a truth table, which would have just 2^5 = 32 rows. You could look at the results and use those to build a simplified, equivalent expression. This does not use "the laws and properties" that your original question requires, but it is a standard technique to simplify Boolean expressions.
You should have learned how to build a truth table in just about any Discrete Mathematics class. In short, you make a table where each element in each row is a T for True or F for False. The rows contain all possible combinations of Ts and Fs. For 5 variables this would use 2^5 = 32 rows. For each row, you assign the first value to A, the second to B, etc. You then evaluate the expression for those values and write the result at the end of the line.
This can be done by hand, but your expression is complicated enough that we could avoid that. Here is a Python 3 script that prints the desired table. Note that Python has the product() function which simplifies getting all possible combinations of Ts and Fs. This script used B[] to convert a Boolean value to a single character T or F.
from itertools import product
"""Make a truth table for the Boolean expression
A.!B.E + !(B.C).D.!E + !(C.D).E+!A.D.!E + A.!(C.D).E + A.E + A.B.!E + !(A.C) + B.C.!D
"""
B = ('F', 'T')
print('A B C D E : Result')
print('- - - - - : ------')
for a, b, c, d, e in product((True, False), repeat=5):
print(B[a], B[b], B[c], B[d], B[e], end=' : ')
print(B[
(a and not b and e)
or (not (b and c) and d and not e)
or (not (c and d) and e)
or (not a and d and not e)
or (a and not (c and d) and e)
or (a and e)
or (a and b and not e)
or (not (a and c))
or (b and c and not d)
])
Here are the results:
A B C D E : Result
- - - - - : ------
T T T T T : T
T T T T F : T
T T T F T : T
T T T F F : T
T T F T T : T
T T F T F : T
T T F F T : T
T T F F F : T
T F T T T : T
T F T T F : T
T F T F T : T
T F T F F : F
T F F T T : T
T F F T F : T
T F F F T : T
T F F F F : T
F T T T T : T
F T T T F : T
F T T F T : T
F T T F F : T
F T F T T : T
F T F T F : T
F T F F T : T
F T F F F : T
F F T T T : T
F F T T F : T
F F T F T : T
F F T F F : T
F F F T T : T
F F F T F : T
F F F F T : T
F F F F F : T
We see that the result is always T except for the single line T F T F F. This means your expression is true unless A is True, B is False, C is True, and D and E are False. So we can simplify your expression (using your notation) to
!(A.!B.C.!D.!E)
A simple use of DeMorgan's laws changes this to normal form:
!A + B + !C + D + E
which is what you wanted.

Related

Simplify the boolean expression F=(Not B and Not C) or (B and Not C) or (Not A and C)

I need to simplify this expression. I know the answer must be (Not A or Not C) but I keep getting C or (Not A and C)
Tried this in Lua:
local a = false
local b = true
local c = true
local f = (not b and not c) or (b and not c) or (not a and c)
local f_= not c or (not a and c)
print(f, f_)
Output: false, false
I also tried all the possibilities with all three variables and both 'f' and 'f_' remained identical.
F = (Not B and Not C) or (B and Not C) or (Not A and C)
-> (Not B and Not C) or (B and Not C) == Not C
F = Not C or (Not A and C)
I like using Karnaugh maps for boolean simplification:
https://en.wikipedia.org/wiki/Karnaugh_map
For your example, we build a 2D truth table:
Then fill in the terms from your question, they all get 'or'd together:
Then you find the smallest number of squares/rectangles that cover the needed parts. The squares and rectangles must have powers of two as a dimension, so 2x2 is ok, 1x4 etc, but not 3x2 for example. These are called 'minterms' and the bigger the square, the simpler the boolean expression they represent. In the example below, the minterm for 'not C' wraps off one end of the map and on to the other, but is still considered a 2x2 square.
You can also do it by covering the unused space with 'maxterms', and then invert it again to get the original expression:
The results of 'not A or not C' and 'not (A and C)' are equivalent by De Morgan's laws. (https://en.wikipedia.org/wiki/De_Morgan%27s_laws)
(Not B and Not C) or (B and Not C) or (Not A and C)
|
| Distributive Law
V
((Not B or B) and Not C) or (Not A and C)
|
| Complement Law
V
Not C or (Not A and C)
|
| Absorption Law
V
Not C or Not A

Is there a infinite loop in my codes? in ocaml

I want to get the sum of function f(i) values when i is equal from a to b
= f(a)+f(a+1)+...+f(b-1)+f(b)
So I wrote code like this.
let rec sigma : (int -> int) -> int -> int -> int
= fun f a b ->
if a=b then f a
else f b + sigma f a b-1 ;;
but result is that there is stack overflow during evaluation. Is there a infinite loop? and why?
sigma f a b-1 is parsed as (sigma f a b) - 1 instead of your intention, sigma f a (b-1). Since sigma f a b calls sigma f a b recursively in your code, it never stops.
The best practice is to put white spaces around binary operators like sigma f a b - 1 so that you would not misread what you write.

User specified function with operators in R

I want to use a user-specified function and apply the function to a list of values. I envision that the user will give a 'formula' as a character string containing the names of variable and operators, e.g. "a * b %% c - d / e ^ f + g %/% h".
The following toy example works
prmlist <- list(a=1:10, b=21:30, c=31:40, d=4, e=5, f=6, g=7, h=8)
with(prmlist, a * b %% c - d / e ^ f + g %/% h)
The problem starts when I want to use this approach within a function. To do that I must get the 'formula' specified by the user inside the function. A character string seems the obvious route. The question is how to evaluate it inside the function. do.call() doesn't seem to be suited because the operators are each really a function. I hoped something simple like
my.formula <- "a * b %% c - d / e ^ f + g %/% h"
with(prmlist, eval(my.formula))
would work but it doesn't.
You can envoke your operators using substitute() instead:
my.formula <- substitute(a * b %% c - d / e ^ f + g %/% h)
with(prmlist, eval(my.formula))
[1] 20.99974 43.99974 68.99974 95.99974 124.99974 155.99974 188.99974
[8] 223.99974 260.99974 299.99974
Update: If the command is a string you can use parse:
myCmd <- "a * b %% c - d / e ^ f + g %/% h"
with(prmlist, eval( parse(text=myCmd) ))
[1] 20.99974 43.99974 68.99974 95.99974 124.99974 155.99974 188.99974
[8] 223.99974 260.99974 299.99974

Ocaml nested if without else

Is it possible to have nested if without else statements. I wrote the following useless program to demonstrate nested ifs. How do I fix this so it's correct in terms of syntax. lines 5 and 6 gives errors.
let rec move_helper b sz r = match b with
[] -> r
|(h :: t) ->
if h = 0 then
if h - 1 = sz then h - 1 ::r
if h + 1 = sz then h + 1 ::r
else move_helper t sz r
;;
let move_pos b =
move_helper b 3 r
;;
let g = move_pos [0;8;7;6;5;4;3;2;1]
You can't have if without else unless the result of the expression is of type unit. This isn't the case for your code, so it's not possible.
Here's an example where the result is unit:
let f x =
if x land 1 <> 0 then print_string "1";
if x land 2 <> 0 then print_string "2";
if x land 4 <> 0 then print_string "4"
You must understand that if ... then is an expression like any other. If no else is present, it must be understood as if ... then ... else () and thus has type unit. To emphasize the fact that it is an expression, suppose you have two functions f and g of type, say, int → int. You can write
(if test then f else g) 1
You must also understand that x :: r does not change r at all, it constructs a new list putting x in front of r (the tail of this list is shared with the list r). In your case, the logic is not clear: what is the result when h=0 but the two if fail?
let rec move_helper b sz r = match b with
| [] -> r
| h :: t ->
if h = 0 then
if h - 1 = sz then (h - 1) :: r
else if h + 1 = sz then (h + 1) :: r
else (* What do you want to return here? *)
else move_helper t sz r
When you have a if, always put an else. Because when you don't put an else, Java will not know if the case is true or false.

How to express variable through other in SAGE

Is there way to express mathematical expression through variable defined earlier in SAGE?
For example if I have variable a = b + c, I want SAGE rewrite expression b + c + d as a + d.
Thank you.
In fact, substituting such expressions is a nontrivial thing if you don't know what part of the expression tree you want. See Richard Fateman's comments here.
The core of the problem is that even the command that would do what you want is not about strings, but expressions.
sage: var("a b c d")
(a, b, c, d)
sage: (a+d).subs({a:b+c})
b + c + d
sage: (b+c+d).subs({b+c:a})
b + c + d
So you will have to use a "wildcard".
sage: w0 = SR.wild(0)
sage: (b+c+d).subs({b+c+w0:a+w0})
a + d
For more information, see
sage: x.match?
sage: SR.wild?
in the interactive shell or notebook.
As you can see in calculus, you can express d as variable with
a = var('a'); b+c
or like a function of b and c variable

Resources