Commits

Volker Braun committed 2bb7e4f

adedd group parent patch

Comments (0)

Files changed (13)

13579_secure_tmp.patch

-# HG changeset patch
-# User Jeroen Demeyer <jdemeyer@cage.ugent.be>
-# Date 1349687927 -7200
-# Node ID a9eaf717e609ed39dc52f30c7a3e9b58bfcc3c0e
-# Parent  91d3aa6f936e5689fe9f33127f3b935971012cdf
-Use tempfile for tmp_dir() and tmp_filename()
-
-diff --git a/sage/misc/interpreter.py b/sage/misc/interpreter.py
---- a/sage/misc/interpreter.py
-+++ b/sage/misc/interpreter.py
-@@ -380,7 +380,7 @@
-     """
-     import sage.misc.misc
-     name = os.path.abspath(name)
--    tmpfilename = os.path.abspath(sage.misc.misc.tmp_filename(name) + ".py")
-+    tmpfilename = sage.misc.misc.tmp_filename('preparse', ext='.py')
-     out = open(tmpfilename,'w')
-     preparse_file_named_to_stream(name, out)
-     out.close()
-diff --git a/sage/misc/misc.py b/sage/misc/misc.py
---- a/sage/misc/misc.py
-+++ b/sage/misc/misc.py
-@@ -1969,30 +1969,33 @@
- # temporary directory
- #################################################################
- 
--def tmp_dir(name='dir'):
-+import tempfile
-+
-+def tmp_dir(name="dir", ext=""):
-     r"""
-     Create and return a temporary directory in
-     ``$HOME/.sage/temp/hostname/pid/``
-+
-+    INPUT:
-+
-+    - ``name`` -- (default: "dir") A prefix for the directory name.
-+
-+    - ``ext`` -- (default: "") A suffix for the directory name.
-+
-+    OUTPUT: The absolute path of the temporary directory created.
-+
-+    EXAMPLES::
-+        
-+        sage: d = tmp_dir('dir_testing_', '.extension')
-+        sage: d  # random
-+        '/home/username/sage/temp/hostname/7961/dir_testing_XgRu4p.extension'
-+        sage: os.chdir(d)
-+        sage: _ = open('file_inside_d', 'w')
-+        sage: os.chdir(DOT_SAGE)
-+        sage: import shutil
-+        sage: shutil.rmtree(d)
-     """
--    name = str(name)
--    n = 0
--    while True:
--        tmp = "%s/%s_%s"%(SAGE_TMP, name, n)
--        if not os.path.exists(tmp):
--            break
--        n += 1
--    try:
--        os.makedirs(tmp)
--    except IOError:
--        # Put in local directory instead, e.g., because user doesn't
--        # have privileges to write in Sage's tmp directory.  That's OK.
--        n = 0
--        while True:
--            tmp = "/temp/tmp_%s_%s"%(name, n)
--            if not os.path.exists(tmp):
--                break
--            n += 1
--        os.makedirs(tmp)
-+    tmp = tempfile.mkdtemp(prefix=name, suffix=ext, dir=SAGE_TMP)
-     return os.path.abspath(tmp)
-     
- 
-@@ -2000,23 +2003,30 @@
- # temporary filename
- #################################################################
- 
--__tmp_n = 0
-+def tmp_filename(name="tmp", ext=""):
-+    r"""
-+    Create and return a temporary file in
-+    ``$HOME/.sage/temp/hostname/pid/``
- 
--def tmp_filename(name='tmp'):
--    name = list(str(name))
--    for i in range(len(name)):
--        # protect against paths with slashes, colons, etc
--        if not (name[i].isalpha() or name[i].isdigit()):
--            name[i] = '_'
--    name = ''.join(name)
-+    INPUT:
- 
--    global __tmp_n
--    while True:
--        tmp = "%s/%s_%s"%(SAGE_TMP, name, __tmp_n)
--        __tmp_n += 1
--        if not os.path.exists(tmp):
--            break
--    return tmp
-+    - ``name`` -- (default: "tmp") A prefix for the file name.
-+
-+    - ``ext`` -- (default: "") A suffix for the file name.
-+
-+    OUTPUT: The absolute path of the temporary file created.
-+
-+    EXAMPLES::
-+
-+        sage: fn = tmp_filename('just_for_testing_', '.extension')
-+        sage: fn  # random
-+        '/home/username/.sage/temp/hostname/8044/just_for_testing_tVVHsn.extension'
-+        sage: _ = open(fn, 'w')
-+        sage: os.unlink(fn)
-+    """
-+    handle, tmp = tempfile.mkstemp(prefix=name, suffix=ext, dir=SAGE_TMP)
-+    os.close(handle)
-+    return os.path.abspath(tmp)
- 
- def graphics_filename(ext='png'):
-     """

13681_sagelib.patch

