I wouldn't have suggested that if I realised you were planning to put
it into a book. As Aaron and I said this is something that should be
handled by refine but isn't implemented yet.

All the same it is straight forward to extract the result manually
when you want to from the Piecewise using either .args or .subs
(that's all refine would do in this case if it was implemented yet).
Does that not work for your problem?

On Sun, 23 Aug 2020 at 01:40, [email protected]
<[email protected]> wrote:
>
> Actually, no, that workaround is only further delaying my attempt to do 
> something very simple in a CAS. I had to abandon Maxima today. I lost a 
> couple of years of work I invested in Sympy when I came up its inability to 
> sum the power series of loa (1+x). I am horrified I have to return to 
> Mathematica for something so simple, and now I have no open-source platform 
> on which to publish my book, and whether my book can be viewed in ten years 
> will depend on the state of Wolfram's business in ten years.
>
> On Wednesday, August 19, 2020 at 1:10:24 AM UTC-7 Oscar wrote:
>>
>> Ideally this would be something that refine could handle and also
>> ideally there would be an argument to summation to specify the
>> conditions so that it could internally use refine or something else
>> internally. That's just not yet implemented in sympy but I think it
>> will be in future.
>>
>> There are a couple of ways to make this work right now. One is that
>> you can directly substitute the conditions in the Piecewise for True.
>>
>> In [109]: z = Symbol('z', real=True)
>>
>> In [110]: k = Symbol('k', integer=True)
>>
>> In [111]: S = summation(z**k/k, (k, 1, oo))
>>
>> In [112]: print(S)
>> Piecewise((-log(1 - z), (z >= -1) & (z < 1)), (Sum(z**k/k, (k, 1, oo)), 
>> True))
>>
>> In [113]: S.subs({z >= -1: True, z < 1: True})
>> Out[113]: -log(1 - z)
>>
>> That only works if you know exactly what form the conditions could
>> take though (no clever inference is going on during this call to
>> subs).
>>
>> The reason that the old assumptions don't work here is because there
>> is no predicate that can be attached to a symbol to specify that |z|<1
>> in the same way that I can declare z to be real or k to be an integer
>> above. Often though it is possible to replace the symbol with an
>> expression in terms of another symbol so that the assumptions on the
>> new symbol ensure the expression has the desired properties. We can do
>> that in this example with the substitution z = tanh(x) where x is real
>> (assuming we want |z| < 1):
>>
>> In [114]: x = Symbol('x', real=True)
>>
>> In [115]: S.subs(z, tanh(x))
>> Out[115]: -log(1 - tanh(x))
>>
>> In [116]: S.subs(z, tanh(x)).subs(tanh(x), z)
>> Out[116]: -log(1 - z)
>>
>> That works because the evaluation of the Piecewise during the call to
>> subs uses the old assumptions and finds that the conditions work out
>> to True.
>>
>> With that we can do:
>>
>> In [124]: print(summation(z**k/k, (k, 1, oo)).subs(z, tanh(x)).subs(tanh(x), 
>> z))
>> -log(1 - z)
>>
>> In [125]: print(summation((-z)**k/k, (k, 1, oo)).subs(z,
>> tanh(x)).subs(tanh(x), z))
>> -log(z + 1)
>>
>> This won't always work though and you might find different results
>> using different expressions rather than tanh(x) for example you could
>> use z=x/(1+x**2) or something else.
>>
>> Ideally this would be handled by refine. It wouldn't be hard to handle
>> this particular case, especially since Piecewise with inequalities is
>> probably the number one reason users want to use refine.
>>
>> --
>> Oscar
>>
>> On Tue, 18 Aug 2020 at 23:27, first last <[email protected]> wrote:
>> >
>> > Where is the design for the new assumptions-system coming from? Is the new 
>> > design based on academic papers, or on previous software, or being 
>> > designed from the ground up here? I'm interested in automated reasoning 
>> > for its own sake, but not an expert.
>> >
>> > On Tuesday, August 18, 2020 at 2:08:37 PM UTC-7, Aaron Meurer wrote:
>> >>
>> >> summation() should probably have a conds argument similar to
>> >> integrate() that lets you disable the piecewise.
>> >>
>> >> You can always manually extract it from the expression:
>> >>
>> >> >>> sympy.summation(sympy.S('z^k / k'), sympy.S('(k, 1, 
>> >> >>> oo)')).args[0].args[0]
>> >> -log(1 - z)
>> >>
>> >> Ideally refine() would let you do this, but it doesn't seem to work yet.
>> >>
>> >> Aaron Meurer
>> >>
>> >> On Tue, Aug 18, 2020 at 7:44 AM [email protected]
>> >> <[email protected]> wrote:
>> >> >
>> >> > I'll try to clarify. Putting software aside momentarily, in pure math, 
>> >> > for z real or complex with abs(z) < 1, for k from 1 to infinity, the 
>> >> > following power-series summations hold:
>> >> >
>> >> > -log(1-x) = sum (z^k / k)
>> >> > log(1-x) = sum(-1 * z^k / k)
>> >> > log(1+x) = sum(-1 * z^k * (-1)^k / k)
>> >> >
>> >> > Maple and Mathematica can both do those, using their sum functions. 
>> >> > (I'm not 100% confident in their handling of edge cases like z=-1 and 
>> >> > z=+1, but my testing their has been haphazard.)
>> >> >
>> >> > I keep changing my story about Maxima, as I learn more about it. 
>> >> > Yesterday I said Maxima cannot do those sums. Last night I learned 
>> >> > Maxima can do them, via its "simplify_sum" feature, whose documentation 
>> >> > is hidden in an obscure Chapter 84. Maxima manual's "Summation" chapter 
>> >> > includes no mention of "simplify_sum". (I'm curious how many decades 
>> >> > this Maxima documentation-bug has persisted without anyone simply 
>> >> > moving "simplify_sum" to the chapter on sums. All 55 years of Maxima's 
>> >> > history?)
>> >> >
>> >> > Sympy can sum those into Piecewise expressions:
>> >> >
>> >> > >>> sympy.summation(sympy.S('z^k / k'), sympy.S('(k, 1, oo)'))
>> >> > Piecewise((-log(1 - z), (z >= -1) & (z < 1)), (Sum(z**k/k, (k, 1, oo)), 
>> >> > True))
>> >> > >>>
>> >> >
>> >> > The catch is, there's no way to ask Sympy "what's that Piecewise 
>> >> > expression assuming abs(z) < 1"? Neither old nor new Sympy assumptions 
>> >> > can express that query.
>> >> >
>> >> > I see two issues: Lack of functionality and room for 
>> >> > documentation-improvement. I haven't designed and implemented my own 
>> >> > assumptions-system, so I can't speak to its difficulty. Maxima's been 
>> >> > worked on by countless geniuses for 55 years and still has an 
>> >> > admittedly weak assumptions system; so maybe assumptions are especially 
>> >> > hard for CAS-designers.
>> >> >
>> >> > The second issue is documentation. I have spent many months in many 
>> >> > CAS's trying to sum the power series of log(1+x). I could have 
>> >> > accomplished the same in a day is the CAS's had been documented better.
>> >> >
>> >> >
>> >> > On Monday, August 17, 2020 at 11:00:47 PM UTC-7 [email protected] 
>> >> > wrote:
>> >> >>
>> >> >> David,
>> >> >>
>> >> >> I'm not on this project, but I think it would save the devs time if 
>> >> >> you would specify the sum you are referring to.
>> >> >>
>> >> >> -- Kind Regards,
>> >> >> Christian
>> >> >>
>> >> >> On Mon, Aug 17, 2020, 3:32 PM first last <[email protected]> wrote:
>> >> >>>
>> >> >>> P.S. Maxima and Axiom are also unable to do this sum. Mathematica and 
>> >> >>> Maple are able to do it.
>> >> >>>
>> >> >>> On Monday, August 17, 2020 at 3:30:26 PM UTC-7, first last wrote:
>> >> >>>>
>> >> >>>> I'll take the response as, there's no way to get Sympy to do this 
>> >> >>>> sum.
>> >> >>>>
>> >> >>>> On Friday, August 14, 2020 at 4:17:20 PM UTC-7, David Bailey wrote:
>> >> >>>>>
>> >> >>>>> Dear group,
>> >> >>>>>
>> >> >>>>> Am I correct that the write-up about assumptions found here relates 
>> >> >>>>> to the old-style assumptions:
>> >> >>>>>
>> >> >>>>> https://docs.sympy.org/latest/modules/assumptions/assume.html
>> >> >>>>>
>> >> >>>>> Is there any documentation relating to the new assumptions?
>> >> >>>>>
>> >> >>>>> It would be really helpful if the documentation for old or new 
>> >> >>>>> assumptions indicated which type it related to.
>> >> >>>>>
>> >> >>>>> David
>> >> >>>
>> >> >>> --
>> >> >>> 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 [email protected].
>> >> >>> To view this discussion on the web visit 
>> >> >>> https://groups.google.com/d/msgid/sympy/bbdc2130-172b-4d04-a542-95321e3de4d1o%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 [email protected].
>> >> > To view this discussion on the web visit 
>> >> > https://groups.google.com/d/msgid/sympy/c9f81be1-4dec-4bb4-8079-af1f044d0ab3n%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 [email protected].
>> > To view this discussion on the web visit 
>> > https://groups.google.com/d/msgid/sympy/59e83ffd-4306-4d0c-9200-1a9676de34b9o%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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/de49bbd5-7da1-4a1f-b253-66152f90bae1n%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxSqE1exS%3D4zCctT3R4xwKXKY0JZaF3UjXvqpzYgou%3D-1w%40mail.gmail.com.

Reply via email to