def actually_solve_math_function(self, math_function): ''' :param math_function: :return: ''' # TODO: DEBUGGING print "Solving:", get_math_function_as_string(math_function), ''' If the function is already just a number, return it. ''' has_operations = False for x in range(len(math_function)): current = math_function[x] if current == '^' or current == '*' or current == '/' or current == '+' or current == '-': has_operations = True if not has_operations: return math_function[0] else: if self.solve_for_operator('^', math_function) == False: return False self.solve_for_operator('*', math_function) if self.solve_for_operator('/', math_function) == False: return False self.solve_for_operator('+', math_function) self.solve_for_operator('-', math_function) if len(math_function) != 1: print "Critical Error, the math function didn't have a length of 1." MyTimer.terminate_program() else: return math_function[0]
def attempt_solution(self): expression = "" if self.data_constant[0]: expression = "f(x) = " + str(self.data[0][0]) elif self.data_constant[1]: expression = "f(x) = " + str(self.data[0][0]) + " + x * " + str(self.data[1][0]) elif self.data_constant_multiplier[0]: expression = "f(x) = " + str(self.data[0][0]) + " * (" + str(self.data_multiplier[0][0]) + " ^ x)" if expression != "": print expression MyTimer.terminate_program()
''' Obtain the data to analyze. ''' user_input = raw_input("Enter the numbers to be analyzed: ") MyTimer.initiate_timer() ''' Parse the data based off commas. ''' user_input = re.split(",", user_input) ''' Convert the data from a string array to an int array ''' user_input = map(int, user_input) ''' Make sure user input is more than one number. ''' if len(user_input) <= 1: print "Too few inputs provided. Program will now terminate." MyTimer.terminate_program() derivative = Derivative(user_input) data = derivative.get_data() data_for_function_generator = [] for x in range(len(data[0])): data_for_function_generator.append(data[0][x]) derivative.print_info() #derivative.attempt_solution() function_generator = FunctionGenerator(data_for_function_generator) function_generator.attempt_to_find_math_function_for_data()
def attempt_to_find_math_function_for_data(self): #NOTE IN THE FUTURE HAVE A PARAMETER FOR NUMBER OF DIGITS: character_limit """ There are X main steps to this program. 0x1. Generate random sudo math functions. 0x2. Ignore sudo math functions that are invalid. 0x3. Prepare the sudo math function conversion. 0x4. Convert the sudo math function to a math function and test it. :return: The math function if it was found. Otherwise return 'f(x)'. """ character_limit = 6 ''' 0x1 ''' # This is the maximum number of different possible characters in the sudo math function. # TODO: Change this variable name to sudo characters. number_of_unique_characters = 5 # Calculate the number of possible sudo functions. number_of_max_sudo_functions = number_of_unique_characters for x in range(character_limit - 1): number_of_max_sudo_functions *= number_of_unique_characters number_of_sudo_functions = 0 # Go through each possible sudo function and test it. for x in range(number_of_max_sudo_functions): # Generate a single permutation. sudo_math_function = DecimalToAnyBaseArray(x, number_of_unique_characters) # Once the sudo function is generated, map the numbers to their respective character. for y in range(len(sudo_math_function)): sudo_math_function[y] = entity_map(sudo_math_function[y]) ''' 0x2 ''' if self.verify_sudo_math_function_dbg(sudo_math_function): ''' 0x3 ''' #sudo_math_function = self.prepare_sudo_math_function_for_converstion(sudo_math_function) ''' 0x4 ''' if self.convert_sudo_math_function_to_math_functions_and_test_them(sudo_math_function): MyTimer.terminate_program() print "f(x) =", get_math_function_as_string(sudo_math_function) number_of_sudo_functions += 1 ''' Max number of subs data zero: 2 ^ x - 1 no zero: x ^ 2 + 1 + x 1: 1 2: 3 3: 7 4: 14 5: 36 6: 116 7: 379 8: 1134 ___________ NEW: 1: 2: 3: 4: 5: 6: 7: 8: ''' print "Max Number of Sudo Functions:", number_of_max_sudo_functions, "\tActual:", number_of_sudo_functions for a in range(len(self.error_list)): print a, "\t", self.error_list[a]