sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.46k stars 485 forks source link

Symbolic Chebyshev polynomials #9706

Closed ac9ad401-3030-4fb0-957e-6c14f81e046a closed 10 years ago

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Apply:

Depends on #864 Depends on #9640 Depends on #10018 Depends on #11868 Depends on #15422

CC: @fredrik-johansson @sagetrac-fstan @kcrisman

Component: symbolics

Keywords: orthogonal polynomials, symbolics

Author: Stefan Reiterer

Branch/Commit: u/vbraun/chebyshev @ bb227b6

Reviewer: Burcin Erocal, Travis Scrimshaw, Stefan Reiterer, Jeroen Demeyer

Issue created by migration from https://trac.sagemath.org/ticket/9706

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Attachment: orthogonal_polys.py.gz

A new version of the orthogonal_polys.py file.

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Newer version, with legendre_P, and faster evaluation of symbolic expressions

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Attachment: orthogonal_polys.2.py.gz

Attachment: orthogonal_polys.3.py.gz

Version from 10. August 2010

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Latest version. It holds classes of all polys (but not all completed yet)

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:1

Attachment: orthogonal_polys.4.py.gz

All Polys now have their own class. Much faster evaluation is added. Numerical evaluation is provided. Except for legendre_Q, gen_legendre_P, and gen_legendre_Q these aren't ready yet

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:2

Replying to @sagetrac-maldun:

All Polys now have their own class. Much faster evaluation is added. Numerical evaluation is provided. Except for legendre_Q, gen_legendre_P, and gen_legendre_Q these aren't ready yet

orthogonal_polys4.py hold all changes but is not a patch yet, because it holds old code fragments, which I have to clean up...

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:4

I added in the latest patch (and orthogonal_polys.4.py contains these changes also) a new symbolic evaluation method for the orthogonal polynomials: Instead of call Maxima or use of the recursion, the polynomial is evaluated just using explicit formulas from Abramowitz and Stegun. This is an O(n) algorithm of course.

a little comparison on my machine: old version:

sage: time chebyshev_T(10,x); CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s Wall time: 0.04 s sage: time chebyshev_T(100,x); CPU times: user 0.13 s, sys: 0.01 s, total: 0.14 s Wall time: 0.23 s sage: time chebyshev_T(1000,x); CPU times: user 5.01 s, sys: 0.01 s, total: 5.02 s Wall time: 6.98 s sage time chebyshev_T(5000,x); ??? (I got no output her after 2min)

sage: time gegenbauer(10,5,x); CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s Wall time: 0.05 s sage: time gegenbauer(100,5,x); CPU times: user 0.19 s, sys: 0.00 s, total: 0.19 s Wall time: 0.29 s sage: time gegenbauer(1000,5,x); CPU times: user 5.46 s, sys: 0.02 s, total: 5.48 s Wall time: 7.79 s

New Version sage: time chebyshev_T(10,x); CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s Wall time: 0.01 s sage: time chebyshev_T(100,x); CPU times: user 0.06 s, sys: 0.00 s, total: 0.06 s Wall time: 0.08 s sage: time chebyshev_T(1000,x); CPU times: user 1.22 s, sys: 0.00 s, total: 1.22 s Wall time: 1.22 s sage: time chebyshev_T(5000,x); CPU times: user 27.17 s, sys: 0.15 s, total: 27.32 s Wall time: 27.46 s

sage: time gegenbauer(10,5,x); CPU times: user 0.01 s, sys: 0.00 s, total: 0.01 s Wall time: 0.01 s sage: time gegenbauer(100,5,x); CPU times: user 0.03 s, sys: 0.00 s, total: 0.03 s Wall time: 0.04 s sage: time gegenbauer(1000,5,x); CPU times: user 1.08 s, sys: 0.01 s, total: 1.09 s Wall time: 1.11 s

A little bit faster :) I also don't need to spawn an instance of maxima which makes the initialisation faster.

