You can generally do this sort of thing using replace().
Unfortunately, the pattern matcher doesn't recognize rational numbers
as a/b, so you have to do a more manual check. This should work:
e.replace(lambda i: i.is_Pow and i.base == x and i.exp.is_Rational,
lambda i: real_root(-1,
i.exp.as_numer_denom()[1])**i.exp.as_numer_denom()[0])
(replace -1 with whatever value you want to replace). A "cleaner"
solution would be to create a custom Pow subclass that evaluates like
you want, and replace instances of Pow with your class before doing a
substitution.
Aaron Meurer
>
https://groups.google.com/d/msgid/sympy/c88261c0-3449-4d7a-abf8-8d28ebdca59d%40googlegroups.com.