sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.22k stars 428 forks source link

Groebner bases for exterior algebras native to Sage #34138

Closed trevorkarn closed 1 year ago

trevorkarn commented 2 years ago

Add a native Sage implementation to compute a Groebner basis for an ideal of a Sage ExteriorAlgebra

Depends on #32369

CC: @tscrim @simon-king-jena

Component: algebra

Keywords: groebner basis, gsoc2022, f4

Author: Trevor K. Karn, Travis Scrimshaw

Branch/Commit: 36b6b20

Reviewer: Travis Scrimshaw, Trevor K. Karn

Issue created by migration from https://trac.sagemath.org/ticket/34138

trevorkarn commented 2 years ago

Last 10 new commits:

b2f9f50Fix sign error
1550f9dFix coboundary on basis
b3ed980Clean up code a bit
fff9062Add doctest
9e19f79All tests pass
001b3c7Add doctest
1601588Rewrite multiplication
a34ae96Merge branch 'u/tkarn/32369-exterior-rewrite-v2' of trac.sagemath.org:sage into exterior-main
697104cFix merge error
d24c5fcInitial commit of f4
trevorkarn commented 2 years ago

Commit: d24c5fc

trevorkarn commented 2 years ago

Branch: u/tkarn/exterior-gb-34138

trevorkarn commented 2 years ago

Dependencies: #32369

tscrim commented 2 years ago

Changed commit from d24c5fc to 9accac5

tscrim commented 2 years ago

Changed branch from u/tkarn/exterior-gb-34138 to public/algebras/exterior_groebner-34138

tscrim commented 2 years ago

New commits:

e94fc2fMerge branch 'u/tkarn/exterior-gb-34138' of https://github.com/sagemath/sagetrac-mirror into u/tkarn/exterior-gb-34138
9accac5Another implementation of Groebner bases for the exterior algebra.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

71113faFixing some little details.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from 9accac5 to 71113fa

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

b0f66e3Cythonizing the element classes.
74490ceAdding more type declarations and renaming the Groebner file.
04dc914Initial version of GB strategy file for exterior algebra.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from 71113fa to 04dc914

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from 04dc914 to bf0e673

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

bf0e673Implementing different term orders for GB.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

be68f0dFixing some things and tests.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from bf0e673 to be68f0d

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from be68f0d to 43045cc

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

63787c4Bringing more to the GB strategy classes.
43045ccImplementing containment of ideals, mostly.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Changed commit from 43045cc to 6480faa

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 2 years ago

Branch pushed to git repo; I updated commit sha1. This was a forced push. Last 10 new commits:

7a79608Another implementation of Groebner bases for the exterior algebra.
c8a3766Fixing some little details.
b62d578Cythonizing the element classes.
d91a556Adding more type declarations and renaming the Groebner file.
3a9d790Initial version of GB strategy file for exterior algebra.
368491cImplementing different term orders for GB.
f2a25e3Fixing some things and tests.
dba5089Bringing more to the GB strategy classes.
2362a63Implementing containment of ideals, mostly.
6480faaRebase off of 9.7.beta6 and fix merge conflicts
trevorkarn commented 2 years ago
comment:10

All tests still pass in clifford_algebra.py and clifford_algebra_element.pyx.

trevorkarn commented 2 years ago
comment:11

There appears to be a bug in the following example

sage: E.<x,y> = ExteriorAlgebra(QQ)
sage: I = E.ideal([x * y - 1, x * y - x])
sage: I.groebner_basis()

where it gets stuck in an infinite while loop on line 206 of exterior_algebra_groebner.pyx. For comparison,

i2 : QQ[x,y, SkewCommutative=>true]
o2 = QQ[x, y]
o2 : PolynomialRing, 2 skew commutative variables
i3 : I = ideal( x*y - 1, x*y - x)
o3 = ideal (x*y - 1, x*y - x)
o3 : Ideal of QQ[x, y]
i4 : groebnerBasis(I)
o4 = | 1 |
                      1                1
o4 : Matrix (QQ[x, y])  <--- (QQ[x, y])
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 6480faa to b3ef1f7

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

e95c546Add examples
b3ef1f7Fix matrix indexing
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

