def test_replaceIndices(self): eq = Equation(" Z \\partial_{\\mu} \\partial_{\\nu}h^{\\mu \\nu} + X \\partial_{\\alpha}\\partial_{\\beta} h^{\\alpha \\beta} ") indices_to_replace = "\\mu, \\nu, \\alpha, \\beta" replacement_indices = "\\gamma, \\zeta, \\chi, \\xi" eq.replaceIndices(indices_to_replace, replacement_indices) self.assertEqual(repr(eq), "\\(Z \\partial_{\\gamma} \\partial_{\\zeta} h^{\\gamma \\zeta} +X \\partial_{\\chi} \\partial_{\\xi} h^{\\chi \\xi} \\)", 'error in replacing indices')
def test_rep_ind1(self): eq = Equation( "4X \\partial_{\\mu} \\partial_{\\nu}h^{\\mu \\nu} +Y \\partial_{\\nu}h^{\\mu \\nu} A^{\\gamma}" ) indices_to_replace = "\\mu" replacement_indices = "\\alpha" eq.replaceIndices(indices_to_replace, replacement_indices) self.assertEqual( repr(eq), "\\(4 X \\partial_{\\alpha} \\partial_{\\nu} h^{\\alpha \\nu} +Y \\partial_{\\nu} h^{\\alpha \\nu} A^{\\gamma} \\)", '')
def compute(self): try: base_equation = Equation(self.equation, self.symmetric_tensors) # base_equation.getTree().printTreeAsTree(base_equation.getTree().traverse()) print(base_equation.getTree().traverse()) self.output_equation = "" if base_equation.getCov(): # self.open_pop("../Kivy/images/cov_warning.png") self.output_equation += "MAY CONTAIN LOGIC ERRORS DUE TO THE USE OF COVARIANT DERIVATIVES: PROCEED WITH CAUTION \n \n" if self.initial_eq: if self.text_statements: self.output_equation += "Starting with the equation \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" if self.foil: base_equation.getTree().foil(base_equation.getTree().getRoot()) if self.text_statements: self.output_equation += "multiplying out terms and distributing partial derivatives using the product rule \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" if self.distribute_partials: base_equation.getTree().distributePs(base_equation.getTree().getRoot()) if self.text_statements: self.output_equation += "using the calculus product rule to distribute partial derivatives \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" if self.foil_no_distribute: base_equation.getTree().noPfoil(base_equation.getTree().getRoot()) if self.text_statements: self.output_equation += "multiplying out terms not under a partial derivative \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" # CONTRACT if self.contract_both: base_equation.contract(base_equation.getTree().getRoot()) if self.text_statements: self.output_equation += "contracting Minkowski metrics and Kronecker deltas \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" if self.contract_etas: base_equation.contract(base_equation.getTree().getRoot(), 'eta') if self.text_statements: self.output_equation += "contracting Minkowski metrics \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" if self.contract_deltas: base_equation.contract(base_equation.getTree().getRoot(), 'delta') if self.text_statements: self.output_equation += "contracting Kronecker deltas \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" # FACTOR if self.factor_gcf: base_equation.factorGCF(base_equation.getTree().getRoot()) if self.text_statements: self.output_equation += "factoring out the greatest common factor \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" if self.factor_term: base_equation.factorUserInputTree(base_equation.getTree().getRoot(), self.term_to_factor) if self.text_statements: self.output_equation += "factoring out $ " + self.term_to_factor + " $ \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" # REPLACE if self.replace_indices: base_equation.replaceIndices(self.indices_to_replace, self.replacement_indices) if self.text_statements: self.output_equation += "replacing indices $ " + self.indices_to_replace + " $ with indices $ " + self.replacement_indices + " $ \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" if self.replace_terms: base_equation.replaceTerms(self.term_to_replace, self.replacement_term) if self.text_statements: self.output_equation += "replacing $ " + self.term_to_replace + " $ with $ " + self.replacement_term + " $ \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" # SORT if self.combine_like_terms_num: base_equation.combineLikeTermsWithoutSymCo(base_equation.getTree().getRoot()) if self.text_statements: self.output_equation += "combining like terms \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" if self.combine_like_terms: base_equation.combineLikeTerms(base_equation.getTree().getRoot()) if self.text_statements: self.output_equation += "combine like terms differing by any (numerical or symbolic) coefficient \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" if self.sort_each: base_equation.sortEach() if self.text_statements: self.output_equation += "organizing the tensors in each term from least to greatest number of partials \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" if self.sort_terms: base_equation.sortTerms() if self.text_statements: self.output_equation += "organizing each term from least to greatest number of partials \n" self.output_equation += repr(base_equation) self.output_equation += "\n" + "\n" except Exception as exceptObj: self.output_equation = str(exceptObj) + "\n\nPlease email [email protected] for if you think this is a bug" traceback.print_tb(exceptObj.__traceback__) # self.exception_str = str(exceptObj) #tb = sys.exc_info()[-1] #stk = traceback.extract_tb(tb, 1) #fname = stk[0][2] #self.exception_str += " method that produced error: " + fname # self.open_except_pop("../Kivy/images/error_popup.png")
def compute(self): try: base_equation = Equation(self.latex_text_input.text, self.symmetric_tensors_str.text) self.latex_text_output.text = "" if base_equation.getCov(): self.open_pop("../Kivy/images/cov_warning.png") self.latex_text_output.text += "MAY CONTAIN LOGIC ERRORS DUE TO THE USE OF COVARIANT DERIVATIVES: PROCEED WITH CAUTION \n \n" if self.initial_eq: if self.text_statements: self.latex_text_output.text += "Starting with the equation \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.foil: base_equation.getTree().foil(base_equation.getTree().getRoot()) if self.text_statements: self.latex_text_output.text += "multiplying out terms and distributing partial derivatives using the product rule \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.dist_part: base_equation.getTree().distributePs( base_equation.getTree().getRoot()) if self.text_statements: self.latex_text_output.text += "using the calculus product rule to distribute partial derivatives \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.foil_no_dist: base_equation.getTree().noPfoil( base_equation.getTree().getRoot()) if self.text_statements: self.latex_text_output.text += "multiplying out terms not under a partial derivative \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.contract_both: base_equation.contract(base_equation.getTree().getRoot()) if self.text_statements: self.latex_text_output.text += "contracting etas and deltas " self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.etas: base_equation.contract(base_equation.getTree().getRoot(), 'eta') if self.text_statements: self.latex_text_output.text += "contracting etas \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.deltas: base_equation.contract(base_equation.getTree().getRoot(), 'delta') if self.text_statements: self.latex_text_output.text += "contracting deltas \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.factor_gcf: base_equation.factorGCF(base_equation.getTree().getRoot()) if self.text_statements: self.latex_text_output.text += "factoring out the greatest common factor \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.factor_term: base_equation.factorUserInputTree( base_equation.getTree().getRoot(), self.term_to_factor_str.text) if self.text_statements: self.latex_text_output.text += "factoring out $ " + self.term_to_factor_str.text + " $ \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.replace_indices: base_equation.replaceIndices(self.indices_to_replace_str.text, self.replacement_indices_str.text) if self.text_statements: self.latex_text_output.text += "replacing indices $ " + self.indices_to_replace_str.text + " $ with indices $ " + self.replacement_indices_str.text + " $ \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.replace_terms: base_equation.replaceTerms(self.term_to_replace_str.text, self.replacement_term_str.text) if self.text_statements: self.latex_text_output.text += "replacing $ " + self.term_to_replace_str.text + " $ with $ " + self.replacement_term_str.text + " $ \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.combine_like_terms_num: base_equation.combineLikeTermsWithoutSymCo( base_equation.getTree().getRoot()) if self.text_statements: self.latex_text_output.text += "combining like terms \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.combine_like_terms: base_equation.combineLikeTerms( base_equation.getTree().getRoot()) if self.text_statements: self.latex_text_output.text += "combine like terms differing by any (numerical or symbolic) coefficient \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.sort_each: base_equation.sortEach() if self.text_statements: self.latex_text_output.text += "organizing the tensors in each term from least to greatest number of partials \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" if self.sort_terms: base_equation.sortTerms() if self.text_statements: self.latex_text_output.text += "organizing each term from least to greatest number of partials \n" self.latex_text_output.text += repr(base_equation) self.latex_text_output.text += "\n" + "\n" except Exception as exceptObj: self.exception_str = str(exceptObj) #tb = sys.exc_info()[-1] #stk = traceback.extract_tb(tb, 1) #fname = stk[0][2] #self.exception_str += " method that produced error: " + fname self.open_except_pop("../Kivy/images/error_popup.png")