subs is limited on how smart it is. I think it only works for numerical
coefficients.

Also note that exp(a*x) != exp(x)**a in general (take x = 2*pi*I and a =
1/2). It should be true if a is an integer, though (but subs doesn't handle
it if you set a = Symbol('a', integer=True)).

If you know what form of expression you want to replace, you can use the
replace() method with Wilds, like

In [26]: b = Wild('b', exclude=[x])

In [27]: print(exp(a*x).replace(exp(b*x), sin(x)**b))
sin(x)**a

Aaron Meurer


On Fri, Aug 14, 2015 at 12:48 PM, Adrián Ashley <adbi...@gmail.com> wrote:

> Hi,
>
> Thanks for the workaround, but
>
> subs doesn't work here:
>
> >>> sin(exp(a*x)).subs({exp(x): x})
> >>> sin(exp(a*x))
>
>
>
> Best,
> Adrian
>
> On Saturday, August 15, 2015 at 12:11:31 AM UTC+5:30, Aaron Meurer wrote:
>>
>> xreplace only does exact structural replacement (the "x" stands for
>> "exact"). To get mathematical replacement, use subs:
>>
>> >>> print(exp(5*x).subs(exp(x), sin(x)))
>> sin(x)**5
>>
>> Aaron Meurer
>>
>> On Fri, Aug 14, 2015 at 5:17 AM, AMiT Kumar <dtu....@gmail.com> wrote:
>>
>>> I am also Interested in getting the solution for this.
>>>
>>> *AMiT Kumar*
>>>
>>>
>>> On Friday, August 14, 2015 at 12:08:25 PM UTC+5:30, Gaurav Dhingra wrote:
>>>>
>>>> Do you want something like replacing some function f1 (say `exponential
>>>> function` you mentioned `{exp(x): x}` ) with some other f2 (say linear
>>>> function, you mentioned `{exp(x): x}`  ) in your expression ?
>>>>
>>>> On Friday, August 14, 2015 at 12:03:08 PM UTC+5:30, Adrián Ashley wrote:
>>>>>
>>>>> Correction previous example:
>>>>>
>>>>> In [9]: sin(exp(a*x)).some_replace_func({exp(x): x})
>>>>> Out[9]: sin(x**a)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Friday, August 14, 2015 at 11:55:55 AM UTC+5:30, Adrián Ashley
>>>>> wrote:
>>>>>>
>>>>>> Hi Sartaj,
>>>>>>
>>>>>> I think you didn't understood my point. I am looking for mathematical
>>>>>> substitution, not exact
>>>>>> substitution.
>>>>>>
>>>>>> exp(5*x).xreplace({exp(5*x): sin(5*x)}) is just a mere example of
>>>>>> usage of xreplace. I am not
>>>>>> looking for exact replacement. the exponent can be anything
>>>>>>
>>>>>> For example:
>>>>>>
>>>>>> >>> sin(exp(x)).some_replace_func({exp: x})
>>>>>>
>>>>>> >>> sin(x)
>>>>>>
>>>>>> >>> exp(5*x).some_replace_func({exp(x): sin(x)})
>>>>>> >>> exp(5*x)
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>> Best,
>>>>>>
>>>>>> Adrian
>>>>>>
>>>>>> On Friday, August 14, 2015 at 1:48:44 AM UTC+5:30, Sartaj Singh wrote:
>>>>>>>
>>>>>>> Try this,
>>>>>>>
>>>>>>> >>> exp(5*x).xreplace({exp(5*x): sin(5*x)})
>>>>>>> sin(5*x)
>>>>>>>
>>>>>>> On 14 August 2015 at 00:24, Adrián Ashley <adb...@gmail.com> wrote:
>>>>>>>
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> How can I substitute/replace something mathematically from an
>>>>>>>> expression:
>>>>>>>>
>>>>>>>> For example:
>>>>>>>>
>>>>>>>> >>> exp(5*x).xreplace({exp(x): sin(x)})
>>>>>>>> >>> exp(5*x)   # I would expect sin(x)**5 here
>>>>>>>>
>>>>>>>>
>>>>>>>> In better way to do the above thing?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Best,
>>>>>>>>
>>>>>>>> --
>>>>>>>> Adrian
>>>>>>>>
>>>>>>>> --
>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>> Groups "sympy" group.
>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>> send an email to sympy+un...@googlegroups.com.
>>>>>>>> To post to this group, send email to sy...@googlegroups.com.
>>>>>>>> Visit this group at http://groups.google.com/group/sympy.
>>>>>>>> To view this discussion on the web visit
>>>>>>>> https://groups.google.com/d/msgid/sympy/4be0109e-a665-4c89-8774-0300163250f0%40googlegroups.com
>>>>>>>> <https://groups.google.com/d/msgid/sympy/4be0109e-a665-4c89-8774-0300163250f0%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>> .
>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Regards
>>>>>>> *Sartaj Singh*
>>>>>>>
>>>>>>> *Mathematics and Computing*,
>>>>>>> Indian Institute of Technology,
>>>>>>> Varanasi - 221 005 INDIA
>>>>>>>
>>>>>>> E-mail: singhs...@gmail.com, *sartaj.si...@itbhu.ac.in*
>>>>>>>
>>>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "sympy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to sympy+un...@googlegroups.com.
>>> To post to this group, send email to sy...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/sympy.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/sympy/f4f3b7a4-00ec-4d0c-85bd-86e6b4731c64%40googlegroups.com
>>> <https://groups.google.com/d/msgid/sympy/f4f3b7a4-00ec-4d0c-85bd-86e6b4731c64%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/1a705f97-779d-4b7b-b5e2-ea14ee4ca967%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/1a705f97-779d-4b7b-b5e2-ea14ee4ca967%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6J5XrgBORKAbVKwywUgCVcDBqRfFKBh7hqiGv%3DenEvoiQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to