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 1
- Issues with using C code in Python | Set 2
- Code introspection in Python
- Optimization Tips for Python Code
- Packaging and Publishing Python code
- Different Python IDEs and Code Editors
- Morse Code Translator In Python
- Execute a String of Code in Python
- Debugging Python code using breakpoint() and pdb
- How to run Python code on Google Colaboratory
- Understanding Code Reuse and Modularity in Python 3
- Performing Google Search using Python code
- How to generate byte code file in python ?
- Python | Generate QR Code using pyqrcode module
- Python Code for time Complexity plot of Heap Sort
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.