def BinRelVec(filtered, func_ent): binRelVec = {"In", "Orthogonal"} operations = {"+", "=", "-"} constraints = [] for i, ent in enumerate(filtered): if type(ent) is VarDecl or type(ent) is int: continue if ent[1] in binRelVec: c = Constraint() c.func = ent[1] vec, space = find2PrevVarDecl(filtered[:i]) c.args.append(vec) c.args.append(space) constraints.append(c) if ent[0] in binRelVec: c = Constraint() c.func = ent[0] vec1, vec2 = find2PrevVarDecl(filtered[:i]) c.args.append(vec1) c.args.append(vec2) constraints.append(c) if ent[0] in operations: if ent[0]=="=": #exp = s1 + s2 exp = findPrevVarDecl(filtered[:i]) s1, s2 = findNext2VarDecl(filtered[i+1:]) c = Constraint() c.func = "Sum" c.args = [exp, s1, s2] constraints.append(c) return constraints
def BinRelFunc(filtered, func_ent): binRelFunc = {"Injection", "Surjection", "Bijection"} # function contraint eg. Injection(f) fconstraint = Constraint() # Bin rel constraint eg. From(f, A, B) tconstraint = Constraint() for i, ent in enumerate(filtered): if type(ent) is VarDecl or type(ent) is int: continue if ent[0] in binRelFunc: fconstraint.func = ent[0] fconstraint.args.append(func_ent) elif ent[1] == "From": fromSet = findNextVarDecl(filtered[i:]) tconstraint.func = "From" tconstraint.args.append(func_ent) tconstraint.args.append(fromSet) elif ent[1] == "To": to = findNextVarDecl(filtered[i:]) tconstraint.args.append(to) return [fconstraint, tconstraint]