summary refs log tree commit diff
path: root/pkgs/applications/science
diff options
context:
space:
mode:
authorTimo Kaufmann <timokau@zoho.com>2018-10-20 01:34:34 +0200
committerGitHub <noreply@github.com>2018-10-20 01:34:34 +0200
commita413dedde117c7bc3dc76a91d36cb65c9c92a4a7 (patch)
tree8ebd46223309af2705e16a7e15809ebfcbe79242 /pkgs/applications/science
parentf6410997923daa61bf165eca2516df0e547f4846 (diff)
parent7ca1c31dfa561bf72444e5863ab35367839c2c9c (diff)
downloadnixlib-a413dedde117c7bc3dc76a91d36cb65c9c92a4a7.tar
nixlib-a413dedde117c7bc3dc76a91d36cb65c9c92a4a7.tar.gz
nixlib-a413dedde117c7bc3dc76a91d36cb65c9c92a4a7.tar.bz2
nixlib-a413dedde117c7bc3dc76a91d36cb65c9c92a4a7.tar.lz
nixlib-a413dedde117c7bc3dc76a91d36cb65c9c92a4a7.tar.xz
nixlib-a413dedde117c7bc3dc76a91d36cb65c9c92a4a7.tar.zst
nixlib-a413dedde117c7bc3dc76a91d36cb65c9c92a4a7.zip
Merge pull request #44527 from timokau/sage-8.4
[WIP] sage: 8.3 -> 8.4
Diffstat (limited to 'pkgs/applications/science')
-rw-r--r--pkgs/applications/science/math/sage/env-locations.nix1
-rw-r--r--pkgs/applications/science/math/sage/patches/dochtml-optional.patch127
-rw-r--r--pkgs/applications/science/math/sage/patches/eclib-20180710.patch24
-rw-r--r--pkgs/applications/science/math/sage/patches/pari-no-threads.patch18
-rw-r--r--pkgs/applications/science/math/sage/patches/singular-4.1.1p2.patch274
-rw-r--r--pkgs/applications/science/math/sage/patches/spkg-scripts.patch46
-rw-r--r--pkgs/applications/science/math/sage/patches/test-in-tmpdir.patch31
-rw-r--r--pkgs/applications/science/math/sage/sage-src.nix110
-rw-r--r--pkgs/applications/science/math/sage/sagelib.nix4
9 files changed, 7 insertions, 628 deletions
diff --git a/pkgs/applications/science/math/sage/env-locations.nix b/pkgs/applications/science/math/sage/env-locations.nix
index 288ffd6e0e1a..098ce3925cf3 100644
--- a/pkgs/applications/science/math/sage/env-locations.nix
+++ b/pkgs/applications/science/math/sage/env-locations.nix
@@ -38,6 +38,7 @@ writeTextFile rec {
     export COMBINATORIAL_DESIGN_DATA_DIR="${combinatorial_designs}/share/combinatorial_designs"
     export CREMONA_MINI_DATA_DIR="${elliptic_curves}/share/cremona"
     export JMOL_DIR="${jmol}"
+    export JSMOL_DIR="${jmol}/share/jsmol"
     export MATHJAX_DIR="${mathjax}/lib/node_modules/mathjax"
     export THREEJS_DIR="${three}/lib/node_modules/three"
     export SAGE_INCLUDE_DIRECTORIES="${cysignals}/lib/python2.7/site-packages"
diff --git a/pkgs/applications/science/math/sage/patches/dochtml-optional.patch b/pkgs/applications/science/math/sage/patches/dochtml-optional.patch
deleted file mode 100644
index a51e30312ed9..000000000000
--- a/pkgs/applications/science/math/sage/patches/dochtml-optional.patch
+++ /dev/null
@@ -1,127 +0,0 @@
-diff --git a/src/doc/common/conf.py b/src/doc/common/conf.py
-index 25f94f7b7d..9f6139ea4a 100644
---- a/src/doc/common/conf.py
-+++ b/src/doc/common/conf.py
-@@ -622,9 +622,9 @@ def call_intersphinx(app, env, node, contnode):
-     Check that the link from the thematic tutorials to the reference
-     manual is relative, see :trac:`20118`::
- 
--        sage: from sage.env import SAGE_DOC
--        sage: thematic_index = os.path.join(SAGE_DOC, "html", "en", "thematic_tutorials", "index.html")
--        sage: for line in open(thematic_index).readlines():
-+        sage: from sage.env import SAGE_DOC  # optional - dochtml
-+        sage: thematic_index = os.path.join(SAGE_DOC, "html", "en", "thematic_tutorials", "index.html")  # optional - dochtml
-+        sage: for line in open(thematic_index).readlines():  # optional - dochtml
-         ....:     if "padics" in line:
-         ....:         sys.stdout.write(line)
-         <li><a class="reference external" href="../reference/padics/sage/rings/padics/tutorial.html#sage-rings-padics-tutorial" title="(in Sage Reference Manual: p-Adics ...)"><span>Introduction to the -adics</span></a></li>
-diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py
-index 4236fd05e0..8e499cbaf7 100644
---- a/src/sage/doctest/control.py
-+++ b/src/sage/doctest/control.py
-@@ -87,7 +87,7 @@ class DocTestDefaults(SageObject):
-         self.sagenb = False
-         self.long = False
-         self.warn_long = None
--        self.optional = set(['sage']) | auto_optional_tags
-+        self.optional = set(['sage', 'dochtml']) | auto_optional_tags
-         self.randorder = None
-         self.global_iterations = 1  # sage-runtests default is 0
-         self.file_iterations = 1    # sage-runtests default is 0
-@@ -343,7 +343,8 @@ class DocTestController(SageObject):
-                     if not optionaltag_regex.search(o):
-                         raise ValueError('invalid optional tag {!r}'.format(o))
- 
--                options.optional |= auto_optional_tags
-+                if "sage" in options.optional:
-+                    options.optional |= auto_optional_tags
- 
-         self.options = options
-         self.files = args
-@@ -741,7 +742,7 @@ class DocTestController(SageObject):
-             sage: DC = DocTestController(DD, [dirname])
-             sage: DC.expand_files_into_sources()
-             sage: sorted(DC.sources[0].options.optional)  # abs tol 1
--            ['guava', 'magma', 'py3']
-+            ['guava', 'magma']
- 
-         We check that files are skipped appropriately::
- 
-@@ -968,7 +969,7 @@ class DocTestController(SageObject):
-             sage: from sage.doctest.control import DocTestDefaults, DocTestController
-             sage: DC = DocTestController(DocTestDefaults(), [])
-             sage: DC._optional_tags_string()
--            'sage'
-+            'dochtml,sage'
-             sage: DC = DocTestController(DocTestDefaults(optional="all,and,some,more"), [])
-             sage: DC._optional_tags_string()
-             'all'
-diff --git a/src/sage/misc/sagedoc.py b/src/sage/misc/sagedoc.py
-index 9255aa848f..cc4712d3ec 100644
---- a/src/sage/misc/sagedoc.py
-+++ b/src/sage/misc/sagedoc.py
-@@ -18,9 +18,9 @@ TESTS:
- Check that argspecs of extension function/methods appear correctly,
- see :trac:`12849`::
- 
--    sage: from sage.env import SAGE_DOC
--    sage: docfilename = os.path.join(SAGE_DOC, 'html', 'en', 'reference', 'calculus', 'sage', 'symbolic', 'expression.html')
--    sage: with open(docfilename) as fobj:
-+    sage: from sage.env import SAGE_DOC  # optional - dochtml
-+    sage: docfilename = os.path.join(SAGE_DOC, 'html', 'en', 'reference', 'calculus', 'sage', 'symbolic', 'expression.html')  # optional - dochtml
-+    sage: with open(docfilename) as fobj:  # optional - dochtml
-     ....:     for line in fobj:
-     ....:         if "#sage.symbolic.expression.Expression.numerical_approx" in line:
-     ....:             print(line)
-@@ -790,11 +790,12 @@ def _search_src_or_doc(what, string, extra1='', extra2='', extra3='',
- 
-     ::
- 
--        sage: len(_search_src_or_doc('src', r'matrix\(', 'incidence_structures', 'self', 'combinat', interact=False).splitlines()) > 1
-+        sage: from sage.misc.sagedoc import _search_src_or_doc  # optional - dochtml
-+        sage: len(_search_src_or_doc('src', r'matrix\(', 'incidence_structures', 'self', 'combinat', interact=False).splitlines()) > 1  # optional - dochtml
-         True
--        sage: 'abvar/homology' in _search_src_or_doc('doc', 'homology', 'variety', interact=False)  # long time (4s on sage.math, 2012)
-+        sage: 'abvar/homology' in _search_src_or_doc('doc', 'homology', 'variety', interact=False)  # optional - dochtml, long time (4s on sage.math, 2012)
-         True
--        sage: 'divisors' in _search_src_or_doc('src', '^ *def prime', interact=False)
-+        sage: 'divisors' in _search_src_or_doc('src', '^ *def prime', interact=False)  # optional - dochtml
-         True
-     """
-     # process keywords
-@@ -1160,9 +1161,9 @@ def search_doc(string, extra1='', extra2='', extra3='', extra4='',
-     counting the length of ``search_doc('tree',
-     interact=False).splitlines()`` gives the number of matches. ::
- 
--        sage: len(search_doc('tree', interact=False).splitlines()) > 4000  # long time
-+        sage: len(search_doc('tree', interact=False).splitlines()) > 4000  # optional - dochtml, long time
-         True
--        sage: len(search_doc('tree', whole_word=True, interact=False).splitlines()) < 2000  # long time
-+        sage: len(search_doc('tree', whole_word=True, interact=False).splitlines()) < 2000  # optional - dochtml, long time
-         True
-     """
-     return _search_src_or_doc('doc', string, extra1=extra1, extra2=extra2,
-@@ -1332,9 +1333,9 @@ class _sage_doc:
- 
-     EXAMPLES::
- 
--        sage: browse_sage_doc._open("reference", testing=True)[0]  # indirect doctest
-+        sage: browse_sage_doc._open("reference", testing=True)[0]  # optional - dochtml, indirect doctest
-         'http://localhost:8000/doc/live/reference/index.html'
--        sage: browse_sage_doc(identity_matrix, 'rst')[-107:-47]
-+        sage: browse_sage_doc(identity_matrix, 'rst')[-107:-47]  # optional - dochtml
-         'Full MatrixSpace of 3 by 3 sparse matrices over Integer Ring'
-     """
-     def __init__(self):
-@@ -1494,9 +1495,9 @@ class _sage_doc:
- 
-         EXAMPLES::
- 
--            sage: browse_sage_doc._open("reference", testing=True)[0]
-+            sage: browse_sage_doc._open("reference", testing=True)[0]  # optional - dochtml
-             'http://localhost:8000/doc/live/reference/index.html'
--            sage: browse_sage_doc._open("tutorial", testing=True)[1]
-+            sage: browse_sage_doc._open("tutorial", testing=True)[1]  # optional - dochtml
-             '.../html/en/tutorial/index.html'
-         """
-         url = self._base_url + os.path.join(name, "index.html")
diff --git a/pkgs/applications/science/math/sage/patches/eclib-20180710.patch b/pkgs/applications/science/math/sage/patches/eclib-20180710.patch
index d06e1e6cedf2..986ae42aeb62 100644
--- a/pkgs/applications/science/math/sage/patches/eclib-20180710.patch
+++ b/pkgs/applications/science/math/sage/patches/eclib-20180710.patch
@@ -14,27 +14,3 @@ index 4417b59276..ae57ca2991 100644
      """
      global instances
      try:
-diff --git a/src/sage/libs/eclib/wrap.cpp b/src/sage/libs/eclib/wrap.cpp
-index 5fd5693b53..d12468faa8 100644
---- a/src/sage/libs/eclib/wrap.cpp
-+++ b/src/sage/libs/eclib/wrap.cpp
-@@ -133,8 +133,8 @@ char* Curvedata_isogeny_class(struct Curvedata* E, int verbose)
- 
- 
- int mw_process(struct Curvedata* curve, struct mw* m,
--                      const struct bigint* x, const struct bigint* y,
--                      const struct bigint* z, int sat)
-+                      const bigint* x, const bigint* y,
-+                      const bigint* z, int sat)
- {
-   Point P(*curve, *x, *y, *z);
-   if (!P.isvalid())
-@@ -188,7 +188,7 @@ int mw_rank(struct mw* m)
- }
- 
- /* Returns index and unsat long array, which user must deallocate */
--int mw_saturate(struct mw* m, struct bigint* index, char** unsat,
-+int mw_saturate(struct mw* m, bigint* index, char** unsat,
-                        long sat_bd, int odd_primes_only)
- {
-   vector<long> v;
diff --git a/pkgs/applications/science/math/sage/patches/pari-no-threads.patch b/pkgs/applications/science/math/sage/patches/pari-no-threads.patch
deleted file mode 100644
index 13b47dbdd31b..000000000000
--- a/pkgs/applications/science/math/sage/patches/pari-no-threads.patch
+++ /dev/null
@@ -1,18 +0,0 @@
-diff --git a/src/sage/libs/pari/__init__.py b/src/sage/libs/pari/__init__.py
-index e451766474..77eda66097 100644
---- a/src/sage/libs/pari/__init__.py
-+++ b/src/sage/libs/pari/__init__.py
-@@ -205,6 +205,13 @@ def _get_pari_instance():
-     # messages in Sage.
-     P.default("debugmem", 0)
- 
-+    # Make sure pari doesn't use threads, regardless of how it was compiled.
-+    # Threads cause some doctest failures (memory issues). Those could probably
-+    # be solved without disabling threads. But that would require figuring out
-+    # some sensible values for `threadsizemax`. See
-+    # https://pari.math.u-bordeaux.fr/dochtml/html/GP_defaults.html
-+    P.default("nbthreads", 1)
-+
-     return P
- 
- pari = _get_pari_instance()
diff --git a/pkgs/applications/science/math/sage/patches/singular-4.1.1p2.patch b/pkgs/applications/science/math/sage/patches/singular-4.1.1p2.patch
deleted file mode 100644
index 4c8df92904ed..000000000000
--- a/pkgs/applications/science/math/sage/patches/singular-4.1.1p2.patch
+++ /dev/null
@@ -1,274 +0,0 @@
-diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py
-index 9d65c9fa6c..a028bbe719 100644
---- a/src/sage/interfaces/singular.py
-+++ b/src/sage/interfaces/singular.py
-@@ -654,7 +654,7 @@ class Singular(ExtraTabCompletion, Expect):
- 
-         s = Expect.eval(self, x, **kwds)
- 
--        if s.find("error") != -1 or s.find("Segment fault") != -1:
-+        if s.find("error occurred") != -1 or s.find("Segment fault") != -1:
-             raise SingularError('Singular error:\n%s'%s)
- 
-         if get_verbose() > 0:
-@@ -1079,7 +1079,7 @@ class Singular(ExtraTabCompletion, Expect):
-             sage: S = singular.ring('real', '(a,b)', 'lp')
-             sage: singular.current_ring()
-             polynomial ring, over a field, global ordering
--            //   coefficients: float
-+            //   coefficients: Float()
-             //   number of vars : 2
-             //        block   1 : ordering lp
-             //                  : names    a b
-@@ -1157,7 +1157,7 @@ class Singular(ExtraTabCompletion, Expect):
-              sage: singular._tab_completion()
-              ['exteriorPower',
-               ...
--              'flintZ']
-+              'crossprod']
-          """
-         p = re.compile("// *([a-z0-9A-Z_]*).*") #compiles regular expression
-         proclist = self.eval("listvar(proc)").splitlines()
-@@ -1183,7 +1183,7 @@ class Singular(ExtraTabCompletion, Expect):
-         EXAMPLES::
- 
-             sage: singular.version()
--            "Singular ... version 4.1.0 ...
-+            "Singular ... version 4...
-         """
-         return singular_version()
- 
-@@ -1562,7 +1562,7 @@ class SingularElement(ExtraTabCompletion, ExpectElement):
-         elif charstr[0] in ['0', 'QQ']:
-             from sage.all import QQ
-             br = QQ
--        elif charstr[0]=='real':
-+        elif charstr[0].startswith('Float'):
-             from sage.all import RealField, ceil, log
-             prec = singular.eval('ringlist(basering)[1][2][1]')
-             br = RealField(ceil((ZZ(prec)+1)/log(2,10)))
-@@ -1750,7 +1750,7 @@ class SingularElement(ExtraTabCompletion, ExpectElement):
- 
-         # Singular 4 puts parentheses around floats and sign outside them
-         charstr = self.parent().eval('charstr(basering)').split(',',1)
--        if charstr[0] in ['real', 'complex']:
-+        if charstr[0]=='complex' or charstr[0].startswith('Float'):
-               for i in range(coeff_start, 2 * coeff_start):
-                   singular_poly_list[i] = singular_poly_list[i].replace('(','').replace(')','')
- 
-@@ -1992,7 +1992,7 @@ class SingularElement(ExtraTabCompletion, ExpectElement):
-             sage: S = singular.ring('real', '(a,b)', 'lp')
-             sage: singular.current_ring()
-             polynomial ring, over a field, global ordering
--            //   coefficients: float
-+            //   coefficients: Float()
-             //   number of vars : 2
-             //        block   1 : ordering lp
-             //                  : names    a b
-@@ -2072,7 +2072,7 @@ class SingularElement(ExtraTabCompletion, ExpectElement):
-             sage: R._tab_completion()
-             ['exteriorPower',
-              ...
--             'flintZ']
-+             'crossprod']
-         """
-         return self.parent()._tab_completion()
- 
-@@ -2358,7 +2358,7 @@ def singular_version():
-     EXAMPLES::
- 
-         sage: singular.version()
--        "Singular ... version 4.1.0 ...
-+        "Singular ... version 4...
-     """
-     return singular.eval('system("--version");')
- 
-diff --git a/src/sage/libs/singular/decl.pxd b/src/sage/libs/singular/decl.pxd
-index 4b658c4807..d863740419 100644
---- a/src/sage/libs/singular/decl.pxd
-+++ b/src/sage/libs/singular/decl.pxd
-@@ -170,7 +170,7 @@ cdef extern from "singular/Singular/libsingular.h":
- 
-     int n_NumberOfParameters(const n_Procs_s* r)
- 
--    ctypedef struct poly "polyrec":
-+    ctypedef struct poly "spolyrec":
-         poly *next
-         number *coef
-         unsigned long exp[1]
-@@ -630,9 +630,13 @@ cdef extern from "singular/Singular/libsingular.h":
-     # return p*q, destroys p and q
-     poly *p_Mult_q(poly *p, poly *q, ring *r)
- 
-+    # polynomial division, ignoring the rest
-+    # via singclap_pdivide resp. idLift, destroys p,q
-+    poly *p_Divide(poly *p, poly *q, ring *r)
-+
-     # divide monomial p by monomial q, p,q const
- 
--    poly *pDivide(poly *p,poly *q)
-+    poly *pMDivide(poly *p,poly *q)
- 
-     # return the i-th power of p; p destroyed, requires global ring
- 
-diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
-index 2a8d9ae021..aeff53af6c 100644
---- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
-+++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
-@@ -190,8 +190,8 @@ from sage.libs.singular.decl cimport (
-     n_IsUnit, n_Invers,
-     p_ISet, rChangeCurrRing, p_Copy, p_Init, p_SetCoeff, p_Setm, p_SetExp, p_Add_q,
-     p_NSet, p_GetCoeff, p_Delete, p_GetExp, pNext, rRingVar, omAlloc0, omStrDup,
--    omFree, pDivide, p_SetCoeff0, n_Init, p_DivisibleBy, pLcm, p_LmDivisibleBy,
--    pDivide, p_IsConstant, p_ExpVectorEqual, p_String, p_LmInit, n_Copy,
-+    omFree, pMDivide, p_Divide, p_SetCoeff0, n_Init, p_DivisibleBy, pLcm, p_LmDivisibleBy,
-+    pMDivide, p_IsConstant, p_ExpVectorEqual, p_String, p_LmInit, n_Copy,
-     p_IsUnit, p_Series, p_Head, idInit, fast_map_common_subexp, id_Delete,
-     p_IsHomogeneous, p_Homogen, p_Totaldegree,pLDeg1_Totaldegree, singclap_pdivide, singclap_factorize,
-     idLift, IDELEMS, On, Off, SW_USE_CHINREM_GCD, SW_USE_EZGCD,
-@@ -1693,8 +1693,8 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base):
-         if not g._poly:
-             raise ZeroDivisionError
- 
--        if r!=currRing: rChangeCurrRing(r)  # pDivide
--        res = pDivide(f._poly, g._poly)
-+        if r!=currRing: rChangeCurrRing(r)  # pMDivide
-+        res = pMDivide(f._poly, g._poly)
-         if coeff:
-             if r.cf.type == n_unknown or r.cf.cfDivBy(p_GetCoeff(f._poly, r), p_GetCoeff(g._poly, r), r.cf):
-                 n = r.cf.cfDiv( p_GetCoeff(f._poly, r) , p_GetCoeff(g._poly, r), r.cf)
-@@ -1853,8 +1853,8 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base):
-                    and (<MPolynomial_libsingular>g) \
-                    and g.parent() is self \
-                    and p_LmDivisibleBy((<MPolynomial_libsingular>g)._poly, m, r):
--                if r!=currRing: rChangeCurrRing(r)  # pDivide
--                flt = pDivide(f._poly, (<MPolynomial_libsingular>g)._poly)
-+                if r!=currRing: rChangeCurrRing(r)  # pMDivide
-+                flt = pMDivide(f._poly, (<MPolynomial_libsingular>g)._poly)
-                 #p_SetCoeff(flt, n_Div( p_GetCoeff(f._poly, r) , p_GetCoeff((<MPolynomial_libsingular>g)._poly, r), r), r)
-                 p_SetCoeff(flt, n_Init(1, r), r)
-                 return new_MP(self,flt), g
-@@ -4023,16 +4023,6 @@ cdef class MPolynomial_libsingular(MPolynomial):
-             Traceback (most recent call last):
-             ...
-             NotImplementedError: Division of multivariate polynomials over non fields by non-monomials not implemented.
--
--        TESTS::
--
--            sage: P.<x,y> = ZZ[]
--            sage: p = 3*(-x^8*y^2 - x*y^9 + 6*x^8*y + 17*x^2*y^6 - x^3*y^2)
--            sage: q = 7*(x^2 + x*y + y^2 + 1)
--            sage: p*q//q == p
--            True
--            sage: p*q//p == q
--            True
-         """
-         cdef MPolynomialRing_libsingular parent = self._parent
-         cdef ring *r = self._parent_ring
-@@ -4052,13 +4042,18 @@ cdef class MPolynomial_libsingular(MPolynomial):
-         _right = <MPolynomial_libsingular>right
- 
-         if r.cf.type != n_unknown:
-+            if r.cf.type == n_Z:
-+                P = parent.change_ring(RationalField())
-+                f = P(self)//P(right)
-+                CM = list(f)
-+                return parent(sum([c.floor()*m for c,m in CM]))
-             if _right.is_monomial():
-                 p = _self._poly
-                 quo = p_ISet(0,r)
--                if r != currRing: rChangeCurrRing(r)   # pDivide
-+                if r != currRing: rChangeCurrRing(r)   # pMDivide
-                 while p:
-                     if p_DivisibleBy(_right._poly, p, r):
--                        temp = pDivide(p, _right._poly)
-+                        temp = pMDivide(p, _right._poly)
-                         p_SetCoeff0(temp, n_Copy(p_GetCoeff(p, r), r), r)
-                         quo = p_Add_q(quo, temp, r)
-                     p = pNext(p)
-@@ -4794,6 +4789,8 @@ cdef class MPolynomial_libsingular(MPolynomial):
-             sage: p = -x*y + x*z + 54*x - 2
-             sage: (5*p^2).lcm(3*p) == 15*p^2
-             True
-+            sage: lcm(2*x,2*x*y)
-+            2*x*y
-         """
-         cdef ring *_ring = self._parent_ring
-         cdef poly *ret
-@@ -4821,9 +4818,7 @@ cdef class MPolynomial_libsingular(MPolynomial):
-         if _ring!=currRing: rChangeCurrRing(_ring)  # singclap_gcd
-         gcd = singclap_gcd(p_Copy(self._poly, _ring), p_Copy(_g._poly, _ring), _ring )
-         prod = pp_Mult_qq(self._poly, _g._poly, _ring)
--        ret = singclap_pdivide(prod , gcd , _ring)
--        p_Delete(&prod, _ring)
--        p_Delete(&gcd, _ring)
-+        ret = p_Divide(prod, gcd, _ring)
-         if count >= 20:
-             sig_off()
-         return new_MP(self._parent, ret)
-@@ -4866,7 +4861,7 @@ cdef class MPolynomial_libsingular(MPolynomial):
-             sage: f.quo_rem(y)
-             (2*x^2, x + 1)
-             sage: f.quo_rem(3*x)
--            (2*x*y + 1, -4*x^2*y - 2*x + 1)
-+            (0, 2*x^2*y + x + 1)
- 
-         TESTS::
- 
-@@ -4888,7 +4883,7 @@ cdef class MPolynomial_libsingular(MPolynomial):
-         if right.is_zero():
-             raise ZeroDivisionError
- 
--        if not self._parent._base.is_field() and not is_IntegerRing(self._parent._base):
-+        if not self._parent._base.is_field():
-             py_quo = self//right
-             py_rem = self - right*py_quo
-             return py_quo, py_rem
-diff --git a/src/sage/rings/polynomial/plural.pyx b/src/sage/rings/polynomial/plural.pyx
-index d5439f7f08..ad20ebcca0 100644
---- a/src/sage/rings/polynomial/plural.pyx
-+++ b/src/sage/rings/polynomial/plural.pyx
-@@ -998,7 +998,7 @@ cdef class NCPolynomialRing_plural(Ring):
-         if not g._poly:
-             raise ZeroDivisionError
- 
--        res = pDivide(f._poly,g._poly)
-+        res = pMDivide(f._poly,g._poly)
-         if coeff:
-             if (r.cf.type == n_unknown) or r.cf.cfDivBy(p_GetCoeff(f._poly, r), p_GetCoeff(g._poly, r), r.cf):
-                 n = r.cf.cfDiv( p_GetCoeff(f._poly, r) , p_GetCoeff(g._poly, r), r.cf)
-@@ -1193,7 +1193,7 @@ cdef class NCPolynomialRing_plural(Ring):
-             if isinstance(g, NCPolynomial_plural) \
-                    and (<NCPolynomial_plural>g) \
-                    and p_LmDivisibleBy((<NCPolynomial_plural>g)._poly, m, r):
--                flt = pDivide(f._poly, (<NCPolynomial_plural>g)._poly)
-+                flt = pMDivide(f._poly, (<NCPolynomial_plural>g)._poly)
-                 #p_SetCoeff(flt, n_Div( p_GetCoeff(f._poly, r) , p_GetCoeff((<NCPolynomial_plural>g)._poly, r), r), r)
-                 p_SetCoeff(flt, n_Init(1, r), r)
-                 return new_NCP(self,flt), g
-diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py
-index 9331169f8b..f753610fd3 100644
---- a/src/sage/rings/polynomial/polynomial_singular_interface.py
-+++ b/src/sage/rings/polynomial/polynomial_singular_interface.py
-@@ -81,8 +81,8 @@ class PolynomialRing_singular_repr:
-             sage: R.<x,y> = PolynomialRing(CC)
-             sage: singular(R)
-             polynomial ring, over a field, global ordering
--            //   coefficients: float[I](complex:15 digits, additional 0 digits)/(I^2+1)
--            //   number of vars : 2
-+            // coefficients: real[I](complex:15 digits, additional 0 digits)/(I^2+1)
-+            // number of vars : 2
-             //        block   1 : ordering dp
-             //                  : names    x y
-             //        block   2 : ordering C
-@@ -90,8 +90,8 @@ class PolynomialRing_singular_repr:
-             sage: R.<x,y> = PolynomialRing(RealField(100))
-             sage: singular(R)
-             polynomial ring, over a field, global ordering
--            //   coefficients: float
--            //   number of vars : 2
-+            // coefficients: Float()
-+            // number of vars : 2
-             //        block   1 : ordering dp
-             //                  : names    x y
-             //        block   2 : ordering C
diff --git a/pkgs/applications/science/math/sage/patches/spkg-scripts.patch b/pkgs/applications/science/math/sage/patches/spkg-scripts.patch
deleted file mode 100644
index 4d37998b288b..000000000000
--- a/pkgs/applications/science/math/sage/patches/spkg-scripts.patch
+++ /dev/null
@@ -1,46 +0,0 @@
-commit f02714d4aea80e17cb8df62bab75d7c1a1b61a8e
-Author: Timo Kaufmann <timokau@zoho.com>
-Date:   Mon Jul 9 18:26:18 2018 +0200
-
-    Don't attempt to create dirs when showing pkg info
-    
-    The script dir cannot be assumed to be writeable after installation.
-
-diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg
-index f3e02aeae5..190d558ad1 100755
---- a/build/bin/sage-spkg
-+++ b/build/bin/sage-spkg
-@@ -167,14 +167,6 @@ if [ -z "$SAGE_BUILD_DIR" ]; then
-     export SAGE_BUILD_DIR="$SAGE_LOCAL/var/tmp/sage/build"
- fi
- 
--for dir in "$SAGE_SPKG_INST" "$SAGE_SPKG_SCRIPTS"; do
--    mkdir -p "$dir"
--    if [ $? -ne 0 ]; then
--        error_msg "Error creating directory $dir"
--        exit 1
--    fi
--done
--
- 
- # Remove '.' from PYTHONPATH, which may also come from SAGE_PATH, to avoid
- # trouble with setuptools / easy_install (cf. #10192, #10176):
-@@ -563,11 +555,13 @@ fi
- # Setup directories
- ##################################################################
- 
--mkdir -p "$SAGE_BUILD_DIR"
--if [ $? -ne 0 ]; then
--    error_msg "Error creating directory $SAGE_BUILD_DIR"
--    exit 1
--fi
-+for dir in "$SAGE_SPKG_INST" "$SAGE_SPKG_SCRIPTS" "$SAGE_BUILD_DIR"; do
-+    mkdir -p "$dir"
-+    if [ $? -ne 0 ]; then
-+        error_msg "Error creating directory $dir"
-+        exit 1
-+    fi
-+done
- 
- # Trac #5852: check write permissions
- if [ ! -w "$SAGE_BUILD_DIR" ]; then
diff --git a/pkgs/applications/science/math/sage/patches/test-in-tmpdir.patch b/pkgs/applications/science/math/sage/patches/test-in-tmpdir.patch
deleted file mode 100644
index febab3702771..000000000000
--- a/pkgs/applications/science/math/sage/patches/test-in-tmpdir.patch
+++ /dev/null
@@ -1,31 +0,0 @@
-diff --git a/src/sage/repl/ipython_kernel/install.py b/src/sage/repl/ipython_kernel/install.py
-index aa23c8405d..8a87de0591 100644
---- a/src/sage/repl/ipython_kernel/install.py
-+++ b/src/sage/repl/ipython_kernel/install.py
-@@ -112,7 +112,7 @@ class SageKernelSpec(object):
-         EXAMPLES::
- 
-             sage: from sage.repl.ipython_kernel.install import SageKernelSpec
--            sage: spec = SageKernelSpec()
-+            sage: spec = SageKernelSpec(prefix = tmp_dir())
-             sage: spec.use_local_mathjax()
-             sage: mathjax = os.path.join(spec.nbextensions_dir, 'mathjax')
-             sage: os.path.isdir(mathjax)
-@@ -129,7 +129,7 @@ class SageKernelSpec(object):
-         EXAMPLES::
- 
-             sage: from sage.repl.ipython_kernel.install import SageKernelSpec
--            sage: spec = SageKernelSpec()
-+            sage: spec = SageKernelSpec(prefix = tmp_dir())
-             sage: spec.use_local_jsmol()
-             sage: jsmol = os.path.join(spec.nbextensions_dir, 'jsmol')
-             sage: os.path.isdir(jsmol)
-@@ -146,7 +146,7 @@ class SageKernelSpec(object):
-         EXAMPLES::
- 
-             sage: from sage.repl.ipython_kernel.install import SageKernelSpec
--            sage: spec = SageKernelSpec()
-+            sage: spec = SageKernelSpec(prefix = tmp_dir())
-             sage: spec.use_local_threejs()
-             sage: threejs = os.path.join(spec.nbextensions_dir, 'threejs')
-             sage: os.path.isdir(threejs)
diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix
index f74da33f4026..f217a7a0caed 100644
--- a/pkgs/applications/science/math/sage/sage-src.nix
+++ b/pkgs/applications/science/math/sage/sage-src.nix
@@ -3,35 +3,17 @@
 , fetchpatch
 }:
 stdenv.mkDerivation rec {
-  version = "8.3";
+  version = "8.4";
   name = "sage-src-${version}";
 
   src = fetchFromGitHub {
     owner = "sagemath";
     repo = "sage";
     rev = version;
-    sha256 = "0mbm99m5xry21xpi4q3q96gx392liwbifywf5awvl0j85a7rkfyx";
+    sha256 = "0gips1hagiz9m7s21bg5as8hrrm2x5k47h1bsq0pc46iplfwmv2d";
   };
 
   nixPatches = [
-    # https://trac.sagemath.org/ticket/25809
-    ./patches/spkg-scripts.patch
-
-    # https://trac.sagemath.org/ticket/25309
-    (fetchpatch {
-      name = "spkg-paths.patch";
-      url = "https://git.sagemath.org/sage.git/patch/?h=97f06fddee920399d4fcda65aa9b0925774aec69&id=a86151429ccce1ddd085e8090ada8ebdf02f3310";
-      sha256 = "1xb9108rzzkdhn71vw44525620d3ww9jv1fph5a77v9y7nf9wgr7";
-    })
-    (fetchpatch {
-      name = "maxima-fas.patch";
-      url = "https://git.sagemath.org/sage.git/patch/?h=97f06fddee920399d4fcda65aa9b0925774aec69";
-      sha256 = "14s50yg3hpw9cp3v581dx7zfmpm2j972im7x30iwki8k45mjvk3i";
-    })
-
-    # https://trac.sagemath.org/ticket/25722
-    ./patches/test-in-tmpdir.patch
-
     # https://trac.sagemath.org/ticket/25358
     (fetchpatch {
       name = "safe-directory-test-without-patch.patch";
@@ -45,46 +27,9 @@ stdenv.mkDerivation rec {
     # https://trac.sagemath.org/ticket/25316
     # https://github.com/python/cpython/pull/7476
     ./patches/python-5755-hotpatch.patch
-
-    # https://trac.sagemath.org/ticket/25315
-    (fetchpatch {
-      name = "find-libraries-in-dyld-library-path.patch";
-      url = "https://git.sagemath.org/sage.git/patch/?h=20d4593876ce9c6004eac2ab6fd61786d0d96a06";
-      sha256 = "1k3afq3qlzmgqwx6rzs5wv153vv9dsf5rk8pi61g57l3r3npbjmc";
-    })
-
-    # https://trac.sagemath.org/ticket/25345
-    # (upstream patch doesn't apply on 8.2 source)
-    ./patches/dochtml-optional.patch
-
-    # work with pari with threads enabled at compile time (disable them at runtime)
-    # https://trac.sagemath.org/ticket/26002
-    ./patches/pari-no-threads.patch
   ];
 
   packageUpgradePatches = [
-    (fetchpatch {
-      name = "cypari2-1.2.1.patch";
-      url = "https://git.sagemath.org/sage.git/patch/?h=62fe6eb15111327d930336d4252d5b23cbb22ab9";
-      sha256 = "1xax7vvs8h4xip16xcsp47xdb6lig6f2r3pl8cksvlz8lhgbyxh2";
-    })
-
-    # matplotlib 2.2.2 deprecated `normed` (replaced by `density`).
-    # This patch only ignores the warning. It would be equally easy to fix it
-    # (by replacing all mentions of `normed` by `density`), but its better to
-    # stay close to sage upstream. I didn't open an upstream ticket about it
-    # because the matplotlib update also requires a new dependency (kiwisolver)
-    # and I don't want to invest the time to learn how to add it.
-    ./patches/matplotlib-normed-deprecated.patch
-
-    # Update to 20171219 broke the doctests because of insignificant precision
-    # changes, make the doctests less fragile.
-    # I didn't open an upstream ticket because its not entirely clear if
-    # 20171219 is really "released" yet. It is listed on the github releases
-    # page, but not marked as "latest release" and the homepage still links to
-    # the last version.
-    ./patches/eclib-regulator-precision.patch
-
     # New glpk version has new warnings, filter those out until upstream sage has found a solution
     # https://trac.sagemath.org/ticket/24824
     ./patches/pari-stackwarn.patch # not actually necessary since tha pari upgrade, but necessary for the glpk patch to apply
@@ -94,66 +39,15 @@ stdenv.mkDerivation rec {
       stripLen = 1;
     })
 
-    (fetchpatch {
-      name = "matplotlib-2.2.2";
-      url = "https://git.sagemath.org/sage.git/patch?id=0d6244ed53b71aba861ce3d683d33e542c0bf0b0";
-      sha256 = "15x4cadxxlsdfh2sblgagqjj6ir13fgdzixxnwnvzln60saahb34";
-    })
-
-    (fetchpatch {
-      name = "scipy-1.1.0";
-      url = "https://git.sagemath.org/sage.git/patch?id=e0db968a51678b34ebd8d34906c7042900272378";
-      sha256 = "0kq5zxqphhrmavrmg830wdr7hwp1bkzdqlf3jfqfr8r8xq12qwf7";
-    })
-
     # https://trac.sagemath.org/ticket/25260
     ./patches/numpy-1.15.1.patch
 
-    # https://trac.sagemath.org/ticket/25862
-    ./patches/eclib-20180710.patch
-
-    # https://trac.sagemath.org/ticket/24735
-    ./patches/singular-4.1.1p2.patch
-
-    # https://trac.sagemath.org/ticket/25567 and dependency #25635
-    (fetchpatch {
-      name = "pari-upgrade-dependency.patch";
-      url = "https://git.sagemath.org/sage.git/patch/?id=6995e7cae1b3476ad0145f8dfc897cf91f0c3c4d";
-      sha256 = "1dvhabl1c9pwd9xkjvbjjg15mvb14b24p1f3cby1mlqk34d4lrs6";
-    })
-    (fetchpatch {
-      name = "pari-2.11.0.patch";
-      url = "https://git.sagemath.org/sage.git/patch/?id=7af4748cab37d651eaa88be501db88f4a5ffc584";
-      sha256 = "13f740ly3c19gcmhjngiycvmc3mcfj61y00i6jv0wmfgpm2z3ank";
-    })
-
     # ntl upgrade
     (fetchpatch {
       name = "lcalc-c++11.patch";
       url = "https://git.archlinux.org/svntogit/community.git/plain/trunk/sagemath-lcalc-c++11.patch?h=packages/sagemath&id=0e31ae526ab7c6b5c0bfacb3f8b1c4fd490035aa";
       sha256 = "0p5wnvbx65i7cp0bjyaqgp4rly8xgnk12pqwaq3dqby0j2bk6ijb";
     })
-
-    # cddlib 0.94i -> 0.94j
-    (fetchpatch {
-      name = "cddlib-0.94j.patch";
-      url = "https://git.sagemath.org/sage.git/patch/?id=2ab1546b3e21d1d0ab3b4fcd58576848b3a2d888";
-      sha256 = "1c5gnasq7y9xxj762bn79bis0zi8d9bgg7jzlf64ifixsrc5cymb";
-    })
-
-    # arb 2.13.0 -> 2.14.0
-    (fetchpatch {
-      name = "arb-2.14.0.patch";
-      url = "https://git.sagemath.org/sage.git/patch?id2=8.4.beta0&id=8bef4fd2876a61969b516fe4eb3b8ad7cc076c5e";
-      sha256 = "00p3hfsfn3w2vxgd9fjd23mz7xfxjfravf8ysjxkyd657jbkpjmk";
-    })
-
-    # https://trac.sagemath.org/ticket/26117
-    (fetchpatch {
-      name = "sympy-1.2.patch";
-      url = "https://git.sagemath.org/sage.git/patch?id2=8.4.beta2&id=d94a0a3a3fb4aec05a6f4d95166d90c284f05c36";
-      sha256 = "0an2xl1pp3jg36kgg2m1vb7sns7rprk1h3d0qy1gxwdab6i7qnvi";
-    })
   ];
 
   patches = nixPatches ++ packageUpgradePatches ++ [
diff --git a/pkgs/applications/science/math/sage/sagelib.nix b/pkgs/applications/science/math/sage/sagelib.nix
index abcefba5e260..d26f5dad724e 100644
--- a/pkgs/applications/science/math/sage/sagelib.nix
+++ b/pkgs/applications/science/math/sage/sagelib.nix
@@ -47,6 +47,8 @@
 , singular
 , pip
 , jupyter_core
+, libhomfly
+, libbraiding
 }:
 
 buildPythonPackage rec {
@@ -109,6 +111,8 @@ buildPythonPackage rec {
     pip
     cython
     cysignals
+    libhomfly
+    libbraiding
   ];
 
   buildPhase = ''