And now also wider symbolic evaluation is possible:

old version: sage: var('a') a sage: gegenbauer(3,a,x) ... NameError: name 'a' is not defined

new version: sage: var('a') a sage: gegenbauer(3,a,x) 4/3x^3gamma(a + 3) - 2xgamma(a + 2)

The code needs now some cleanup, especially the documentations. The complete versions for legendre_Q, gen_legendre_P, and gen_legendre_Q will not be finished soon since the mpmath functions, don't seem to work correctly... I only provide a call function for maxima for them now.

fredrik-johansson commented 14 years ago
comment:5

The complete versions for legendre_Q, gen_legendre_P, and gen_legendre_Q will not be finished soon since the mpmath functions, don't seem to work correctly...

Care to elaborate?

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Attachment: orthogonal_polys.5.py.gz

Latest version from 12. August 2010 (with bugfix in legendre_P)

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:6

Killed bug in legendre_P

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:7

Replying to @fredrik-johansson:

The complete versions for legendre_Q, gen_legendre_P, and gen_legendre_Q will not be finished soon since the mpmath functions, don't seem to work correctly...

Care to elaborate?

Sorry for the late answer, I was on holidays.

In mpmath I have probs with the legenp and legenq functions. For some inputs I get this error:

sage: mpmath.call(mpmath.legenp,5,1,2)
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)

/home/maldun/prog/sage/ortho/<ipython console> in <module>()

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/sage/libs/mpmath/utils.so in sage.libs.mpmath.utils.call (sage/libs/mpmath/utils.c:5021)()

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/mpmath/functions/hypergeometric.pyc in legenp(ctx, n, m, z, type, **kwargs)
   1481             T = [1+z, 1-z], [g, -g], [], [1-m], [-n, n+1], [1-m], 0.5*(1-z)
   1482             return (T,)
-> 1483         return ctx.hypercomb(h, [n,m], **kwargs)
   1484     if type == 3:
   1485         def h(n,m):

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/mpmath/functions/hypergeometric.pyc in hypercomb(ctx, function, params, discard_known_zeros, **kwargs)
    125                     [ctx.gamma(a) for a in alpha_s] + \
    126                     [ctx.rgamma(b) for b in beta_s] + \
--> 127                     [ctx.power(w,c) for (w,c) in zip(w_s,c_s)])
    128                 if verbose:
    129                     print "    Value:", v

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/mpmath/ctx_base.pyc in power(ctx, x, y)
    417             3.16470269330255923143453723949e+12978188
    418         """
--> 419         return ctx.convert(x) ** ctx.convert(y)
    420 
    421     def _zeta_int(ctx, n):

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/sage/libs/mpmath/ext_main.so in sage.libs.mpmath.ext_main.mpnumber.__pow__ (sage/libs/mpmath/ext_main.c:13946)()

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/sage/libs/mpmath/ext_main.so in sage.libs.mpmath.ext_main.binop (sage/libs/mpmath/ext_main.c:4588)()

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/mpmath/libmp/libelefun.pyc in mpf_pow(s, t, prec, rnd)
    340     # General formula: s**t = exp(t*log(s))
    341     # TODO: handle rnd direction of the logarithm carefully
--> 342     c = mpf_log(s, prec+10, rnd)
    343     return mpf_exp(mpf_mul(t, c), prec, rnd)
    344 

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/mpmath/libmp/libelefun.pyc in mpf_log(x, prec, rnd)
    725     # optimal between 1000 and 100,000 digits.
    726     if wp <= LOG_TAYLOR_PREC:
--> 727         m = log_taylor_cached(lshift(man, wp-bc), wp)
    728         if mag:
    729             m += mag*ln2_fixed(wp)

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/mpmath/libmp/libelefun.pyc in log_taylor_cached(x, prec)
    643     else:
    644         a = n << (cached_prec - LOG_TAYLOR_SHIFT)
--> 645         log_a = log_taylor(a, cached_prec, 8)
    646         log_taylor_cache[n, cached_prec] = (a, log_a)
    647     a >>= dprec

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/mpmath/libmp/libelefun.pyc in log_taylor(x, prec, r)
    607     """
    608     for i in xrange(r):
