class_docstr: Stores (expr, dummy) pairs, and how to rewrite expr-s.
  
  Explanation
  ===========
  
  The gruntz algorithm needs to rewrite certain expressions in term of a new
  variable w. We cannot use subs, because it is just too smart for us. For
  example::
  
      > Omega=[exp(exp(_p - exp(-_p))/(1 - 1/_p)), exp(exp(_p))]
      > O2=[exp(-exp(_p) + exp(-exp(-_p))*exp(_p)/(1 - 1/_p))/_w, 1/_w]
      > e = exp(exp(_p - exp(-_p))/(1 - 1/_p)) - exp(exp(_p))
      > e.subs(Omega[0],O2[0]).subs(Omega[1],O2[1])
      -1/w + exp(exp(p)*exp(-exp(-p))/(1 - 1/p))
  
  is really not what we want!
  
  So we do it the hard way and keep track of all the things we potentially
  want to substitute by dummy variables. Consider the expression::
  
      exp(x - exp(-x)) + exp(x) + x.
  
  The mrv set is {exp(x), exp(-x), exp(x - exp(-x))}.
  We introduce corresponding dummy variables d1, d2, d3 and rewrite::
  
      d3 + d1 + x.
  
  This class first of all keeps track of the mapping expr->variable, i.e.
  will at this stage be a dictionary::
  
      {exp(x): d1, exp(-x): d2, exp(x - exp(-x)): d3}.
  
  [It turns out to be more convenient this way round.]
  But sometimes expressions in the mrv set have other expressions from the
  mrv set as subexpressions, and we need to keep track of that as well. In
  this case, d3 is really exp(x - d2), so rewrites at this stage is::
  
      {d3: exp(x-d2)}.
  
  The function rewrite uses all this information to correctly rewrite our
  expression in terms of w. In this case w can be chosen to be exp(-x),
  i.e. d2. The correct rewriting then is::
  
      exp(-w)/w + 1/w + x.
class_docstr_tok: ["Stores","(","expr",",","dummy",")","pairs",",","and","how","to","rewrite","expr-s",".","Explanation","===========","The","gruntz","algorithm","needs","to","rewrite","certain","expressions","in","term","of","a","new","variable","w.","We","can","not","use","subs",",","because","it","is","just","too","smart","for","us",".","For","example",":",":",">","Omega=","[","exp","(","exp","(","_p","-","exp","(","-_p",")",")","\/","(","1","-","1\/_p",")",")",",","exp","(","exp","(","_p",")",")","]",">","O2=","[","exp","(","-exp","(","_p",")","+","exp","(","-exp","(","-_p",")",")","*","exp","(","_p",")","\/","(","1","-","1\/_p",")",")","\/_w",",","1\/_w","]",">","e","=","exp","(","exp","(","_p","-","exp","(","-_p",")",")","\/","(","1","-","1\/_p",")",")","-","exp","(","exp","(","_p",")",")",">","e.subs","(","Omega","[","0","]",",","O2","[","0","]",")",".subs","(","Omega","[","1","]",",","O2","[","1","]",")","-1\/w","+","exp","(","exp","(","p",")","*","exp","(","-exp","(","-p",")",")","\/","(","1","-","1\/p",")",")","is","really","not","what","we","want","!","So","we","do","it","the","hard","way","and","keep","track","of","all","the","things","we","potentially","want","to","substitute","by","dummy","variables",".","Consider","the","expression",":",":","exp","(","x","-","exp","(","-x",")",")","+","exp","(","x",")","+","x",".","The","mrv","set","is","{","exp","(","x",")",",","exp","(","-x",")",",","exp","(","x","-","exp","(","-x",")",")","}",".","We","introduce","corresponding","dummy","variables","d1",",","d2",",","d3","and","rewrite",":",":","d3","+","d1","+","x",".","This","class","first","of","all","keeps","track","of","the","mapping","expr-",">","variable",",","i.e",".","will","at","this","stage","be","a","dictionary",":",":","{","exp","(","x",")",":","d1",",","exp","(","-x",")",":","d2",",","exp","(","x","-","exp","(","-x",")",")",":","d3","}",".","[","It","turns","out","to","be","more","convenient","this","way","round",".","]","But","sometimes","expressions","in","the","mrv","set","have","other","expressions","from","the","mrv","set","as","subexpressions",",","and","we","need","to","keep","track","of","that","as","well",".","In","this","case",",","d3","is","really","exp","(","x","-","d2",")",",","so","rewrites","at","this","stage","is",":",":","{","d3",":","exp","(","x-d2",")","}",".","The","function","rewrite","uses","all","this","information","to","correctly","rewrite","our","expression","in","terms","of","w.","In","this","case","w","can","be","chosen","to","be","exp","(","-x",")",",","i.e",".","d2",".","The","correct","rewriting","then","is",":",":","exp","(","-w",")","\/w","+","1\/w","+","x","."]
docstr: Substitute the variables with expressions
docstr_tok: ["Substitute","the","variables","with","expressions"]
code: def do_subs(self, e):
      """Substitute the variables with expressions"""
      for expr, var in self.items():
          e = e.xreplace({var: expr})
      return e
  
imports: from functools import reduce
  from sympy.core import Basic, S, Mul, PoleError, expand_mul
  from sympy.core.cache import cacheit
  from sympy.core.intfunc import ilcm
  from sympy.core.numbers import I, oo
  from sympy.core.symbol import Dummy, Wild
  from sympy.core.traversal import bottom_up
  from sympy.functions import log, exp, sign
  from sympy.series.order import Order
  from sympy.utilities.exceptions import SymPyDeprecationWarning
  from sympy.utilities.misc import debug_decorator
  from sympy.utilities.timeutils import timethis
label_desc: Use image node_id 4 for calling the SubsSet obj's underlying member method code with example usage: obj.do_subs(e) and returns: e