def computeTransitiveClosure(R): x0, x1, x2, x3, x4 = pyeda.bddvars('x', 5) y0, y1, y2, y3, y4 = pyeda.bddvars('y', 5) z0, z1, z2, z3, z4 = pyeda.bddvars('z', 5) # Transitive closure alg H = R HPrime = None while True: HPrime = H # H ff1 = H.compose({y0: z0, y1: z1, y2: z2, y3: z3, y4: z4}) # R ff2 = R.compose({x0: z0, x1: z1, x2: z2, x3: z3, x4: z4}) # H x R ff3 = ff1 & ff2 # H = H v (H x R) H = HPrime | ff3 # apply smoothing over all z BDD Vars to rid them from the graph H = H.smoothing((z0, z1, z2, z3, z4)) if H.equivalent(HPrime): break return H
def __init__(self, number_of_states, suffix=''): self._number_of_states = number_of_states self._model_index_length = (number_of_states-1).bit_length() self.msb = bddvars(consts.MODEL_IDX + suffix, self._model_index_length) self.msb_other = bddvars( consts.MODEL_OTHER_IDX + suffix, self._model_index_length) self.msb_compose = {self.msb[i]: self.msb_other[i] for i in range(self._model_index_length)} self.atomic = bdd_utils.ZERO self.relations = bdd_utils.ZERO self.atomic_str = []
def transitive_closure(R): x0, x1, x2, x3, x4 = pyeda.bddvars('x', 5) y0, y1, y2, y3, y4 = pyeda.bddvars('y', 5) z0, z1, z2, z3, z4 = pyeda.bddvars('z', 5) Temp = R temp_prime = None while True: temp_prime=Temp ff1 = Temp.compose({y0:z0, y1:z1, y2:z2, y3:z3, y4:z4 }) ff2 = R.compose({x0:z0, x1:z1, x2:z2, x3:z3, x4:z4 }) ff3 = ff1 & ff2 Temp = temp_prime | ff3 Temp = Temp.smoothing((z0, z1, z2, z3, z4)) if Temp.equivalent(temp_prime): break return Temp
def main(): edgeFormulaList = [] x0, x1, x2, x3, x4 = pyeda.bddvars('x', 5) y0, y1, y2, y3, y4 = pyeda.bddvars('y', 5) print("Generating Graph...") for i in range(0, 32): for j in range(0,32): if (((i+3) % 32) == (j % 32)) | (((i+7) % 32) == (j % 32)): newFormula = conjure_formula(i, j) edgeFormulaList.append(newFormula) F = connect_to_edges(edgeFormulaList) R = pyeda.expr2bdd(F) print("Generating transitive closure, R*") RStar = transitive_closure(R) print("Negating the transitive closure, R*") negRStar = ~RStar result = negRStar.smoothing((x0, x1, x2, x3, x4, y0, y1, y2, y3, y4)) result = ~result print("Let x,y be in the set S. Node x can reach node y in one+ steps in a graph G. . .") print(f"\n{result.equivalent(True)}\n")
def doTC(R): i0, i1, i2, i3, i4 = pyeda.bddvars('i', 5) j0, j1, j2, j3, j4 = pyeda.bddvars('j', 5) k0, k1, k2, k3, k4 = pyeda.bddvars('k', 5) # Transitive closure algorithm H = R Hprime = None while True: Hprime = H p1 = H.compose({j0: k0, j1: k1, j2: k2, j3: k3, j4: k4}) p2 = R.compose({i0: k0, i1: k1, i2: k2, i3: k3, i4: k4}) p = p1 & p2 H = Hprime | p H = H.smoothing((k0, k1, k2, k3, k4)) if H.equivalent(Hprime): break return H
`N` is the length of the `X` vector. ''' from pyeda.inter import bddvars # The number of total variables that will be allocated. Set to 16 based on the # requirements found in [1] W. Arthur and W. Polak, “The evolution of # technology within a simple computer model,” Complexity, vol. 11, no. 5, pp. # 23–31, 2006. N = 16 X = bddvars('x', N) def evaluated_at(circuit, bitstring): ''' Evaluates the given circuit (function array) at the given bitstring and returns the resulting bitstring. The input and output bitstrings will be lists of `0` and `1`. If the input bitstring is shorter than `N`, it will be padded to the right with zeroes. :param circuit: the boolean circuit to evaluate :param bitstring: a list of `0` and `1` integers ''' if len(bitstring) < N: inbits = bitstring + [0] * (N - len(bitstring)) else:
import pydot graph = pydot.graph_from_dot_data(func.to_dot())[0] graph.create_png('graph.png') except Exception as e: print("Failed to graph. No graph rendering for you! <" + type(e) + ">") def debug(obj): if isDebug: print(str(obj)) if __name__ == '__main__': i0, i1, i2, i3, i4 = pyeda.bddvars('i', 5) j0, j1, j2, j3, j4 = pyeda.bddvars('j', 5) k0, k1, k2, k3, k4 = pyeda.bddvars('k', 5) primes = list(filter(is_prime, range(0, 32))) evens = list(filter(lambda x: x % 2 == 0, range(0, 32))) print("Building boolean expressions...") rList = [ edge2Bool(i, j) for i in range(0, 32) for j in range(0, 32) if (((i + 3) % 32) == (j % 32)) | (((i + 8) % 32) == (j % 32)) ] #this just makes a list of all pairs that satisfy the condition pList = [num2Bool(p) for p in primes] eList = [num2Bool(e) for e in evens] debug(rList)
# apply smoothing over all z BDD Vars to rid them from the graph H = H.smoothing((z0, z1, z2, z3, z4)) if H.equivalent(HPrime): break return H # MAIN, not gucci if __name__ == '__main__': edgeFormulaList = [] x0, x1, x2, x3, x4 = pyeda.bddvars('x', 5) y0, y1, y2, y3, y4 = pyeda.bddvars('y', 5) print("Building the graph, G..") # for (i, j) in G: for i in range(0, 32): for j in range(0, 32): if (((i + 3) % 32) == (j % 32)) | (((i + 7) % 32) == (j % 32)): # send the edge to to formula creation function newFormula = edgeToBooleanFormula(i, j) # add the formula to the list edgeFormulaList.append(newFormula)