Beispiel #1
0
 def _eval_subs(self, old, new):
     if old in self.variables:
         newexpr = self.expr.subs(old, new)
         i = self.variables.index(old)
         newvars = list(self.variables)
         newpt = list(self.point)
         if new.is_Symbol:
             newvars[i] = new
         else:
             syms = new.free_symbols
             if len(syms) == 1 or old in syms:
                 if old in syms:
                     var = self.variables[i]
                 else:
                     var = syms.pop()
                 # First, try to substitute self.point in the "new"
                 # expr to see if this is a fixed point.
                 # E.g.  O(y).subs(y, sin(x))
                 point = new.subs(var, self.point[i])
                 if point != self.point[i]:
                     from sympy.solvers import solve
                     d = Dummy()
                     res = solve(old - new.subs(var, d), d, dict=True)
                     point = d.subs(res[0]).limit(old, self.point[i])
                 newvars[i] = var
                 newpt[i] = point
             elif old not in syms:
                 del newvars[i], newpt[i]
                 if not syms and new == self.point[i]:
                     newvars.extend(syms)
                     newpt.extend([S.Zero] * len(syms))
             else:
                 return
         return Order(newexpr, *zip(newvars, newpt))
Beispiel #2
0
 def _eval_subs(self, old, new):
     if old in self.variables:
         newexpr = self.expr.subs(old, new)
         i = self.variables.index(old)
         newvars = list(self.variables)
         newpt = list(self.point)
         if new.is_Symbol:
             newvars[i] = new
         else:
             syms = new.free_symbols
             if len(syms) == 1 or old in syms:
                 if old in syms:
                     var = self.variables[i]
                 else:
                     var = syms.pop()
                 # First, try to substitute self.point in the "new"
                 # expr to see if this is a fixed point.
                 # E.g.  O(y).subs(y, sin(x))
                 point = new.subs(var, self.point[i])
                 if point != self.point[i]:
                     from sympy.solvers import solve
                     d = Dummy()
                     res = solve(old - new.subs(var, d), d, dict=True)
                     point = d.subs(res[0]).limit(old, self.point[i])
                 newvars[i] = var
                 newpt[i] = point
             elif old not in syms:
                 del newvars[i], newpt[i]
                 if not syms and new == self.point[i]:
                     newvars.extend(syms)
                     newpt.extend([S.Zero]*len(syms))
             else:
                 return
         return Order(newexpr, *zip(newvars, newpt))
Beispiel #3
0
    def _eval_subs(self, old, new):
        if old in self.variables:
            newexpr = self.expr.subs(old, new)
            i = self.variables.index(old)
            newvars = list(self.variables)
            newpt = list(self.point)
            if new.is_symbol:
                newvars[i] = new
            else:
                syms = new.free_symbols
                if len(syms) == 1 or old in syms:
                    if old in syms:
                        var = self.variables[i]
                    else:
                        var = syms.pop()
                    # First, try to substitute self.point in the "new"
                    # expr to see if this is a fixed point.
                    # E.g.  O(y).subs(y, sin(x))
                    point = new.subs(var, self.point[i])
                    if point != self.point[i]:
                        from sympy.solvers.solveset import solveset

                        d = Dummy()
                        sol = solveset(old - new.subs(var, d), d)
                        if isinstance(sol, Complement):
                            e1 = sol.args[0]
                            e2 = sol.args[1]
                            sol = set(e1) - set(e2)
                        res = [dict(zip((d, ), sol))]
                        point = d.subs(res[0]).limit(old, self.point[i])
                    newvars[i] = var
                    newpt[i] = point
                elif old not in syms:
                    del newvars[i], newpt[i]
                    if not syms and new == self.point[i]:
                        newvars.extend(syms)
                        newpt.extend([S.Zero] * len(syms))
                else:
                    return
            return Order(newexpr, *zip(newvars, newpt))
Beispiel #4
0
 def _eval_subs(self, old, new):
     if old in self.variables:
         newexpr = self.expr.subs(old, new)
         i = self.variables.index(old)
         newvars = list(self.variables)
         newpt = list(self.point)
         if new.is_symbol:
             newvars[i] = new
         else:
             syms = new.free_symbols
             if len(syms) == 1 or old in syms:
                 if old in syms:
                     var = self.variables[i]
                 else:
                     var = syms.pop()
                 # First, try to substitute self.point in the "new"
                 # expr to see if this is a fixed point.
                 # E.g.  O(y).subs(y, sin(x))
                 point = new.subs(var, self.point[i])
                 if point != self.point[i]:
                     from sympy.solvers.solveset import solveset
                     d = Dummy()
                     sol = solveset(old - new.subs(var, d), d)
                     if isinstance(sol, Complement):
                         e1 = sol.args[0]
                         e2 = sol.args[1]
                         sol = set(e1) - set(e2)
                     res = [dict(zip((d, ), sol))]
                     point = d.subs(res[0]).limit(old, self.point[i])
                 newvars[i] = var
                 newpt[i] = point
             elif old not in syms:
                 del newvars[i], newpt[i]
                 if not syms and new == self.point[i]:
                     newvars.extend(syms)
                     newpt.extend([S.Zero]*len(syms))
             else:
                 return
         return Order(newexpr, *zip(newvars, newpt))