rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
sage: J.is_S_integral(J.[K.ideal(5)])
sage: J.is_S_integral([K.ideal(5)])
def is_S_integral(self,S): r""" Return True if this fractional ideal is integral with respect to the list of primes ``S``.
EXAMPLES:
EXAMPLES::
def __call__(self, im_gens, check=True): """ Return the homomorphism defined by images of generators.
([0], [0])
([0], [])
def blocks_and_cut_vertices(self): """ Computes the blocks and cut vertices of the graph. In the case of a digraph, this computation is done on the underlying graph. A cut vertex is one whose deletion increases the number of connected components. A block is a maximal induced subgraph which itself has no cut vertices. ...
return [s],[s]
return [s],[]
def blocks_and_cut_vertices(self): """ Computes the blocks and cut vertices of the graph. In the case of a digraph, this computation is done on the underlying graph. A cut vertex is one whose deletion increases the number of connected components. A block is a maximal induced subgraph which itself has no cut vertices. ...
def tamagawa_product(self):
def tamagawa_product_bsd(self):
def tamagawa_product(self): r""" Given an elliptic curve `E` over a number field `K`, this function returns the integer `C(E/K)` that appears in the Birch and Swinnerton-Dyer conjecture accounting for the local information at finite places. If the model is a global minimal model then `C(E/K)` is simply the product of t...
sage: E.tamagawa_product()
sage: E.tamagawa_product_bsd()
def tamagawa_product(self): r""" Given an elliptic curve `E` over a number field `K`, this function returns the integer `C(E/K)` that appears in the Birch and Swinnerton-Dyer conjecture accounting for the local information at finite places. If the model is a global minimal model then `C(E/K)` is simply the product of t...
sage: E2 Elliptic Curve defined by y^2 + a*x*y + (a+1)*y = x^3 + (a+1)*x^2 + (12289755603565800754*a-75759141535687466985)*x + (51556320144761417221790307379*a-317814501841918807353201512829) over Number Field in a with defining polynomial x^2 - 38
sage: E2 Elliptic Curve defined by y^2 + a*x*y + (a+1)*y = x^3 + (a+1)*x^2 + (368258520200522046806318444*a-2270097978636731786720859345)*x + (8456608930173478039472018047583706316424*a-52130038506793883217874390501829588391299) over Number Field in a with defining polynomial x^2 - 38
def global_minimal_model(self, proof = None): r""" Returns a model of self that is integral, minimal at all primes. .. note::
This function is equivalent to the plot command with the options
This function is equivalent to the :func:`plot` command with the options
def polar_plot(funcs, *args, **kwds): r""" ``polar_plot`` takes a single function or a list or tuple of functions and plots them with polar coordinates in the given domain. This function is equivalent to the plot command with the options ``polar=True`` and ``aspect_ratio=1``. For more help on options, see the document...
see the documentation for plot.
see the documentation for :func:`plot`.
def polar_plot(funcs, *args, **kwds): r""" ``polar_plot`` takes a single function or a list or tuple of functions and plots them with polar coordinates in the given domain. This function is equivalent to the plot command with the options ``polar=True`` and ``aspect_ratio=1``. For more help on options, see the document...
_vars = str(self.gen())
_vars = '(%s)'%self.gen()
def _singular_init_(self, singular=singular_default): """ Return a newly created Singular ring matching this ring. """ if not can_convert_to_singular(self): raise TypeError, "no conversion of this ring to a Singular ring defined" if self.ngens()==1: _vars = str(self.gen()) if "*" in _vars: # 1.000...000*x _vars = _var...
bound = ZZ(floor(bound))
bound = ZZ(floor(max(bound, 0)))
def vectors_by_length(self, bound): """ Returns a list of short vectors together with their values. This is a naive algorithm which uses the Cholesky decomposition, but does not use the LLL-reduction algorithm. INPUT: bound -- an integer >= 0 OUTPUT: A list L of length (bound + 1) whose entry L[i] is a list of all v...
Returns the tableau object corresponding to t.
Returns the tableau object corresponding to t. A tableau in sage is a finite list of lists, whose lengths are weakly decreasing, or an empty list, representing the empty tableau. The entries of a tableau can be any sage object.
def Tableau(t): """ Returns the tableau object corresponding to t. Note that Sage uses the English convention for partitions and tableaux. EXAMPLES:: sage: t = Tableau([[1,2,3],[4,5]]); t [[1, 2, 3], [4, 5]] sage: t.shape() [3, 2] sage: t.is_standard() True """ if isinstance(t, Tableau_class): return t elif t in Tab...
self that are filled with a number less than
self that are filled with a number less than `n`.
def anti_restrict(self, n): """ Returns the skew tableau formed by removing all of the cells from self that are filled with a number less than EXAMPLES:: sage: t = Tableau([[1,2,3],[4,5]]); t [[1, 2, 3], [4, 5]] sage: t.anti_restrict(1) [[None, 2, 3], [4, 5]] sage: t.anti_restrict(2) [[None, None, 3], [4, 5]] sage: t...
then it returns the combinatorial class of all tableaux of size n.
then it returns the combinatorial class of all tableaux of size n. A tableau in sage is a finite list of lists, whose lengths are weakly decreasing. The entries can be anything at all.
def Tableaux(n=None): """ Returns the combinatorial class of tableaux. If n is specified, then it returns the combinatorial class of all tableaux of size n. EXAMPLES:: sage: T = Tableaux(); T Tableaux sage: [[1,2],[3,4]] in T True sage: [[1,2],[3]] in T True sage: [1,2,3] in T False :: sage: T = Tableaux(4); T Tabl...
sage: [1,2,3] in T False
def Tableaux(n=None): """ Returns the combinatorial class of tableaux. If n is specified, then it returns the combinatorial class of all tableaux of size n. EXAMPLES:: sage: T = Tableaux(); T Tableaux sage: [[1,2],[3,4]] in T True sage: [[1,2],[3]] in T True sage: [1,2,3] in T False :: sage: T = Tableaux(4); T Tabl...
def __repr__(self):
def _repr_(self):
def __repr__(self): """ TESTS:: sage: repr(Tableaux()) 'Tableaux' """ return "Tableaux"
def __repr__(self):
def _repr_(self):
def __repr__(self): """ TESTS:: sage: repr(Tableaux(4)) 'Tableaux of size 4' """ return "Tableaux of size %s"%self.n
def __repr__(self):
def _repr_(self):
def __repr__(self): """ TESTS:: sage: repr(StandardTableaux()) 'Standard tableaux' """ return "Standard tableaux"
def __repr__(self):
def _repr_(self):
def __repr__(self): """ TESTS:: sage: repr(StandardTableaux(3)) 'Standard tableaux of size 3' """ return "Standard tableaux of size %s"%self.n
def __repr__(self):
def _repr_(self):
def __repr__(self): """ TESTS:: sage: repr(StandardTableaux([2,1,1])) 'Standard tableaux of shape [2, 1, 1]' """ return "Standard tableaux of shape %s"%str(self.p)
def SemistandardTableaux(p=None, mu=None):
def SemistandardTableaux(p=None, mu=None, max_entry=None):
def SemistandardTableaux(p=None, mu=None): """ Returns the combinatorial class of semistandard tableaux. If p is specified and is a partition, then it returns the class of semistandard tableaux of shape p (and max entry sum(p)) If p is specified and is an integer, it returns the class of semistandard tableaux of size...
semistandard tableaux of shape p (and max entry sum(p))
semistandard tableaux of shape p.
def SemistandardTableaux(p=None, mu=None): """ Returns the combinatorial class of semistandard tableaux. If p is specified and is a partition, then it returns the class of semistandard tableaux of shape p (and max entry sum(p)) If p is specified and is an integer, it returns the class of semistandard tableaux of size...
If mu is also specified, then it returns the class of semistandard
If mu is specified, then it returns the class of semistandard
def SemistandardTableaux(p=None, mu=None): """ Returns the combinatorial class of semistandard tableaux. If p is specified and is a partition, then it returns the class of semistandard tableaux of shape p (and max entry sum(p)) If p is specified and is an integer, it returns the class of semistandard tableaux of size...
Semistandard tableaux of shape [2, 1]
Semistandard tableaux of shape [2, 1] and maximum entry 3
def SemistandardTableaux(p=None, mu=None): """ Returns the combinatorial class of semistandard tableaux. If p is specified and is a partition, then it returns the class of semistandard tableaux of shape p (and max entry sum(p)) If p is specified and is an integer, it returns the class of semistandard tableaux of size...
::
def SemistandardTableaux(p=None, mu=None): """ Returns the combinatorial class of semistandard tableaux. If p is specified and is a partition, then it returns the class of semistandard tableaux of shape p (and max entry sum(p)) If p is specified and is an integer, it returns the class of semistandard tableaux of size...
Semistandard tableaux of size 3
Semistandard tableaux of size 3 and maximum entry 3
def SemistandardTableaux(p=None, mu=None): """ Returns the combinatorial class of semistandard tableaux. If p is specified and is a partition, then it returns the class of semistandard tableaux of shape p (and max entry sum(p)) If p is specified and is an integer, it returns the class of semistandard tableaux of size...
if p == None: return SemistandardTableaux_all()
is_inf = max_entry is PlusInfinity() if max_entry is not None and not is_inf: if not isinstance(max_entry, (int, Integer)): raise ValueError, "max_entry must be an integer" elif max_entry < 0: raise ValueError, "max_entry must be non-negative" if p is None: if mu is None: return SemistandardTableaux_all(max_entry) el...
def SemistandardTableaux(p=None, mu=None): """ Returns the combinatorial class of semistandard tableaux. If p is specified and is a partition, then it returns the class of semistandard tableaux of shape p (and max entry sum(p)) If p is specified and is an integer, it returns the class of semistandard tableaux of size...
if mu == None: return SemistandardTableaux_p(p)
if mu is None: if is_inf: if sum(p) != 0: return SemistandardTableaux_p_inf(p) else: return SemistandardTableaux_p(p) else: return SemistandardTableaux_p(p, max_entry)
def SemistandardTableaux(p=None, mu=None): """ Returns the combinatorial class of semistandard tableaux. If p is specified and is a partition, then it returns the class of semistandard tableaux of shape p (and max entry sum(p)) If p is specified and is an integer, it returns the class of semistandard tableaux of size...
if mu == None: return SemistandardTableaux_n(p)
if p >= 0: if mu is None: if is_inf: if p != 0: return SemistandardTableaux_n_inf(p) else: return SemistandardTableaux_n(p) else: return SemistandardTableaux_n(p, max_entry) else: if p != sum(mu): raise ValueError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu)
def SemistandardTableaux(p=None, mu=None): """ Returns the combinatorial class of semistandard tableaux. If p is specified and is a partition, then it returns the class of semistandard tableaux of shape p (and max entry sum(p)) If p is specified and is an integer, it returns the class of semistandard tableaux of size...
if p != sum(mu): raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu)
raise ValueError, "p must be non-negative"
def SemistandardTableaux(p=None, mu=None): """ Returns the combinatorial class of semistandard tableaux. If p is specified and is a partition, then it returns the class of semistandard tableaux of shape p (and max entry sum(p)) If p is specified and is an integer, it returns the class of semistandard tableaux of size...
def __init__(self):
def __init__(self, max_entry=None):
def __init__(self): """ TESTS:: sage: SST = SemistandardTableaux() sage: SST == loads(dumps(SST)) True """
"""
sage: SST = SemistandardTableaux(max_entry=5) sage: SST == loads(dumps(SST)) True """ self.max_entry = None if max_entry is not PlusInfinity(): self.max_entry = max_entry def _repr_(self): """ TESTS:: sage: SST = SemistandardTableaux() sage: SST Semistandard tableaux sage: SemistandardTableaux(max_entry=3) Semistan...
def __init__(self): """ TESTS:: sage: SST = SemistandardTableaux() sage: SST == loads(dumps(SST)) True """
sage: [[1,1],[2]] in SemistandardTableaux() True """
sage: [[1,1],[5]] in SemistandardTableaux(max_entry=4) False """
def __contains__(self, x): """ TESTS:: sage: [[1,2],[1]] in SemistandardTableaux() False sage: SST = SemistandardTableaux() sage: all([st in SST for st in StandardTableaux(4)]) True sage: [[1,1],[2]] in SemistandardTableaux() True """ if x not in Tableaux(): return False else: t = Tableau(x) #Check to make sure the f...
for row in t: for i in row: if not isinstance(i, (int, Integer)):
for i, row in enumerate(t): for j, entry in enumerate(row): if not isinstance(entry, (int, Integer)):
def __contains__(self, x): """ TESTS:: sage: [[1,2],[1]] in SemistandardTableaux() False sage: SST = SemistandardTableaux() sage: all([st in SST for st in StandardTableaux(4)]) True sage: [[1,1],[2]] in SemistandardTableaux() True """ if x not in Tableaux(): return False else: t = Tableau(x) #Check to make sure the f...
for row in t: for i in range(1, len(row)): if row[i] < row[i-1]:
if j > 0 and entry < row[j-1]:
def __contains__(self, x): """ TESTS:: sage: [[1,2],[1]] in SemistandardTableaux() False sage: SST = SemistandardTableaux() sage: all([st in SST for st in StandardTableaux(4)]) True sage: [[1,1],[2]] in SemistandardTableaux() True """ if x not in Tableaux(): return False else: t = Tableau(x) #Check to make sure the f...
conj = t.conjugate() for row in conj: for i in range(1, len(row)): if row[i] <= row[i-1]: return False
if i > 0 and entry <= t[i-1][j]: return False if self.max_entry is not None and row[-1] > self.max_entry: return False
def __contains__(self, x): """ TESTS:: sage: [[1,2],[1]] in SemistandardTableaux() False sage: SST = SemistandardTableaux() sage: all([st in SST for st in StandardTableaux(4)]) True sage: [[1,1],[2]] in SemistandardTableaux() True """ if x not in Tableaux(): return False else: t = Tableau(x) #Check to make sure the f...
def __init__(self, n):
def __init__(self, n, max_entry=None):
def __init__(self, n): """ TESTS:: sage: SST = SemistandardTableaux(3) sage: SST == loads(dumps(SST)) True """ self.n = n
def __repr__(self):
self.max_entry = None if max_entry is None: self.max_entry = n else: self.max_entry = max_entry def _repr_(self):
def __repr__(self): """ TESTS:: sage: repr(SemistandardTableaux(3)) 'Semistandard tableaux of size 3' """ return "Semistandard tableaux of size %s"%str(self.n)
'Semistandard tableaux of size 3' """ return "Semistandard tableaux of size %s"%str(self.n)
'Semistandard tableaux of size 3 and maximum entry 3' sage: repr(SemistandardTableaux(3, max_entry=6)) 'Semistandard tableaux of size 3 and maximum entry 6' """ return "Semistandard tableaux of size %s and maximum entry %s"%(str(self.n), str(self.max_entry))
def __repr__(self): """ TESTS:: sage: repr(SemistandardTableaux(3)) 'Semistandard tableaux of size 3' """ return "Semistandard tableaux of size %s"%str(self.n)
return x in SemistandardTableaux() and sum(map(len, x)) == self.n
return x in SemistandardTableaux_all(self.max_entry) and sum(map(len, x)) == self.n
def __contains__(self, x): """ EXAMPLES:: sage: [[1,2],[3,3]] in SemistandardTableaux(3) False sage: [[1,2],[3,3]] in SemistandardTableaux(4) True sage: SST = SemistandardTableaux(4) sage: all([sst in SST for sst in SST]) True """ return x in SemistandardTableaux() and sum(map(len, x)) == self.n
c += SemistandardTableaux(part).cardinality()
c += SemistandardTableaux_p(part, self.max_entry).cardinality()
def cardinality(self): """ EXAMPLES:: sage: SemistandardTableaux(3).cardinality() 19 sage: SemistandardTableaux(4).cardinality() 116 sage: ns = range(1, 6) sage: ssts = [ SemistandardTableaux(n) for n in ns ] sage: all([sst.cardinality() == len(sst.list()) for sst in ssts]) True """ c = 0 for part in partition.Partiti...
for sst in SemistandardTableaux(part):
for sst in SemistandardTableaux_p(part, self.max_entry):
def __iter__(self): """ EXAMPLES:: sage: [ t for t in SemistandardTableaux(2) ] [[[1, 1]], [[1, 2]], [[2, 2]], [[1], [2]]] sage: [ t for t in SemistandardTableaux(3) ] [[[1, 1, 1]], [[1, 1, 2]], [[1, 1, 3]], [[1, 2, 2]], [[1, 2, 3]], [[1, 3, 3]], [[2, 2, 2]], [[2, 2, 3]], [[2, 3, 3]], [[3, 3, 3]], [[1, 1], [2]], [[1, ...
def __repr__(self):
def _repr_(self):
def __repr__(self): """ TESTS:: sage: repr(SemistandardTableaux([2,1],[2,1])) 'Semistandard tableaux of shape [2, 1] and evaluation [2, 1]' """ return "Semistandard tableaux of shape %s and evaluation %s"%(self.p, self.mu)
if not x in SemistandardTableaux(self.p):
if x not in SemistandardTableaux_p(self.p, self.max_entry):
def __contains__(self, x): """ EXAMPLES:: sage: SST = SemistandardTableaux([2,1], [2,1]) sage: all([sst in SST for sst in SST]) True sage: len(filter(lambda x: x in SST, SemistandardTableaux(3))) 1 sage: SST.cardinality() 1 """ if not x in SemistandardTableaux(self.p): return False n = sum(self.p)
def __init__(self, p):
def __init__(self, p, max_entry=None):
def __init__(self, p): """ TESTS:: sage: SST = SemistandardTableaux([2,1]) sage: SST == loads(dumps(SST)) True """ self.p = p
""" return x in SemistandardTableaux_all() and map(len, x) == self.p def __repr__(self):
sage: SST = SemistandardTableaux([2,1], max_entry=4) sage: all([sst in SST for sst in SST]) True sage: SST.cardinality() 20 """ return x in SemistandardTableaux_all(self.max_entry) and map(len, x) == self.p def _repr_(self):
def __contains__(self, x): """ EXAMPLES:: sage: SST = SemistandardTableaux([2,1]) sage: all([sst in SST for sst in SST]) True sage: len(filter(lambda x: x in SST, SemistandardTableaux(3))) 8 sage: SST.cardinality() 8 """ return x in SemistandardTableaux_all() and map(len, x) == self.p
'Semistandard tableaux of shape [2, 1]' """ return "Semistandard tableaux of shape %s" % str(self.p)
'Semistandard tableaux of shape [2, 1] and maximum entry 3' sage: repr(SemistandardTableaux([2,1], max_entry=5)) 'Semistandard tableaux of shape [2, 1] and maximum entry 5' """ return "Semistandard tableaux of shape %s and maximum entry %s" %(str(self.p), str(self.max_entry))
def __repr__(self): """ TESTS:: sage: repr(SemistandardTableaux([2,1])) 'Semistandard tableaux of shape [2, 1]' """ return "Semistandard tableaux of shape %s" % str(self.p)
for comp in IntegerVectors(sum(self.p), sum(self.p)):
for comp in IntegerVectors(sum(self.p), self.max_entry):
def cardinality(self): """ EXAMPLES:: sage: SemistandardTableaux([2,1]).cardinality() 8 sage: SemistandardTableaux([2,2,1]).cardinality() 75 sage: s = SFASchur(QQ) sage: s([2,2,1]).expand(5)(1,1,1,1,1) 75 sage: SemistandardTableaux([5]).cardinality() 126 sage: SemistandardTableaux([3,2,1]).cardinality() 896 """ c = 0 ...
""" for c in IntegerVectors(sum(self.p), sum(self.p)): for sst in SemistandardTableaux(self.p, c):
sage: [ t for t in SemistandardTableaux([1,1,1], max_entry=4) ] [[[1], [2], [3]], [[1], [2], [4]], [[1], [3], [4]], [[2], [3], [4]]] """ for c in IntegerVectors(sum(self.p), self.max_entry): for sst in SemistandardTableaux_pmu(self.p, c):
def __iter__(self): """ An iterator for the semistandard partitions of shape p. EXAMPLES:: sage: [ t for t in SemistandardTableaux([3]) ] [[[1, 1, 1]], [[1, 1, 2]], [[1, 1, 3]], [[1, 2, 2]], [[1, 2, 3]], [[1, 3, 3]], [[2, 2, 2]], [[2, 2, 3]], [[2, 3, 3]], [[3, 3, 3]]] sage: [ t for t in SemistandardTableaux([2,1]) ] ...
def __repr__(self):
self.max_entry = len(mu) def _repr_(self):
def __init__(self, n, mu): """ TESTS:: sage: SST = SemistandardTableaux(3, [2,1]) sage: SST == loads(dumps(SST)) True """ self.n = n self.mu = mu
return x in SemistandardTableaux_all() and x in SemistandardTableaux(map(len, x), self.mu)
return x in SemistandardTableaux_pmu(map(len, x), self.mu)
def __contains__(self, x): """ TESTS:: sage: SST = SemistandardTableaux(6, [2,2,2]) sage: all([sst in SST for sst in SST]) True sage: all([sst in SST for sst in SemistandardTableaux([3,2,1],[2,2,2])]) True """ return x in SemistandardTableaux_all() and x in SemistandardTableaux(map(len, x), self.mu)
have_tkzgraph = not bool(os.system('kpsewhich tkz-graph.sty > /dev/null'))
have_tkzgraph = not bool(os.system('kpsewhich tkz-graph.sty &> /dev/null'))
def check_tkz_graph(): r""" Checks if the proper `\mbox{\rm\LaTeX}` packages for the ``tikzpicture`` environment are installed in the user's environment. If the requisite packages are not found on the first call to this function, warnings are printed. Thereafter, the function caches its result in the variable ``_have_...
have_tkzberge = not bool(os.system('kpsewhich tkz-berge.sty > /dev/null'))
have_tkzberge = not bool(os.system('kpsewhich tkz-berge.sty &> /dev/null'))
def check_tkz_graph(): r""" Checks if the proper `\mbox{\rm\LaTeX}` packages for the ``tikzpicture`` environment are installed in the user's environment. If the requisite packages are not found on the first call to this function, warnings are printed. Thereafter, the function caches its result in the variable ``_have_...
have_tkzgraph = not bool(os.system('kpsewhich tkz-graph.sty > /dev/null')) have_tkzberge = not bool(os.system('kpsewhich tkz-berge.sty > /dev/null'))
have_tkzgraph = not bool(os.system('kpsewhich tkz-graph.sty &> /dev/null')) have_tkzberge = not bool(os.system('kpsewhich tkz-berge.sty &> /dev/null'))
def have_tkz_graph(): r""" Returns ``True`` if the proper `\mbox{\rm\LaTeX}` packages for the ``tikzpicture`` environment are installed in the user's environment. The first time it is run, this function caches its result in the variable ``_have_tkz_graph``, and any subsequent time, it just checks the value of the vari...
- ``weighted`` (boolean) -- whether the label on the edges are tobe considered as weights (a label set to ``None`` or
- ``weighted`` (boolean) -- whether the labels on the edges are to be considered as weights (a label set to ``None`` or
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
weighting, setting ``weighted`` to ``True`` will force
weighting, setting ``weighted=True`` will force
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
- ``solver`` -- (default: ``None``) Specify a Linear Program (LP)
- ``solver`` -- (default: ``None``) Specify the Linear Program (LP)
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
Let us compute longest path on random graphs with random weights. We each time ensure the given graph is indeed a
Let us compute longest paths on random graphs with random weights. Each time, we ensure the resulting graph is indeed a
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
sage: for i in xrange(20): ... g = graphs.RandomGNP(15,.3) ... for u,v in g.edges(labels = False): ... g.set_edge_label(u,v,random())
sage: for i in range(20): ... g = graphs.RandomGNP(15, 0.3) ... for u, v in g.edges(labels=False): ... g.set_edge_label(u, v, random())
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
... print "Error !"
... print("Error!")
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
sage: print "Test finished !" Test finished ! TESTS::
ValueError: algorithm must be either 'backtrack' or 'MILP'
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
sage: for i in xrange(20): ... g = digraphs.RandomDirectedGNP(15,.3) ... for u,v in g.edges(labels = False): ... g.set_edge_label(u,v,random())
sage: for i in range(20): ... g = digraphs.RandomDirectedGNP(15, 0.3) ... for u, v in g.edges(labels=False): ... g.set_edge_label(u, v, random())
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
... sage: print "Test finished !" Test finished !
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
if algorithm not in ("backtrack", "MILP"): raise ValueError("algorithm must be either 'backtrack' or 'MILP'")
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
(s != None and (
(s is not None and (
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
(t != None and (
(t is not None and (
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
(self._directed and s != None and t != None and len(self.shortest_path(s,t) == 0))):
(self._directed and (s is not None) and (t is not None) and len(self.shortest_path(s, t) == 0))):
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
else: from sage.graphs.all import Graph return [0, Graph()] if weighted else Graph()
from sage.graphs.all import Graph return [0, Graph()] if weighted else Graph()
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
if s!=None: p.add_constraint( Sum( edge_used[(u,s)] for u in self.neighbors_in(s)), max = 0, min = 0) p.add_constraint( Sum( edge_used[(s,u)] for u in self.neighbors_out(s)), min = 1, max = 1)
if s is not None: p.add_constraint( Sum(edge_used[(u,s)] for u in self.neighbors_in(s)), max=0, min=0) p.add_constraint( Sum(edge_used[(s,u)] for u in self.neighbors_out(s)), min=1, max=1)
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
if t!=None: p.add_constraint( Sum( edge_used[(u,t)] for u in self.neighbors_in(t)), min = 1, max = 1) p.add_constraint( Sum( edge_used[(t,u)] for u in self.neighbors_out(t)), max = 0, min = 0)
if t is not None: p.add_constraint( Sum(edge_used[(u,t)] for u in self.neighbors_in(t)), min=1, max=1) p.add_constraint( Sum(edge_used[(t,u)] for u in self.neighbors_out(t)), max=0, min=0)
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
if s != None: p.add_constraint( Sum( f_edge_used(s,u) for u in self.neighbors(s) ), max = 1, min = 1) if t != None: p.add_constraint( Sum( f_edge_used(t,u) for u in self.neighbors(t) ), max = 1, min = 1)
if s is not None: p.add_constraint( Sum(f_edge_used(s,u) for u in self.neighbors(s)), max=1, min=1) if t is not None: p.add_constraint( Sum(f_edge_used(t,u) for u in self.neighbors(t)), max=1, min=1)
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
g = self.subgraph( vertices = (v for v in self if vertex_used[v] >= .5), edges = ( (u,v,l) for u,v,l in self.edges() if edge_used[(u,v)] >= .5 ))
g = self.subgraph( vertices=(v for v in self if vertex_used[v] >= 0.5), edges=((u,v,l) for u, v, l in self.edges() if edge_used[(u,v)] >= 0.5))
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
g = self.subgraph( vertices = (v for v in self if vertex_used[v] >= .5), edges = ( (u,v,l) for u,v,l in self.edges() if f_edge_used(u,v) >= .5 ))
g = self.subgraph( vertices=(v for v in self if vertex_used[v] >= 0.5), edges=((u,v,l) for u, v, l in self.edges() if f_edge_used(u,v) >= 0.5))
def longest_path(self, s = None, t = None, weighted = False, algorithm = "MILP", solver = None, verbose = 0): r""" Returns a longest path of ``self``.
sage: GenericDeclaration(x, 'rational').contradicts(y==pi) False sage: GenericDeclaration(x, 'rational').contradicts(y==pi)
sage: GenericDeclaration(x, 'rational').contradicts(x==pi) True sage: GenericDeclaration(x, 'irrational').contradicts(x!=pi)
def contradicts(self, soln): """ Returns ``True`` if this assumption is violated by the given variable assignment(s). EXAMPLES:: sage: from sage.symbolic.assumptions import GenericDeclaration sage: GenericDeclaration(x, 'integer').contradicts(x==4) False sage: GenericDeclaration(x, 'integer').contradicts(x==4.0) Fals...
return matrix_space.MatrixSpace(ring, n, n, sparse).identity_matrix()
return matrix_space.MatrixSpace(ring, n, n, sparse)(1)
def identity_matrix(ring, n=0, sparse=False): r""" Return the `n \times n` identity matrix over the given ring. The default ring is the integers. EXAMPLES:: sage: M = identity_matrix(QQ, 2); M [1 0] [0 1] sage: M.parent() Full MatrixSpace of 2 by 2 dense matrices over Rational Field sage: M = identity_matrix(2); M [...
return matrix_space.MatrixSpace(ring, nrows, ncols, sparse).zero_matrix()
return matrix_space.MatrixSpace(ring, nrows, ncols, sparse)(0)
def zero_matrix(ring, nrows, ncols=None, sparse=False): r""" Return the `nrows \times ncols` zero matrix over the given ring. The default ring is the integers. EXAMPLES:: sage: M = zero_matrix(QQ, 2); M [0 0] [0 0] sage: M.parent() Full MatrixSpace of 2 by 2 dense matrices over Rational Field sage: M = zero_matrix(2...
def __cmp__(self, other):
def __hash__(self): """ TESTS:: sage: P = Poset([[1,2],[3],[3]]) sage: P.__hash__() 6557284140853143473 584755121 sage: P = Poset([[1],[3],[3]]) sage: P.__hash__() 5699294501102840900 278031428 """ if self._hash is None: self._hash = tuple(map(tuple, self.cover_relations())).__hash__() return self._hash def __eq__(se...
def __cmp__(self, other): r""" Define comparison for finite posets.
Define comparison for finite posets. We compare types, then number of elements, then Hasse
Define equality for finite posets. We test equality of types, then number of elements and elements, then Hasse
def __cmp__(self, other): r""" Define comparison for finite posets.
sage: Q < P True sage: Q > P False
sage: p1, p2 = Posets(2).list() sage: p2 == p1, p1 != p2 (False, True) sage: [[p1.__eq__(p2) for p1 in Posets(2)] for p2 in Posets(2)] [[True, False], [False, True]] sage: [[p2.__eq__(p1) for p1 in Posets(2)] for p2 in Posets(2)] [[True, False], [False, True]] sage: [[p2 == p1 for p1 in Posets(3)] for p2 in Posets(3)] ...
def __cmp__(self, other): r""" Define comparison for finite posets.
if len(self._elements) == len(other._elements): return cmp(self._elements, other._elements) and \ cmp(self._hasse_diagram, other._hasse_diagram)
if len(self._elements) == len(other._elements) and self._elements == other._elements: return self._hasse_diagram == other._hasse_diagram
def __cmp__(self, other): r""" Define comparison for finite posets.
return len(self._elements) - len(other._elements)
return False
def __cmp__(self, other): r""" Define comparison for finite posets.
return cmp(type(other), type(self))
return False def __ne__(self, other): r""" Return True if ``self`` and ``other`` are two different posets. TESTS:: sage: [[p1.__ne__(p2) for p1 in Posets(2)] for p2 in Posets(2)] [[False, True], [True, False]] sage: P = Poset([[1,2,4],[3],[3]]) sage: Q = Poset([[1,2],[],[1],[4]]) sage: P != Q True sage: P != P Fals...
def __cmp__(self, other): r""" Define comparison for finite posets.
- ``s`` (vertex) -- forces the source of the path. Set to ``None`` by default. - ``t`` (vertex) -- forces the destination of the path. Set to ``None`` by default. - ``weighted`` (boolean) -- whether the labels on the edges are to be considered as weights (a label set to ``None`` or ``{}`` being considered as a weight...
- ``s`` (vertex) -- forces the source of the path (the method then returns the longest path starting at ``s``). The argument is set to ``None`` by default, which means that no constraint is set upon the first vertex in the path. - ``t`` (vertex) -- forces the destination of the path (the method then returns the longes...
def longest_path(self, s=None, t=None, weighted=False, algorithm="MILP", solver=None, verbose=0): r""" Returns a longest path of ``self``.
summing the sizes of the enumerated sets:
summing the sizes of the enumerated sets::
def cardinality(self): """ Returns the cardinality of this disjoint union.
L = [] for k in xrange(icount): L.append(start) start += step if include_endpoint: L.append(end) return L def xsrange(start, end=None, step=1, universe=None, check=True, include_endpoint=False, endpoint_tolerance=1e-5): """ Return an iterator over numbers ``a, a+step, ..., a+k*step``, where ``a+k*step < b`` and ``a+...
def srange(start, end=None, step=1, universe=None, check=True, include_endpoint=False, endpoint_tolerance=1e-5): r""" Return list of numbers ``a, a+step, ..., a+k*step``, where ``a+k*step < b`` and ``a+(k+1)*step >= b`` over exact rings, and makes a best attempt for inexact rings (see note below). This provides one wa...
cur = start for k in xrange(icount): yield cur cur += step if include_endpoint: yield end
if icount >=0: cur = start for k in xrange(icount): yield cur cur += step if include_endpoint: yield end
def generic_xsrange(): cur = start for k in xrange(icount): yield cur cur += step if include_endpoint: yield end
- ``scope`` -- namespace (default: global);
- ``scope`` -- namespace (default: global, not just the scope from which this function was called);
def inject_coefficients(self, scope=None, verbose=True): r""" Inject generators of the base field of ``self`` into ``scope``.
sage: P1xP1 = ToricVariety(fan) sage: P1xP1.inject_coefficients() The last command does nothing, since ``P1xP1`` is defined over `\QQ`. Let's construct a toric variety over a more complicated field::
def inject_coefficients(self, scope=None, verbose=True): r""" Inject generators of the base field of ``self`` into ``scope``.
""" if is_FractionField(self.base_ring()):
We check that we can use names ``a`` and ``b``, Trac sage: a + b a + b sage: a + b in P1xP1.coordinate_ring() True """ if scope is None: depth = 0 while True: scope = sys._getframe(depth).f_globals if (scope["__name__"] == "__main__" and scope["__package__"] is None): break depth += 1 try:
def inject_coefficients(self, scope=None, verbose=True): r""" Inject generators of the base field of ``self`` into ``scope``.
sage: S == loads(dumps(S)) True
sage: TestSuite(S).run()
def __init__(self, s): """ TESTS:: sage: S = Subsets([1,2,3]) sage: S == loads(dumps(S)) True sage: s = Subsets(Set([1])) sage: e = s.first() sage: isinstance(e, s.element_class) True """ self.s = Set(s)
element_class = Set_generic
def _element_constructor_(self, x): """ TESTS:: sage: S3 = Subsets(3); S3([1,2]) {1, 2} sage: S3([0,1,2]) Traceback (most recent call last): ... ValueError: [0, 1, 2] not in Subsets of {1, 2, 3} """ return Set(x) element_class = Set_object_enumerated
def unrank(self, r): """ Returns the subset of s that has rank k. EXAMPLES:: sage: Subsets(3).unrank(0) {} sage: Subsets([2,4,5]).unrank(1) {2} sage: s = Subsets([2,4,5]) """
sage: S == loads(dumps(S)) True
sage: TestSuite(S).run()
def __init__(self, s, k): """ TESTS:: sage: S = Subsets(3,2) sage: S == loads(dumps(S)) True sage: s = Subsets(Set([1])) sage: e = s.first() sage: isinstance(e, s.element_class) True """ self.s = Set(s) self.k = k
return Set([lset[i] for i in choose_nk.from_rank(r, n, self.k)]) element_class = Set_generic
return Set([lset[i] for i in choose_nk.from_rank(r, n, self.k)]) def _element_constructor_(self, x): """ TESTS:: sage: S32 = Subsets(3,2); S32([1,2]) {1, 2} sage: S32([0,1,2]) Traceback (most recent call last): ... ValueError: [0, 1, 2] not in Subsets of {1, 2, 3} of size 2 """ return Set(x) element_class = Set_obje...
def unrank(self, r): """ Returns the subset of s that has rank k. EXAMPLES:: sage: Subsets(3,2).unrank(0) {1, 2} sage: Subsets([2,4,5],2).unrank(0) {2, 4} """
sage: S == loads(dumps(S)) True
sage: TestSuite(S).run()
def unrank(self, r): """ Returns the subset of s that has rank k. EXAMPLES:: sage: Subsets(3,2).unrank(0) {1, 2} sage: Subsets([2,4,5],2).unrank(0) {2, 4} """
sage: S == loads(dumps(S)) True
sage: TestSuite(S).run()
def __iter__(self): """ Iterates through the subsets of the multiset ``self._s``. Note that each subset is represented by a list of its elements rather than a set since we can have multiplicities (no multiset data structure yet in sage).
- ``triangular`` a boolean (default: False)
- ``triangular`` - "upper" or "lower" or None - "upper": if the `leading_support()` of the image of `F(i)` is `i`, or - "lower": if the `trailing_support()` of the image of `F(i)` is `i`.
def module_morphism(self, on_basis = None, diagonal = None, triangular = None, **keywords): r""" Constructs morphisms by linearity
implements operations on elements of tensor products of Hopf algebras
implements operations on elements of tensor products of modules with basis
def extra_super_categories(self): """ EXAMPLES::
- ``domain`` - a modules with basis `F` - ``codomain`` - a modules with basis `G` (defaults to `F`)
- ``domain`` - a module with basis `F` - ``codomain`` - a module with basis `G` (defaults to `F`)
sage: def phi_on_basis(i): return Y.monomial(abs(i))
elements of `G`
elements of `G` which describes the morphism
sage: def phi_on_basis(i): return Y.monomial(abs(i))
J\mapsto I` with the folowing property: for any `j\in J` the function ``inverse_on_support`` should returns a `i\in I` such that the leading term of ``on_basis(i)`` is `j` if there exists such a `i` or ``None`` if not.
J\mapsto I` with the following property: for any `j\in J`, `r(j)` should return an `i\in I` such that the leading term of ``on_basis(i)`` is `j` if there exists such a `i` or ``None`` if not.
sage: def phi_on_basis(i): return Y.monomial(abs(i))