def rs_fun(p, f, *args):
 _R = p.ring
 (R1, _x) = ring('_x', _R.domain)
 h = int(args[(-1)])
 args1 = (args[:(-2)] + (_x, h))
 zm = _R.zero_monom
 if (zm in p):
  x1 = (_x + p[zm])
  p1 = (p - p[zm])
 else:
  x1 = _x
  p1 = p
 if isinstance(f, str):
  q = getattr(x1, f)(*args1)
 else:
  q = f(x1, *args1)
 a = sorted(q.items())
 c = ([0] * h)
 for x in a:
  c[x[0][0]] = x[1]
 p1 = rs_series_from_list(p1, c, args[(-2)], args[(-1)])
 return p1

def rs_fun ( p , f , * args ) : _R = p . ring ( R1 , _x ) = ring ( '_x' , _R . domain ) h = int ( args [ ( - 1 ) ] ) args1 = ( args [ : ( - 2 ) ] + ( _x , h ) ) zm = _R . zero_monom if ( zm in p ) : x1 = ( _x + p [ zm ] ) p1 = ( p - p [ zm ] ) else : x1 = _x p1 = p if isinstance ( f , str ) : q = getattr ( x1 , f ) ( * args1 ) else : q = f ( x1 , * args1 ) a = sorted ( q . items ( ) ) c = ( [ 0 ] * h ) for x in a : c [ x [ 0 ] [ 0 ] ] = x [ 1 ] p1 = rs_series_from_list ( p1 , c , args [ ( - 2 ) ] , args [ ( - 1 ) ] ) return p1
function of a multivariate series computed by substitution .