Ask Your Question

trenzafeeds's profile - activity

2022-07-12 05:45:08 +0200 received badge  Nice Question (source)
2022-05-15 21:35:11 +0200 received badge  Popular Question (source)
2019-09-08 05:25:09 +0200 received badge  Famous Question (source)
2019-04-11 21:29:25 +0200 commented answer Quicker expansion of multivariate polynomials

You're completely right, they are symbolic expressions! I think I'll investigate the savings I can make by switching over to real polynomials before I go any further down the expansion rabbit hole. If I ask the question again I'll certainly post my code, but for now I think it's better left unposted, its a bit of a behemoth. Thanks!

2019-04-11 19:41:03 +0200 asked a question Quicker expansion of multivariate polynomials

Hi everyone,

I'm working on a project that involves first generating polynomials, then checking to see if certain terms exist within them. Essentially, I have a function build_polynomial that builds polynomials in un-expanded form according to a certain set of specifications. The polynomials produced by this function usually look something like this:

(x1 - x2 - x3 + y1 - y2 + y3 - y4)*(x1 - x2)*(x1 - x3)*(x1 + y1 - y2)*(x2 + x3 - y1 + y2 - y3 + y4)*(x2 + x3 + y2 - y3)*(x2 + x3 - y3 + y4)*(x2 + x3)*(x2 - x3)*(x2 + y2 - y3)*(y1 - y2)*(y1 - y3)*(y1 - y4)*(y2 - y3)*(y2 - y4)*(y3 - y4)

This is a particularly small example, the polynomials expand quite rapidly as the problem grows in size, but this example should give an idea of generally what they look like.

Next, my program must check too see if specific terms exist in the expanded form of the polynomial. Currently, I do this by first expanding the polynomial with the Sage expand function, then using the coefficient function with the specific terms as arguments.

My issue is that as the polynomial grows, the completion time of the expand function also grows quite rapidly. For example, at medium-to-large complexity, the polynomial can take days to be expanded.

Is there any way around this? Possibly a more efficient function that anybody knows of? I know that Sage is not really the best option for large computations like this, but I'm looking for a way to at least slightly improve performance while I research a longer-term solution.

Thanks!

2018-11-26 03:57:39 +0200 received badge  Notable Question (source)
2018-11-02 16:19:18 +0200 received badge  Popular Question (source)
2018-02-21 16:04:13 +0200 commented answer Getting my own module to work in Sage

Turns out it was a mistake that I was making, not a code problem! Sorry for troubling you guys, turns out that first answer was totally correct!

2018-02-21 14:25:09 +0200 received badge  Editor (source)
2018-02-21 00:01:00 +0200 commented answer Getting my own module to work in Sage

For sure. The entire document is pretty long, but I've taken what I think are the most important parts. Let me know if anything else seems important. Here's the header of the document (everything I'm importing):

from sage.calculus.var import var
import itertools
from sympy.utilities.iterables import multiset_permutations

and here's the beginning of the function that gives the above-mentioned error when I call it:

def sift(r, s):
    polynomial = 1

    p = r/2
    q = (s-1)/2
    poly_degree = 0

    #For x-terms
    for j in xrange(2, r+1):
        for i in xrange(1, j):
            term = (var("x" + str(j))-var("x" + str(i)))
            polynomial = polynomial *term
            poly_degree += 1

it's the first 'var("x" + str(j)) there that's giving me the error.

2018-02-20 22:20:34 +0200 commented answer Getting my own module to work in Sage

Unfortunately still getting the same error, any other ideas?

2018-02-20 21:54:48 +0200 asked a question Getting my own module to work in Sage

Hey everyone. I wrote a sage module that defines a couple functions that I'd like to be able to import into sage any time I want. From what I've researched, it seems the way to do this is save the file that defines the functions as a .py file, then put it into sage's version of python. I've done that, and sage imports the file just fine without errors, except when I attempt to call functions from the file in the sage prompt, it gets stuck on the first sage-specific function, in this case var(). I get this error message:

 sage: polyv1.sift(4, 3)

    ---------------------------------------------------------------------------
    NameError                                 Traceback (most recent call last)
    <ipython-input-20-d64cf99d698f> in <module>()
    ----> 1 polyv1.sift(Integer(4), Integer(3))

    /usr/lib/sagemath/local/lib/python/polyv1.py in sift(r, s)

    NameError: global name 'var' is not defined

I've tried adding 'from sage.all import *' to the beginning of the file, and it doesn't create an error, but it also doesn't fix the problem. Am I missing something really easy? How do you get sage to recognize the sage functions?

2018-02-20 21:41:28 +0200 received badge  Scholar (source)
2018-02-20 21:41:25 +0200 received badge  Supporter (source)
2018-02-20 21:40:46 +0200 commented answer Converting strings into expressions

Thank you! This worked perfect for me

2018-02-15 23:33:14 +0200 received badge  Student (source)
2018-02-15 23:25:00 +0200 asked a question Converting strings into expressions

Hey everyone, This is probably pretty straightforward, but I couldn't find any straightforward answers with google searching. I'm looking for a function that works in the same way as python's str() and float() functions, but turns variables (especially strings) into sage's different classes of variables, like expressions. For example, if I have string variable: expression = "x1^2*x2*x3*4" and x1, x2, and x3 are already declared as variables, how can I turn that variable into a sage expression so it will work with things like the coefficient() function? Thanks!