On Tue, Nov 25, 2008 at 11:00 PM, Burcin Erocal <[EMAIL PROTECTED]> wrote:
>
> On Tue, 25 Nov 2008 12:15:41 +0100
> "Ondrej Certik" <[EMAIL PROTECTED]> wrote:
>
>>
>> > One of the issues right now is that sage's piecewise is a completely
>> > separate class then the rest of the calculus library. I think it
>> > should descend from symbolic expression and be on the same level as,
>> > e.g. sin and addition (and probably even have a pynac counterpart).
>> > Letting the operands be the conditions (as symbolic equations,
>> > giving much more flexibility then we now have) and the corresponding
>> > expressions (as symbolic equations) would allow it to fit into the
>> > symbolic ring nicely. This would have the advantage that one could
>> > leverage all the generic SR functionality like subs, pow,
>> > composition, etc. without having to re-implement it for every method
>> > that's missing.
>>
>> Exactly. In fact, that is how Piecewise works in sympy. So I think
>> pynac has to know how to properly dispatch stuff like .subs(),
>> .series() and other things into the Piecewise class (after it is
>> integrated into the calculus). And I know it is possible to do that
>> with Cython. Btw, how about pattern matching? Will you extend the C++
>> code in ginac to handle Piecewise functions?
>
> Ok. Now I see what you mean, first let me explain why I failed to
> understand you before.
>
> Sage treats piecewise functions as functions, and in Sage, once you
> have a function, it remains a function even when you do arithmetic with
> it, unless you apply it to values and get an expression. E.g.,
>
> sage: var('x,y,z,n')
> (x, y, z, n)
> sage: f(x) = 2*x^n
> sage: f
> x |--> 2*x^n
> sage: g = f + y; g
> x |--> y + 2*x^n
> sage: g.subs(x=z)
> 2*z^n + y
> sage: e = g(x,z); e
> y + 2*x^n
> sage: type(e)
> <class 'sage.calculus.calculus.SymbolicArithmetic'>
>
> So, when we were talking about piecewise functions, I thought that
> would also stay as a piecewise function object all along. No matter
> what arithmetic you do with it.
>
> When you start having piecewise (or conditional?) expressions, things
> do get complicated as you have been trying to point out all this
> time. :)
>
>
> Note that we already call python functions from c++ in pynac. Just look
> at the sage.symbolic.function.SFunction class. You can specify python
> functions for evaluation, derivation, conjugation, etc. just as ginac
> lets you do this with c++ functions.
>
> sage: from sage.symbolic.function import function as nfunction
> sage: var('x,y',ns=1)
> (x, y)
> sage: def npow(x, power_param=None): return x*power_param
>
> sage: foo = nfunction("foo", 1, power_func=npow)
> sage: foo(y)^(x+y)
> (x + y)*y
>
> sage: def nseries(*args, **kwds): return sum(args[0]^i for i in
> range(kwds['order']))
>
> sage: foo = nfunction("foo", 1, series_func=nseries)
> sage: foo(y).series(y, 5)
> y^4 + y^3 + y^2 + y + 1
>
> Once a couple more glitches are fixed, this should allow people to
> implement new special functions using only python.
>
> It should be straightforward to add a new class to ginac, which also
> dispatches substitution and pattern matching to custom functions as
> well. I'll have to think more about the best way to do this.
>
> As you might have noticed from the lack of progress on the pynac front,
> I don't have much time to spend on pynac these days. I will have at
> least a week to work on this in december, than more january. I hope to
> have most of the lower level stuff sorted out by then, so we can start
> moving things over to pynac.
>
>> The other option is to reimplement the .subs(), .series() and pattern
>> matching in Python. Burcin, please don't take my comments as sarcastic
>> --- I am really interested how to handle this and how to cooperate as
>> much as possible.
>
> Thanks for pointing these out. I don't use symbolics much, and was
> stuck with the idea of piecewise functions for some reason. I
> guess I hadn't looked at your initial example carefully. So piecewise
> functions are on my todo list now:
>
> http://wiki.sagemath.org/symbolics/pynac_todo
>
> Please suggest anything else that you think should be in there. I don't
> use symbolics enough to know about different use cases and common
> problems. Your experience here is definitely needed.

I only wanted to do stuff in this issue:

http://code.google.com/p/sympy/issues/detail?id=1214

e.g. substitue in the Piecewise function and then integrate it. Since
the integration failed in sympy, I was curious how far Sage is on this
front, and it is not far either. So the aim is that one should be able
to do everything in the issue.

>
>
>> Also, how will you approach to fix the bug in pynac
>> series I reported here:
>>
>> http://groups.google.com/group/sage-devel/msg/a59f3c5d0586766b
>>
>> E.g. will you fix ginac, or rather reimplement it in Cython/Python?
>
> This was already on my todo list, see item "1/gamma(-1) = 0" in the
> above link. I will fix ginac, as this annoys me too. This is also on
> the ginac todo list (see the 4th item):
>
> http://www.ginac.de/ToDo.html
>
>> You can actually still use Maxima for that, so that's not a problem in
>> fact. And later just reimplement it in Python/Cython.
>
> I would like to use pynac as much as possible and avoid calling maxima.
> I don't think I need to reimplement anything in cython to fix this
> specific problem though. I just need to go around and modify a few eval
> functions to take infinity into account. Covering all the possible
> cases might take a couple of days, but it's definitely within reach. In
> fact, I already did something similar to get around ginac's shortcuts in
> arithmetic when handling modular coefficients.

Thanks for pointing everything out. Now I can see where it's heading.
Btw, the last big problem are assumptions ---- I just told Michael on
irc, when we get this implemented, I could finally sleep well at
night, because then all the necessary pieces will be there.

Ondrej

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to