This class implements Ohm’s law for circuit analysis It requires any two parameters and it will calculate the other two.
>>> myCalc = OhmsLaw()
>>> myCalc.evaluate(p=1254.8,i=7.5)
{'i': 7.5, 'p': 1254.8, 'r': 22.307555555555556, 'v': 167.30666666666667}
This class implements Ohm’s law for circuit analysis using AC current It requires any three parameters and it will calculate the other two.
>>> myCalc = OhmsLaw_AC()
>>> myCalc.evaluate(p=1254.8,i=7.5,cos=2.0)
>>> {'i': 7.5, 'p': 1254.8, 'r': 11.15, 'v': 83.625}
Converts logical expression to an implementable form. Make two_input 1 if only two input gates must be used. Make only_nand 1 if only 2 input nand gates must be used. Make only_nor 1 if only 2 input nor gates must be used. Make only_and_or_not 1 if only 2 input AND, OR and NOTs be used. Error occurs if more than one variable is put to 1.
convertExpression(‘( NOT(a) and NOT(b)) or (C and Not(d) and E and F)’) OR(AND(NOT(a), NOT(b)), AND(C, NOT(d), E, F))
convertExpression(‘( NOT(a) and NOT(b)) or (C and Not(d) and E and F)’, two_input=1) OR(AND(NOT(a), NOT(b)), AND(C, AND(NOT(d), E)))
convertExpression(‘( NOT(a) and NOT(b)) or (C and Not(d) and E and F)’, only_nand=1) NAND(NAND(NAND(a, a), NAND(b, b)), NAND(C, NAND(NAND(NAND(d, d), E), NAND(NAND(d, d), E))))
convertExpression(‘( NOT(a) and NOT(b)) or (C and Not(d) and E and F)’, only_nor=1) NOR(NOR(NOR(a, b), NOR(NOR(C, C), NOR(NOR(d, NOR(E, E)),... NOR(d, NOR(E, E))))), NOR(NOR(a, b), NOR(NOR(C, C), NOR(NOR(d, NOR(E, E)), NOR(d, NOR(E, E))))))
convertExpression(‘( NOT(a) and NOT(b)) or (C and Not(d) and E and F)’, only_and_or_not=1) OR(AND(NOT(a), NOT(b)), AND(C, AND(NOT(d), AND(E, F))))
Creates a list which can be used by convertExpression for conversion.
Used by convertExpression to convert logical operators to english words.
Combines NOR gate with othes to minimize the number of gates used.
Converts a NOT gate and its operand to use the specified gate only. The input gate must be NAND or NOR only.
Converts a general two input gate and two of its operands to use only OR, NOT, or AND gates
An interactive function which takes in minterms/maxterms and prints the Boolean Function and implementable form. Don’t Care Conditions can also be provided (optional) Eg: Enter the list of variables A,B,C Do you want to enter minterms (m) or maxterms(M)? m Enter list of minterms 1,4,7 Enter list of Don’t Care terms Enter X if there are none 2,5 The logical expression is (((NOT B) AND C) OR (A AND C) OR (A AND (NOT B))) Can be implemented as OR(AND(NOT(B), C), AND(A, C), AND(A, NOT(B)))
This class implements a Moore state machine solver. Using the Quine-McCluskey algorithm it minimizes the necessary next state and output functions for a given state machine.
This class is the base for creating a Moore state machine optimizer.
Bases: BinPy.Algorithms.MooreOptimizer.StateMachineOptimizer
This class implements a Moore state machine optimizer that tries all possible permutations for assignment of state word values to states.
Bases: BinPy.Algorithms.MooreOptimizer.StateMachineOptimizer
This class is used for testing the state machine optimizer.
Bases: BinPy.Algorithms.MooreOptimizer.StateMachineOptimizer
This class implements a Moore state machine optimizer that tries permutations at random.
This class provides access to the input variables from the lambda expressions.
Evaluates a list of lambda expressions in the state and variables environment. The lambda expressions are terms of an OR expression.
f_array: a list of lambda expressions
returns: the logical OR after evaluate the lambda expression in the setup environment
Retrieve a human readable form of the given function.
Returns a function that satisfies the conditions given.
f_on: a list of lambda expressions; if one of the lambda expressions evaluates to True then the requested function should evaluate to True f_off: a list of lambda expressions; if one of them evaluates to True then the requested function whould evaluate to False
returns: a tuple a,b; a is the complexity of the function and b is the function
Given a state map return the transition and output functions.
state_map: a dictionary; key is the state and value is the value of the state word that identifies this state
returns: a tuple a,b,c; a is the sum of the functions’ complexities, b is the next state functions (one for each state word bit) and c is the output functions
This class implements the Quine-McCluskey algorithm for minimization of boolean functions.
Based on code from Robert Dick <dickrp@eecs.umich.edu> and Pat Maupin <pmaupin@gmail.com>. Most of the original code was re-written for performance reasons.
>>> qm = QM(['A','B'])
>>> qm.get_function(qm.solve([])[1])
'0'
>>> qm.get_function(qm.solve([1,3],[0,2])[1])
'1'
>>> qm.get_function(qm.solve([0,1,2,3])[1])
'1'
>>> qm.get_function(qm.solve([3])[1])
'(A AND B)'
>>> qm.get_function(qm.solve([0])[1])
'((NOT A) AND (NOT B))'
>>> qm.get_function(qm.solve([1,3])[1])
'A'ls
>>> qm.get_function(qm.solve([1],[3])[1])
'A'
>>> qm.get_function(qm.solve([2,3])[1])
'B'
>>> qm.get_function(qm.solve([0,2])[1])
'(NOT A)'
>>> qm.get_function(qm.solve([0,1])[1])
'(NOT B)'
>>> qm.get_function(qm.solve([1,2,3])[1])
'(A OR B)'
>>> qm.get_function(qm.solve([0,1,2])[1])
'((NOT B) OR (NOT A))'
Calculate the complexity of the given function. The complexity is calculated based on the following rules: A NOT gate adds 1 to the complexity. A n-input AND or OR gate adds n to the complexity.
minterms: a list of minterms that form the function
returns: an integer that is the complexity of the function
>>> qm = QM(['A','B','C'])
>>> qm.calculate_complexity([(1,6)])
0
>>> qm.calculate_complexity([(0,6)])
1
>>> qm.calculate_complexity([(3,4)])
2
>>> qm.calculate_complexity([(7,0)])
3
>>> qm.calculate_complexity([(1,6),(2,5),(4,3)])
3
>>> qm.calculate_complexity([(0,6),(2,5),(4,3)])
4
>>> qm.calculate_complexity([(0,6),(0,5),(4,3)])
5
>>> qm.calculate_complexity([(0,6),(0,5),(0,3)])
6
>>> qm.calculate_complexity([(3,4),(7,0),(5,2)])
10
>>> qm.calculate_complexity([(1,4),(7,0),(5,2)])
11
>>> qm.calculate_complexity([(2,4),(7,0),(5,2)])
11
>>> qm.calculate_complexity([(0,4),(7,0),(5,2)])
12
>>> qm.calculate_complexity([(0,4),(0,0),(5,2)])
15
>>> qm.calculate_complexity([(0,4),(0,0),(0,2)])
17
Find all prime implicants of the function.
cubes: a list of indices for the minterms for which the function evaluates to 1 or don’t-care.
Return in human readable form a sum of products function.
minterms: a list of minterms that form the function
returns: a string that represents the function using operators AND, OR and NOT.
Executes the Quine-McCluskey algorithm and returns its results.
ones: a list of indices for the minterms for which the function evaluates to 1 dc: a list of indices for the minterms for which we do not care about the function evaluation
returns: a tuple a,b; a is the complexity of the result and b is a list of minterms which is the minified boolean function expressed as a sum of products
Use the prime implicants to find the essential prime implicants of the function, as well as other prime implicants that are necessary to cover the function. This method uses the Petrick’s method, which is a technique for determining all minimum sum-of-products solutions from a prime implicant chart.
primes: the prime implicants that we want to minimize. ones: a list of indices for the minterms for which we want the function to evaluate to 1.