Пример #1
0
 def test_rep_term2(self):
     eq = Equation("A^{\\alpha \\gamma} +  A^{\\gamma}  + C^{} ")
     term_to_replace = "A^{\\gamma}"
     replacement_term = "B^{\\gamma}"
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(repr(eq),
                      "\\( A^{\\alpha \\gamma} + B^{\\gamma} + C^{} \\)",
                      'tensor -> tensor, replacing a tensor on its own')
Пример #2
0
 def test_rep_term17(self):
     eq = Equation("A^{\\alpha \\gamma} +  A^{\\gamma}  + C^{} ")
     term_to_replace = "A^{\\gamma}"
     replacement_term = "B^{\\gamma} + 8fG^{\\gamma}"
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq),
         "\\( A^{\\alpha \\gamma} + C^{} \\)+\\( B^{\\gamma} +8 f G^{\\gamma} \\)",
         'tensor -> sum, replacing just a tensor')
Пример #3
0
 def test_rep_term4(self):
     eq = Equation(
         "\\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu} + \\frac{3}{4} Y")
     term_to_replace = "\\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu} "
     replacement_term = "B^{\\gamma}_{\\gamma} "
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq), "\\( B_{\\gamma}^{\\gamma} +\\frac{3}{4} Y \\)",
         'tensor -> tensor, replacing a tensor that has partial derivatives with just a tensor'
     )
Пример #4
0
 def test_rep_term19(self):
     eq = Equation(
         "\\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu} + \\frac{3}{4} Y")
     term_to_replace = "\\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu}"
     replacement_term = "\\partial_{\\gamma} B^{\\gamma} + 5 + G^{\\mu}_{\\mu} "
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq),
         "\\(\\frac{3}{4} Y \\)+\\( \\partial_{\\gamma} B^{\\gamma} +5 + G_{\\mu}^{\\mu} \\)",
         'tensor -> sum, replacing a tensor that has partial derivatives')
Пример #5
0
 def test_rep_term1(self):
     eq = Equation(
         "4X \\partial_{\\mu} \\partial_{\\nu}h^{\\mu \\nu} +Y \\partial_{\\nu}h^{\\mu \\nu} A^{\\gamma}"
     )
     term_to_replace = "A^{\\gamma}"
     replacement_term = "B^{\\gamma}"
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq),
         "\\(4 X \\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu} +Y \\partial_{\\nu} h^{\\mu \\nu} B^{\\gamma} \\)",
         '')
Пример #6
0
 def test_rep_term20(self):
     eq = Equation(
         "\\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu} + \\frac{3}{4} Y")
     term_to_replace = " \\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu}"
     replacement_term = "B^{\\gamma}_{\\gamma} + \\frac{5}{4}V"
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq),
         "\\(\\frac{3}{4} Y \\)+\\( B_{\\gamma}^{\\gamma} +\\frac{5}{4} V \\)",
         'tensor -> sum, replacing a tensor and some of its partial derivatives'
     )
Пример #7
0
 def test_rep_term12(self):
     eq = Equation(
         "A^{\\zeta} \\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu} \\square M_{\\zeta}"
     )
     term_to_replace = "\\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu}"
     replacement_term = "B^{\\mu}_{\\mu}"
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq), "A^{\\zeta} \\square M_{\\zeta} B_{\\mu}^{\\mu}",
         'tensor -> tensor, replacing a tensor that has partial derivatives and is multiplied by other elements'
     )
Пример #8
0
 def test_rep_term8(self):
     eq = Equation(
         "\\partial_{\\gamma} \\partial_{\\nu} h^{\\mu \\nu} + \\frac{3}{4} Y"
     )
     term_to_replace = "\\partial_{\\nu} h^{\\mu \\nu}"
     replacement_term = "B^{\\mu}"
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq), "\\( \\partial_{\\gamma} B^{\\mu} +\\frac{3}{4} Y \\)",
         'tensor -> tensor, replacing a tensor and some of its partial derivatives: must replace the derivative with the sum'
     )
Пример #9
0
 def test_rep_term22(self):
     eq = Equation(
         "A^{\\zeta} \\partial_{\\gamma} \\partial_{\\nu} h^{\\mu \\nu} \\square M_{\\zeta}"
     )
     term_to_replace = "\\partial_{\\nu} h^{\\mu \\nu} "
     replacement_term = "B^{\\mu} + C^{\\mu}"
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq),
         "A^{\\zeta} \\square M_{\\zeta} \\partial_{\\gamma} \\( B^{\\mu} + C^{\\mu} \\)",
         'tensor -> sum, replacing a tensor and some of its partial derivatives when it is multiplied by other elements'
     )
Пример #10
0
 def test_rep_term16(self):
     eq = Equation(
         "\\partial_{\\mu} \\partial^{\\gamma}\\(A^{\\zeta} \\partial_{\\gamma} \\partial_{\\nu} h^{\\mu \\nu} \\square M_{\\zeta}\\)"
     )
     term_to_replace = "h^{\\mu \\nu}"
     replacement_term = "B^{\\mu \\nu} "
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq),
         "\\partial_{\\mu} \\partial^{\\gamma} \\( A^{\\zeta} \\square M_{\\zeta} \\partial_{\\gamma} \\partial_{\\nu} B^{\\mu \\nu} \\)",
         'tensor -> tensor, replacing a tensor in a multgroup with derivatives'
     )
Пример #11
0
 def test_rep_term15(self):
     eq = Equation(
         "A^{\\zeta} \\partial_{\\gamma} \\partial_{\\nu} h^{\\mu \\nu} \\square M_{\\zeta}"
     )
     term_to_replace = "\\partial_{\\gamma} h^{\\mu \\nu} "
     replacement_term = " B^{\\mu \\nu}_{\\gamma} "
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq),
         "A^{\\zeta} \\square M_{\\zeta} \\partial_{\\nu} B_{\\gamma}^{\\mu \\nu}",
         'tensor -> tensor, replacing a tensor and some of its partial derivatives when it is multiplied by other elements: must replace the derivative without the sum'
     )
Пример #12
0
 def test_rep_term6(self):
     eq = Equation(
         "\\(\\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu} \\) \\(\\partial_{\\xi} \\partial_{\\beta} h^{\\chi \\beta} \\)"
     )
     term_to_replace = " \\partial_{\\mu} \\partial_{\\nu} h^{\\mu \\nu} "
     replacement_term = "\\partial_{\\gamma}B^{\\gamma}"
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(
         repr(eq),
         "\\( \\partial_{\\gamma} B^{\\gamma} \\)\\( \\partial_{\\xi} \\partial_{\\beta} h^{\\chi \\beta} \\)",
         "tensor -> tensor, replacing a tensor that has partial derivatives, includes a term that shouldn't be replaced"
     )
Пример #13
0
 def test_rep_term29(self):
     eq = Equation("")
     term_to_replace = ""
     replacement_term = ""
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(repr(eq), "", 'tensor -> sum, ')
Пример #14
0
 def test_replaceTerms(self):
     eq = Equation(" Z \\partial_{\mu} \\partial_{\\nu}h^{\\mu \\nu} + X \\partial_{\\alpha}\\partial_{\\beta} h^{\\alpha \\beta} ")
     term_to_replace = "\\partial_{\\gamma} \\partial_{\\zeta}h^{\\gamma \\zeta}"
     replacement_term = "m^{}"
     eq.replaceTerms(term_to_replace, replacement_term)
     self.assertEqual(repr(eq), "\\(Z m^{} +X m^{} \\)")
Пример #15
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")
Пример #16
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")