Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimize generator for multivariate polynomial exponents
    primarykey
    data
    text
    <p>HI, I'm try to find a general expression to obtain exponents of a multivariate polynomial of order <code>order</code> and with <code>n_variables</code>, like the one presented in this <a href="http://www.siam.org/students/siuro/vol1issue1/S01002.pdf" rel="nofollow">reference</a> in equation (3).</p> <p>Here is my current code, which uses an <code>itertools.product</code> generator.</p> <pre><code>def generalized_taylor_expansion_exponents( order, n_variables ): """ Find the exponents of a multivariate polynomial expression of order `order` and `n_variable` number of variables. """ exps = (p for p in itertools.product(range(order+1), repeat=n_variables) if sum(p) &lt;= order) # discard the first element, which is all zeros.. exps.next() return exps </code></pre> <p>The desired out is this:</p> <pre><code>for i in generalized_taylor_expansion_exponents(order=3, n_variables=3): print i (0, 0, 1) (0, 0, 2) (0, 0, 3) (0, 1, 0) (0, 1, 1) (0, 1, 2) (0, 2, 0) (0, 2, 1) (0, 3, 0) (1, 0, 0) (1, 0, 1) (1, 0, 2) (1, 1, 0) (1, 1, 1) (1, 2, 0) (2, 0, 0) (2, 0, 1) (2, 1, 0) (3, 0, 0) </code></pre> <p>Actually this code executes fast, because the generator object is only created. If i want to fill a list with values from this generator execution really starts to be slow, mainly because of the high number of calls to <code>sum</code>. Tipical value for <code>order</code> and <code>n_variables</code> is 5 and 10, respectively.</p> <p>How can i significantly improve execution speed?</p> <p>Thanks for any help.</p> <p>Davide Lasagna</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload