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
- Different Python IDEs and Code Editors
- Optimization Tips for Python Code
- Debugging Python code using breakpoint() and pdb
- How to run Python code on Google Colaboratory
- Morse Code Translator In Python
- Execute a String of Code in Python
- Packaging and Publishing Python code
- How to generate byte code file in python ?
- Performing Google Search using Python code
- Python | Accessing variable value from code scope
- Python | Generate QR Code using pyqrcode module
- Understanding Code Reuse and Modularity in Python 3
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.