--> 609         x = isqrt_fast(x<<prec)
    610     one = MPZ_ONE << prec
    611     v = ((x-one)<<prec)//(x+one)

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/mpmath/libmp/libintmath.pyc in isqrt_fast_python(x)
    240                     y = (y + x//y) >> 1
    241         return y
--> 242     bc = bitcount(x)
    243     guard_bits = 10
    244     x <<= 2*guard_bits

/home/maldun/sage/sage-4.5.1/local/lib/python2.6/site-packages/mpmath/libmp/libintmath.pyc in python_bitcount(n)
     78     if bc != 300:
     79         return bc
---> 80     bc = int(math.log(n, 2)) - 4
     81     return bc + bctable[n>>bc]
     82 

OverflowError: cannot convert float infinity to integer
fredrik-johansson commented 14 years ago
comment:8

That looks strange. I get:

sage: import sage.libs.mpmath.all as mpmath
sage: mpmath.call(mpmath.legenp, 5,1,2)
-2.96434298694874e-22 - 912.574269237852*I
sage: mpmath.call(mpmath.legenp, 5,1,2, prec=100)
-2.1062923756778274648015607872e-36 - 912.57426923785222402727329118*I
ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:9

Replying to @fredrik-johansson:

That looks strange. I get:

sage: import sage.libs.mpmath.all as mpmath
sage: mpmath.call(mpmath.legenp, 5,1,2)
-2.96434298694874e-22 - 912.574269237852*I
sage: mpmath.call(mpmath.legenp, 5,1,2, prec=100)
-2.1062923756778274648015607872e-36 - 912.57426923785222402727329118*I

Hm strange. Today I install the new Sage version, perhaps it will then work again

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:10

Replying to @fredrik-johansson:

That looks strange. I get:

sage: import sage.libs.mpmath.all as mpmath
sage: mpmath.call(mpmath.legenp, 5,1,2)
-2.96434298694874e-22 - 912.574269237852*I
sage: mpmath.call(mpmath.legenp, 5,1,2, prec=100)
-2.1062923756778274648015607872e-36 - 912.57426923785222402727329118*I

It was the old version!a Thanx for pointing that out, I will continue soon =)

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Version from 19. August 2010

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:11

Attachment: orthogonal_polys.6.py.gz

So now a "beta" is ready with full support of all classes.

Only the Legendre functions are still using Maxima.

some advances for the future:

-Zernike polys (this should be done in the next time, since explicit formulas are available) -support for numpy_eval. (But this will be done, when the scipy package is updated to 0.8, else it has no sense, because the current version of scipy does not support ortho polys well, but the newer can handle them)

Now I need some people for testing this out =)

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:12

And there was an interisting bug:

the import of mpmath at the beginning of the file caused the whole trouble I had with the numeric evaluation of the legendre functions....

I think I should report this..

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Added numpy support, eliminated some bugs (19.08.2010)

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:14

Attachment: orthogonal_polys.7.py.gz

-support for numpy_eval. (But this will be done, when the scipy package is updated to 0.8, else it has no sense, because the current version of scipy does not support ortho polys well, but the newer can handle them)

I decided to give at least some numpy support for compability reasons. But this is a bad hack...when scipy 0.8 comes I use scipy itself, I change this to a better version :)

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:17

Some of the old doctests fail. But it is not my fault, it seem's that it is a bug in the SymbolicFunction class.

see: https://github.com/sagemath/sage-prod/issues/9769

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Attachment: orthogonal_polys.8.py.gz

Latest version with some code cleanup (no program changes)

burcin commented 14 years ago
comment:20

