Am 30.03.2015 um 21:33 schrieb Aaron Meurer:
I would definitely test the different alternatives for sympy.abc to
see what's faster.
I just ran bin/test with `a = Symbol('a')` etc.
Runtime went from 56:29 to 56:37, i.e. below the noise threshold.
That was with Python 2.7. I guess the Pyton compiler is "fast enough"
after all.
It's not too surprising actually: symbol creation happens just once at
first module import, for ~75 symbols, which isn't particularly often.
Other considerations
--------------------
Error situation:
Importing abc offers the trap that `import * from sympy.abc` overwrites
the COSINEQ single-letter definitions from other SymPy modules. It's a
trap that everybody walks into once, has trouble figuring out, then
knows how to avoid.
For ..., n, m, ... = symbols('... m, n, ...')" we have a trap that
everybody walks into, has trouble figuring out, then fixes easily and
knows how to avoid... essentially the same situation as with a star
import. Well, worse because the problem is harder to diagnose with more
varied failure mode, less bad because it bites only those who import a
lot of names from abc.
Static analysis:
Importing from sympy.abc will confuse all static analysis tools because
sympy.abc uses exec with a constructed string.
Using symbols() will not cause that problem.
Performance:
Using symbols() in all contexts might have performance ramifications,
creating new Symbol() objects means more memory pressure than reusing
precreated symbols from sympy.abc (which happen 521 times in SymPy
itself, hopefully just in test code).
Implementation effort:
Switching to symbols() wherever sympy.abc is used would mean touching
521 imports, and checking whether symbol reuse is actually okay for all
uses of the imported names.
Alternate implementation
------------------------
Implement sympy.abc using this:
--
a, b, c, d, e, f, g, h, i, j = symbols('a, b, c, d, e, f, g, h, i, j')
k, l, m, n, o, p, q, r, s, t = symbols('k, l, m, n, o, p, q, r, s, t')
u, v, w, x, y, z = symbols('u, v, w, x, y, z')
A, B, C, D, E, F, G, H, I, J = symbols('A, B, C, D, E, F, G, H, I, J')
K, L, M, N, O, P, Q, R, S, T = symbols('K, L, M, N, O, P, Q, R, S, T')
U, V, W, X, Y, Z = symbols('U, V, W, X, Y, Z')
alpha, beta, gamma = symbols('alpha, beta, gamma')
delta, epsilon, zeta = symbols('delta, epsilon, zeta')
eta, theta, iota = symbols('zeta, eta, theta, iota')
kappa, lamda, mu = symbols('kappa, lamda, mu')
nu, xi, omicron = symbols('nu, xi, omicron')
pi, rho, sigma = symbols('pi, rho')
tau, upsilon, phi = symbols('sigma, tau, upsilon, phi')
chi, psi, omega = symbols('phi, chi, psi, omega')
--
Error situation: As with importing.
Static analysis: As with symbols().
Performance: As with importing (minimally faster, perhaps).
Implementation effort: Very, very easy.
Also, I wonder what the effect of sympy.abc on the cache is. We have
an LRU cache, and assumedly importing it messes with that, at least
for a little bit.
How can I test this?
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/551CF4A8.5050709%40durchholz.org.
For more options, visit https://groups.google.com/d/optout.