Closed fuglede closed 9 years ago
This is completely baffling to me:
sage: R.<x> = QQ[]
sage: p = R.random_element(degree=5000)
sage: %timeit p.subs(x=x^2)
1 loops, best of 3: 1.18 s per loop
sage: %timeit p(x=x^2)
1 loops, best of 3: 1.22 s per loop
sage: %timeit p(x^2)
10 loops, best of 3: 38.6 ms per loop
sage: %timeit p.subs(x^2)
10 loops, best of 3: 38.3 ms per loop
sage: %timeit p(x=x^2)
1 loops, best of 3: 1.23 s per loop
So calling subs
or direct evaluation without parameters with way faster for regular polynomials (and deserves a separate ticket if there isn't one already). However nothing beats direct coercion:
sage: S.<x> = LaurentPolynomialRing(QQ)
sage: q = x^-2300 * p
sage: T.<y> = LaurentPolynomialRing(QQ)
sage: %timeit T(q)
The slowest run took 5.28 times longer than the fastest. This could mean that an intermediate result is being cached
10000 loops, best of 3: 158 µs per loop
I will make this change as part of my review (which I am starting now).
Reviewer: Travis Scrimshaw
Changed branch from u/fuglede/jones_rep to u/tscrim/jones_rep-19011
Okay, I've made my first pass of reviewer changes. There's probably some more documentation stuff that will need to be addressed, but I wanted you to run some speed tests against your previous timings to see what improvements (or regressions) have been made.
New commits:
6bede85 | Merge branch 'u/fuglede/jones_rep' of git://trac.sagemath.org/sage into u/tscrim/jones_rep-19011 |
53eedfe | First pass of review changes. |
3f29732 | Doing some more reviewer changes; hopefully gaining some speed. |
Thanks for the detailed review!
Since most of the changes were related to internals in TL_representation
and jones_polynomial
, I ran some tests on those methods. Each test was performed three times on a fresh instance of sage (so caching specifics have not been tested), alternating between the old branch and the one that includes your fixes.
Test 1: Calculation of a huge TL_representation
(34 13260x13260 matrices):
My branch:
```
sage: B = BraidGroup(18)
sage: %time B.TL_representation(4)
CPU times: user 1min 23s, sys: 104 ms, total: 1min 23s
CPU times: user 1min 23s, sys: 104 ms, total: 1min 23s
CPU times: user 1min 22s, sys: 92 ms, total: 1min 22s
```
Your branch:
```
sage: B = BraidGroup(18)
sage: %time B.TL_representation(4)
CPU times: user 1min 12s, sys: 84 ms, total: 1min 12s
CPU times: user 1min 12s, sys: 80 ms, total: 1min 12s
CPU times: user 1min 13s, sys: 116 ms, total: 1min 13s
```
Conclusion: Considerable speed gain.
Test 2: Calculation of the Jones polynomials of 2961 knots obtained as closures of braids on at most 7 strands. The test does not use skein_normalisation
so that in particular, any speed gain obtained through the removal of subs
should be visible here. The (somewhat ad hoc) test is available here.
My branch:
```
sage: load("jonesdata.py")
sage: test_against_dictionary()
2961 matches and 0 mismatches found in 36.658627 seconds
2961 matches and 0 mismatches found in 35.956593 seconds
2961 matches and 0 mismatches found in 36.534720 seconds
```
Your branch:
```
sage: load("jonesdata.py")
sage: test_against_dictionary()
2961 matches and 0 mismatches found in 34.822386 seconds
2961 matches and 0 mismatches found in 34.758321 seconds
2961 matches and 0 mismatches found in 36.320710 seconds
```
Conclusion: Speed gain appears to be less significant here.
Thank you for running those timings. I'm glad to see that we've squeezed some more speed out of this. I'm going to make another pass over the documentation shortly, but there will likely be minimal changes.
Okay, I'm done making reviewer changes. If you're happy with my latest changes, then you can set a positive review.
Changed branch from u/tscrim/jones_rep-19011 to u/fuglede/jones_rep
Looks good to me. I'm setting to positive review after changing just a single variable name.
Changed branch from u/fuglede/jones_rep to 37ca1e8
First off, this is my first ticket here, so please let me know about process related stuff that I missed.
As per this discussion on sage-devel, these commits contain methods for Braid and BraidGroup_class to allow for the calculation of the Temperley--Lieb--Jones representations of braid groups. While interesting in their own right, this also allows for a straightforward implementation of the (uncoloured) Jones polynomial of trace closures of braids, also included, which for a fixed number of braid strands is polynomial in the number of crossings. The algorithm uses Kauffman's diagrammatic description of the Temperley--Lieb algebra.
It should be noted that there is some overlap here with #17030 but as discussed on sage-devel, this is not necessarily a problem (although of course any code that is duplicated exactly should be coordinated between that ticket and this one).
One sillily todo is to add my own name (Søren Fuglede Jørgensen) to the list of authors. No matter how I've tried to do this, the building failes; probably due to encoding issues, I would imagine (but simply translating the string to unicode does not solve the issue).
The branch also contains a small bit of code clean-up cf. GH PR #47.
CC: @miguelmarco @amitjamadagni
Component: algebraic topology
Author: Søren Fuglede Jørgensen
Branch/Commit:
37ca1e8
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/19011