+# HG changeset patch
+# User Jeroen Demeyer <jdemeyer@cage.ugent.be>
+# Date 1351972010 -3600
+# Node ID 12f48e5fe23d178a11d305e33a70917bcceaf93d
+# Parent  ac04c0a5230b1925f81c980d54b69319ba1100b3
+Use os.path.join() to construct temporary filenames
+
+diff --git a/sage/calculus/calculus.py b/sage/calculus/calculus.py
+--- a/sage/calculus/calculus.py
++++ b/sage/calculus/calculus.py
+@@ -1301,7 +1301,7 @@
+         629/8*e^(-4*t) + 91/8*e^(4*t)
+         sage: p1 = plot(xt,0,1/2,rgbcolor=(1,0,0))
+         sage: p2 = plot(yt,0,1/2,rgbcolor=(0,1,0))
+-        sage: (p1+p2).save(SAGE_TMP + "de_plot.png")
++        sage: (p1+p2).save(os.path.join(SAGE_TMP, "de_plot.png"))
+ 
+     Another example::
+ 
+diff --git a/sage/combinat/words/morphism.py b/sage/combinat/words/morphism.py
+--- a/sage/combinat/words/morphism.py
++++ b/sage/combinat/words/morphism.py
+@@ -563,7 +563,7 @@
+             <class 'sage.combinat.words.word.FiniteWord_iter_with_caching'>
+             sage: w == loads(dumps(w))
+             True
+-            sage: save(w, filename=SAGE_TMP + 'test.sobj')
++            sage: save(w, filename=os.path.join(SAGE_TMP, 'test.sobj'))
+ 
+         One may impose the datatype of the resulting word::
+ 
+diff --git a/sage/geometry/polytope.py b/sage/geometry/polytope.py
+--- a/sage/geometry/polytope.py
++++ b/sage/geometry/polytope.py
+@@ -50,7 +50,7 @@
+ if os.path.exists(path):
+     os.environ['PATH'] = '%s:'%path + os.environ['PATH']
+ 
+-tmp_file = '%s/tmp.poly'%SAGE_TMP
++tmp_file = os.path.join(SAGE_TMP, 'tmp.poly')
+ 
+ class Polytope(SageObject):
+     """
+diff --git a/sage/graphs/bipartite_graph.py b/sage/graphs/bipartite_graph.py
+--- a/sage/graphs/bipartite_graph.py
++++ b/sage/graphs/bipartite_graph.py
+@@ -202,7 +202,7 @@
+ 
+     5. From an alist file::
+ 
+-         sage: file_name = SAGE_TMP + 'deleteme.alist.txt'
++         sage: file_name = os.path.join(SAGE_TMP, 'deleteme.alist.txt')
+          sage: fi = open(file_name, 'w')
+          sage: fi.write("7 4 \n 3 4 \n 3 3 1 3 1 1 1 \n 3 3 3 4 \n\
+                          1 2 4 \n 1 3 4 \n 1 0 0 \n 2 3 4 \n\
+@@ -903,7 +903,7 @@
+ 
+         EXAMPLE::
+ 
+-            sage: file_name = SAGE_TMP + 'deleteme.alist.txt'
++            sage: file_name = os.path.join(SAGE_TMP, 'deleteme.alist.txt')
+             sage: fi = open(file_name, 'w')
+             sage: fi.write("7 4 \n 3 4 \n 3 3 1 3 1 1 1 \n 3 3 3 4 \n\
+                             1 2 4 \n 1 3 4 \n 1 0 0 \n 2 3 4 \n\
+@@ -999,7 +999,7 @@
+             [0 1 0 1 0 1 0]
+             [1 1 0 1 0 0 1]
+             sage: b = BipartiteGraph(M)
+-            sage: file_name = SAGE_TMP + 'deleteme.alist.txt'
++            sage: file_name = os.path.join(SAGE_TMP, 'deleteme.alist.txt')
+             sage: b.save_afile(file_name)
+             sage: b2 = BipartiteGraph(file_name)
+             sage: b == b2
+@@ -1007,7 +1007,7 @@
+ 
+         TESTS::
+ 
+-            sage: file_name = SAGE_TMP + 'deleteme.alist.txt'
++            sage: file_name = os.path.join(SAGE_TMP, 'deleteme.alist.txt')
+             sage: for order in range(3, 13, 3):
+             ...       num_chks = int(order / 3)
+             ...       num_vars = order - num_chks
+diff --git a/sage/gsl/ode.pyx b/sage/gsl/ode.pyx
+--- a/sage/gsl/ode.pyx
++++ b/sage/gsl/ode.pyx
+@@ -226,7 +226,7 @@
+         sage: T.function=f_1
+         sage: T.jacobian=j_1
+         sage: T.ode_solve(y_0=[1,0],t_span=[0,100],params=[10.0],num_points=1000)
+-        sage: outfile = SAGE_TMP + 'sage.png'
++        sage: outfile = os.path.join(SAGE_TMP, 'sage.png')
+         sage: T.plot_solution(filename=outfile)
+         
+     The solver line is equivalent to::
+@@ -316,7 +316,7 @@
+         sage: vander = van_der_pol()               # not tested
+         sage: T.function=vander                    # not tested
+         sage: T.ode_solve(y_0 = [1,0], t_span=[0,2000], num_points=1000)   # not tested
+-        sage: T.plot_solution(i=0, filename=SAGE_TMP + '/test.png')        # not tested
++        sage: T.plot_solution(i=0, filename=os.path.join(SAGE_TMP, 'test.png'))        # not tested
+ 
+ 
+     """
+diff --git a/sage/interfaces/cleaner.py b/sage/interfaces/cleaner.py
+--- a/sage/interfaces/cleaner.py
++++ b/sage/interfaces/cleaner.py
+@@ -15,16 +15,16 @@
+ import os
+ 
+ import sage.misc.misc as misc
+-F = '%s/spawned_processes'%misc.SAGE_TMP
+ 
+ def cleaner(pid, cmd=''):
+     if cmd != '':
+         cmd = cmd.strip().split()[0]
+     # This is safe, since only this process writes to this file.
++    F = os.path.join(misc.SAGE_TMP, 'spawned_processes')
+     if os.path.exists(F):
+         o = open(F,'a')
+     else:
+-        if not os.path.exists(misc.SAGE_TMP):
++        if not os.path.exists(str(misc.SAGE_TMP)):
+             return
+         o = open(F,'w')
+     o.write('%s %s\n'%(pid, cmd))
+diff --git a/sage/interfaces/expect.py b/sage/interfaces/expect.py
+--- a/sage/interfaces/expect.py
++++ b/sage/interfaces/expect.py
+@@ -72,21 +72,6 @@
+ 
+ failed_to_start = []
+ 
+-#tmp_expect_interface_local='%s/tmp'%SAGE_TMP_INTERFACE
+-
+-#def tmp_expect_interface_local():
+-#    return '%s/tmp'%SAGE_TMP_INTERFACE + str(os.getpid())
+-
+-## On some platforms, e.g., windows, this can easily take 10 seconds!?!  Terrible.  And
+-## it should not be necessary or used anyways. 
+-## def _absolute(cmd):
+-##     c = cmd.split()
+-##     s  = c[0]
+-##     t = os.popen('which %s'%s).read().strip()
+-##     if len(t) == 0:
+-##         raise RuntimeError
+-##     return ' '.join([t] + c[1:])
+-
+ # The subprocess is a shared resource.  In a multi-threaded
+ # environment, there would have to be a lock to control access to the
+ # subprocess.  Fortunately, Sage does not use Python threads.
+@@ -613,11 +598,10 @@
+         - Simon King (2010-09): Making the tmp-file unique for the interface instance
+ 
+         """
+-        #return '%s/tmp'%SAGE_TMP_INTERFACE + str(self.pid())
+         try:
+             return self.__local_tmpfile
+         except AttributeError:
+-            self.__local_tmpfile = '%s/tmp'%SAGE_TMP_INTERFACE + str(self.pid())
++            self.__local_tmpfile = os.path.join(SAGE_TMP_INTERFACE, 'tmp' + str(self.pid()))
+             return self.__local_tmpfile
+ 
+     def _remote_tmpdir(self):
+diff --git a/sage/interfaces/gap.py b/sage/interfaces/gap.py
+--- a/sage/interfaces/gap.py
++++ b/sage/interfaces/gap.py
+@@ -1026,7 +1026,7 @@
+         workspace file contains more than 82 characters) is fixed::
+ 
+             sage: ORIGINAL_WORKSPACE = sage.interfaces.gap.WORKSPACE
+-            sage: sage.interfaces.gap.WORKSPACE = SAGE_TMP + "gap" + "0"*(80-len(SAGE_TMP))
++            sage: sage.interfaces.gap.WORKSPACE = os.path.join(SAGE_TMP, "gap" + "0"*(80-len(SAGE_TMP)))
+             sage: gap = Gap()
+             sage: gap('3+2')
+             5
+diff --git a/sage/interfaces/gnuplot.py b/sage/interfaces/gnuplot.py
+--- a/sage/interfaces/gnuplot.py
++++ b/sage/interfaces/gnuplot.py
+@@ -176,7 +176,7 @@
+ 
+     def interact(self, cmd):
+         from sage.misc.all import SAGE_TMP
+-        file= '%s/gnuplot'%SAGE_TMP
++        file = os.path.join(SAGE_TMP, 'gnuplot')
+         open(file, 'w').write(cmd + '\n pause -1 "Press return to continue (no further rotation possible)"')
+         os.system('sage-native-execute gnuplot -persist %s'%file)
+ 
+diff --git a/sage/interfaces/magma.py b/sage/interfaces/magma.py
+--- a/sage/interfaces/magma.py
++++ b/sage/interfaces/magma.py
+@@ -1001,9 +1001,10 @@
+         
+         EXAMPLES::
+         
+-            sage: open(SAGE_TMP + 'a.m','w').write('function f(n) return n^2; end function;\nprint "hi";')
+-            sage: print magma.load(SAGE_TMP + 'a.m')      # optional - magma
+-            Loading ".../.sage//temp/.../a.m"
++            sage: filename = os.path.join(SAGE_TMP, 'a.m')
++            sage: open(filename, 'w').write('function f(n) return n^2; end function;\nprint "hi";')
++            sage: print magma.load(filename)      # optional - magma
++            Loading ".../tmp/.../a.m"
+             hi
+             sage: magma('f(12)')       # optional - magma
+             144
+diff --git a/sage/libs/mwrank/mwrank.pyx b/sage/libs/mwrank/mwrank.pyx
+--- a/sage/libs/mwrank/mwrank.pyx
++++ b/sage/libs/mwrank/mwrank.pyx
+@@ -117,8 +117,7 @@
+ 
+         sage: from sage.libs.mwrank.mwrank import get_precision
+         sage: get_precision()
+-	50
+-
++        50
+     """
+     return mwrank_get_precision()
+ 
+@@ -154,7 +153,7 @@
+ 
+     EXAMPLES::
+ 
+-        sage: file= SAGE_TMP + '/PRIMES'
++        sage: file = os.path.join(SAGE_TMP, 'PRIMES')
+         sage: open(file,'w').write(' '.join([str(p) for p in prime_range(10^7,10^7+20)]))
+         sage: mwrank_initprimes(file, verb=True)
+ 
+diff --git a/sage/matrix/matrix2.pyx b/sage/matrix/matrix2.pyx
+--- a/sage/matrix/matrix2.pyx
++++ b/sage/matrix/matrix2.pyx
+@@ -7333,7 +7333,7 @@
+         EXAMPLE::
+         
+             sage: M = random_matrix(CC, 4)
+-            sage: M.visualize_structure(SAGE_TMP + "matrix.png")
++            sage: M.visualize_structure(os.path.join(SAGE_TMP, "matrix.png"))
+         """
+         import gd
+         import os
+diff --git a/sage/misc/cython.py b/sage/misc/cython.py
+--- a/sage/misc/cython.py
++++ b/sage/misc/cython.py
+@@ -373,7 +373,7 @@
+     # This is the *temporary* directory where we build the pyx file.
+     # This is deleted when sage exits, which means pyx files must be
+     # rebuilt every time Sage is restarted at present.
+-    build_dir = '%s/%s'%(SPYX_TMP, base)
++    build_dir = os.path.join(SPYX_TMP, base)
+ 
+     if os.path.exists(build_dir):
+         # There is already a module here. Maybe we do not have to rebuild?
+diff --git a/sage/misc/dist.py b/sage/misc/dist.py
+--- a/sage/misc/dist.py
++++ b/sage/misc/dist.py
+@@ -70,7 +70,7 @@
+ 
+     EXAMPLES::
+ 
+-        sage: install_scripts(SAGE_TMP, ignore_existing=True)
++        sage: install_scripts(str(SAGE_TMP), ignore_existing=True)
+         Checking that Sage has the command 'gap' installed
+         ...
+     """
+diff --git a/sage/misc/latex.py b/sage/misc/latex.py
+--- a/sage/misc/latex.py
++++ b/sage/misc/latex.py
+@@ -2112,7 +2112,7 @@
+     EXAMPLES::
+ 
+         sage: from sage.misc.latex import png
+-        sage: png(ZZ[x], SAGE_TMP + "zz.png") # random - error if no latex
++        sage: png(ZZ[x], os.path.join(SAGE_TMP, "zz.png")) # random - error if no latex
+     """
+     if not pdflatex:
+         engine = "latex"
+diff --git a/sage/misc/misc.py b/sage/misc/misc.py
+--- a/sage/misc/misc.py
++++ b/sage/misc/misc.py
+@@ -135,15 +135,14 @@
+ 
+ #################################################
+ # Next we create the Sage temporary directory.
+-# It is called temp instead of tmp mainly for
+-# "historical reasons"...
++#################################################
+ 
+ SAGE_TMP = os.path.join(DOT_SAGE, 'tmp', HOSTNAME, str(os.getpid()))
+ sage_makedirs(SAGE_TMP)
+ 
+-SPYX_TMP = os.path.join(SAGE_TMP, 'spyx/')
++SPYX_TMP = os.path.join(SAGE_TMP, 'spyx')
+ 
+-SAGE_TMP_INTERFACE = os.path.join(SAGE_TMP, 'interface/')
++SAGE_TMP_INTERFACE = os.path.join(SAGE_TMP, 'interface')
+ sage_makedirs(SAGE_TMP_INTERFACE)
+ 
+ SAGE_DB = os.path.join(DOT_SAGE, 'db')
+diff --git a/sage/misc/sageinspect.py b/sage/misc/sageinspect.py
+--- a/sage/misc/sageinspect.py
++++ b/sage/misc/sageinspect.py
+@@ -1430,9 +1430,9 @@
+         source_lines = open(filename).readlines()
+     except IOError:
+         try:
+-            from sage.all import SAGE_TMP
++            from sage.misc.misc import SPYX_TMP
+             raw_name = filename.split('/')[-1]
+-            newname = SAGE_TMP+'/spyx/'+'_'.join(raw_name.split('_')[:-1])+'/'+raw_name
++            newname = os.path.join(SPYX_TMP, '_'.join(raw_name.split('_')[:-1]), raw_name)
+             source_lines = open(newname).readlines()
+         except IOError:
+             return None
+diff --git a/sage/misc/session.pyx b/sage/misc/session.pyx
+--- a/sage/misc/session.pyx
++++ b/sage/misc/session.pyx
+@@ -17,11 +17,11 @@
+ save your session permanently, since SAGE_TMP will be removed when
+ leaving Sage!::
+ 
+-    sage: save_session(SAGE_TMP+'session')
++    sage: save_session(os.path.join(SAGE_TMP, 'session'))
+ 
+ This saves a dictionary with $w$ as one of the keys::
+ 
+-    sage: z = load(SAGE_TMP+'session')
++    sage: z = load(os.path.join(SAGE_TMP, 'session'))
+     sage: z.keys()
+     ['w']
+     sage: z['w']
+@@ -32,7 +32,7 @@
+     sage: reset()
+     sage: show_identifiers()
+     []
+-    sage: load_session(SAGE_TMP+'session')
++    sage: load_session(os.path.join(SAGE_TMP, 'session'))
+ 
+ Indeed $w$ is now defined again.::
+ 
+diff --git a/sage/numerical/backends/coin_backend.pyx b/sage/numerical/backends/coin_backend.pyx
+--- a/sage/numerical/backends/coin_backend.pyx
++++ b/sage/numerical/backends/coin_backend.pyx
+@@ -1035,7 +1035,7 @@
+             1
+             sage: p.add_linear_constraint([(0, 1), (1, 2)], None, 3)          # optional - Coin
+             sage: p.set_objective([2, 5])                          # optional - Coin
+-            sage: p.write_mps(SAGE_TMP+"/lp_problem.mps", 0)       # optional - Coin
++            sage: p.write_mps(os.path.join(SAGE_TMP, "lp_problem.mps"), 0)       # optional - Coin
+         """
+ 
+         cdef char * mps = "mps"
+@@ -1057,7 +1057,7 @@
+             1
+             sage: p.add_linear_constraint([(0, 1), (1, 2)], None, 3)          # optional - Coin
+             sage: p.set_objective([2, 5])                          # optional - Coin
+-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")       # optional - Coin
++            sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp"))       # optional - Coin
+         """
+ 
+         cdef char * lp = "lp"
+diff --git a/sage/numerical/backends/cplex_backend.pyx b/sage/numerical/backends/cplex_backend.pyx
+--- a/sage/numerical/backends/cplex_backend.pyx
++++ b/sage/numerical/backends/cplex_backend.pyx
+@@ -1274,7 +1274,7 @@
+             1
+             sage: p.add_linear_constraint([(0, 1), (1, 2)], None, 3)          # optional - CPLEX
+             sage: p.set_objective([2, 5])                          # optional - CPLEX
+-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")            # optional - CPLEX
++            sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp"))            # optional - CPLEX
+         """
+ 
+         cdef int status
+@@ -1298,7 +1298,7 @@
+             1
+             sage: p.add_linear_constraint([(0, 1), (1, 2)], None, 3)          # optional - CPLEX
+             sage: p.set_objective([2, 5])                          # optional - CPLEX
+-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")            # optional - CPLEX
++            sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp"))            # optional - CPLEX
+         """
+ 
+         cdef int status
+diff --git a/sage/numerical/backends/generic_backend.pyx b/sage/numerical/backends/generic_backend.pyx
+--- a/sage/numerical/backends/generic_backend.pyx
++++ b/sage/numerical/backends/generic_backend.pyx
+@@ -554,7 +554,7 @@
+             2
+             sage: p.add_linear_constraint([(0, 1], (1, 2)], None, 3) # optional - Nonexistent_LP_solver
+             sage: p.set_objective([2, 5])                          # optional - Nonexistent_LP_solver
+-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")            # optional - Nonexistent_LP_solver
++            sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp"))            # optional - Nonexistent_LP_solver
+         """
+         raise NotImplementedError()
+ 
+@@ -574,7 +574,7 @@
+             2
+             sage: p.add_linear_constraint([(0, 1), (1, 2)], None, 3) # optional - Nonexistent_LP_solver
+             sage: p.set_objective([2, 5])                          # optional - Nonexistent_LP_solver
+-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")            # optional - Nonexistent_LP_solver
++            sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp"))            # optional - Nonexistent_LP_solver
+         """
+         raise NotImplementedError()
+ 
+diff --git a/sage/numerical/backends/glpk_backend.pyx b/sage/numerical/backends/glpk_backend.pyx
+--- a/sage/numerical/backends/glpk_backend.pyx
++++ b/sage/numerical/backends/glpk_backend.pyx
+@@ -1211,7 +1211,7 @@
+             1
+             sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)
+             sage: p.set_objective([2, 5])
+-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")
++            sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp"))
+         """
+         glp_write_lp(self.lp, NULL, filename)
+ 
+@@ -1231,7 +1231,7 @@
+             1
+             sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)
+             sage: p.set_objective([2, 5])
+-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")
++            sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp"))
+         """
+         glp_write_mps(self.lp, modern, NULL,  filename)
+ 
+diff --git a/sage/numerical/backends/gurobi_backend.pyx b/sage/numerical/backends/gurobi_backend.pyx
+--- a/sage/numerical/backends/gurobi_backend.pyx
++++ b/sage/numerical/backends/gurobi_backend.pyx
+@@ -1101,7 +1101,7 @@
+             1
+             sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)                # optional - Gurobi
+             sage: p.set_objective([2, 5])                                           # optional - Gurobi
+-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")                             # optional - Gurobi
++            sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp"))               # optional - Gurobi
+         """
+         check(self.env, GRBwrite(self.model[0], filename))
+ 
+@@ -1121,7 +1121,7 @@
+             1
+             sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)                # optional - Gurobi
+             sage: p.set_objective([2, 5])                                           # optional - Gurobi
+-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")                             # optional - Gurobi
++            sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp"))               # optional - Gurobi
+         """
+         check(self.env, GRBwrite(self.model[0], filename))
+ 
+diff --git a/sage/numerical/mip.pyx b/sage/numerical/mip.pyx
+--- a/sage/numerical/mip.pyx
++++ b/sage/numerical/mip.pyx
+@@ -724,7 +724,7 @@
+             sage: x = p.new_variable()
+             sage: p.set_objective(x[1] + x[2])
+             sage: p.add_constraint(-3*x[1] + 2*x[2], max=2,name="OneConstraint")
+-            sage: p.write_mps(SAGE_TMP+"/lp_problem.mps")
++            sage: p.write_mps(os.path.join(SAGE_TMP, "lp_problem.mps"))
+ 
+         For information about the MPS file format :
+         http://en.wikipedia.org/wiki/MPS_%28format%29
+@@ -749,7 +749,7 @@
+             sage: x = p.new_variable()
+             sage: p.set_objective(x[1] + x[2])
+             sage: p.add_constraint(-3*x[1] + 2*x[2], max=2)
+-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")
++            sage: p.write_lp(os.path.join(SAGE_TMP, "lp_problem.lp"))
+ 
+         For more information about the LP file format :
+         http://lpsolve.sourceforge.net/5.5/lp-format.htm
+diff --git a/sage/plot/plot3d/base.pyx b/sage/plot/plot3d/base.pyx
+--- a/sage/plot/plot3d/base.pyx
++++ b/sage/plot/plot3d/base.pyx
+@@ -1082,7 +1082,7 @@
+         # Tachyon resolution options
+         if DOCTEST_MODE:
+             opts = '-res 10 10'
+-            filename = sage.misc.misc.SAGE_TMP + "/tmp"
++            filename = os.path.join(sage.misc.misc.SAGE_TMP, "tmp")
+         elif EMBEDDED_MODE:
+             opts = '-res %s %s'%(figsize[0]*100, figsize[1]*100)
+             filename = sage.misc.temporary_file.graphics_filename()[:-4]
+diff --git a/sage/plot/plot3d/tachyon.py b/sage/plot/plot3d/tachyon.py
+--- a/sage/plot/plot3d/tachyon.py
++++ b/sage/plot/plot3d/tachyon.py
+@@ -314,7 +314,7 @@
+         import sage.plot.plot
+         if sage.plot.plot.DOCTEST_MODE:
+             filename = graphics_filename()
+-            self.save(SAGE_TMP + '/test.png', verbose=verbose, extra_opts=extra_opts)
++            self.save(os.path.join(SAGE_TMP, 'test.png'), verbose=verbose, extra_opts=extra_opts)
+             return
+         if sage.plot.plot.EMBEDDED_MODE:
+             filename = graphics_filename()
+diff --git a/sage/plot/text.py b/sage/plot/text.py
+--- a/sage/plot/text.py
++++ b/sage/plot/text.py
+@@ -232,7 +232,7 @@
+ 
+     You can save text as part of PDF output::
+ 
+-        sage: text("sage", (0,0), rgbcolor=(0,0,0)).save(SAGE_TMP + 'a.pdf')
++        sage: text("sage", (0,0), rgbcolor=(0,0,0)).save(os.path.join(SAGE_TMP, 'a.pdf'))
+ 
+     Text must be 2D (use the text3d command for 3D text)::
+ 
+diff --git a/sage/server/notebook/notebook.py b/sage/server/notebook/notebook.py
+--- a/sage/server/notebook/notebook.py
++++ b/sage/server/notebook/notebook.py
+@@ -1180,7 +1180,7 @@
+         
+         ::
+ 
+-            sage: savefile = SAGE_TMP + 'tmp.sws'
++            sage: savefile = os.path.join(SAGE_TMP, 'tmp.sws')
+         
+             sage: nb.export_worksheet(W.filename(),  savefile, verbose=False)
+         
+diff --git a/sage/structure/sage_object.pyx b/sage/structure/sage_object.pyx
+--- a/sage/structure/sage_object.pyx
++++ b/sage/structure/sage_object.pyx
+@@ -185,8 +185,8 @@
+         EXAMPLES::
+         
+             sage: f = x^3 + 5
+-            sage: f.save(SAGE_TMP + '/file')
+-            sage: load(SAGE_TMP + '/file.sobj')
++            sage: f.save(os.path.join(SAGE_TMP, 'file'))
++            sage: load(os.path.join(SAGE_TMP, 'file.sobj'))
+             x^3 + 5
+         """
+         if filename is None:
+@@ -814,8 +814,8 @@
+     EXAMPLES::
+     
+         sage: a = matrix(2, [1,2,3,-5/2])
+-        sage: objfile = SAGE_TMP + 'test.sobj'
+-        sage: objfile_short = SAGE_TMP + 'test'
++        sage: objfile = os.path.join(SAGE_TMP, 'test.sobj')
++        sage: objfile_short = os.path.join(SAGE_TMP, 'test')
+         sage: save(a, objfile)
+         sage: load(objfile_short)
+         [   1    2]
+@@ -823,14 +823,14 @@
+         sage: E = EllipticCurve([-1,0])
+         sage: P = plot(E)
+         sage: save(P, objfile_short)   # saves the plot to "test.sobj"
+-        sage: save(P, filename=SAGE_TMP + "sage.png", xmin=-2)
+-        sage: save(P, SAGE_TMP + "filename.with.some.wrong.ext")
++        sage: save(P, filename=os.path.join(SAGE_TMP, "sage.png"), xmin=-2)
++        sage: save(P, os.path.join(SAGE_TMP, "filename.with.some.wrong.ext"))
+         Traceback (most recent call last):
+         ...
+         ValueError: allowed file extensions for images are '.eps', '.pdf', '.png', '.ps', '.sobj', '.svg'!
+         sage: print load(objfile)
+         Graphics object consisting of 2 graphics primitives
+-        sage: save("A python string", SAGE_TMP + 'test')
++        sage: save("A python string", os.path.join(SAGE_TMP, 'test'))
+         sage: load(objfile)
+         'A python string'
+         sage: load(objfile_short)
+@@ -840,7 +840,7 @@
+ 
+     Check that #11577 is fixed::
+ 
+-        sage: filename = SAGE_TMP + "foo.bar" # filename containing a dot
++        sage: filename = os.path.join(SAGE_TMP, "foo.bar")  # filename containing a dot
+         sage: save((1,1),filename)            # saves tuple to "foo.bar.sobj"
+         sage: load(filename)
+         (1, 1)
 trac_13650_base_ring.patch
 trac_13650_normalize_coefficients.patch
 trac_12091_constraints_parents.patch
