def valid_changes(array): valid = [] for i in range(len(array)): possible_changes = expr.find_changes(str(array[i])) for j in range(len(possible_changes)): section = possible_changes[j] for k in range(len(section)): if len(section[1]) != 0: part = section[1] if len(part) > 0: for m in range(len(part)): change = part[m] if change[1] != []: #print(change) valid.append(change) output = [] for element in array: element = element.replace(" ", "") #print("element: "+str(element)) for change in valid: #print("change: " + str(change)) if element == change[1][0]: if not (change in output): output.append(change) break for change in valid: if not (change in output): output.append(change) return output
def valid_changes(array): valid = [] for i in range(len(array)): possible_changes = expr.find_changes(str(array[i])) for j in range(len(possible_changes)): section = possible_changes[j] for k in range(len(section)): if len(section[1]) != 0: part = section[1] if len(part)>0: for m in range(len(part)): change = part[m] if change[1] != []: #print(change) valid.append(change) output = [] for element in array: element = element.replace(" ","") #print("element: "+str(element)) for change in valid: #print("change: " + str(change)) if element==change[1][0]: if not(change in output): output.append(change) break for change in valid: if not(change in output): output.append(change) return output
#print("jumble: " + str(jumble)) return tree #print(changes[0]) #print("change being made: " + str(changes[0][1])) replacement = do_math(changes[0]) #print("replacement: " + str(replacement)) simplified = simplified.replace(changes[0][1][0], replacement) #print("current: "+str(simplified)) new_tree = eqsim.reparse(simplified) return simplify_expression(new_tree) tree = eqsim.parse() possible_matches = expr.look_for_match(str(tree)) possible_changes = expr.find_changes(str(tree)) #print("possible matches: " + str(possible_matches)) #BFSarray = BFS(tree) #DFSarray = DFS(tree) #print("BFS: " + str(BFSarray)) #print("DFS: " + str(DFSarray)) #changeA = valid_changes(DFSarray) #changeB = valid_changes(BFSarray) #print("A: " + str(changeA)) #print("B: " + str(changeB)) #valid_moves = [] new_tree = simplify_expression(copy.copy(tree))
linear = "27 = 3*x + 15 " sine = "sin(y + 3*s + 15)" cosi = "cos(z + 1 - 16)" tang = "tan(q + 4)" sinesq = "sin(y * pi)^2" cosisq = "cos(z - 16)^2" tangsq = "tan(d + 5)^2" logr = "log(a+b+c)" inv = "inv(a-x+b)" test_expressions = [quad1, quad2,quad3,foil, linear, sine, cosi, tang, sinesq, cosisq, tangsq, logr, inv] for test1 in test_expressions: print("Testing: " + str(test1)) match_array = expr.look_for_match(test1) print("Possible Matches: "+str(match_array)) print for test2 in test_expressions: print("Testing: " + str(test2)) change_array = expr.find_changes(test2) print("Possible Changes: "+str(change_array)) print for test3 in test_expressions: print("Testing: " + str(test3)) expr.find_parts(test3) print print(test_expressions[6])
#jumble = math.associative_jumble(str(tree)) #print("jumble: " + str(jumble)) return tree #print(changes[0]) #print("change being made: " + str(changes[0][1])) replacement = do_math(changes[0]) #print("replacement: " + str(replacement)) simplified = simplified.replace(changes[0][1][0],replacement) #print("current: "+str(simplified)) new_tree = eqsim.reparse(simplified) return simplify_expression(new_tree) tree = eqsim.parse() possible_matches = expr.look_for_match(str(tree)) possible_changes = expr.find_changes(str(tree)) #print("possible matches: " + str(possible_matches)) #BFSarray = BFS(tree) #DFSarray = DFS(tree) #print("BFS: " + str(BFSarray)) #print("DFS: " + str(DFSarray)) #changeA = valid_changes(DFSarray) #changeB = valid_changes(BFSarray) #print("A: " + str(changeA)) #print("B: " + str(changeB)) #valid_moves = []