Hi Stefan,

can you post a patch corresponding to attachment: orthogonal_polys.8.py for review?

Thanks,

Burcin

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Patch for latest version with some code cleanup (no program changes)

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:21

Attachment: trac_9706_ortho_polys.patch.gz

Replying to @burcin:

Hi Stefan,

can you post a patch corresponding to attachment: orthogonal_polys.8.py for review?

Thanks,

Burcin

Done!

fredrik-johansson commented 14 years ago
comment:22

Why is mpmath's precision used by default? Shouldn't the default be RR / CC precision? Actually, does _evalf_ ever get called without this information?

Some complex tests would be nice.

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:23

Replying to @fredrik-johansson:

Why is mpmath's precision used by default? Shouldn't the default be RR / CC precision? Actually, does _evalf_ ever get called without this information?

Some complex tests would be nice.

This is a good point, and it shouldn't be a problem to change that. But I don't think it's a big deal, because the function takes the "parents" precision, which means, if my input is RR it evals it with RR's precision.

Of course can you call _evalf_ just with (), and then the default value is used.

I just sticked to the old's version tests, and expanded it. Of course it's possible to expand the tests. I hope I will find some time for it soon, since I have some other more urgent things todo also.

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:24

Replying to @sagetrac-maldun:

Replying to @fredrik-johansson:

Why is mpmath's precision used by default? Shouldn't the default be RR / CC precision? Actually, does _evalf_ ever get called without this information?

Some complex tests would be nice.

This is a good point, and it shouldn't be a problem to change that. But I don't think it's a big deal, because the function takes the "parents" precision, which means, if my input is RR it evals it with RR's precision.

Of course can you call _evalf_ just with (), and then the default value is used.

Ok sorry, wrong explination: when your input are exact data types like ZZ ore QQ then the parent has no precision, then you need a default value

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:25

