Re: [sympy] Defining custom invertible functions

2018-09-12 Thread Aaron Meurer
On Wed, Sep 12, 2018 at 7:47 AM, Oscar Benjamin
 wrote:
> Hi,
>
> I was just looking at a way to solve ODEs algebraically and came up with the
> code below which almost works (just needs integration constants). I have a
> few questions though.
>
> 1. What is the right way to define an arbitrary invertible function and its
> inverse?

I believe so. There was an issue about being able to make undefined
functions invertible (I can't find it right now), but it isn't
implemented.

>
> 2. Is the code below abusing doit() or is that a reasonable way to use it?

It's fine. The only potential issue is that it will also evaluate any
other unevaluated subexpression.

>
> 3. Should I check for the inverses in __new__ or is there a better way to do
> that?

You shouldn't define __new__ on Function subclasses. Rather, define
the classmethod eval, which returns what the function should evaluate
to, or None if it shouldn't evaluate.

>
> 4. Does this represent a reasonable approach for something that could be
> implemented in dsolve?

As far as I know it should work. It might even solve weird ODEs like

>
> 5. How can I make a different integration constant each time I call
> intx.doit()?

I think there is a iterator in the dsolve module that gives new constants.

Aaron Meurer

>
> class diffx(Function):
> def __new__(cls, expr):
> if isinstance(expr, intx):
> return expr.args[0]
> else:
> return super().__new__(cls, expr)
> def inverse(self):
> return intx
>
> class intx(Function):
> def __new__(cls, expr):
> if isinstance(expr, diffx):
> return expr.args[0]
> else:
> return super().__new__(cls, expr)
> def inverse(self):
> return intx
> def doit(self):
> return Integral(self.args[0].doit(), x).doit()  # + Symbol('C')
>
> eqn = diffx(x*diffx(f(x)))/x - exp(x)
> soln,= solve(eqn, f(x))
> print(soln.doit())
>
> --
> Oscar
>
> --
> 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 https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/CAHVvXxS%2Brg9Jd4U%2BiHQH%3Df64MvJKxPB4RpO9t%3DLYfyGzESuyDA%40mail.gmail.com.
> 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 https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6JfBDw14XKRU2HagPz6wBHiNzLdKSAunS9R-Bs01rrnUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Re: Newbie to open source

2018-09-12 Thread somit mittal
Yeah sure  Thank you Shekhar.

On Wed, Sep 12, 2018, 19:55 Shekhar Prasad Rajak <
shekharrajak.1...@gmail.com> wrote:

> Hi,
>
> Go through this link:
> https://github.com/sympy/sympy/wiki/Introduction-to-contributing and
> clear your doubts in SymPy gitter channel.
>
> Regard,
> Shekhar 
>
>
> On Thursday, 30 August 2018 23:03:12 UTC+5:30, OpenSourcerer wrote:
>>
>> Hi I am a student at IIIT Gwalior and I am new to open source. I have a
>> good amount of coding experience and I wish to contribute to Sympy as I
>> love python. Please help me by guiding me through things. I just know very
>> basic git so I also will be needing help with that. Look forward to working
>> with sympy :) .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "sympy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sympy/LDkFWYCRHhI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/a31374ca-2242-4754-b0e5-3b909fa31f72%40googlegroups.com
> 
> .
> 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 https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAPS%3DkL0F9A5Oh%2Bt-S-h3OFXVcthJ5YLXaAhmO1M1m%2BdbU2cqiw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[sympy] Re: Newbie to open source

2018-09-12 Thread Shekhar Prasad Rajak
Hi,

Go through this 
link: https://github.com/sympy/sympy/wiki/Introduction-to-contributing and 
clear your doubts in SymPy gitter channel. 

Regard,
Shekhar 


On Thursday, 30 August 2018 23:03:12 UTC+5:30, OpenSourcerer wrote:
>
> Hi I am a student at IIIT Gwalior and I am new to open source. I have a 
> good amount of coding experience and I wish to contribute to Sympy as I 
> love python. Please help me by guiding me through things. I just know very 
> basic git so I also will be needing help with that. Look forward to working 
> with sympy :) .
>

-- 
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 https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/a31374ca-2242-4754-b0e5-3b909fa31f72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[sympy] Defining custom invertible functions

2018-09-12 Thread Oscar Benjamin
Hi,

I was just looking at a way to solve ODEs algebraically and came up with
the code below which almost works (just needs integration constants). I
have a few questions though.

1. What is the right way to define an arbitrary invertible function and its
inverse?

2. Is the code below abusing doit() or is that a reasonable way to use it?

3. Should I check for the inverses in __new__ or is there a better way to
do that?

4. Does this represent a reasonable approach for something that could be
implemented in dsolve?

5. How can I make a different integration constant each time I call
intx.doit()?

class diffx(Function):
def __new__(cls, expr):
if isinstance(expr, intx):
return expr.args[0]
else:
return super().__new__(cls, expr)
def inverse(self):
return intx

class intx(Function):
def __new__(cls, expr):
if isinstance(expr, diffx):
return expr.args[0]
else:
return super().__new__(cls, expr)
def inverse(self):
return intx
def doit(self):
return Integral(self.args[0].doit(), x).doit()  # + Symbol('C')

eqn = diffx(x*diffx(f(x)))/x - exp(x)
soln,= solve(eqn, f(x))
print(soln.doit())

--
Oscar

-- 
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 https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxS%2Brg9Jd4U%2BiHQH%3Df64MvJKxPB4RpO9t%3DLYfyGzESuyDA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.