These are chat archives for symengine/symengine

30th
Dec 2015
Shivam Vats
@shivamvats
Dec 30 2015 03:48
@isuruf About sin(p).
This is interesting. Did you compare the Python timings also?
Btw, how do you decide how many terms of you need in sin(x) to get the required order in the final expansion?
Isuru Fernando
@isuruf
Dec 30 2015 04:24
@shivamvats, I didn't compare python timings. You need exactly the order terms in sin(x)
It is a simplified version of rs_series_from_list
Shivam Vats
@shivamvats
Dec 30 2015 05:16
@isuruf Even in Python, substitution seems to be faster. You might want to look at rs_fun. It also uses rs_series_from_list. The idea was that since rs_tan uses rs_fun, expanding rs_sin using rs_tan should be fast. But, now I notice that rs_fun doesn't get called by rs_tan for one generator (in which case rs_sin calls rs_tan).
We can actually do with fewer terms. For example:
In [45]: rs_sin(x**2,x,10)
Out[45]: -1/6*x**6 + x**2

In [46]: p = rs_sin(x,x,5)

In [47]: rs_subs(p,{x:x**2},x,10)
Out[47]: -1/6*x**6 + x**2
Shivam Vats
@shivamvats
Dec 30 2015 05:24
So, if we implement rs_fun and use it in rs_tan, it should make rs_sin faster too.
Ralf Stephan
@rwst
Dec 30 2015 07:50
Comparing sin(cos(1+x)) with Sage/Pynac needs to acknowledge that Pynac arrives at the result by differentiation. The advantage
of differentiation is that any function can be expanded that just has a diff() member, no additional code needed in series().
Isuru Fernando
@isuruf
Dec 30 2015 07:53
Ah. yes. I'll add another method that uses diff for generating the series
Isuru Fernando
@isuruf
Dec 30 2015 08:05
import symengine as se
def series_se(fun, x, p):
    t = fun.subs({x:0})
    d = fun
    fac = se.Integer(1)
    for i in range(1, p):
        fac *= i
        d = d.diff(x)
        t += x**i/fac*d.subs({x:0})
    return t
