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. Two distinct blocks cannot overlap in more than a single cut vertex. OUTPUT: ( B, C ), where B is a list of blocks- each is a list of vertices and the blocks are the corresponding induced subgraphs- and C is a list of cut vertices. EXAMPLES:: sage: graphs.PetersenGraph().blocks_and_cut_vertices() ([[6, 4, 9, 7, 5, 8, 3, 2, 1, 0]], []) sage: graphs.PathGraph(6).blocks_and_cut_vertices() ([[5, 4], [4, 3], [3, 2], [2, 1], [1, 0]], [4, 3, 2, 1]) sage: graphs.CycleGraph(7).blocks_and_cut_vertices() ([[6, 5, 4, 3, 2, 1, 0]], []) sage: graphs.KrackhardtKiteGraph().blocks_and_cut_vertices() ([[9, 8], [8, 7], [7, 4, 6, 5, 2, 3, 1, 0]], [8, 7]) sage: G=Graph() # make a bowtie graph where 0 is a cut vertex sage: G.add_vertices(range(5)) sage: G.add_edges([(0,1),(0,2),(0,3),(0,4),(1,2),(3,4)]) sage: G.blocks_and_cut_vertices() ([[2, 1, 0], [4, 3, 0]], [0]) sage: graphs.StarGraph(3).blocks_and_cut_vertices() ([[1, 0], [2, 0], [3, 0]], [0]) TESTS::
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. Two distinct blocks cannot overlap in more than a single cut vertex. OUTPUT: ( B, C ), where B is a list of blocks- each is a list of vertices and the blocks are the corresponding induced subgraphs- and C is a list of cut vertices. EXAMPLES:: sage: graphs.PetersenGraph().blocks_and_cut_vertices() ([[6, 4, 9, 7, 5, 8, 3, 2, 1, 0]], []) sage: graphs.PathGraph(6).blocks_and_cut_vertices() ([[5, 4], [4, 3], [3, 2], [2, 1], [1, 0]], [4, 3, 2, 1]) sage: graphs.CycleGraph(7).blocks_and_cut_vertices() ([[6, 5, 4, 3, 2, 1, 0]], []) sage: graphs.KrackhardtKiteGraph().blocks_and_cut_vertices() ([[9, 8], [8, 7], [7, 4, 6, 5, 2, 3, 1, 0]], [8, 7]) sage: G=Graph() # make a bowtie graph where 0 is a cut vertex sage: G.add_vertices(range(5)) sage: G.add_edges([(0,1),(0,2),(0,3),(0,4),(1,2),(3,4)]) sage: G.blocks_and_cut_vertices() ([[2, 1, 0], [4, 3, 0]], [0]) sage: graphs.StarGraph(3).blocks_and_cut_vertices() ([[1, 0], [2, 0], [3, 0]], [0]) TESTS::
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 the Tamagawa numbers `c_v` where `v` runs over all prime ideals of `K`. Otherwise, if the model has to be changed at a place `v` a correction factor appears. The definition is such that `C(E/K)` times the periods at the infinite places is invariant under change of the Weierstrass model. See [Ta2] and [Do] for details. .. note:: This definition is slightly different from the definition of ``tamagawa_product`` for curves defined over `\QQ`. Over the rational number it is always defined to be the product of the Tamagawa numbers, so the two definitions only agree when the model is global minimal. OUTPUT: A rational number EXAMPLES:: sage: K.<i> = NumberField(x^2+1) sage: E = EllipticCurve([0,2+i]) sage: E.tamagawa_product() 1 sage: E = EllipticCurve([(2*i+1)^2,i*(2*i+1)^7]) sage: E.tamagawa_product() 4 An example where the Neron model changes over K:: sage: K.<t> = NumberField(x^5-10*x^3+5*x^2+10*x+1) sage: E = EllipticCurve(K,'75a1') sage: E.tamagawa_product() 5 sage: da = E.local_data() sage: [dav.tamagawa_number() for dav in da] [1, 1] REFERENCES: - [Ta2] Tate, John, On the conjectures of Birch and Swinnerton-Dyer and a geometric analog. Seminaire Bourbaki, Vol. 9, Exp. No. 306. - [Do] Dokchitser, Tim and Vladimir, On the Birch-Swinnerton-Dyer quotients modulo squares, Annals of Math., 2010. """ da = self.local_data() pr = 1 for dav in da: pp = dav.prime() cv = dav.tamagawa_number() # uu is the quotient of the Neron differential at pp divided by # the differential associated to this particular equation E uu = self.isomorphism_to(dav.minimal_model()).u uu_abs_val = pp.smallest_integer()**(pp.residue_class_degree()*valuation(uu,pp)) pr *= cv * uu_abs_val return pr
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 the Tamagawa numbers `c_v` where `v` runs over all prime ideals of `K`. Otherwise, if the model has to be changed at a place `v` a correction factor appears. The definition is such that `C(E/K)` times the periods at the infinite places is invariant under change of the Weierstrass model. See [Ta2] and [Do] for details. .. note:: This definition is slightly different from the definition of ``tamagawa_product`` for curves defined over `\QQ`. Over the rational number it is always defined to be the product of the Tamagawa numbers, so the two definitions only agree when the model is global minimal. OUTPUT: A rational number EXAMPLES:: sage: K.<i> = NumberField(x^2+1) sage: E = EllipticCurve([0,2+i]) sage: E.tamagawa_product() 1 sage: E = EllipticCurve([(2*i+1)^2,i*(2*i+1)^7]) sage: E.tamagawa_product() 4 An example where the Neron model changes over K:: sage: K.<t> = NumberField(x^5-10*x^3+5*x^2+10*x+1) sage: E = EllipticCurve(K,'75a1') sage: E.tamagawa_product() 5 sage: da = E.local_data() sage: [dav.tamagawa_number() for dav in da] [1, 1] REFERENCES: - [Ta2] Tate, John, On the conjectures of Birch and Swinnerton-Dyer and a geometric analog. Seminaire Bourbaki, Vol. 9, Exp. No. 306. - [Do] Dokchitser, Tim and Vladimir, On the Birch-Swinnerton-Dyer quotients modulo squares, Annals of Math., 2010. """ da = self.local_data() pr = 1 for dav in da: pp = dav.prime() cv = dav.tamagawa_number() # uu is the quotient of the Neron differential at pp divided by # the differential associated to this particular equation E uu = self.isomorphism_to(dav.minimal_model()).u uu_abs_val = pp.smallest_integer()**(pp.residue_class_degree()*valuation(uu,pp)) pr *= cv * uu_abs_val return pr
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 documentation for plot. INPUT: - ``funcs`` - a function - other options are passed to plot EXAMPLES: Here is a blue 8-leaved petal:: sage: polar_plot(sin(5*x)^2, (x, 0, 2*pi), color='blue') A red figure-8:: sage: polar_plot(abs(sqrt(1 - sin(x)^2)), (x, 0, 2*pi), color='red') A green limacon of Pascal:: sage: polar_plot(2 + 2*cos(x), (x, 0, 2*pi), color=hue(0.3)) Several polar plots:: sage: polar_plot([2*sin(x), 2*cos(x)], (x, 0, 2*pi)) A filled spiral:: sage: polar_plot(sqrt, 0, 2 * pi, fill = True) Fill the area between two functions:: sage: polar_plot(cos(4*x) + 1.5, 0, 2*pi, fill=0.5 * cos(4*x) + 2.5, fillcolor='orange').show(aspect_ratio=1) Fill the area between several spirals:: sage: polar_plot([(1.2+k*0.2)*log(x) for k in range(6)], 1, 3 * pi, fill = {0: [1], 2: [3], 4: [5]}) Exclude points at discontinuities:: sage: polar_plot(log(floor(x)), (x, 1, 4*pi), aspect_ratio = 1, exclude = [1..12]) """ kwds['polar']=True return plot(funcs, *args, **kwds)
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 documentation for plot. INPUT: - ``funcs`` - a function - other options are passed to plot EXAMPLES: Here is a blue 8-leaved petal:: sage: polar_plot(sin(5*x)^2, (x, 0, 2*pi), color='blue') A red figure-8:: sage: polar_plot(abs(sqrt(1 - sin(x)^2)), (x, 0, 2*pi), color='red') A green limacon of Pascal:: sage: polar_plot(2 + 2*cos(x), (x, 0, 2*pi), color=hue(0.3)) Several polar plots:: sage: polar_plot([2*sin(x), 2*cos(x)], (x, 0, 2*pi)) A filled spiral:: sage: polar_plot(sqrt, 0, 2 * pi, fill = True) Fill the area between two functions:: sage: polar_plot(cos(4*x) + 1.5, 0, 2*pi, fill=0.5 * cos(4*x) + 2.5, fillcolor='orange').show(aspect_ratio=1) Fill the area between several spirals:: sage: polar_plot([(1.2+k*0.2)*log(x) for k in range(6)], 1, 3 * pi, fill = {0: [1], 2: [3], 4: [5]}) Exclude points at discontinuities:: sage: polar_plot(log(floor(x)), (x, 1, 4*pi), aspect_ratio = 1, exclude = [1..12]) """ kwds['polar']=True return plot(funcs, *args, **kwds)
_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 = _vars.split("*")[1] order = 'lp' else: _vars = str(self.gens()) order = self.term_order().singular_str() base_ring = self.base_ring()
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 vectors of length i. Reference: This is a slightly modified version of Cohn's Algorithm 2.7.5 in "A Course in Computational Number Theory", with the increment step moved around and slightly re-indexed to allow clean looping. Note: We could speed this up for very skew matrices by using LLL first, and then changing coordinates back, but for our purposes the simpler method is efficient enough. =) EXAMPLES: sage: Q = DiagonalQuadraticForm(ZZ, [1,1]) sage: Q.vectors_by_length(5) [[[0, 0]], [[0, -1], [-1, 0]], [[-1, -1], [1, -1]], [], [[0, -2], [-2, 0]], [[-1, -2], [1, -2], [-2, -1], [2, -1]]] sage: Q1 = DiagonalQuadraticForm(ZZ, [1,3,5,7]) sage: Q1.vectors_by_length(5) [[[0, 0, 0, 0]], [[-1, 0, 0, 0]], [], [[0, -1, 0, 0]], [[-1, -1, 0, 0], [1, -1, 0, 0], [-2, 0, 0, 0]], [[0, 0, -1, 0]]] sage: Q = QuadraticForm(ZZ, 4, [1,1,1,1, 1,0,0, 1,0, 1]) sage: map(len, Q.vectors_by_length(2)) [1, 12, 12] """ # pari uses eps = 1e-6 ; nothing bad should happen if eps is too big # but if eps is too small, roundoff errors may knock off some # vectors of norm = bound (see #7100) eps = RDF(1e-6) bound = ZZ(floor(bound)) Theta_Precision = bound + eps n = self.dim() ## Make the vector of vectors which have a given value ## (So theta_vec[i] will have all vectors v with Q(v) = i.) theta_vec = [[] for i in range(bound + 1)] ## Initialize Q with zeros and Copy the Cholesky array into Q Q = self.cholesky_decomposition() ## 1. Initialize T = n * [RDF(0)] ## Note: We index the entries as 0 --> n-1 U = n * [RDF(0)] i = n-1 T[i] = RDF(Theta_Precision) U[i] = RDF(0) L = n * [0] x = n * [0] Z = RDF(0) ## 2. Compute bounds Z = (T[i] / Q[i][i]).sqrt(extend=False) L[i] = ( Z - U[i]).floor() x[i] = (-Z - U[i]).ceil() done_flag = False Q_val_double = RDF(0) Q_val = 0 ## WARNING: Still need a good way of checking overflow for this value... ## Big loop which runs through all vectors while not done_flag: ## 3b. Main loop -- try to generate a complete vector x (when i=0) while (i > 0): #print " i = ", i #print " T[i] = ", T[i] #print " Q[i][i] = ", Q[i][i] #print " x[i] = ", x[i] #print " U[i] = ", U[i] #print " x[i] + U[i] = ", (x[i] + U[i]) #print " T[i-1] = ", T[i-1] T[i-1] = T[i] - Q[i][i] * (x[i] + U[i]) * (x[i] + U[i]) #print " T[i-1] = ", T[i-1] #print " x = ", x #print i = i - 1 U[i] = 0 for j in range(i+1, n): U[i] = U[i] + Q[i][j] * x[j] ## Now go back and compute the bounds... ## 2. Compute bounds Z = (T[i] / Q[i][i]).sqrt(extend=False) L[i] = ( Z - U[i]).floor() x[i] = (-Z - U[i]).ceil() ## 4. Solution found (This happens when i = 0) #print "-- Solution found! --" #print " x = ", x #print " Q_val = Q(x) = ", Q_val Q_val_double = Theta_Precision - T[0] + Q[0][0] * (x[0] + U[0]) * (x[0] + U[0]) Q_val = Q_val_double.round() ## SANITY CHECK: Roundoff Error is < 0.001 if abs(Q_val_double - Q_val) > 0.001: print " x = ", x print " Float = ", Q_val_double, " Long = ", Q_val raise RuntimeError, "The roundoff error is bigger than 0.001, so we should use more precision somewhere..." #print " Float = ", Q_val_double, " Long = ", Q_val, " XX " #print " The float value is ", Q_val_double #print " The associated long value is ", Q_val if (Q_val <= bound): #print " Have vector ", x, " with value ", Q_val theta_vec[Q_val].append(deepcopy(x)) ## 5. Check if x = 0, for exit condition. =) j = 0 done_flag = True while (j < n): if (x[j] != 0): done_flag = False j += 1 ## 3a. Increment (and carry if we go out of bounds) x[i] += 1 while (x[i] > L[i]) and (i < n-1): i += 1 x[i] += 1 #print " Leaving ThetaVectors()" return theta_vec
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 Tableaux_all(): return Tableau_class(t) raise ValueError, "invalid tableau"
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.anti_restrict(3) [[None, None, None], [4, 5]] sage: t.anti_restrict(4) [[None, None, None], [None, 5]] """ t = list(copy.deepcopy(self))
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 Tableaux of size 4 sage: [[1,2],[3,4]] in T True sage: [[1,2],[3]] in T False sage: [1,2,3] in T False """ if n == None: return Tableaux_all() else: return Tableaux_n(n)
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 Tableaux of size 4 sage: [[1,2],[3,4]] in T True sage: [[1,2],[3]] in T False sage: [1,2,3] in T False """ if n == None: return Tableaux_all() else: return Tableaux_n(n)
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 p. If mu is also specified, then it returns the class of semistandard tableaux with evaluation/content mu. EXAMPLES:: sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] sage: SST.list() [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] :: sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 sage: SST.list() [[[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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ if p == None: return SemistandardTableaux_all() elif p in partition.Partitions(): if mu == None: return SemistandardTableaux_p(p) else: if sum(p) != sum(mu): #Error size mismatch raise TypeError, "p and mu must be of the same size" else: return SemistandardTableaux_pmu(p, mu) elif isinstance(p, (int, Integer)): if mu == None: return SemistandardTableaux_n(p) else: if p != sum(mu): #Error size mismatch raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu) else: raise ValueError
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 p. If mu is also specified, then it returns the class of semistandard tableaux with evaluation/content mu. EXAMPLES:: sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] sage: SST.list() [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] :: sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 sage: SST.list() [[[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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ if p == None: return SemistandardTableaux_all() elif p in partition.Partitions(): if mu == None: return SemistandardTableaux_p(p) else: if sum(p) != sum(mu): #Error size mismatch raise TypeError, "p and mu must be of the same size" else: return SemistandardTableaux_pmu(p, mu) elif isinstance(p, (int, Integer)): if mu == None: return SemistandardTableaux_n(p) else: if p != sum(mu): #Error size mismatch raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu) else: raise ValueError
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 p. If mu is also specified, then it returns the class of semistandard tableaux with evaluation/content mu. EXAMPLES:: sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] sage: SST.list() [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] :: sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 sage: SST.list() [[[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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ if p == None: return SemistandardTableaux_all() elif p in partition.Partitions(): if mu == None: return SemistandardTableaux_p(p) else: if sum(p) != sum(mu): #Error size mismatch raise TypeError, "p and mu must be of the same size" else: return SemistandardTableaux_pmu(p, mu) elif isinstance(p, (int, Integer)): if mu == None: return SemistandardTableaux_n(p) else: if p != sum(mu): #Error size mismatch raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu) else: raise ValueError
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 p. If mu is also specified, then it returns the class of semistandard tableaux with evaluation/content mu. EXAMPLES:: sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] sage: SST.list() [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] :: sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 sage: SST.list() [[[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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ if p == None: return SemistandardTableaux_all() elif p in partition.Partitions(): if mu == None: return SemistandardTableaux_p(p) else: if sum(p) != sum(mu): #Error size mismatch raise TypeError, "p and mu must be of the same size" else: return SemistandardTableaux_pmu(p, mu) elif isinstance(p, (int, Integer)): if mu == None: return SemistandardTableaux_n(p) else: if p != sum(mu): #Error size mismatch raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu) else: raise ValueError
::
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 p. If mu is also specified, then it returns the class of semistandard tableaux with evaluation/content mu. EXAMPLES:: sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] sage: SST.list() [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] :: sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 sage: SST.list() [[[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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ if p == None: return SemistandardTableaux_all() elif p in partition.Partitions(): if mu == None: return SemistandardTableaux_p(p) else: if sum(p) != sum(mu): #Error size mismatch raise TypeError, "p and mu must be of the same size" else: return SemistandardTableaux_pmu(p, mu) elif isinstance(p, (int, Integer)): if mu == None: return SemistandardTableaux_n(p) else: if p != sum(mu): #Error size mismatch raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu) else: raise ValueError
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 p. If mu is also specified, then it returns the class of semistandard tableaux with evaluation/content mu. EXAMPLES:: sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] sage: SST.list() [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] :: sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 sage: SST.list() [[[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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ if p == None: return SemistandardTableaux_all() elif p in partition.Partitions(): if mu == None: return SemistandardTableaux_p(p) else: if sum(p) != sum(mu): #Error size mismatch raise TypeError, "p and mu must be of the same size" else: return SemistandardTableaux_pmu(p, mu) elif isinstance(p, (int, Integer)): if mu == None: return SemistandardTableaux_n(p) else: if p != sum(mu): #Error size mismatch raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu) else: raise ValueError
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) else: return SemistandardTableaux_nmu(sum(mu), 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 p. If mu is also specified, then it returns the class of semistandard tableaux with evaluation/content mu. EXAMPLES:: sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] sage: SST.list() [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] :: sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 sage: SST.list() [[[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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ if p == None: return SemistandardTableaux_all() elif p in partition.Partitions(): if mu == None: return SemistandardTableaux_p(p) else: if sum(p) != sum(mu): #Error size mismatch raise TypeError, "p and mu must be of the same size" else: return SemistandardTableaux_pmu(p, mu) elif isinstance(p, (int, Integer)): if mu == None: return SemistandardTableaux_n(p) else: if p != sum(mu): #Error size mismatch raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu) else: raise ValueError
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 p. If mu is also specified, then it returns the class of semistandard tableaux with evaluation/content mu. EXAMPLES:: sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] sage: SST.list() [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] :: sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 sage: SST.list() [[[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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ if p == None: return SemistandardTableaux_all() elif p in partition.Partitions(): if mu == None: return SemistandardTableaux_p(p) else: if sum(p) != sum(mu): #Error size mismatch raise TypeError, "p and mu must be of the same size" else: return SemistandardTableaux_pmu(p, mu) elif isinstance(p, (int, Integer)): if mu == None: return SemistandardTableaux_n(p) else: if p != sum(mu): #Error size mismatch raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu) else: raise ValueError
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 p. If mu is also specified, then it returns the class of semistandard tableaux with evaluation/content mu. EXAMPLES:: sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] sage: SST.list() [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] :: sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 sage: SST.list() [[[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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ if p == None: return SemistandardTableaux_all() elif p in partition.Partitions(): if mu == None: return SemistandardTableaux_p(p) else: if sum(p) != sum(mu): #Error size mismatch raise TypeError, "p and mu must be of the same size" else: return SemistandardTableaux_pmu(p, mu) elif isinstance(p, (int, Integer)): if mu == None: return SemistandardTableaux_n(p) else: if p != sum(mu): #Error size mismatch raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu) else: raise ValueError
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 p. If mu is also specified, then it returns the class of semistandard tableaux with evaluation/content mu. EXAMPLES:: sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] sage: SST.list() [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] :: sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 sage: SST.list() [[[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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ if p == None: return SemistandardTableaux_all() elif p in partition.Partitions(): if mu == None: return SemistandardTableaux_p(p) else: if sum(p) != sum(mu): #Error size mismatch raise TypeError, "p and mu must be of the same size" else: return SemistandardTableaux_pmu(p, mu) elif isinstance(p, (int, Integer)): if mu == None: return SemistandardTableaux_n(p) else: if p != sum(mu): #Error size mismatch raise TypeError, "mu must be of size p (= %s)"%p else: return SemistandardTableaux_nmu(p, mu) else: raise ValueError
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) Semistandard tableaux with maximum entry 3 """ if self.max_entry is not None: return "Semistandard tableaux with maximum entry %s"%str(self.max_entry) return "Semistandard tableaux"
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 first position is 1 for row in t: for i in row: if not isinstance(i, (int, Integer)): return False
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 first position is 1 for row in t: for i in row: if not isinstance(i, (int, Integer)): return False
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 first position is 1 for row in t: for i in row: if not isinstance(i, (int, Integer)): return False
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 first position is 1 for row in t: for i in row: if not isinstance(i, (int, Integer)): return False
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.Partitions(self.n): c += SemistandardTableaux(part).cardinality() return c
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, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]], [[1], [2], [3]]] """ for part in partition.Partitions(self.n): for sst in SemistandardTableaux(part): yield sst
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 comp in IntegerVectors(sum(self.p), sum(self.p)): c += SemistandardTableaux_pmu(self.p, comp).cardinality() return c
""" 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]) ] [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], [[1, 2], [3]], [[1, 3], [2]], [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] sage: [ t for t in SemistandardTableaux([1,1,1]) ] [[[1], [2], [3]]] """ for c in IntegerVectors(sum(self.p), sum(self.p)): for sst in SemistandardTableaux(self.p, c): yield sst
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_tkz_graph``, and any subsequent time, it just checks the value of the variable, without printing any warnings. So any doctest that illustrates the use of the tkz-graph packages should call this once as having random output to exhaust the warnings before testing output. TESTS:: sage: from sage.graphs.graph_latex import check_tkz_graph sage: check_tkz_graph() # random - depends on TeX installation sage: check_tkz_graph() # at least the second time, so no output """ global _checked_tkz_graph if not _checked_tkz_graph: import os have_tkzgraph = not bool(os.system('kpsewhich tkz-graph.sty > /dev/null')) if not have_tkzgraph: print 'Warning: tkz-graph.sty is not part' print "of this computer's TeX installation." print 'This package is required to' print 'render graphs in LaTeX. Visit' print 'http://altermundus.com/pages/graph.html' have_tkzberge = not bool(os.system('kpsewhich tkz-berge.sty > /dev/null')) if not have_tkzberge: print 'Warning: tkz-berge.sty is not part' print "of this computer's TeX installation." print 'This package is required to' print 'render graphs in LaTeX. Visit' print 'http://altermundus.com/pages/graph.html' _checked_tkz_graph = True
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_tkz_graph``, and any subsequent time, it just checks the value of the variable, without printing any warnings. So any doctest that illustrates the use of the tkz-graph packages should call this once as having random output to exhaust the warnings before testing output. TESTS:: sage: from sage.graphs.graph_latex import check_tkz_graph sage: check_tkz_graph() # random - depends on TeX installation sage: check_tkz_graph() # at least the second time, so no output """ global _checked_tkz_graph if not _checked_tkz_graph: import os have_tkzgraph = not bool(os.system('kpsewhich tkz-graph.sty > /dev/null')) if not have_tkzgraph: print 'Warning: tkz-graph.sty is not part' print "of this computer's TeX installation." print 'This package is required to' print 'render graphs in LaTeX. Visit' print 'http://altermundus.com/pages/graph.html' have_tkzberge = not bool(os.system('kpsewhich tkz-berge.sty > /dev/null')) if not have_tkzberge: print 'Warning: tkz-berge.sty is not part' print "of this computer's TeX installation." print 'This package is required to' print 'render graphs in LaTeX. Visit' print 'http://altermundus.com/pages/graph.html' _checked_tkz_graph = True
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 variable. TESTS:: sage: from sage.graphs.graph_latex import have_tkz_graph, _have_tkz_graph sage: have_tkz_graph() # random - depends on TeX installation sage: _have_tkz_graph is None False sage: _have_tkz_graph == have_tkz_graph() True """ global _have_tkz_graph if _have_tkz_graph is None: import os 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_tkz_graph = have_tkzgraph and have_tkzberge return _have_tkz_graph
- ``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) False sage: GenericDeclaration(x, 'integer').contradicts(x==4.5) True sage: GenericDeclaration(x, 'integer').contradicts(x==sqrt(17)) True sage: GenericDeclaration(x, 'noninteger').contradicts(x==sqrt(17)) False sage: GenericDeclaration(x, 'noninteger').contradicts(x==17) True sage: GenericDeclaration(x, 'even').contradicts(x==3) True sage: GenericDeclaration(x, 'complex').contradicts(x==3) False sage: GenericDeclaration(x, 'imaginary').contradicts(x==3) True sage: GenericDeclaration(x, 'imaginary').contradicts(x==I) False
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 [1 0] [0 1] sage: M.parent() Full MatrixSpace of 2 by 2 dense matrices over Integer Ring sage: M = identity_matrix(3, sparse=True); M [1 0 0] [0 1 0] [0 0 1] sage: M.parent() Full MatrixSpace of 3 by 3 sparse matrices over Integer Ring """ if isinstance(ring, (int, long, rings.Integer)): n = ring ring = rings.ZZ return matrix_space.MatrixSpace(ring, n, n, sparse).identity_matrix()
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, 3); M [0 0 0] [0 0 0] sage: M.parent() Full MatrixSpace of 2 by 3 dense matrices over Integer Ring sage: M = zero_matrix(3, 1, sparse=True); M [0] [0] [0] sage: M.parent() Full MatrixSpace of 3 by 1 sparse matrices over Integer Ring """ if isinstance(ring, (int, long, rings.Integer)): nrows, ncols = (ring, nrows) ring = rings.ZZ return matrix_space.MatrixSpace(ring, nrows, ncols, sparse).zero_matrix()
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__(self, other):
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)] [[True, False, False, False, False], [False, True, False, False, False], [False, False, True, False, False], [False, False, False, True, False], [False, False, False, False, True]]
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 False sage: Q != Q False sage: [[p1.__ne__(p2) for p1 in Posets(2)] for p2 in Posets(2)] [[False, True], [True, False]] """ return (not self.__eq__(other))
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 of `1`). Set to ``False`` by default. - ``algorithm`` -- one of ``"MILP"`` (default) or ``"backtrack"``. Two remarks on this respect: * While the MILP formulation returns an exact answer, the backtrack algorithm is a randomized heuristic. * As the backtrack algorithm does not support edge weighting, setting ``weighted=True`` will force the use of the MILP algorithm.
- ``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 longest path ending at ``t``). The argument is set to ``None`` by default, which means that no constraint is set upon the last vertex in the path. - ``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 of `1`). Set to ``False`` by default. - ``algorithm`` -- one of ``"MILP"`` (default) or ``"backtrack"``. Two remarks on this respect: * While the MILP formulation returns an exact answer, the backtrack algorithm is a randomized heuristic. * As the backtrack algorithm does not support edge weighting, setting ``weighted=True`` will force the use of the MILP algorithm.
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+(k+1)*step > b``. INPUT: universe -- Parent or type where all the elements should live (default: deduce from inputs) check -- make sure a, b, and step all lie in the same universe include_endpoint -- whether or not to include the endpoint (default: False) endpoint_tolerance -- used to determine whether or not the endpoint is hit for inexact rings (default 1e-5) - ``a`` - number - ``b`` - number - ``step`` - number (default: 1) OUTPUT: iterator Unlike range, a and b can be any type of numbers, and the resulting iterator involves numbers of that type. .. seealso:: :func:`srange` .. note:: This function is called ``xsrange`` to distinguish it from the builtin Python ``xrange`` command. EXAMPLES:: sage: list(xsrange(1,10)) [1, 2, 3, 4, 5, 6, 7, 8, 9] sage: Q = RationalField() sage: list(xsrange(1, 10, Q('1/2'))) [1, 3/2, 2, 5/2, 3, 7/2, 4, 9/2, 5, 11/2, 6, 13/2, 7, 15/2, 8, 17/2, 9, 19/2] sage: list(xsrange(1, 5, 0.5)) [1.00000000000000, 1.50000000000000, 2.00000000000000, 2.50000000000000, 3.00000000000000, 3.50000000000000, 4.00000000000000, 4.50000000000000] sage: list(xsrange(0, 1, 0.4)) [0.000000000000000, 0.400000000000000, 0.800000000000000] Negative ranges are also allowed:: sage: list(xrange(4,1,-1)) [4, 3, 2] sage: list(sxrange(4,1,-1)) [4, 3, 2] sage: list(sxrange(4,1,-1/2)) [4, 7/2, 3, 5/2, 2, 3/2] """ from sage.structure.sequence import Sequence from sage.rings.all import ZZ if end is None: end = start start = 0 if check: if universe is None: universe = Sequence([start, end, step]).universe() start, end, step = universe(start), universe(end), universe(step) if universe in [int, long, ZZ]: if include_endpoint and (end-start) % step == 0: end += step include_endpoint = False if universe is not ZZ: return xrange(start, end, step) count = (end-start)/step if universe is long or not isinstance(universe, type) and universe.is_exact(): icount = int(math.ceil(float(count))) if icount != count: include_endpoint = False else: icount = int(math.ceil(float(count) - endpoint_tolerance)) if abs(float(count) - icount) > endpoint_tolerance: include_endpoint = False
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 way to iterate over Sage integers as opposed to Python int's. It also allows you to specify step sizes for such an iteration. Note, however, that what is returned is a full list of Integers and not an iterator. It is potentially much slower than the Python range function, depending on the application. The function xsrange() provides an iterator with similar functionality which would usually be more efficient than using srange(). INPUT: - ``a`` - number - ``b`` - number (default: None) - ``step`` - number (default: 1) - ``universe`` - Parent or type where all the elements should live (default: deduce from inputs) - ``check`` - make sure a, b, and step all lie in the same universe - ``include_endpoint`` - whether or not to include the endpoint (default: False) - ``endpoint_tolerance`` - used to determine whether or not the endpoint is hit for inexact rings (default 1e-5) OUTPUT: - list If b is None, then b is set equal to a and a is set equal to the 0 in the parent of b. Unlike range, a and b can be any type of numbers, and the resulting list involves numbers of that type. .. note:: The list elements are computed via repeated addition rather than multiplication, which may produce slightly different results with inexact rings. For example:: sage: sum([1.1] * 10) == 1.1 * 10 False Also, the question of whether the endpoint is hit exactly for a given ``a + k*step`` is fuzzy for an inexact ring. If ``a + k*step = b`` for some k within ``endpoint_tolerance`` of being integral, it is considered an exact hit, thus avoiding spurious values falling just below the endpoint. .. note:: This function is called ``srange`` to distinguish it from the built-in Python ``range`` command. The s at the beginning of the name stands for "Sage". .. seealso: :func:`xsrange` -- iterator version EXAMPLES:: sage: v = srange(5); v [0, 1, 2, 3, 4] sage: type(v[2]) <type 'sage.rings.integer.Integer'> sage: srange(1, 10) [1, 2, 3, 4, 5, 6, 7, 8, 9] sage: srange(10, 1, -1) [10, 9, 8, 7, 6, 5, 4, 3, 2] sage: srange(10,1,-1, include_endpoint=True) [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] sage: srange(1, 10, universe=RDF) [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] sage: srange(1, 10, 1/2) [1, 3/2, 2, 5/2, 3, 7/2, 4, 9/2, 5, 11/2, 6, 13/2, 7, 15/2, 8, 17/2, 9, 19/2] sage: srange(1, 5, 0.5) [1.00000000000000, 1.50000000000000, 2.00000000000000, 2.50000000000000, 3.00000000000000, 3.50000000000000, 4.00000000000000, 4.50000000000000] sage: srange(0, 1, 0.4) [0.000000000000000, 0.400000000000000, 0.800000000000000] sage: srange(1.0, 5.0, include_endpoint=True) [1.00000000000000, 2.00000000000000, 3.00000000000000, 4.00000000000000, 5.00000000000000] sage: srange(1.0, 1.1) [1.00000000000000] sage: srange(1.0, 1.0) [] sage: V = VectorSpace(QQ, 2) sage: srange(V([0,0]), V([5,5]), step=V([2,2])) [(0, 0), (2, 2), (4, 4)] Including the endpoint:: sage: srange(0, 10, step=2, include_endpoint=True) [0, 2, 4, 6, 8, 10] sage: srange(0, 10, step=3, include_endpoint=True) [0, 3, 6, 9] Try some inexact rings:: sage: srange(0.5, 1.1, 0.1, universe=RDF, include_endpoint=False) [0.5, 0.6, 0.7, 0.8, 0.9, 1.0] sage: srange(0.5, 1, 0.1, universe=RDF, include_endpoint=False) [0.5, 0.6, 0.7, 0.8, 0.9] sage: srange(0.5, 0.9, 0.1, universe=RDF, include_endpoint=False) [0.5, 0.6, 0.7, 0.8] sage: srange(0, 1.1, 0.1, universe=RDF, include_endpoint=True) [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1] sage: srange(0, 0.2, 0.1, universe=RDF, include_endpoint=True) [0.0, 0.1, 0.2] sage: srange(0, 0.3, 0.1, universe=RDF, include_endpoint=True) [0.0, 0.1, 0.2, 0.3] """ from sage.structure.sequence import Sequence from sage.rings.all import ZZ if end is None: end = start start = 0 if check: if universe is None: universe = Sequence([start, end, step]).universe() start, end, step = universe(start), universe(end), universe(step) if universe in [int, long, ZZ]: if include_endpoint and (end-start) % step == 0: end += step if universe is ZZ: return ZZ.range(start, end, step) else: # universe is int or universe is long: return range(start, end, step) count = (end-start)/step if not isinstance(universe, type) and universe.is_exact(): icount = int(math.ceil(float(count))) if icount != count: include_endpoint = False else: icount = int(math.ceil(float(count) - endpoint_tolerance)) if abs(float(count) - icount) > endpoint_tolerance: include_endpoint = False L = [] for k in xrange(icount): L.append(start) start += step if include_endpoint: L.append(end) return L
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_object_enumerated
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))