Example #1
0
 def test_sortTerms6(self):
     eq = Equation(
         "\\partial_{\\xi}H^{}\\partial_{\\omega}G^{}\\partial^{\\xi}M^{} + \\square A^{}"
     )
     eq.sortTerms()
     self.assertEqual(
         repr(eq),
         "\\( \\square A^{} + \\partial_{\\xi} H^{} \\partial_{\\omega} G^{} \\partial^{\\xi} M^{} \\)",
         'error in sorting the terms by number of derivatives (least to greatest)'
     )
Example #2
0
 def test_sortTerms5(self):
     eq = Equation(
         "\\(\\partial_{\\gamma} \\partial_{\\kappa}\\square A^{\\gamma}\\partial_{\\omega}G^{} + \\square \\partial^{\\chi}B_{\\chi} + \\square X_{\\xi}+ \\square V_{}C^{} \\)"
     )
     eq.sortTerms()
     self.assertEqual(
         repr(eq),
         "\\( \\square X_{\\xi} + \\square V^{} C^{} + \\partial^{\\chi} \\square B_{\\chi} + \\partial_{\\gamma} \\partial_{\\kappa} \\square A^{\\gamma} \\partial_{\\omega} G^{} \\)",
         'error in sorting the terms by number of derivatives (least to greatest)'
     )
Example #3
0
 def test_sortTerms3(self):
     eq = Equation(
         "\\(  9\\partial^{\\chi}B_{\\chi} +\\frac{1}{2}T \\partial_{\\gamma}\\partial_{\\kappa}A^{\\gamma} +M C^{} \\)"
     )
     eq.sortTerms()
     self.assertEqual(
         repr(eq),
         "\\(M C^{} +9 \\partial^{\\chi} B_{\\chi} +\\frac{1}{2} T \\partial_{\\gamma} \\partial_{\\kappa} A^{\\gamma} \\)",
         'error in sorting the terms by number of derivatives (least to greatest)'
     )
 def test_sortTerms(self):
     eq = Equation("X \\partial_{\\alpha}\\partial_{\\beta} h^{\\alpha \\beta} + Z \\partial_{\\nu}h^{\\mu \\nu} ")
     eq.sortTerms()
     self.assertEqual(repr(eq), "\\(Z \\partial_{\\nu} h^{\\mu \\nu} +X \\partial_{\\alpha} \\partial_{\\beta} h^{\\alpha \\beta} \\)",
     'error in sorting terms by number of derivatives (least to greatest)')
Example #5
0
    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")
Example #6
0
    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")