x = se.Symbol("x")
%time e=g(se.sin(se.cos(x+1)), x, 30)
takes 26.2ms whereas Pynac 0.5.3 takes 115ms
Ralf Stephan
@rwst
Dec 30 2015 08:07
So that's only 5x faster instead of 10x faster. Accordingly using diff is about 2x slower than polys in symengine, right?
Isuru Fernando
@isuruf
Dec 30 2015 08:37
Yes
Abhinav Agarwal
@abhinavagarwal07
Dec 30 2015 13:07
Why did test for #700 failed?
Isuru Fernando
@isuruf
Dec 30 2015 13:09
That's a network failure in appveyor VM. I restarted the build
Abhinav Agarwal
@abhinavagarwal07
Dec 30 2015 14:12
thanks
Srajan Garg
@srajangarg
Dec 30 2015 14:17
Hello everyone,
I was working on #698, and the PolyGamma function takes only non-negative integers as it's first argument. http://mathworld.wolfram.com/PolygammaFunction.html So, what if someone calls polygamma(n,x) and I know for sure that n is not an integer (say Rational), how do I return an invalid response?
I assume is_canonical() only checks if the expression is in it's simplest form or not, and not if the expression is valid
Isuru Fernando
@isuruf
Dec 30 2015 14:23
throw a std::runtime_error
Srajan Garg
@srajangarg
Dec 30 2015 14:23
Where should the checking be happening? In is_canonical() or in polygamma ?
Isuru Fernando
@isuruf
Dec 30 2015 14:24
Both
Srajan Garg
@srajangarg
Dec 30 2015 14:26
It returns false in is_canonical() (and not the runtime_error) right?
Just confirming
Isuru Fernando
@isuruf
Dec 30 2015 14:26
Yes.
Srajan Garg
@srajangarg
Dec 30 2015 14:29
Are there functions like is_not_a implemented? or I have to make cases to check if it's definitely not an int
Isuru Fernando
@isuruf
Dec 30 2015 14:29
is_canonical checks if it's in simplest form and the expression is valid. If code is written correctly, then output of is_canonical would be true everywhere
not is_a works
Srajan Garg
@srajangarg
Dec 30 2015 14:32
No, what I mean is, say I pass an Add to it. That'll return true on not is_a. But it doesn't mean it won't evaluate to an int. In other words, a function is_definitely_not
Isuru Fernando
@isuruf
Dec 30 2015 14:33
Ah, there's nothing like that
You can check that if it is a number is_a_Number then it should be an Integer
Srajan Garg
@srajangarg
Dec 30 2015 14:35
Oh right! that works
Isuru Fernando
@isuruf
Dec 30 2015 14:36
Btw, polygamma(n, x) is defined if n is not an integer right?
Srajan Garg
@srajangarg
Dec 30 2015 14:36
no, it is not
Isuru Fernando
@isuruf
Dec 30 2015 14:38
For arbitrary complex n the polygamma function is defined by fractional calculus analytic continuation.
Srajan Garg
@srajangarg
Dec 30 2015 14:39
o_O
Will check it out, thanks
Strange, it does not talk about a non integer n either on Wikipedia or on Mathworld
Anyways, i'll keep it in mind
Isuru Fernando
@isuruf
Dec 30 2015 14:44
In wikipedia, there's a integral representation
Srajan Garg
@srajangarg
Dec 30 2015 14:44
Ah
Ralf Stephan
@rwst
Dec 30 2015 14:47
sage: psi(.1,.1).n()
-10.4237549404111
Srajan Garg
@srajangarg
Dec 30 2015 15:23
Another question, so if n is and int >= 0, should is_canonical() return false? As technically it can be broken down into a multiplication of a factorial and a Zeta. Would that be considered a simpler form or not?
Ralf Stephan
@rwst
Dec 30 2015 15:24
The simplification would be done by a polylog member function?
In Sage these are done autmatically but this is just a convention.
Srajan Garg
@srajangarg
Dec 30 2015 15:26
Does it have to be a function? I can't just the return the result in polygamma(x,n)
RCP<const Basic> zeta(const RCP<const Basic> &s, const RCP<const Basic> &a)
{
    if (is_a_Number(*s)) {
        if (rcp_static_cast<const Number>(s)->is_zero()) {
            if (is_a_Number(*a) and
                rcp_static_cast<const Number>(a)->is_negative()) {
                return sub(div(minus_one, i2), a);
            } else {
                return sub(div(one, i2), a);
            }
        } else if (rcp_static_cast<const Number>(s)->is_one()) {
            throw std::runtime_error("Complex infinity is not yet implemented");
        } else if (is_a<Integer>(*s) and is_a<Integer>(*a)) {
            // Implement Harmonic and simplify this
            return make_rcp<const Zeta>(s, a);
        }
    }
    return make_rcp<const Zeta>(s, a);
}
Here, zeta returns simplified versions automatically (if possible) (at the same time it's is_canonical() will return false)
Should it be the same way in PolyGamma?
Ralf Stephan
@rwst
Dec 30 2015 15:29
You could because it's always a Basic but I just see that there is a member function rewrite_as_zeta so you could do it there
Srajan Garg
@srajangarg
Dec 30 2015 15:32
One more question, in general, is it true that when is_canonical() return false, function() won't return the class Function (and vice versa)?
Isuru Fernando
@isuruf
Dec 30 2015 15:32
@srajangarg, yes
Srajan Garg
@srajangarg
Dec 30 2015 15:35
And what I meant to also ask is, how exactly is "simplest form" defined? If a PolyGamma can be expressed in terms of some other already defined classes, does it mean it's not in the simplest form? Is this always true? Even if the "simplified" form is actually pretty complicated (in terms of already defined stuff)
Isuru Fernando
@isuruf
Dec 30 2015 15:37
It depends on the function. For eg: sin(pi/2 -x) returns cos(x) because it's simpler. On the other hand sinh(x) doesn't return (exp(x)-exp(-x))/2
Srajan Garg
@srajangarg
Dec 30 2015 15:37
Alright! Thanks!
Akash Trehan
@CodeMaxx
Dec 30 2015 16:17
@certik Your opinion on #715 ?
Pradyot Prakash
@pradyotprakash
Dec 30 2015 18:01
Is there any existing function which does modular exponentiation?
Isuru Fernando
@isuruf
Dec 30 2015 18:03
powermod
Pradyot Prakash
@pradyotprakash
Dec 30 2015 18:06
Cool.