-13579_secure_tmp.patch
-trac_13579_fix_test_executable.patch
 trac_13211_fix_gap_doctests.patch
 trac_13211_pool_size.patch
+trac_13211_itanium_fix.patch
+trac_13211_quit_after_workspace.patch
+13681_sagelib.patch
 trac_6391_libGAP.patch
 trac_13588_improve_libGAP.patch
+trac_13687_Parent_for_groups.patch
 trac_11395_update_gfan.patch
 trac11395-fix_tutorial.patch
 trac_11395_doctest_fix.patch
 trac_13638_ray_adjacency_fix.patch
 trac_11763-polyhedra_coercion_folded.2.patch
 trac_11763_fix_associahedron.patch
+trac_11763_lazy_import.patch
 trac_13312_polyhedral_neg_polar.patch
 trac12215_weak_cached_function.patch    #+SimonKing
 trac12215_segfault_fixes.patch          #+SimonKing
 trac_11667_use_groebner_basis_with_degree_bound.patch  #+todo
 trac_11559_fix_Chow_group.patch   #+todo maybe delete
 trac_11763_ZZ_polyhedron.patch          #+todo
-trac_11763_parents_for_polyhedron.patch #+todo
 trac_12193_fix_dimension.patch
 trac_12553_ppl_count_points.patch
 trac_12553_ppl_lattice_polytope.patch

