Beispiel #1
0
 def CS12_simp(self, sym, silent=False):
     """
     Example
     =======
     >> print SymbolManager().CS12_simp(sympify("C2*C3 - S2*S3"))
     C23 = C2*C3 - S2*S3
     C23
     >> print SymbolManager().CS12_simp(sympify("C2*S3*R + S2*C3*R"))
     S23 = C2*S3 + S2*C3
     R*S23
     """
     if not sym.is_Add:
         repl_dict = {}
         for term in sym.atoms(Add):
             repl_dict[term] = self.CS12_simp(term)
         sym = sym.xreplace(repl_dict)
         return sym
     names, short_form = tools.trignometric_info(sym)
     names = list(names)
     if short_form:
         names.sort()
     sym2 = sym
     for n1, n2 in itertools.combinations(names, 2):
         if short_form:
             C1, S1 = tools.cos_sin_syms(n1)
             C2, S2 = tools.cos_sin_syms(n2)
             np1, nm1 = tools.get_pos_neg(n1)
             np2, nm2 = tools.get_pos_neg(n2)
             n12 = tools.ang_sum(np1, np2, nm1, nm2)
             nm12 = tools.ang_sum(np1, nm2, nm1, np2)
             C12, S12 = tools.cos_sin_syms(n12)
             C1m2, S1m2 = tools.cos_sin_syms(nm12)
         else:
             C1, S1 = cos(n1), sin(n1)
             C2, S2 = cos(n2), sin(n2)
             C12, S12 = cos(n1+n2), sin(n1+n2)
             C1m2, S1m2 = cos(n1-n2), sin(n1-n2)
         sym2 = self.try_opt(S12, S1m2, S1*C2, C1*S2, sym2, silent)
         sym2 = self.try_opt(C12, C1m2, C1*C2, -S1*S2, sym2, silent)
     if sym2 != sym:
         return self.CS12_simp(sym2, silent)
     else:
         return sym
Beispiel #2
0
 def CS12_simp(self, sym, silent=False):
     """
     Example
     =======
     >> print SymbolManager().CS12_simp(sympify("C2*C3 - S2*S3"))
     C23 = C2*C3 - S2*S3
     C23
     >> print SymbolManager().CS12_simp(sympify("C2*S3*R + S2*C3*R"))
     S23 = C2*S3 + S2*C3
     R*S23
     """
     if not sym.is_Add:
         repl_dict = {}
         for term in sym.atoms(Add):
             repl_dict[term] = self.CS12_simp(term)
         sym = sym.xreplace(repl_dict)
         return sym
     names, short_form = tools.trignometric_info(sym)
     names = list(names)
     if short_form:
         names.sort()
     sym2 = sym
     for n1, n2 in itertools.combinations(names, 2):
         if short_form:
             C1, S1 = tools.cos_sin_syms(n1)
             C2, S2 = tools.cos_sin_syms(n2)
             np1, nm1 = tools.get_pos_neg(n1)
             np2, nm2 = tools.get_pos_neg(n2)
             n12 = tools.ang_sum(np1, np2, nm1, nm2)
             nm12 = tools.ang_sum(np1, nm2, nm1, np2)
             C12, S12 = tools.cos_sin_syms(n12)
             C1m2, S1m2 = tools.cos_sin_syms(nm12)
         else:
             C1, S1 = cos(n1), sin(n1)
             C2, S2 = cos(n2), sin(n2)
             C12, S12 = cos(n1 + n2), sin(n1 + n2)
             C1m2, S1m2 = cos(n1 - n2), sin(n1 - n2)
         sym2 = self.try_opt(S12, S1m2, S1 * C2, C1 * S2, sym2, silent)
         sym2 = self.try_opt(C12, C1m2, C1 * C2, -S1 * S2, sym2, silent)
     if sym2 != sym:
         return self.CS12_simp(sym2, silent)
     else:
         return sym
Beispiel #3
0
 def C2S2_simp(self, sym):
     """
     Example
     =======
     >> print C2S2_simp(sympify("-C**2*RL + S*(D - RL*S)"))
     D*S - RL
     """
     if not sym.is_Add:
         repl_dict = {}
         for term in sym.atoms(Add):
             repl_dict[term] = self.C2S2_simp(term)
         sym = sym.xreplace(repl_dict)
         return sym
     names, short_form = tools.trignometric_info(sym)
     for name in names:
         if short_form:
             cos_term, sin_term = tools.cos_sin_syms(name)
         else:
             cos_term, sin_term = cos(name), sin(name)
         sym = self.try_opt(tools.ONE, None, sin_term**2, cos_term**2, sym)
     return sym
Beispiel #4
0
 def C2S2_simp(self, sym):
     """
     Example
     =======
     >> print C2S2_simp(sympify("-C**2*RL + S*(D - RL*S)"))
     D*S - RL
     """
     if not sym.is_Add:
         repl_dict = {}
         for term in sym.atoms(Add):
             repl_dict[term] = self.C2S2_simp(term)
         sym = sym.xreplace(repl_dict)
         return sym
     names, short_form = tools.trignometric_info(sym)
     for name in names:
         if short_form:
             cos_term, sin_term = tools.cos_sin_syms(name)
         else:
             cos_term, sin_term = cos(name), sin(name)
         sym = self.try_opt(
             tools.ONE, None, sin_term**2, cos_term**2, sym
         )
     return sym