Python code to convert SOP to POS
Write a program in python to convert standard SOP(sum of products) form to standard POS(product of sums) form.
Assumptions:The input SOP expression is standard. The variables in SOP expression are continuous i.e. if expression contains variable A then it will have variables B, C respectively and each Product term contains the alphabets in sorted order i.e. ABC (not like BAC).
Input : ABC'+A'BC+ABC+AB'C Output : (A+B+C).(A+B+C').(A+B'+C).(A'+B+C) Input : A'B+AB' Output : (A+B).(A'+B')
- First of all convert each product term to its equivalent binary form(for ex: if ABC’ then take 1 for uncomplement variable(A, B) and take 0 for complement variable(C) so binary conversion is 110) and then finally equivalent to its decimal form(for ex: 110 = 6) and store in a list.
- Now for POS form take all those terms which are not present in the list formed in step 1st and then convert each term to binary and hence change to SOP form.For ex: suppose 5 was not in the list then
5 ==> 101 (binary)
Now, replace 1 by complement variables(A, C)
replace 0 by uncomplement variables(B)
and between the variables use ‘+’
101 ==> A’+B+C’
After each individual sum term use ‘.’
For more clarity use brackets between each individual term.
Standard POS form of ABC'+A'BC + ABC + AB'C ==> (A+B+C).(A+B+C').(A+B'+C).(A+B'+C').(A'+B+C).(A'+B+C') Standard POS form of A'B + AB' ==> (A+B).(A+B').(A'+B) Standard POS form of xyz'+x'y'z'+xy'z ==> (x+y+z').(x+y'+z).(x+y'+z').(x'+y+z).(x'+y'+z')