Since it seems that numpy-1.4.1, and scipy 0.8 should work now (see #9808) I programmed a version which uses scipy itself to evaluate the orthogonal polys for numpy arrays. When the new versions of numpy/scipy become merged into sage I will provide a patch for these.

Another thing I have to mention are these 2 failde doctests:

sage -t -long "devel/sage/sage/symbolic/random_tests.py"    
**********************************************************************
File "/home/maldun/sage/sage-4.5.2/devel/sage/sage/symbolic/random_tests.py", line 17:
    sage: [f for (one,f,arity) in _mk_full_functions()]
Expected:
    [Ei, abs, arccos, arccosh, arccot, arccoth, arccsc, arccsch,
    arcsec, arcsech, arcsin, arcsinh, arctan, arctan2, arctanh,
    binomial, ceil, conjugate, cos, cosh, cot, coth, csc, csch,
    dickman_rho, dilog, dirac_delta, elliptic_e, elliptic_ec,
    elliptic_eu, elliptic_f, elliptic_kc, elliptic_pi, erf, exp,
    factorial, floor, heaviside, imag_part, integrate,
    kronecker_delta, log, polylog, real_part, sec, sech, sgn, sin,
    sinh, tan, tanh, unit_step, zeta, zetaderiv]
Got:
    [Ei, abs, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctan2, arctanh, binomial, ceil, chebyshev_T, chebyshev_U, conjugate, cos, cosh, cot, coth, csc, csch, dickman_rho, dilog, dirac_delta, elliptic_e, elliptic_ec, elliptic_eu, elliptic_f, elliptic_kc, elliptic_pi, erf, exp, factorial, floor, gegenbauer, gen_laguerre, gen_legendre_P, gen_legendre_Q, heaviside, hermite, imag_part, integrate, jacobi_P, kronecker_delta, laguerre, legendre_P, legendre_Q, log, polylog, real_part, sec, sech, sgn, sin, sinh, tan, tanh, unit_step, zeta, zetaderiv]
**********************************************************************
File "/home/maldun/sage/sage-4.5.2/devel/sage/sage/symbolic/random_tests.py", line 237:
    sage: random_expr(50, nvars=3, coeff_generator=CDF.random_element)
Expected:
    (euler_gamma - v3^(-e) + (v2 - factorial(-e/v2))^(((2.85879036573 - 1.18163393202*I)*v2 + (2.85879036573 - 1.18163393202*I)*v3)*pi - 0.247786879678 + 0.931826724898*I)*arccsc((0.891138386848 - 0.0936820840629*I)/v1) + (-0.553423153995 + 0.5481180572*I)*v3 + 0.149683576515 - 0.155746451854*I)*v1 + arccsch(pi + e)*elliptic_f(khinchin*v2, 1.4656989704 + 0.863754357069*I)
Got:
    -v1*e^((0.0666829501658 + 0.206976992303*I)/(v3 + e))/v3 + hermite(-(v3^(-0.48519994364 - 0.485764091302*I) - log((1.21734510331 - 1.22580558833*I)*pi*v1 + zeta((0.781366128261 + 0.957400336147*I)*v1*e + (-1.8919687109 + 0.753422167447*I)*elliptic_f(v1, v1))*arccsch(v3)))*v1, (-0.647983235144 + 1.20665952957*I)*v1 + (0.0909404921682 + 0.281538203756*I)/v3)
**********************************************************************
File "/home/maldun/sage/sage-4.5.2/devel/sage/sage/symbolic/random_tests.py", line 239:
    sage: random_expr(5, verbose=True)
Exception raised:
    Traceback (most recent call last):
      File "/home/maldun/sage/sage-4.5.2/local/bin/ncadoctest.py", line 1231, in run_one_test
        self.run_one_example(test, example, filename, compileflags)
      File "/home/maldun/sage/sage-4.5.2/local/bin/sagedoctest.py", line 38, in run_one_example
        OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags)
      File "/home/maldun/sage/sage-4.5.2/local/bin/ncadoctest.py", line 1172, in run_one_example
        compileflags, 1) in test.globs
      File "<doctest __main__.example_5[5]>", line 1, in <module>
        random_expr(Integer(5), verbose=True)###line 239:
    sage: random_expr(5, verbose=True)
      File "/home/maldun/sage/sage-4.5.2/local/lib/python/site-packages/sage/symbolic/random_tests.py", line 254, in random_expr
        return random_expr_helper(size, internal, leaves, verbose)
      File "/home/maldun/sage/sage-4.5.2/local/lib/python/site-packages/sage/symbolic/random_tests.py", line 210, in random_expr_helper
        return r[1](*children)
      File "element.pyx", line 1529, in sage.structure.element.RingElement.__div__ (sage/structure/element.c:11992)
      File "coerce.pyx", line 713, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:6126)
      File "element.pyx", line 1527, in sage.structure.element.RingElement.__div__ (sage/structure/element.c:11973)
      File "expression.pyx", line 2269, in sage.symbolic.expression.Expression._div_ (sage/symbolic/expression.cpp:11444)
    ZeroDivisionError: Symbolic division by zero
**********************************************************************
2 items had failures:
   1 of   4 in __main__.example_0
   2 of   6 in __main__.example_5
***Test Failed*** 3 failures.
For whitespace errors, see the file /home/maldun/.sage//tmp/.doctest_random_tests.py
         [7.7 s]

----------------------------------------------------------------------
The following tests failed:

        sage -t -long "devel/sage/sage/symbolic/random_tests.py"
Total time for all tests: 7.8 seconds

I quite understand these, because we have introduced new functions, but I don't understand the exception in the last one

sage -t -long "devel/sage/sage/symbolic/pynac.pyx"          
**********************************************************************
File "/home/maldun/sage/sage-4.5.2/devel/sage/sage/symbolic/pynac.pyx", line 386:
    sage: get_sfunction_from_serial(i) == foo
Expected:
    True