trac_11763-polyhedra_coercion_folded.2.patch

 # User Volker Braun <vbraun@stp.dias.ie>
 # Date 1315501129 14400
 # Node ID 72fa3dd63afb47e375297e85483bc1358eacf998
-# Parent 1b1e12bf62ad00310f4a66f4b9d1d0b93e1c038b
+# Parent 8df636d1b8e0ec623ce4e4fa60540419d71176a6
 Trac #11763: Add ZZ as allowed base ring for polyhedra
 * * *
 Trac #11763: Parents for polyhedra
 diff --git a/sage/geometry/polyhedron/constructor.py b/sage/geometry/polyhedron/constructor.py
 --- a/sage/geometry/polyhedron/constructor.py
 +++ b/sage/geometry/polyhedron/constructor.py
+@@ -12,7 +12,7 @@
+     finite number of
+ 
+         * linear inequalities `A \vec{x} + b \geq 0`, and
+-        * linear equations  `C \vec{x} + d \geq 0`.
++        * linear equations  `C \vec{x} + d = 0`.
+ 
+ 
+ **V(ertex)-representation**
 @@ -21,13 +21,13 @@
      polyhedron is then the Minkowski sum
  

trac_11763_lazy_import.patch

+# HG changeset patch
+# Parent c6f0386fe64054ecf920477e9c312bba111e6b01
+
+Lazily import Polyhedron
+
+diff --git a/sage/categories/all.py b/sage/categories/all.py
+--- a/sage/categories/all.py
++++ b/sage/categories/all.py
+@@ -129,4 +129,5 @@
+ from classical_crystals import ClassicalCrystals
+ 
+ # polyhedra
+-from polyhedra import PolyhedralSets
++from sage.misc.lazy_import import lazy_import
++lazy_import('sage.categories.polyhedra', 'PolyhedralSets')
+diff --git a/sage/geometry/polyhedron/all.py b/sage/geometry/polyhedron/all.py
+--- a/sage/geometry/polyhedron/all.py
++++ b/sage/geometry/polyhedron/all.py
+@@ -1,5 +1,5 @@
+ 
++from sage.misc.lazy_import import lazy_import
++lazy_import('sage.geometry.polyhedron.constructor', 'Polyhedron')
++lazy_import('sage.geometry.polyhedron.library', 'polytopes')
+ 
+-from constructor import Polyhedron
+-from library import polytopes
+-

trac_11763_parents_for_polyhedron.patch