59a30c1Merge branch 'public/algebras/exterior_groebner-34138' of https://github.com/sagemath/sagetrac-mirror into public/algebras/exterior_groebner-34138
b6174b4Merge branch 'u/tkarn/32369-exterior-rewrite-v2' of https://github.com/sagemath/sagetrac-mirror into public/algebras/exterior_algebra_index_set-32369
a325339Doing some reviewer changes.
47281faMerge branch 'public/algebras/exterior_algebra_index_set-32369' into public/algebras/exterior_groebner-34138
692f2f5Fixing containment and reduction of exterior algebra ideals.
6c92f18Implementing multiplication of exterior algebra ideals.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from b3ef1f7 to 6c92f18

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 6c92f18 to 698e051

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

698e051Some last details for pyflakes and full coverage.
tscrim commented 1 year ago
comment:15

I rebased this over my changes in #32369, fixed the comparison of ideals, and implemented multiplication of ideals. This is all of the low hanging fruit that I can see from a GB implementation. I think this is ready for review. I have looked at your changes, and I think they are good. All that remains is for you to check mine.

tscrim commented 1 year ago

Reviewer: Travis Scrimshaw, Trevor K. Karn

tscrim commented 1 year ago

Changed author from Trevor K. Karn to Trevor K. Karn, Travis Scrimshaw

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

12d76e7Revert change in morphisms
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 698e051 to 12d76e7

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 12d76e7 to eada96a

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

ea9610dCaching the leading support FrozenBitset and Integer.
eada96aMerge branch 'public/algebras/exterior_groebner-34138' of https://github.com/sagemath/sagetrac-mirror into public/algebras/exterior_groebner-34138
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from eada96a to d21d2e8

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

d21d2e8Forgot to remove the Cython profiling directive.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from d21d2e8 to 5734555

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

5734555Fixing a number of small bugs and adding option for non-reduced GB.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

c01586dRevert with_basis/morphism.py.
8b777a0Fixing up doctests and some other compatibility issues.
ae696dbMerge branch 'public/algebras/exterior_algebra_index_set-32369' into public/algebras/exterior_groebner-34138
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 5734555 to ae696db

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

2637750Small doc tweak.
da58876Merge branch 'public/algebras/exterior_algebra_index_set-32369' into public/algebras/exterior_groebner-34138
140ac6cMigration of RAAG cohomology to Cython.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from ae696db to 140ac6c

tscrim commented 1 year ago
comment:22

This should fix the remaining doctest failures in groups/raag.py. The issue was that we can't override cdef _mul_ with def _mul_. That cohomology ring has a simple description of an exterior algebra modulo relations of the form e_i ^ e_j = 0. So that implementation likely could be improved as well, but that can be done on a followup ticket.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from 140ac6c to b227973

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

b227973Speeding up multiplication even further.
tscrim commented 1 year ago
comment:24

These changes now make this multiplication test twice as fast:

sage: E = ExteriorAlgebra(QQ, 'x', 10)
sage: r = sum(E.basis())
sage: %timeit r * r
57.2 ms ± 842 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

versus before

129 ms ± 700 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

e7e84b7Special casing multiplication by a term.
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Changed commit from b227973 to e7e84b7

tscrim commented 1 year ago
comment:26

Here is an improvement to multiplication by a single term:

sage: %timeit a * r
2.4 µs ± 34.9 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
sage: %timeit r * a
4.88 µs ± 76.6 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
sage: %timeit E(2) * r
5.51 µs ± 41.2 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
sage: %timeit r * E(2)
5.63 µs ± 63.1 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
sage: %timeit E(0) * r
1.05 µs ± 7.86 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
sage: %timeit r * E(0)
1.02 µs ± 5.09 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

versus b227973:

5.09 µs ± 64.5 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
6.43 µs ± 19.7 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
5.17 µs ± 19.9 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
8.1 µs ± 33.9 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
1.34 µs ± 6.96 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
1.76 µs ± 13.4 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

The difference with the left versus right is because we do not choose which term to slide past the other. We can maybe address that here, along with removing the code duplication I have introduced.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 1 year ago

Branch pushed to git repo; I updated commit sha1. New commits:

36b6b20Doing reduction in place; being careful about duplicates.