Got:
    False
**********************************************************************
File "/home/maldun/sage/sage-4.5.2/devel/sage/sage/symbolic/pynac.pyx", line 388:
    sage: py_latex_function_pystring(i, (x,y^z))
Expected:
    'my args are: x, y^z'
Got:
    '\\mathrm{bar}\\left(x, y^{z}\\right)'
**********************************************************************
File "/home/maldun/sage/sage-4.5.2/devel/sage/sage/symbolic/pynac.pyx", line 478:
    sage: get_sfunction_from_serial(i) == foo
Expected:
    True
Got:
    False
**********************************************************************
File "/home/maldun/sage/sage-4.5.2/devel/sage/sage/symbolic/pynac.pyx", line 480:
    sage: py_print_fderivative(i, (0, 1, 0, 1), (x, y^z))
Expected:
    D[0, 1, 0, 1]func_with_args(x, y^z)
Got:
    D[0, 1, 0, 1](foo)(x, y^z)
**********************************************************************
File "/home/maldun/sage/sage-4.5.2/devel/sage/sage/symbolic/pynac.pyx", line 540:
    sage: get_sfunction_from_serial(i) == foo
Expected:
    True
Got:
    False
**********************************************************************
File "/home/maldun/sage/sage-4.5.2/devel/sage/sage/symbolic/pynac.pyx", line 542:
    sage: py_latex_fderivative(i, (0, 1, 0, 1), (x, y^z))
Expected:
    D[0, 1, 0, 1]func_with_args(x, y^z)
Got:
    D[0, 1, 0, 1]\left(\mathrm{bar}\right)\left(x, y^{z}\right)
**********************************************************************
3 items had failures:
   2 of  19 in __main__.example_14
   2 of  14 in __main__.example_16
   2 of  18 in __main__.example_18
***Test Failed*** 6 failures.
For whitespace errors, see the file /home/maldun/.sage//tmp/.doctest_pynac.py
         [7.3 s]

----------------------------------------------------------------------
The following tests failed:

        sage -t -long "devel/sage/sage/symbolic/pynac.pyx"
Total time for all tests: 7.3 seconds

And these are really strange, because when I type then into sage by hand everything works. wtf?? Can anyone have a look at these?

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

ortho polys with scipy support

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:26

Attachment: orthogonal_polys.9.py.gz

kcrisman commented 14 years ago
comment:27

Just cc:ing myself by commenting.

Also, there seems to be a lot of stuff in the latest Python file that is the same as the original one (in terms of explanation, not code). Maybe posting an updated patch (once the numpy/scipy-fest is over, which is hopefully the case) would help some of us figure this out. Thanks for working on this - there is still a lot of overhauling that symbolics could use, but this is a great step.

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:28

@kcrisman thanks for paying attention. I added now an updated patch and extended instructions.

the doctest changes in symbolic.random_tests.py are easy to explain: new functions are involved -> new random expressions. But I had to change random_expr(50, nvars=3, coeff_generator=CDF.random_element) to random_expr(60, nvars=3, coeff_generator=CDF.random_element) or else one gets an expression generated where a division through zero occours.

As mentioned on sage-devel I repaired the doctests in symbolic.pynac.pyx, the trick is to enlarge the range of the for loop: for i in range(get_ginac_serial(), get_ginac_serial()+50): changed to for i in range(get_ginac_serial(), get_ginac_serial()+100): now it works. My explaination: since we have new functions we have longer to search, and then we reach our goal. What I can not explain is, that it works, when I type it in by hand.

All doctests pass now, so I think a review would be nice.

-maldun

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Description changed:

