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')
- Issues with using C code in Python | Set 2
- code.compile_command() in Python
- Code introspection in Python
- Issues with using C code in Python | Set 1
- Code Golfing in Python
- Python code formatting using Black
- Different Python IDEs and Code Editors
- Optimization Tips for Python Code
- Morse Code Translator In Python
- Packaging and Publishing Python code
- Debugging Python code using breakpoint() and pdb
- Hamming Code implementation in Python
- Execute a String of Code in Python
- Top 10 Python IDE and Code Editors in 2020
- How to run Python code on Google Colaboratory
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.