Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8800645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:38:37+00:00 2026-06-14T00:38:37+00:00

I have written some very simple trial-and-error code in Sage (a computer algebra system

  • 0

I have written some very simple trial-and-error code in Sage (a computer algebra system written in python where you can use regular python syntax in scripting). The little code snippet creates a polynomial and does some calculations with the coefficients, especially it determines the Groebner basis for the ideal generated by three expressions in the coefficients.

The problem is: This program goes on and eats up all my memory until it’s killed by the kernel. Every iteration consumes only like 200kB, but this memory is never freed again.

Here is the code. The details are not that important and very bulky, therefore left out:

R = PolynomialRing(QQ, 2, 'bc', order='lex')
expr1, expr2, expr3 = ...

for i in range (0,50):
    for j in range(i+1,50):
        for k in range(j+1,50):
            for l in range(k+1,50):
                for m in range(l+1,50):
                    for n in range(m+1,50):
                        poly = (x-i)*(x-j)*(x-k)*(x-l)*(x-m)*(x-n)
                        r = poly.coeffs()

                        p1 = expr1.substitute(r...)
                        p2 = expr2.substitute(r...)
                        p3 = expr3.substitute(r...)

                        I = (p1, p2, p3)*R
                        B = I.groebner_basis()

As far as I understood python’s memory management, the variables in the loop body are freed every so often. Now, it may be a programming problem, an internal python problem or some problem in the Sage routines. I don’t know. Can you spot a problem with my code or is it something else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:38:38+00:00Added an answer on June 14, 2026 at 12:38 am

    The problem doesn’t appear to be your loops (in python2.7, OS-X 10.5.8):

    a = 0
    for i in range (0,50):
        for j in range(i+1,50):
            for k in range(j+1,50):
                for l in range(k+1,50):
                    for m in range(l+1,50):
                        for n in range(m+1,50):
                            a += 1
    
    print( a )
    

    Which takes very little additional memory on both python2.x and python3.x.

    And it really doesn’t take all that long to run either:

    time python test.py
    15890700
    
    real   0m6.015s
    user   0m5.940s
    sys    0m0.032s
    

    Perhaps something is funky when running with sage? Or maybe it’s something else in your loops that is causing the problem…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple client server code written java(server listens on some port
I have written very very simple console application which supports some command line options.
I am in the process of learning backbone.js and have written some very simple
I have written some Python scripts in Eclipse where at some point I have
I have written some code that loads an XML document using an XmlDocument object
I have written some relatively simple jQuery plug-ins, but I am contemplating writing something
I have written some code for displaying a drop down list, but the code
I have written some code in JSP to download .docx files which is hosted
I have written some code for playing a .wav through my application. Now I
I have written some jQuery ajax code where I am sending a request to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.