--- 
+++ 
@@ -1,10 +1,12 @@
 The current implementation of orthogonal polynomials is just a wrapper around maxima. (see http://wiki.sagemath.org/symbolics/)
-There are the following improvements planed:
+This update holds the following changes:

--using of the pynac class for symbolic functions.
--faster evaluation in general
--evaluation of special values
--mpmath for numeric evaluation
+  *using of the pynac class for symbolic functions.
+  *faster evaluation in general
+  *evaluation of special values
+  *mpmath for numeric evaluation

-
-
+**Remarks:** 
+   *The current patch needs scipy-0.8. One has to install it before testing (see #9808 for spkg's and installation instructions) 
+* Some of the old doctests in the old file don't work any more, due to coercion problems with pynac (see #9769)
+* Some doctests in Sage change, due to the fact that new BuiltIn functions are added. symbolic.random_test.py had output changes since the random expression creation changed of course. The tests in pynac.pyx also changed, but this has a strange behavior (see below).
ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Description changed:

--- 
+++ 
@@ -1,12 +1,12 @@
 The current implementation of orthogonal polynomials is just a wrapper around maxima. (see http://wiki.sagemath.org/symbolics/)
 This update holds the following changes:

-  *using of the pynac class for symbolic functions.
-  *faster evaluation in general
-  *evaluation of special values
-  *mpmath for numeric evaluation
+* using of the pynac class for symbolic functions.
+* faster evaluation in general
+* evaluation of special values
+* mpmath for numeric evaluation

 **Remarks:** 
-   *The current patch needs scipy-0.8. One has to install it before testing (see #9808 for spkg's and installation instructions) 
+* The current patch needs scipy-0.8. One has to install it before testing (see #9808 for spkg's and installation instructions) 
 * Some of the old doctests in the old file don't work any more, due to coercion problems with pynac (see #9769)
 * Some doctests in Sage change, due to the fact that new BuiltIn functions are added. symbolic.random_test.py had output changes since the random expression creation changed of course. The tests in pynac.pyx also changed, but this has a strange behavior (see below).
ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:29

Cleaned up discription of the ticket and some comments in the ortho polys file.

kcrisman commented 14 years ago
comment:30

I don't have time to review this for a while, but did take a quick look - thanks for polishing that patch! I don't think we are allowed to import numpy or scipy like that anymore, but rather have to do it in an individual function (lest startup times get huge). I don't quite understand exactly how that works, but anyway such a blanket import statement probably isn't appropriate, the way I understand what others have said.

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago

Latest version of orthogonal polys with scipy support, and changed doctests. Tested in sage-4.6.alpha3

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 14 years ago
comment:31

Attachment: trac_9706_orthogonal_polys.patch.gz

Replying to @kcrisman:

I don't have time to review this for a while, but did take a quick look - thanks for polishing that patch! I don't think we are allowed to import numpy or scipy like that anymore, but rather have to do it in an individual function (lest startup times get huge). I don't quite understand exactly how that works, but anyway such a blanket import statement probably isn't appropriate, the way I understand what others have said.

But thanks for giving feedback! I know that this patch isn't easy for review because the code grew from 650 to about 2300 lines of code. But I'm happy to get at least some info.

You are right the imports didn't change since I started this ticket and importing the whole numpy and scipy packages is to much. This isn't a very good Idea if one thinks about performance either. I changed that now so that only functions that are really needed are importet. I did this also for mpmath but the problem with the global import remains. (see above). Also changed some errors in the discription I missed and repaired a wrong doctest.

PS: If diffs or more changelogs are needed let me know. I'm keeping track with git on my machine of the changes.

burcin commented 14 years ago
comment:32

Great work Stefan. Your patch looks good overall, but it needs a lot of polish. Thank you very much for this.

Here are some quick comments after reading attachment: trac_9706_orthogonal_polys.patchI didn't try to apply and run the code yet. It would be better if other people try this as well since I am really short on time these days.

Then after using one of these functions, it changes:: (The value is now  
False for chebyshev_T because chebyshev_T uses clenshaw method instead...)

I don't think this is valid Sphinx.

#load /home/maldun/sage/sage-4.5.2/devel/sage-ortho/sage/functions/orthogonal_polys.py 
try: 
    #s = maxima(self._maxima_init_evaled_(*args)) 
    #This above is very inefficient! The older 
    #methods were much faster... 
    return self._maxima_init_evaled_(*args) 
except TypeError: 
    return None 
if self._maxima_name in repr(s): 
    return None 
else: 
    return s.sage() 
try: 
    step_parent = kwds['parent'] 
except KeyError: 
    step_parent = parent(args[-1]) 

try: 
    precision = step_parent.prec() 
except AttributeError: 
    precision = RR.prec() 

See #9566.

I give up at this point. It seems that there are similar issues in the rest of the file as well.

After you clean up the code according to the comments above, perhaps a native English speaker like Karl-Dieter or Minh can help with the documentation.

Thanks again for all your work.

burcin commented 14 years ago

Reviewer: Burcin Erocal

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 11 years ago
comment:35

Hi!

I will now retry to build the new orthogonal polynomials. The last time I ran out of time due to my phd studies/theses this time i will split the changes up into several patches. So it will be easier to apply the changes step by step, and the review process gets simpler.

Hope this time everything will work out!

tscrim commented 11 years ago
comment:37

Here is a review patch which does a bunch of documentation formatting tweaks. There are probably one or two other things that will need to be addressed, but I'd like to get the ball rolling on this again (and I need some sleep right now).

Best,

Travis

For patchbot:

Apply: trac_9706_chebyshev.patch​, trac_9706-review-ts.patch

tscrim commented 11 years ago

Description changed:

--- 
+++ 
@@ -10,3 +10,8 @@
 * The current patch needs scipy-0.8. One has to install it before testing (see #9808 for spkg's and installation instructions) 
 * Some of the old doctests in the old file don't work any more, due to coercion problems with pynac (see #9769)
 * Some doctests in Sage change, due to the fact that new BuiltIn functions are added. symbolic.random_test.py had output changes since the random expression creation changed of course. The tests in pynac.pyx also changed, but this has a strange behavior (see below).
+
+Apply:
+
+* [attachment: trac_9706_chebyshev.patch](https://github.com/sagemath/sage-prod/files/10650399/trac_9706_chebyshev.patch.gz)
+* [attachment: trac_9706-review-ts.patch](https://github.com/sagemath/sage-prod/files/10650409/trac_9706-review-ts.patch.gz)
ac9ad401-3030-4fb0-957e-6c14f81e046a commented 10 years ago
comment:38

Thanks for reviewing. It would be great if the new Chebyshev Polynomials could be added. If this ticket is done I will open the next issue and start working on the Legendre Polynomials

tscrim commented 10 years ago
comment:39

Okay, I've done a few other tweaks and I'd okay with it. If you're happy with my changes, then go ahead and set this to positive review.

For patchbot:

Apply: trac_9706_chebyshev.patch​, trac_9706-review-ts.patch

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 10 years ago

Changed reviewer from Burcin Erocal to Burcin Erocal, Travis Scrimshaw

ac9ad401-3030-4fb0-957e-6c14f81e046a commented 10 years ago
comment:40

Thanks for your hard work in correcting all those small mistakes!

I'm very happy, that finally the new ortho polys are going into sage!

kcrisman commented 10 years ago

Changed author from Stefan Reiterer to Stefan Reiterer, Travis Scrimshaw

kcrisman commented 10 years ago

Changed reviewer from Burcin Erocal, Travis Scrimshaw to Burcin Erocal, Travis Scrimshaw, Stefan Reiterer

kcrisman commented 10 years ago
comment:41

I'm elevating Travis to an author because these are quite substantial review changes - thanks for being so meticulous on the formatting etc!

I'd love one final check from either of you. There are a lot of imports added; I think most should be okay but the Maxima-related ones scare me, so if you can just check that startup time hasn't budged more than a couple milliseconds, that would be helpful. I don't think this should import numpy, at least!