After a page of sympy manipulations I get and expression involving LambertW, but the answer given is for the zeroth branch cut. I can tell that I wanted the -1 branch. So, I’d like to change every occurrence of LambertW(y)
into LambertW(y, -1).real
, where y is an arbitrary sympy expression (that is different in each instance), in a set of expressions that are large enough so that doing it by hand is error prone.
There must be an easy way.
OK, there is a simple way of doing this. sympy
has a Lambda
function that is functionally equivalent to Python core lambda
function but designed to work correctly with sympy
. In particular, it doesn’t choke on automatic simplifications and the like. I was trying a bunch of variations of the Python lambda
functions for def
.
The solutions is:
from sympy.functions.elementary.exponential import LambertW
from sympy import Lambda
ySym = Symbol('y', positive=True)
LambertW(1 - ySym).subs(LambertW, Lambda(ySym, LambertW(ySym,-1)))
The result is:
W_{-1}(1 – y)
1