Ask Your Question

jb's profile - activity

2023-07-23 15:22:05 +0200 received badge  Popular Question (source)
2022-04-26 16:51:38 +0200 received badge  Famous Question (source)
2021-04-16 01:29:16 +0200 received badge  Enthusiast
2021-04-16 01:29:16 +0200 received badge  Enthusiast
2021-04-07 01:52:34 +0200 marked best answer Issue on numerical_integral with a Pari/GP function

Hello there,

I tried to evaluate the integral of a Pari/GP function but failed so far. Here is an example code on (SageMath version 8.9, Release Date: 2019-09-29 and windows 10):

sage: lchi4 = DirichletGroup(4).list()[1].lfunction(); lchi4
PARI L-function associated to Dirichlet character modulo 4 of conductor 4 mapping 3 |--> -1
sage: numerical_integral(lambda t: lchi4(t).real(), 2,3)
---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
/opt/sagemath-8.9/local/lib/python2.7/site-packages/sage/all_cmdline.pyc in <module>()
----> 1 numerical_integral(lambda t: lchi4(t).real(), Integer(2),Integer(3))

/opt/sagemath-8.9/local/lib/python2.7/site-packages/sage/calculus/integration.pyx in 
sage.calculus.integration.numerical_integral (build/cythonized/sage/calculus/integration.c:4061)()
353          _b = b
354          W = <gsl_integration_workspace*> gsl_integration_workspace_alloc(n)
--> 355          sig_on()
356          gsl_integration_qag(&F,_a,_b,eps_abs,eps_rel,n,rule,W,&result,&abs_err)
357          sig_off()

SystemError: calling remove_from_pari_stack() inside sig_on()

However, for the Riemann zeta function, numerical_integral works fine as below:

sage: numerical_integral(lambda t: zeta(t), 2,3)
(1.3675256886839795, 1.518258506343328e-14)

It looks like it would work for lchi4 if it can be coerced into a symbolic expression like zeta(x) as shown below:

sage: type(lchi4(3))
<type 'sage.rings.complex_number.ComplexNumber'>
sage: type(zeta(3))
<type 'sage.symbolic.expression.Expression'>

Can you please let me know how to evaluate the integral numerically for a Pari/GP function as lchi4?

Thank you in advance.

2021-03-23 00:35:35 +0200 received badge  Teacher (source)
2021-03-23 00:35:35 +0200 received badge  Self-Learner (source)
2021-03-23 00:29:16 +0200 edited answer Issue on numerical_integral with a Pari/GP function

After searching Google for this issue, I've found myself an answer: sage: def lchi4(s): ....: return RR(gp('lfun(lf

2021-03-23 00:20:01 +0200 answered a question Issue on numerical_integral with a Pari/GP function

After searching Google for this issue, I've found myself an answer: sage: def lchi4(s): ....: return gp('lfun(lfunc

2021-03-18 22:41:37 +0200 received badge  Editor (source)
2021-03-18 22:41:37 +0200 edited question Issue on numerical_integral with a Pari/GP function

Issue on numerical_integral with a Pari/GP function Hello there, I tried to evaluate the integral of a Pari/GP function

2021-03-18 22:37:39 +0200 asked a question Issue on numerical_integral with a Pari/GP function

Issue on numerical_integral with a Pari/GP function Hello there, I tried to evaluate the integral of a Pari/GP function

2021-03-14 16:54:40 +0200 received badge  Notable Question (source)
2020-05-15 13:31:48 +0200 received badge  Popular Question (source)
2019-03-23 01:17:48 +0200 received badge  Scholar (source)
2019-03-23 01:17:21 +0200 received badge  Supporter (source)
2019-03-22 20:25:59 +0200 received badge  Good Question (source)
2019-03-22 19:40:02 +0200 commented question Memory usage strictly increasing on Sage interactive shell

You're absolutely right! Thank you very much for your comment. If I use pari(pi), it works without memory leaks. However, if gp(pi) used, it just hangs. I still want to know how the leaks happen; I guess that this issue is related with gp('znprimroot(10007)') and pari('znprimroot(10007)') shown on Interfaces--Sage Tutorial v86. By the way, if you put it in Answer, I will mark yours as an answer. Best, jb.

2019-03-22 16:25:34 +0200 received badge  Nice Question (source)
2019-03-22 13:24:34 +0200 received badge  Student (source)
2019-03-22 08:35:21 +0200 asked a question Memory usage strictly increasing on Sage interactive shell

Hello,

I executed the following script on the Sage interactive shell on Ubuntu 18.04 (on SageMath version 8.7.beta5):

sage: import gc
sage: t = 100000
sage: l = [n for n in xrange(t,t+100)]
sage: ll = []
sage: for x in l:
....:     s = 0
....:     for n in xrange(0,x):
....:         s += cos(RDF(2)*RDF(pi)*RDF(n)/RDF(x))
....:     ll.append([x, s])
....:     del(s)
....:     print "memory usage: " + str(get_memory_usage()) + ", gc: " + str(gc.collect())
....:
memory usage: 5824.5546875, gc: 277
memory usage: 5828.3046875, gc: 0
memory usage: 5832.0546875, gc: 0
memory usage: 5836.0546875, gc: 0
                :
memory usage: 6203.5546875, gc: 0
memory usage: 6207.5546875, gc: 0

As we can see the memory usages, it increases by about 4 MB per each step. Thus, after completed, it increased around 400 MB in total. It is frustrating since it eventually eats up all memories in my system as the size of the input list grows and gc.collect() does not seem to help.

I suspect that there were memory leaks or Sage(or Python) stored all the values of cos() and never freed them for some reasons while the shell not killed.

Can someone please explain what was going on and suggest how to avoid this unwanted memory consumption? Thank you in advance.