Difference between revisions of "CSC270 Homework 1 2011 Solution"
(Created page with "--~~~~ ---- This is the solution page for the CSC270 Homework #1. =Problem #1= f = a' + bc g = a' . (b' + c' ) h = 1 k = a' + b + c' =Problem...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
--[[User:Thiebaut|D. Thiebaut]] 12:10, 8 February 2011 (EST) | --[[User:Thiebaut|D. Thiebaut]] 12:10, 8 February 2011 (EST) | ||
---- | ---- | ||
− | + | <onlydft> | |
This is the solution page for the [[CSC270 Homework 1 2011 | CSC270 Homework #1]]. | This is the solution page for the [[CSC270 Homework 1 2011 | CSC270 Homework #1]]. | ||
Line 28: | Line 28: | ||
k = Π( 5 ) | k = Π( 5 ) | ||
+ | =Program= | ||
+ | <code><pre> | ||
+ | # ---------------------------------------------------------------------------- | ||
+ | # File: hw1.py | ||
+ | # Author: Tiffany Q. Liu | ||
+ | # Acct: 270b-ae | ||
+ | # Date: February 4, 2010 | ||
+ | # Desc: Modification of code take from D. Thiebaut used to verify that the | ||
+ | # simplified boolean expressions are equivalent to their non-simplified | ||
+ | # counterparts. Functions are defined such that fcnName1 = original, | ||
+ | # non-simplified boolean expression and fcnName2 = simplified boolean | ||
+ | # expression. | ||
+ | # | ||
+ | # Output: | ||
+ | # a b c | f1 f2 | g1 g2 | h1 h2 | k1 k2 | ||
+ | #-----------+----------+----------+----------+---------- | ||
+ | # 0 0 0 | 1 1 | 1 1 | 1 1 | 1 1 | ||
+ | # 0 0 1 | 1 1 | 1 1 | 1 1 | 1 1 | ||
+ | # 0 1 0 | 1 1 | 1 1 | 1 1 | 1 1 | ||
+ | # 0 1 1 | 1 1 | 0 0 | 1 1 | 1 1 | ||
+ | # 1 0 0 | 0 0 | 0 0 | 1 1 | 1 1 | ||
+ | # 1 0 1 | 0 0 | 0 0 | 1 1 | 0 0 | ||
+ | # 1 1 0 | 0 0 | 0 0 | 1 1 | 1 1 | ||
+ | # 1 1 1 | 1 1 | 0 0 | 1 1 | 1 1 | ||
+ | # | ||
+ | # ---------------------------------------------------------------------------- | ||
+ | |||
+ | # ------------------------------------------------------------- | ||
+ | # f1(a,b,c) = a'.b'.c' + a'.b'.c + a'.b.c' + a'.b.c + a.b.c | ||
+ | # ------------------------------------------------------------- | ||
+ | def f1(a,b,c): | ||
+ | return ((not a) & (not b) & (not c)) | ((not a) & (not b) & c) | \ | ||
+ | ((not a) & b & (not c)) | ((not a) & b & c) | (a & b & c) | ||
+ | |||
+ | # ------------------------------------------------------------- | ||
+ | # f2(a,b,c) = a' + b.c | ||
+ | # ------------------------------------------------------------- | ||
+ | def f2(a,b,c): | ||
+ | return (not a) | (b & c) | ||
+ | |||
+ | # ------------------------------------------------------------- | ||
+ | # g1(a,b,c) = a'.b'.c' + a'.b'.c + a'.b.c' | ||
+ | # ------------------------------------------------------------- | ||
+ | def g1(a,b,c): | ||
+ | return ((not a) & (not b) & (not c)) | ((not a) & (not b) & c) | \ | ||
+ | ((not a) & b & (not c)) | ||
+ | |||
+ | # ------------------------------------------------------------- | ||
+ | # g2(a,b,c) = a'.b' + a'.c' | ||
+ | # ------------------------------------------------------------- | ||
+ | def g2(a,b,c): | ||
+ | return ((not a) & (not b)) | ((not a) & (not c)) | ||
+ | |||
+ | # ------------------------------------------------------------- | ||
+ | # h1(a,b,c) = a'.b'.c' + a'.b'.c + a'.b.c' + a'.b.c + a.b'.c' | ||
+ | # + a.b'.c + a.b.c' + a.b.c | ||
+ | # ------------------------------------------------------------- | ||
+ | def h1(a,b,c): | ||
+ | return ((not a) & (not b) & (not c)) | ((not a) & (not b) & c) | \ | ||
+ | ((not a) & b & (not c)) | ((not a) & b & c) | \ | ||
+ | (a & (not b) & (not c)) | (a & (not b) & c) | (a & b & (not c)) | \ | ||
+ | (a & b & c) | ||
+ | |||
+ | # ------------------------------------------------------------- | ||
+ | # h2(a,b,c) = 1 | ||
+ | # ------------------------------------------------------------- | ||
+ | def h2(a,b,c): | ||
+ | return 1 | ||
+ | |||
+ | # ------------------------------------------------------------- | ||
+ | # k1(a,b,c) = a'.b'.c' + a'.b'.c + a'.b.c' + a'.b.c + a.b'.c' | ||
+ | # + a.b.c' + a.b.c | ||
+ | # ------------------------------------------------------------- | ||
+ | def k1(a,b,c): | ||
+ | return ((not a) & (not b) & (not c)) | ((not a) & (not b) & c) | \ | ||
+ | ((not a) & b & (not c)) | ((not a) & b & c) | \ | ||
+ | (a & (not b) & (not c)) | (a & b & (not c)) | (a & b & c) | ||
+ | |||
+ | # ------------------------------------------------------------- | ||
+ | # k2(a,b,c) = a' + a.b + a.c' | ||
+ | # ------------------------------------------------------------- | ||
+ | def k2(a,b,c): | ||
+ | return (not a) | (a & b) | (a & (not c)) | ||
+ | |||
+ | # ------------------------------------------------------------- | ||
+ | # Print out truth table for f1, f2, g1, g2, h1, h2, k1, and k2. | ||
+ | # ------------------------------------------------------------- | ||
+ | def main(): | ||
+ | print " a b c | f1 f2 | g1 g2 | h1 h2 | k1 k2 " | ||
+ | print "-----------+----------+----------+----------+----------" | ||
+ | for a in [0,1]: | ||
+ | for b in [0,1]: | ||
+ | for c in [0,1]: | ||
+ | print "%3d%3d%3d |%3d%4d |%3d%4d |%3d%4d |%3d%4d" % \ | ||
+ | (a, b, c, f1(a,b,c), f2(a,b,c), g1(a,b,c), g2(a,b,c), | ||
+ | h1(a,b,c), h2(a,b,c), k1(a,b,c), k2(a,b,c)) | ||
+ | |||
+ | main() | ||
+ | |||
+ | |||
+ | </pre></code> | ||
+ | </onlydft> | ||
[[Category:CSC270]][[Category:Homework]] | [[Category:CSC270]][[Category:Homework]] |