-# HG changeset patch
-# Parent c6ab6420b9ba645d56eb4aeaf3bfc117700b604a
-# HG changeset patch
-# Parent c6ab6420b9ba645d56eb4aeaf3bfc117700b604a
-
-Trac #11763: Add parents for polyhedra
-diff --git a/sage/categories/all.py b/sage/categories/all.py
---- a/sage/categories/all.py
-+++ b/sage/categories/all.py
-@@ -127,3 +127,6 @@
- from highest_weight_crystals import HighestWeightCrystals
- from finite_crystals import FiniteCrystals
- from classical_crystals import ClassicalCrystals
-+
-+# polyhedra
-+from polyhedra import PolyhedralSets
-diff --git a/sage/categories/polyhedra.py b/sage/categories/polyhedra.py
-new file mode 100644
---- /dev/null
-+++ b/sage/categories/polyhedra.py
-@@ -0,0 +1,75 @@
-+r"""
-+Polyhedral subsets of free ZZ, QQ or RR-modules.
-+"""
-+#*****************************************************************************
-+#       Copyright (C) 2011 Volker Braun <vbraun.name@gmail.com>
-+#
-+#  Distributed under the terms of the GNU General Public License (GPL)
-+#                  http://www.gnu.org/licenses/
-+#******************************************************************************
-+
-+from sage.structure.element_wrapper import ElementWrapper
-+from sage.categories.category_types import Category_over_base_ring
-+from sage.misc.cachefunc import cached_method
-+from sage.categories.category import HomCategory
-+
-+
-+
-+class PolyhedralSets(Category_over_base_ring):
-+    r"""
-+    The category of Polyhedra over a ring.
-+
-+    EXAMPLES:
-+
-+    We create the category of polyhedra over `\QQ`::
-+
-+        sage: PolyhedralSets(QQ)
-+        Category of Polyhedra over Rational Field
-+
-+    TESTS::
-+
-+        sage: TestSuite(PolyhedralSets(RDF)).run()
-+
-+        sage: P = Polyhedron()
-+        sage: P.parent().category().element_class
-+        <class 'sage.categories.category.PolyhedralSets.element_class'>
-+        sage: P.parent().category().element_class.mro()
-+        [<class 'sage.categories.category.PolyhedralSets.element_class'>,
-+         <class 'sage.categories.magmas.Magmas.element_class'>,
-+         <class 'sage.categories.additive_magmas.AdditiveMagmas.element_class'>,
-+         <class 'sage.categories.sets_cat.Sets.element_class'>,
-+         <class 'sage.categories.category.SetsWithPartialMaps.element_class'>,
-+         <class 'sage.categories.objects.Objects.element_class'>,
-+         <type 'object'>]
-+        sage: isinstance(P, P.parent().category().element_class)
-+        True
-+    """
-+
-+    def __init__(self, R):
-+        """
-+        TESTS::
-+
-+            sage: PolyhedralSets((1,2,3))
-+            Traceback (most recent call last):
-+            ...
-+            TypeError: base ring R (=(1, 2, 3)) must be ZZ, QQ, or RDF.
-+        """
-+        from sage.rings.all import ZZ, QQ, RDF
-+        if R not in [ZZ, QQ, RDF]:
-+            raise TypeError, 'base ring R (='+str(R)+') must be ZZ, QQ, or RDF.'
-+        Category_over_base_ring.__init__(self, R, 'Polyhedra')
-+
-+    @cached_method
-+    def super_categories(self):
-+        """
-+        EXAMPLES::
-+
-+            sage: PolyhedralSets(QQ).super_categories()
-+            [Category of magmas, Category of additive magmas]
-+        """
-+        from sage.categories.all import Magmas, AdditiveMagmas
-+        return [Magmas(), AdditiveMagmas()]
-+
-+
-+
-+
-diff --git a/sage/geometry/cone.py b/sage/geometry/cone.py
---- a/sage/geometry/cone.py
-+++ b/sage/geometry/cone.py
-@@ -144,7 +144,7 @@
-     sage: four_rays.lattice_polytope()
-     A lattice polytope: 3-dimensional, 5 vertices.
-     sage: four_rays.polyhedron()
--    A 3-dimensional polyhedron in QQ^3 defined as
-+    A 3-dimensional polyhedron in ZZ^3 defined as
-     the convex hull of 1 vertex and 4 rays
- 
- And of course you are always welcome to suggest new features that should be
-@@ -532,7 +532,10 @@
-         V = lattice.base_extend(QQ)
-         for n, ray in enumerate(rays):
-             try:
--                ray = V(ray)
-+                if isinstance(ray, (list, tuple, V._element_class)):
-+                    ray = V(ray)
-+                else:
-+                    ray = V(list(ray))
-             except TypeError:
-                 raise TypeError("cannot convert %s to %s!" % (ray, V))
-             if ray.is_zero():
-@@ -2876,18 +2879,18 @@
- 
-             sage: quadrant = Cone([(1,0), (0,1)])
-             sage: quadrant.polyhedron()
--            A 2-dimensional polyhedron in QQ^2 defined as the convex hull
-+            A 2-dimensional polyhedron in ZZ^2 defined as the convex hull
-             of 1 vertex and 2 rays
-             sage: line = Cone([(1,0), (-1,0)])
-             sage: line.polyhedron()
--            A 1-dimensional polyhedron in QQ^2 defined as the convex hull
-+            A 1-dimensional polyhedron in ZZ^2 defined as the convex hull
-             of 1 vertex and 1 line
-             
-         Here is an example of a trivial cone (see Trac #10237)::
-         
-             sage: origin = Cone([], lattice=ZZ^2)
-             sage: origin.polyhedron()
--            A 0-dimensional polyhedron in QQ^2 defined as the convex hull
-+            A 0-dimensional polyhedron in ZZ^2 defined as the convex hull
-             of 1 vertex
-         """
-         if "_polyhedron" not in self.__dict__:
-diff --git a/sage/geometry/integral_points.pyx b/sage/geometry/integral_points.pyx
---- a/sage/geometry/integral_points.pyx
-+++ b/sage/geometry/integral_points.pyx
-@@ -266,7 +266,7 @@
-     
-         sage: v = [(1,0,7,-1), (-2,-2,4,-3), (-1,-1,-1,4), (2,9,0,-5), (-2,-1,5,1)]
-         sage: simplex = Polyhedron(v); simplex
--        A 4-dimensional polyhedron in QQ^4 defined as the convex hull of 5 vertices
-+        A 4-dimensional polyhedron in ZZ^4 defined as the convex hull of 5 vertices
-         sage: pts = simplex_points(simplex.Vrepresentation())
-         sage: len(pts)
-         49
-@@ -279,7 +279,7 @@
-         
-         sage: v = [(4,-1,-1,-1), (-1,4,-1,-1), (-1,-1,4,-1), (-1,-1,-1,4), (-1,-1,-1,-1)]
-         sage: P4mirror = Polyhedron(v); P4mirror
--        A 4-dimensional polyhedron in QQ^4 defined as the convex hull of 5 vertices
-+        A 4-dimensional polyhedron in ZZ^4 defined as the convex hull of 5 vertices
-         sage: len( simplex_points(P4mirror.Vrepresentation()) )
-         126
-     """
-@@ -878,7 +878,7 @@
-         max_abs_coordinates = permutation.action(max_abs_coordinates)
-         self.ineqs_int = []
-         self.ineqs_generic = []
--        if not polyhedron:
-+        if polyhedron is None:
-             return
-         for Hrep_obj in polyhedron.inequality_generator():
-             A, b = self._make_A_b(Hrep_obj, permutation)
-diff --git a/sage/geometry/polyhedron/backend_cdd.py b/sage/geometry/polyhedron/backend_cdd.py
---- a/sage/geometry/polyhedron/backend_cdd.py
-+++ b/sage/geometry/polyhedron/backend_cdd.py
-@@ -10,12 +10,6 @@
- from base import Polyhedron_base
- from base_QQ import Polyhedron_QQ
- from base_RDF import Polyhedron_RDF
--from representation import (
--    PolyhedronRepresentation,
--    Hrepresentation,
--    Inequality, Equation,
--    Vrepresentation,
--    Vertex, Ray, Line )
- 
- 
- 
-@@ -25,14 +19,12 @@
-     Base class for the cdd backend.
-     """
- 
--    def _init_from_Vrepresentation(self, ambient_dim, vertices, rays, lines, verbose=False):
-+    def _init_from_Vrepresentation(self, vertices, rays, lines, verbose=False):
-         """
-         Construct polyhedron from V-representation data.
- 
-         INPUT:
- 
--        - ``ambient_dim`` -- integer. The dimension of the ambient space.
--        
-         - ``vertices`` -- list of point. Each point can be specified
-            as any iterable container of
-            :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
-@@ -51,7 +43,7 @@
-         EXAMPLES::
- 
-             sage: Polyhedron(vertices=[(0,0)], rays=[(1,1)],
--            ...              lines=[(1,-1)], backend='cddr')  # indirect doctest
-+            ...              lines=[(1,-1)], backend='cdd', base_ring=QQ)  # indirect doctest
-             A 2-dimensional polyhedron in QQ^2 defined as the
-             convex hull of 1 vertex, 1 ray, 1 line
-         """
-@@ -60,14 +52,12 @@
-         self._init_from_cdd_input(s, '--reps', verbose)
- 
- 
--    def _init_from_Hrepresentation(self, ambient_dim, ieqs, eqns, verbose=False):
-+    def _init_from_Hrepresentation(self, ieqs, eqns, verbose=False):
-         """
-         Construct polyhedron from H-representation data.
- 
-         INPUT:
- 
--        - ``ambient_dim`` -- integer. The dimension of the ambient space.
--        
-         - ``ieqs`` -- list of inequalities. Each line can be specified
-           as any iterable container of
-           :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
-@@ -82,7 +72,7 @@
-         EXAMPLES::
- 
-             sage: Polyhedron(ieqs=[(0,1,1)], eqns=[(0,1,-1)],
--            ...              backend='cddr')  # indirect doctest
-+            ...              backend='cdd', base_ring=QQ)  # indirect doctest
-             A 1-dimensional polyhedron in QQ^2 defined as the
-             convex hull of 1 vertex and 1 ray
-         """
-@@ -98,7 +88,7 @@
- 
-         EXAMPLES::
-         
--            sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], backend='cddr')
-+            sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], backend='cdd', base_ring=QQ)
-             sage: '_H_adjacency_matrix' in p.__dict__
-             False
-             sage: p._init_facet_adjacency_matrix()
-@@ -118,7 +108,7 @@
- 
-         EXAMPLES::
-         
--            sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], backend='cddr')
-+            sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], backend='cdd', base_ring=QQ)
-             sage: '_V_adjacency_matrix' in p.__dict__
-             False
-             sage: p._init_vertex_adjacency_matrix()
-@@ -138,7 +128,7 @@
- 
-         TESTS::
-         
--            sage: p = Polyhedron(vertices = [[0,0,0],[1,0,0],[0,1,0],[0,0,1]], backend='cddr')
-+            sage: p = Polyhedron(vertices = [[0,0,0],[1,0,0],[0,1,0],[0,0,1]], backend='cdd', base_ring=QQ)
-             sage: from sage.geometry.polyhedron.cdd_file_format import cdd_Vrepresentation
-             sage: s = cdd_Vrepresentation('rational', [[0,0,1],[0,1,0],[1,0,0]], [], [])
-             sage: p._init_from_cdd_input(s)
-@@ -168,13 +158,14 @@
-             sage: from subprocess import Popen, PIPE
-             sage: cdd_proc = Popen(['cdd_both_reps_gmp', '--all'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
-             sage: ans, err = cdd_proc.communicate(input=s)
--            sage: p = Polyhedron(vertices = [[0,0],[1,0],[0,1],[1,1]], backend='cddr')
-+            sage: p = Polyhedron(vertices = [[0,0],[1,0],[0,1],[1,1]], backend='cdd', base_ring=QQ)
-             sage: p._init_from_cdd_output(ans)
-             sage: p.vertices()
--            [[0, 0], [1, 0], [0, 1], [1, 1]]
-+            (A vertex at (0, 0), A vertex at (1, 0), A vertex at (0, 1), A vertex at (1, 1))
-         """
-         cddout=cdd_output_string.splitlines()
-         suppressed_vertex = False   # whether cdd suppressed the vertex in output
-+        parent = self.parent()
- 
-         # nested function
-         def expect_in_cddout(expected_string):
-@@ -219,22 +210,22 @@
-             lines = cdd_linearities()
-             expect_in_cddout('begin')
-             l = cddout.pop(0).split()
--            assert self._ambient_dim == int(l[1])-1,  "Different ambient dimension?"
-+            assert self.ambient_dim() == int(l[1])-1,  "Different ambient dimension?"
-             suppressed_vertex = True
-             for i in range(int(l[0])):
-                 l = cddout.pop(0).strip()
-                 l_type = l[0]
-                 l = l[1:]
-                 if i in lines:
--                    Line(self, cdd_convert(l));
-+                    parent._make_Line(self, cdd_convert(l));
-                 elif l_type == '0':
--                    Ray(self, cdd_convert(l));
-+                    parent._make_Ray(self, cdd_convert(l));
-                 else:
--                    Vertex(self, cdd_convert(l));
-+                    parent._make_Vertex(self, cdd_convert(l));
-                     suppressed_vertex = False
-             if suppressed_vertex and self.n_Vrepresentation()>0:
-                 # cdd does not output the vertex if it is only the origin
--                Vertex(self, [0] * self._ambient_dim)
-+                parent._make_Vertex(self, [0] * self.ambient_dim())
-             self._Vrepresentation = tuple(self._Vrepresentation)
-             expect_in_cddout('end')
-         
-@@ -243,13 +234,13 @@
-             equations = cdd_linearities()
-             expect_in_cddout('begin')
-             l = cddout.pop(0).split()
--            assert self._ambient_dim == int(l[1])-1, "Different ambient dimension?"
-+            assert self.ambient_dim() == int(l[1])-1, "Different ambient dimension?"
-             for i in range(int(l[0])):
-                 l = cddout.pop(0)
-                 if i in equations:
--                    Equation(self, cdd_convert(l));
-+                    parent._make_Equation(self, cdd_convert(l));
-                 else:
--                    Inequality(self, cdd_convert(l));
-+                    parent._make_Inequality(self, cdd_convert(l));
-             self._Hrepresentation = tuple(self._Hrepresentation)
-             expect_in_cddout('end')
- 
-@@ -306,16 +297,19 @@
- 
-     INPUT:
- 
--    - ``ambient_dim`` -- integer. The dimension of the ambient space.
-+    - ``parent`` -- the parent, an instance of
-+      :class:`~sage.geometry.polyhedron.parent.Polyhedra`.
- 
--    - ``Vrep`` -- a list ``[vertices, rays, lines]``.
-+    - ``Vrep`` -- a list ``[vertices, rays, lines]`` or ``None``.
-         
--    - ``Hrep`` -- a list ``[ieqs, eqns]``.
-+    - ``Hrep`` -- a list ``[ieqs, eqns]`` or ``None``.
- 
-     EXAMPLES::
- 
-+        sage: from sage.geometry.polyhedron.parent import Polyhedra
-+        sage: parent = Polyhedra(QQ, 2, backend='cdd')
-         sage: from sage.geometry.polyhedron.backend_cdd import Polyhedron_QQ_cdd
--        sage: Polyhedron_QQ_cdd(2, [ [(1,0),(0,1),(0,0)], [], []], None, verbose=False)
-+        sage: Polyhedron_QQ_cdd(parent, [ [(1,0),(0,1),(0,0)], [], []], None, verbose=False)
-         A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices
-     """
- 
-@@ -323,7 +317,7 @@
- 
-     _cdd_executable = 'cdd_both_reps_gmp'
- 
--    def __init__(self, ambient_dim, Vrep, Hrep, **kwds):
-+    def __init__(self, parent, Vrep, Hrep, **kwds):
-         """
-         The Python constructor.
- 
-@@ -332,12 +326,12 @@
- 
-         TESTS::
-         
--            sage: p = Polyhedron(backend='cddr')
-+            sage: p = Polyhedron(backend='cdd', base_ring=QQ)
-             sage: type(p)
--            <class 'sage.geometry.polyhedron.backend_cdd.Polyhedron_QQ_cdd'>
-+            <class 'sage.geometry.polyhedron.backend_cdd.Polyhedra_QQ_cdd_with_category.element_class'>
-             sage: TestSuite(p).run()
-         """
--        Polyhedron_cdd.__init__(self, ambient_dim, Vrep, Hrep, **kwds)
-+        Polyhedron_cdd.__init__(self, parent, Vrep, Hrep, **kwds)
-     
- 
- #########################################################################
-@@ -349,21 +343,23 @@
- 
-     - ``ambient_dim`` -- integer. The dimension of the ambient space.
- 
--    - ``Vrep`` -- a list ``[vertices, rays, lines]``.
-+    - ``Vrep`` -- a list ``[vertices, rays, lines]`` or ``None``.
-         
--    - ``Hrep`` -- a list ``[ieqs, eqns]``.
-+    - ``Hrep`` -- a list ``[ieqs, eqns]`` or ``None``.
- 
-     EXAMPLES::
- 
-+        sage: from sage.geometry.polyhedron.parent import Polyhedra
-+        sage: parent = Polyhedra(RDF, 2, backend='cdd')
-         sage: from sage.geometry.polyhedron.backend_cdd import Polyhedron_RDF_cdd
--        sage: Polyhedron_RDF_cdd(2, [ [(1,0),(0,1),(0,0)], [], []], None, verbose=False)
-+        sage: Polyhedron_RDF_cdd(parent, [ [(1,0),(0,1),(0,0)], [], []], None, verbose=False)
-         A 2-dimensional polyhedron in RDF^2 defined as the convex hull of 3 vertices
-     """
-     _cdd_type = 'real'
-     
-     _cdd_executable = 'cdd_both_reps'
- 
--    def __init__(self, ambient_dim, Vrep, Hrep, **kwds):
-+    def __init__(self, parent, Vrep, Hrep, **kwds):
-         """
-         The Python constructor.
- 
-@@ -372,10 +368,10 @@
- 
-         TESTS::
-         
--            sage: p = Polyhedron(backend='cddf')
-+            sage: p = Polyhedron(backend='cdd', base_ring=RDF)
-             sage: type(p)
--            <class 'sage.geometry.polyhedron.backend_cdd.Polyhedron_RDF_cdd'>
-+            <class 'sage.geometry.polyhedron.backend_cdd.Polyhedra_RDF_cdd_with_category.element_class'>
-             sage: TestSuite(p).run()
-         """
--        Polyhedron_cdd.__init__(self, ambient_dim, Vrep, Hrep, **kwds)
-+        Polyhedron_cdd.__init__(self, parent, Vrep, Hrep, **kwds)
-     
-diff --git a/sage/geometry/polyhedron/backend_ppl.py b/sage/geometry/polyhedron/backend_ppl.py
---- a/sage/geometry/polyhedron/backend_ppl.py
-+++ b/sage/geometry/polyhedron/backend_ppl.py
-@@ -3,7 +3,7 @@
- """
- 
- from sage.rings.all import ZZ, QQ
--from sage.rings.arith import lcm
-+from sage.rings.integer import LCM_list
- from sage.misc.functional import denominator
- from sage.matrix.constructor import matrix
- from sage.libs.ppl import (
-@@ -14,13 +14,6 @@
- from base import Polyhedron_base
- from base_QQ import Polyhedron_QQ
- from base_ZZ import Polyhedron_ZZ
--from representation import (
--    PolyhedronRepresentation,
--    Hrepresentation,
--    Inequality, Equation,
--    Vrepresentation,
--    Vertex, Ray, Line )
--
- 
- 
- #########################################################################
-@@ -30,11 +23,9 @@
- 
-     INPUT:
- 
--    - ``ambient_dim`` -- integer. The dimension of the ambient space.
--
--    - ``Vrep`` -- a list ``[vertices, rays, lines]``.
-+    - ``Vrep`` -- a list ``[vertices, rays, lines]`` or ``None``.
-         
--    - ``Hrep`` -- a list ``[ieqs, eqns]``.
-+    - ``Hrep`` -- a list ``[ieqs, eqns]`` or ``None``.
- 
-     EXAMPLES::
- 
-@@ -42,14 +33,12 @@
-         sage: TestSuite(p).run()
-     """
- 
--    def _init_from_Vrepresentation(self, ambient_dim, vertices, rays, lines, minimize=True):
-+    def _init_from_Vrepresentation(self, vertices, rays, lines, minimize=True):
-         """
-         Construct polyhedron from V-representation data.
- 
-         INPUT:
- 
--        - ``ambient_dim`` -- integer. The dimension of the ambient space.
--        
-         - ``vertices`` -- list of point. Each point can be specified
-            as any iterable container of
-            :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
-@@ -66,36 +55,45 @@
- 
-             sage: p = Polyhedron(backend='ppl')
-             sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_ppl
--            sage: Polyhedron_ppl._init_from_Vrepresentation(p, 2, [], [], [])
-+            sage: Polyhedron_ppl._init_from_Vrepresentation(p, [], [], [])
-         """
-         gs = Generator_System()
-         if vertices is None: vertices = []
-         for v in vertices:
--            d = lcm([denominator(v_i) for v_i in v])
--            dv = [ ZZ(d*v_i) for v_i in v ]
--            gs.insert(point(Linear_Expression(dv, 0), d))
-+            d = LCM_list([denominator(v_i) for v_i in v])
-+            if d.is_one():
-+                gs.insert(point(Linear_Expression(v, 0)))
-+            else:
-+                dv = [ d*v_i for v_i in v ]
-+                gs.insert(point(Linear_Expression(dv, 0), d))
-         if rays is None: rays = []
-         for r in rays:
--            d = lcm([denominator(r_i) for r_i in r])
--            dr = [ ZZ(d*r_i) for r_i in r ]
--            gs.insert(ray(Linear_Expression(dr, 0)))
-+            d = LCM_list([denominator(r_i) for r_i in r])
-+            if d.is_one():
-+                gs.insert(ray(Linear_Expression(r, 0)))
-+            else:
-+                dr = [ d*r_i for r_i in r ]
-+                gs.insert(ray(Linear_Expression(dr, 0)))
-         if lines is None: lines = []
-         for l in lines:
--            d = lcm([denominator(l_i) for l_i in l])
--            dl = [ ZZ(d*l_i) for l_i in l ]
--            gs.insert(line(Linear_Expression(dl, 0)))
--        self._ppl_polyhedron = C_Polyhedron(gs)
-+            d = LCM_list([denominator(l_i) for l_i in l])
-+            if d.is_one():
-+                gs.insert(line(Linear_Expression(l, 0)))
-+            else:
-+                dl = [ d*l_i for l_i in l ]
-+                gs.insert(line(Linear_Expression(dl, 0)))
-+        if gs.empty():
-+            self._ppl_polyhedron = C_Polyhedron(self.ambient_dim(), 'empty')
-+        else:
-+            self._ppl_polyhedron = C_Polyhedron(gs)
-         self._init_Vrepresentation_from_ppl(minimize)
-         self._init_Hrepresentation_from_ppl(minimize)
- 
--
--    def _init_from_Hrepresentation(self, ambient_dim, ieqs, eqns, minimize=True):
-+    def _init_from_Hrepresentation(self, ieqs, eqns, minimize=True):
-         """
-         Construct polyhedron from H-representation data.
- 
-         INPUT:
--
--        - ``ambient_dim`` -- integer. The dimension of the ambient space.
-         
-         - ``ieqs`` -- list of inequalities. Each line can be specified
-           as any iterable container of
-@@ -109,28 +107,30 @@
- 
-             sage: p = Polyhedron(backend='ppl')
-             sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_ppl
--            sage: Polyhedron_ppl._init_from_Hrepresentation(p, 2, [], [])
-+            sage: Polyhedron_ppl._init_from_Hrepresentation(p, [], [])
-         """
-         cs = Constraint_System()
-         if ieqs is None: ieqs = []
-         for ieq in ieqs:
--            d = lcm([denominator(ieq_i) for ieq_i in ieq])
-+            d = LCM_list([denominator(ieq_i) for ieq_i in ieq])
-             dieq = [ ZZ(d*ieq_i) for ieq_i in ieq ]
-             b = dieq[0]
-             A = dieq[1:]
-             cs.insert(Linear_Expression(A, b) >= 0)
-         if eqns is None: eqns = []
-         for eqn in eqns:
--            d = lcm([denominator(eqn_i) for eqn_i in eqn])
-+            d = LCM_list([denominator(eqn_i) for eqn_i in eqn])
-             deqn = [ ZZ(d*eqn_i) for eqn_i in eqn ]
-             b = deqn[0]
-             A = deqn[1:]
-             cs.insert(Linear_Expression(A, b) == 0)
--        self._ppl_polyhedron = C_Polyhedron(cs)
-+        if cs.empty():
-+            self._ppl_polyhedron = C_Polyhedron(self.ambient_dim(), 'universe')
-+        else:
-+            self._ppl_polyhedron = C_Polyhedron(cs)
-         self._init_Vrepresentation_from_ppl(minimize)
-         self._init_Hrepresentation_from_ppl(minimize)
- 
--        
-     def _init_Vrepresentation_from_ppl(self, minimize):
-         """
-         Create the Vrepresentation objects from the ppl polyhedron.
-@@ -152,19 +152,22 @@
-         """
-         self._Vrepresentation = []
-         gs = self._ppl_polyhedron.minimized_generators()
-+        parent = self.parent()
-         for g in gs:
-             if g.is_point():
-                 d = g.divisor()
--                Vertex(self, [x/d for x in g.coefficients()])
-+                if d.is_one():
-+                    parent._make_Vertex(self, g.coefficients())
-+                else:
-+                    parent._make_Vertex(self, [x/d for x in g.coefficients()])
-             elif g.is_ray():
--                Ray(self, g.coefficients())
-+                parent._make_Ray(self, g.coefficients())
-             elif g.is_line():
--                Line(self, g.coefficients())
-+                parent._make_Line(self, g.coefficients())
-             else:
-                 assert False
-         self._Vrepresentation = tuple(self._Vrepresentation)
-         
--
-     def _init_Hrepresentation_from_ppl(self, minimize):
-         """
-         Create the Vrepresentation objects from the ppl polyhedron.
-@@ -186,37 +189,32 @@
-         """
-         self._Hrepresentation = []
-         cs = self._ppl_polyhedron.minimized_constraints()
-+        parent = self.parent()
-         for c in cs:
-             if c.is_inequality():
--                Inequality(self, (c.inhomogeneous_term(),) + c.coefficients())
-+                parent._make_Inequality(self, (c.inhomogeneous_term(),) + c.coefficients())
-             elif c.is_equality():
--                Equation(self, (c.inhomogeneous_term(),) + c.coefficients())
-+                parent._make_Equation(self, (c.inhomogeneous_term(),) + c.coefficients())
-         self._Hrepresentation = tuple(self._Hrepresentation)
--        
- 
--    def _init_empty_polyhedron(self, ambient_dim):
-+    def _init_empty_polyhedron(self):
-         """
-         Initializes an empty polyhedron.
- 
--        INPUT:
--
--        - ``ambient_dim`` -- integer. The dimension of the ambient space.
--
-         TESTS::
- 
-             sage: empty = Polyhedron(backend='ppl'); empty
--            The empty polyhedron in QQ^0
-+            The empty polyhedron in ZZ^0
-             sage: empty.Vrepresentation()
-             ()
-             sage: empty.Hrepresentation()
-             (An equation -1 == 0,)
-             sage: Polyhedron(vertices = [], backend='ppl')
--            The empty polyhedron in QQ^0
--            sage: Polyhedron(backend='ppl')._init_empty_polyhedron(0)
-+            The empty polyhedron in ZZ^0
-+            sage: Polyhedron(backend='ppl')._init_empty_polyhedron()
-         """
--        super(Polyhedron_ppl, self)._init_empty_polyhedron(ambient_dim)
--        self._ppl_polyhedron = C_Polyhedron(ambient_dim, 'empty')
--
-+        super(Polyhedron_ppl, self)._init_empty_polyhedron()
-+        self._ppl_polyhedron = C_Polyhedron(self.ambient_dim(), 'empty')
- 
- 
- 
-@@ -227,11 +225,9 @@
- 
-     INPUT:
- 
--    - ``ambient_dim`` -- integer. The dimension of the ambient space.
-+    - ``Vrep`` -- a list ``[vertices, rays, lines]`` or ``None``.
- 
--    - ``Vrep`` -- a list ``[vertices, rays, lines]``.
--
--    - ``Hrep`` -- a list ``[ieqs, eqns]``.
-+    - ``Hrep`` -- a list ``[ieqs, eqns]`` or ``None``.
- 
-     EXAMPLES::
- 
-@@ -249,11 +245,9 @@
- 
-     INPUT:
- 
--    - ``ambient_dim`` -- integer. The dimension of the ambient space.
-+    - ``Vrep`` -- a list ``[vertices, rays, lines]`` or ``None``.
- 
--    - ``Vrep`` -- a list ``[vertices, rays, lines]``.
--
--    - ``Hrep`` -- a list ``[ieqs, eqns]``.
-+    - ``Hrep`` -- a list ``[ieqs, eqns]`` or ``None``.
- 
-     EXAMPLES::
- 
-diff --git a/sage/geometry/polyhedron/base.py b/sage/geometry/polyhedron/base.py
---- a/sage/geometry/polyhedron/base.py
-+++ b/sage/geometry/polyhedron/base.py
-@@ -13,7 +13,7 @@
- ########################################################################
- 
- 
--from sage.structure.sage_object import SageObject
-+from sage.structure.element import Element, coerce_binop, is_Vector
- 
- from sage.misc.all import union, cached_method, prod
- from sage.misc.package import is_package_installed
-@@ -33,12 +33,6 @@
- from sage.groups.perm_gps.permgroup_named import AlternatingGroup
- 
- from constructor import Polyhedron
--from representation import (
--    PolyhedronRepresentation,
--    Hrepresentation,
--    Inequality, Equation,
--    Vrepresentation,
--    Vertex, Ray, Line )
- 
- 
- #########################################################################
-@@ -55,6 +49,7 @@
- #
- #  * You can of course also override any other method for which you
- #    have a faster implementation.
-+#########################################################################
- 
- 
- #########################################################################
-@@ -83,13 +78,14 @@
- 
- 
- #########################################################################
--class Polyhedron_base(SageObject):
-+class Polyhedron_base(Element):
-     """
-     Base class for Polyhedron objects
- 
-     INPUT:
- 
--    - ``ambient_dim`` -- integer. The dimension of the ambient space.
-+    - ``parent`` -- the parent, an instance of
-+      :class:`~sage.geometry.polyhedron.parent.Polyhedra`.
- 
-     - ``Vrep`` -- a list `[vertices, rays, lines]`` or ``None``. The
-       V-representation of the polyhedron. If ``None``, the polyhedron
-@@ -107,7 +103,7 @@
-         sage: TestSuite(p).run()
-     """
- 
--    def __init__(self, ambient_dim, Vrep, Hrep, **kwds):
-+    def __init__(self, parent, Vrep, Hrep, **kwds):
-         """
-         Initializes the polyhedron.
- 
-@@ -118,27 +114,22 @@
- 
-             sage: p = Polyhedron()    # indirect doctests
-         """
--        self._ambient_dim = ambient_dim
-+        Element.__init__(self, parent=parent)
-         if Vrep is not None:
-             vertices, rays, lines = Vrep
--            if len(vertices)==0:
--                vertices = [[0] * ambient_dim]
--            self._init_from_Vrepresentation(ambient_dim, vertices, rays, lines, **kwds)
-+            self._init_from_Vrepresentation(vertices, rays, lines, **kwds)
-         elif Hrep is not None:
-             ieqs, eqns = Hrep
--            self._init_from_Hrepresentation(ambient_dim, ieqs, eqns, **kwds)
-+            self._init_from_Hrepresentation(ieqs, eqns, **kwds)
-         else:
--            self._init_empty_polyhedron(ambient_dim)
--
--
--    def _init_from_Vrepresentation(self, ambient_dim, vertices, rays, lines, **kwds):
-+            self._init_empty_polyhedron()
-+
-+    def _init_from_Vrepresentation(self, vertices, rays, lines, **kwds):
-         """
-         Construct polyhedron from V-representation data.
- 
-         INPUT:
- 
--        - ``ambient_dim`` -- integer. The dimension of the ambient space.
--        
-         - ``vertices`` -- list of point. Each point can be specified
-            as any iterable container of
-            :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
-@@ -155,22 +146,19 @@
- 
-             sage: p = Polyhedron()
-             sage: from sage.geometry.polyhedron.base import Polyhedron_base
--            sage: Polyhedron_base._init_from_Vrepresentation(p, 2, [], [], [])
-+            sage: Polyhedron_base._init_from_Vrepresentation(p, [], [], [])
-             Traceback (most recent call last):
-             ...
-             NotImplementedError: A derived class must implement this method.
-         """
-         raise NotImplementedError('A derived class must implement this method.')
- 
--
--    def _init_from_Hrepresentation(self, ambient_dim, ieqs, eqns, **kwds):
-+    def _init_from_Hrepresentation(self, ieqs, eqns, **kwds):
-         """
-         Construct polyhedron from H-representation data.
- 
-         INPUT:
- 
--        - ``ambient_dim`` -- integer. The dimension of the ambient space.
--        
-         - ``ieqs`` -- list of inequalities. Each line can be specified
-           as any iterable container of
-           :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
-@@ -183,48 +171,47 @@
- 
-             sage: p = Polyhedron()
-             sage: from sage.geometry.polyhedron.base import Polyhedron_base
--            sage: Polyhedron_base._init_from_Hrepresentation(p, 2, [], [])
-+            sage: Polyhedron_base._init_from_Hrepresentation(p, [], [])
-             Traceback (most recent call last):
-             ...
-             NotImplementedError: A derived class must implement this method.
-         """
-         raise NotImplementedError('A derived class must implement this method.')
- 
--
--    def _init_empty_polyhedron(self, ambient_dim):
-+    def _init_empty_polyhedron(self):
-         """
-         Initializes an empty polyhedron.
- 
--        INPUT:
--
--        - ``ambient_dim`` -- integer. The dimension of the ambient space.
--
-         TESTS::
- 
-             sage: empty = Polyhedron(); empty
--            The empty polyhedron in QQ^0
-+            The empty polyhedron in ZZ^0
-             sage: empty.Vrepresentation()
-             ()
-             sage: empty.Hrepresentation()
-             (An equation -1 == 0,)
-             sage: Polyhedron(vertices = [])
--            The empty polyhedron in QQ^0
--            sage: Polyhedron()._init_empty_polyhedron(0)
-+            The empty polyhedron in ZZ^0
-+            sage: Polyhedron(vertices = [])._init_empty_polyhedron()
-+            sage: from sage.geometry.polyhedron.parent import Polyhedra
-+            sage: Polyhedra(QQ,7)()
-+            A 0-dimensional polyhedron in QQ^7 defined as the convex hull of 1 vertex
-         """
-         self._Vrepresentation = []
-         self._Hrepresentation = []
--        Equation(self, [-1] + [0]*ambient_dim);
-+        self.parent()._make_Equation(self, [-1] + [0]*self.ambient_dim());
-         self._Vrepresentation = tuple(self._Vrepresentation)
-         self._Hrepresentation = tuple(self._Hrepresentation)
- 
--        self._V_adjacency_matrix = matrix(ZZ, 0, 0, 0)
--        self._V_adjacency_matrix.set_immutable()
--
--        self._H_adjacency_matrix = matrix(ZZ, 1, 1, 0)
--        self._H_adjacency_matrix.set_immutable()
--
--
--    def _init_facet_adjacency_matrix(self):
-+        V_matrix = matrix(ZZ, 0, 0, 0)
-+        V_matrix.set_immutable()
-+        self.vertex_adjacency_matrix.set_cache(V_matrix)
-+
-+        H_matrix = matrix(ZZ, 1, 1, 0)
-+        H_matrix.set_immutable()
-+        self.facet_adjacency_matrix.set_cache(H_matrix)
-+
-+    def _facet_adjacency_matrix(self):
-         """
-         Compute the facet adjacency matrix in case it has not been
-         computed during initialization.
-@@ -232,10 +219,7 @@
-         EXAMPLES::
-         
-             sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)])
--            sage: '_H_adjacency_matrix' in p.__dict__
--            False
--            sage: p._init_facet_adjacency_matrix()
--            sage: p._H_adjacency_matrix
-+            sage: p._facet_adjacency_matrix()
-             [0 1 1]
-             [1 0 1]
-             [1 1 0]
-@@ -256,11 +240,9 @@
-             Hrep = face.element.ambient_Hrepresentation()
-             if len(Hrep) == 2:
-                 set_adjacent(Hrep[0], Hrep[1])
--
--        self._H_adjacency_matrix = M
--
--
--    def _init_vertex_adjacency_matrix(self):
-+        return M
-+
-+    def _vertex_adjacency_matrix(self):
-         """
-         Compute the vertex adjacency matrix in case it has not been
-         computed during initialization.
-@@ -268,10 +250,7 @@
-         EXAMPLES::
-         
-             sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)])
--            sage: '_V_adjacency_matrix' in p.__dict__
--            False
--            sage: p._init_vertex_adjacency_matrix()
--            sage: p._V_adjacency_matrix
-+            sage: p._vertex_adjacency_matrix()
-             [0 1 1]
-             [1 0 1]
-             [1 1 0]
-@@ -299,168 +278,105 @@
-         for r in self.ray_generator():
-             for vrep in self.Vrep_generator():
-                 set_adjacent(r, vrep)
--                
--        self._V_adjacency_matrix = M
--
--
--    def __lt__(self, other):
-+        return M
-+
-+    def delete(self):
-         """
--        Test whether ``self`` is a strict sub-polyhedron of ``other``.
-+        Delete this polyhedron.
-+
-+        This speeds up creation of new polyhedra by reusing
-+        objects. After recycling a polyhedron object, it is not in a
-+        consistent state any more and neither the polyhedron nor its
-+        H/V-representation objects may be used any more.
-+
-+        .. seealso:: :meth:`~sage.geometry.polyhedron.Polyhedra_base.recycle`
-+
-+
-+        EXAMPLES::
-+
-+            sage: p = Polyhedron([(0,0),(1,0),(0,1)])
-+            sage: p.delete()
-+
-+            sage: def loop_polyhedra():
-+            ...       for i in range(0,100):
-+            ...           p = Polyhedron([(0,0),(1,0),(0,1),(1,1)])
-+
-+            sage: timeit('loop_polyhedra()', repeat=25)                   # random output
-+            5 loops, best of 25: 44.2 ms per loop
-+
-+            sage: def loop_polyhedra_with_recycling():
-+            ...       for i in range(0,100):
-+            ...           p = Polyhedron([(0,0),(1,0),(0,1),(1,1)])
-+            ...           p.delete()
-+
-+            sage: timeit('loop_polyhedra_with_recycling()', repeat=25)    # random output
-+            25 loops, best of 25: 36.3 ms per loop
-+        """
-+        self.parent().recycle(self)
-+        self._Hrepresentation = None
-+        self._Vrepresentation = None
-+
-+    def base_extend(self, base_ring, backend=None):
-+        """
-+        EXAMPLES::
-+
-+            sage: P = Polyhedron(vertices=[(1,0), (0,1)], rays=[(1,1)], base_ring=ZZ);  P
-+            A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices and 1 ray
-+            sage: P.base_extend(QQ)
-+            A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 2 vertices and 1 ray
-+        """
-+        new_parent = self.parent().base_extend(base_ring, backend)
-+        return new_parent(self)
-+
-+    def __cmp__(self, other):
-+        """
-+        Compare ``self`` and ``other``.
- 
-         INPUT:
- 
--        - ``other`` -- a :class:`Polyhedron`.
-+        - ``other`` -- anything.
- 
-         OUTPUT:
- 
--        Boolean.
-+        `-1, 0, +1` depending on how ``self`` and ``other``
-+        compare. If ``other`` is a polyhedron, then the comparison
-+        operator "less or equal than" means "is contained in", and
-+        "less than" means "is strictly contained in".
- 
-         EXAMPLES::
- 
-             sage: P = Polyhedron(vertices=[(1,0), (0,1)], rays=[(1,1)])
-             sage: Q = Polyhedron(vertices=[(1,0), (0,1)])
--            sage: P < Q   # indirect doctest
-+            sage: cmp(P,Q)
-+            1
-+            sage: cmp(Q,P)
-+            -1
-+            sage: cmp(P,P)
-+            0
-+            sage: cmp(P, 'anything')
-+            -1
-+
-+       The polytope ``Q`` is contained in ``P``::
-+
-+            sage: P > Q
-+            True
-+            sage: P < Q
-             False
--            sage: P < P   # indirect doctest
--            False
--            sage: Q < P   # indirect doctest
--            True
--        """
--        return self._is_subpolyhedron(other) and not other._is_subpolyhedron(self)
--
--
--    def __le__(self, other):
--        """
--        Test whether ``self`` is a (not necessarily strict)
--        sub-polyhedron of ``other``.
--
--        INPUT:
--
--        - ``other`` -- a :class:`Polyhedron`.
--
--        OUTPUT:
--
--        Boolean.
--
--        EXAMPLES::
--
--            sage: P = Polyhedron(vertices=[(1,0), (0,1)], rays=[(1,1)])
--            sage: Q = Polyhedron(vertices=[(1,0), (0,1)])
--            sage: P <= Q   # indirect doctest
--            False
--            sage: P <= P   # indirect doctest
--            True
--            sage: Q <= P   # indirect doctest
--            True
--        """
--        return self._is_subpolyhedron(other)
--        
--
--    def __eq__(self, other):
--        """
--        Test whether ``self`` is a strict sub-polyhedron of ``other``.
--
--        INPUT:
--
--        - ``other`` -- a :class:`Polyhedron`.
--
--        OUTPUT:
--
--        Boolean.
--
--        EXAMPLES::
--
--            sage: P = Polyhedron(vertices=[(1,0), (0,1)], rays=[(1,1)])
--            sage: Q = Polyhedron(vertices=[(1,0), (0,1)])
--            sage: P == Q   # indirect doctest
--            False
--            sage: P == P   # indirect doctest
--            True
--            sage: Q == P   # indirect doctest
-+            sage: P == Q
-             False
-         """
--        return self._is_subpolyhedron(other) and other._is_subpolyhedron(self)
--
--
--    def __ne__(self, other):
--        """
--        Test whether ``self`` is not equal to ``other``.
--
--        INPUT:
--
--        - ``other`` -- a :class:`Polyhedron`.
--
--        OUTPUT:
--
--        Boolean.
--
--        EXAMPLES::
--
--            sage: P = Polyhedron(vertices=[(1,0), (0,1)], rays=[(1,1)])
--            sage: Q = Polyhedron(vertices=[(1,0), (0,1)])
--            sage: P != Q   # indirect doctest
--            True
--            sage: P != P   # indirect doctest
--            False
--            sage: Q != P   # indirect doctest
--            True
--        """
--        return not self.__eq__(other)
--
--
--    def __gt__(self, other):
--        """
--        Test whether ``self`` is a strict super-polyhedron of ``other``.
--
--        INPUT:
--
--        - ``other`` -- a :class:`Polyhedron`.
--
--        OUTPUT:
--
--        Boolean.
--
--        EXAMPLES::
--
--            sage: P = Polyhedron(vertices=[(1,0), (0,1)], rays=[(1,1)])
--            sage: Q = Polyhedron(vertices=[(1,0), (0,1)])
--            sage: P > Q   # indirect doctest
--            True
--            sage: P > P   # indirect doctest
--            False
--            sage: Q > P   # indirect doctest
--            False
--        """
--        return other._is_subpolyhedron(self) and not self._is_subpolyhedron(other)
--
--
--    def __ge__(self, other):
--        """
--        Test whether ``self`` is a (not necessarily strict)
--        super-polyhedron of ``other``.
--
--        INPUT:
--
--        - ``other`` -- a :class:`Polyhedron`.
--
--        OUTPUT:
--
--        Boolean.
--
--        EXAMPLES::
--
--            sage: P = Polyhedron(vertices=[(1,0), (0,1)], rays=[(1,1)])
--            sage: Q = Polyhedron(vertices=[(1,0), (0,1)])
--            sage: P >= Q   # indirect doctest
--            True
--            sage: P >= P   # indirect doctest
--            True
--            sage: Q >= P   # indirect doctest
--            False
--        """
--        return other._is_subpolyhedron(self)
--
--
-+        c = cmp(self.ambient_dim(), other.ambient_dim())
-+        if c != 0: return c
-+        c0 = self._is_subpolyhedron(other)
-+        c1 = other._is_subpolyhedron(self)
-+        if c0 and c1:
-+            return 0
-+        if c0:
-+            return -1
-+        else:
-+            return +1
-+
-+    @coerce_binop
-     def _is_subpolyhedron(self, other):
-         """
-         Test whether ``self`` is a (not necessarily strict)
-@@ -483,12 +399,9 @@
-             sage: Q._is_subpolyhedron(P)
-             True
-         """
--        if not is_Polyhedron(other):
--            raise ValueError('Can only compare Polyhedron objects.')
-         return all( other_H.contains(self_V)
-                     for other_H, self_V in
-                     CartesianProduct(other.Hrep_generator(), self.Vrep_generator()) )
--        
- 
-     def plot(self, **kwds):
-         """
-@@ -519,10 +432,8 @@
-         raise NotImplementedError('Plotting of '+str(self.ambient_dim())+
-                                   '-dimensional polyhedra not implemented')
- 
--
-     show = plot
- 
--
-     def _repr_(self):
-         """
-         Return a description of the polyhedron.
-@@ -531,10 +442,10 @@
- 
-             sage: poly_test = Polyhedron(vertices = [[1,2,3,4],[2,1,3,4],[4,3,2,1]])
-             sage: poly_test._repr_()
--            'A 2-dimensional polyhedron in QQ^4 defined as the convex hull of 3 vertices'
-+            'A 2-dimensional polyhedron in ZZ^4 defined as the convex hull of 3 vertices'
-             sage: grammar_test = Polyhedron(vertices = [[1,1,1,1,1,1]])
-             sage: grammar_test._repr_()
--            'A 0-dimensional polyhedron in QQ^6 defined as the convex hull of 1 vertex'
-+            'A 0-dimensional polyhedron in ZZ^6 defined as the convex hull of 1 vertex'
-         """
-         desc = ''
-         if self.n_vertices()==0:
-@@ -570,7 +481,6 @@
- 
-         return desc
- 
--
-     def cdd_Hrepresentation(self):
-         """
-         Write the inequalities/equations data of the polyhedron in
-@@ -598,13 +508,16 @@
-         try:
-             cdd_type = self._cdd_type
-         except AttributeError:
--            ring_to_cdd = { QQ:'rational', RDF:'real' }
--            cdd_type = ring_to_cdd[self.base_ring()]
-+            if self.base_ring() is ZZ or self.base_ring() is QQ:
-+                cdd_type = 'rational'
-+            elif self.base_ring() is RDF:
-+                cdd_type = 'real'
-+            else:
-+                raise TypeError('The base ring must be ZZ, QQ, or RDF')
-         return cdd_Hrepresentation(cdd_type,
-                                    list(self.inequality_generator()),
-                                    list(self.equation_generator()) )
- 
--
-     def cdd_Vrepresentation(self):
-         """
-         Write the vertices/rays/lines data of the polyhedron in cdd's
-@@ -632,14 +545,18 @@
-         try:
-             cdd_type = self._cdd_type
-         except AttributeError:
--            ring_to_cdd = { QQ:'rational', RDF:'real' }
--            cdd_type = ring_to_cdd[self.base_ring()]
-+            if self.base_ring() is ZZ or self.base_ring() is QQ:
-+                cdd_type = 'rational'
-+            elif self.base_ring() is RDF:
-+                cdd_type = 'real'
-+            else:
-+                raise TypeError('The base ring must be ZZ, QQ, or RDF')
-         return cdd_Vrepresentation(cdd_type,
-                                    list(self.vertex_generator()),
-                                    list(self.ray_generator()),
-                                    list(self.line_generator()) )
- 
--
-+    @cached_method
-     def n_equations(self):
-         """
-         Return the number of equations. The representation will
-@@ -652,13 +569,9 @@
-             sage: p.n_equations()
-             1
-         """
--        try:
--            return self._n_equations
--        except AttributeError:
--            self._n_equations = len(self.equations())