Actually, thinking a bit more, I can get away with the assumption that x is 
an integer (in practice numerically it can be any positive real, but that 
won't matter for the formula's analysis I'm trying to do).

Le samedi 27 juillet 2024 à 18:00:16 UTC+2, Pierre H a écrit :

> Thanks a lot for your replies. I suspected it was about domain 
> assumptions, but thanks to Oscar's example of the square root of -1 having 
> two values it's got clear to me.
>
> Now, I can rise the bar to the next question: the example I gave was a 
> minimal one, but the way I stumbled upon was slightly more elaborate:
>
> Let b=symbol('b') and a = 1+b,
> so that
> a**x * (1/a)**x
> is in fact
> (1+b) * (1/(1+b))**x
>
> This means Peter's suggestion (assume a,x positive), which applies to my 
> case, cannot be applied for a. Indeed, I just reread the "old assumption 
> mechanism" doc https://docs.sympy.org/latest/guides/assumptions.html and 
> it seems that the assumption I need (b>-1) cannot be implemented. Indeed 
> the doc says "At the time of writing (SymPy 1.7)", but I guess it's still 
> valid in 2024, correct?
>
> Pierre
>
>
>
>
> Le samedi 27 juillet 2024 à 16:12:34 UTC+2, Oscar a écrit :
>
>> It is a classic question about SymPy. By default SymPy assumes that 
>> all symbols represent arbitrary complex numbers. For the most part 
>> only simplifications that are compatible with any complex numbers will 
>> be applied either automatically or by explicit simplification 
>> functions such as powsimp, simplify etc. I say "for the most part" 
>> because some evaluation/simplification routines ignore degenerate 
>> cases like x/x -> 1 even though x could be zero. 
>>
>> In this case the question is whether (1/a)^x = 1/(a^x). Suppose that a 
>> = -1 and x = 1/2 then we have: 
>>
>> (1/(-1))^(1/2) = (-1)^(1/2) = i 
>>
>> On the other hand 
>>
>> 1/(-1)^(1/2) = 1/i = -i 
>>
>> So for a = -1 and x = 1/2 we have (1/a)^x = -1/(a^x). 
>>
>> Recognising that 1/a = a^-1 the more general question is when will 
>> (a^x)^y be equal to a^(x*y). If all symbols are positive or if y is an 
>> integer then this holds but more generally it does not necessarily 
>> hold. From first principles SymPy defines x^y as being exp(log(x)*y) 
>> where log should be understood as having a branch cut on the negative 
>> reals so that log(x) = log(abs(x)) + I*arg(x) and arg(x) is in 
>> (-pi,pi]. This branch cut determines when identities like (1/a)^x = 
>> 1/a^x will hold. 
>>
>> -- 
>> Oscar 
>>
>> On Sat, 27 Jul 2024 at 13:49, <peter.st...@gmail.com> wrote: 
>> > 
>> > If you declare a to be positive, it simplifies with me. 
>> > 
>> > 
>> > 
>> > From: sy...@googlegroups.com <sy...@googlegroups.com> On Behalf Of 
>> Pierre H 
>> > Sent: Saturday, July 27, 2024 2:38 PM 
>> > To: sympy <sy...@googlegroups.com> 
>> > Subject: [sympy] Simplification of a^x * (1/a)^x: not equal to 1? 
>> > 
>> > 
>> > 
>> > Hello, 
>> > 
>> > 
>> > 
>> > This is perhaps a classical question, but since I'm only using SymPy 
>> every now and then... 
>> > 
>> > 
>> > 
>> > I wonder why the expression a^x * (1/a)^x doesn't simplify to 1. See 
>> code (with SymPy 1.12) 
>> > 
>> > 
>> > 
>> > a,x = symbols('a x') 
>> > simplify(a**x * (1/a)**x) 
>> > 
>> > 
>> > 
>> > (then of course the variant a**x * (1/(a**x)) does simplify to 1). 
>> > 
>> > 
>> > 
>> > So is a SymPy issue that the power of x isn't propagated inside the 
>> 1/(a) expression. Or I'm just missing a mathematical subtlety which 
>> requires adding some assertions about x and a? 
>> > 
>> > 
>> > 
>> > Pierre 
>> > 
>> > 
>> > 
>> > -- 
>> > 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sympy/1b37bc0c-aa69-4e89-99d0-fb5700920dccn%40googlegroups.com.
>>  
>>
>> > 
>> > -- 
>> > 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sympy/003401dae023%246da70330%2448f50990%24%40gmail.com.
>>  
>>
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/4c72538d-b230-491c-8f61-c3bced87b44en%40googlegroups.com.

Reply via email to