Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi Niles!

Let's try.

Substitution:

sage: R.<x> = QQ[]
sage: p = R.random_element(50)
sage: q = R.random_element(50)
sage: %time r=p(q)
CPU times: user 0.11 s, sys: 0.00 s, total: 0.11 s
Wall time: 0.11 s
sage: p = R.random_element(100)
sage: q = R.random_element(100)
sage: %time r=p(q)
CPU times: user 1.10 s, sys: 0.02 s, total: 1.12 s
Wall time: 1.12 s
sage: p = R.random_element(200)
sage: q = R.random_element(200)
sage: %time r=p(q)
CPU times: user 25.27 s, sys: 0.27 s, total: 25.54 s
Wall time: 25.61 s

Homomorphism:

sage: p = R.random_element(50)
sage: q = R.random_element(50)
sage: f = R.hom([q])
# Test that the result is the same
sage: p(q)==f(p)
True
sage: %time r=f(p)
CPU times: user 0.45 s, sys: 0.00 s, total: 0.45 s
Wall time: 0.45 s
sage: p = R.random_element(100)
sage: q = R.random_element(100)
sage: f = R.hom([q])
sage: %time r=f(p)
CPU times: user 16.73 s, sys: 0.00 s, total: 16.74 s
Wall time: 16.79 s

So, substitution is considerably faster than a homomorphism. I find that's a shame! If other people agree, we should open a ticket.

By the way: I tried the same using a multivariate ring with one variable. The degree 50 example didn't even finish.