| 3282 | |
| 3283 | def zeta_polynomial(self): |
| 3284 | r""" |
| 3285 | Return the zeta polynomial of the poset |
| 3286 | |
| 3287 | The zeta polynomial of a poset is the unique polynomial `Z(q)` |
| 3288 | such that for every integer `m > 1`, `Z(m)` is the number of |
| 3289 | weakly increasing sequences `x_1 \leq x_2 \leq \dots \leq x_{m-1}`. |
| 3290 | |
| 3291 | In particular, `Z(2)` is the number of vertices and `Z(3)` is |
| 3292 | the number of intervals. |
| 3293 | |
| 3294 | EXAMPLES:: |
| 3295 | |
| 3296 | sage: Posets.ChainPoset(2).zeta_polynomial() |
| 3297 | q |
| 3298 | sage: Posets.ChainPoset(3).zeta_polynomial() |
| 3299 | 1/2*q^2 + 1/2*q |
| 3300 | sage: P = posets.PentagonPoset() |
| 3301 | sage: P.zeta_polynomial() |
| 3302 | 1/6*q^3 + q^2 - 1/6*q |
| 3303 | sage: P = Posets.DiamondPoset(5) |
| 3304 | sage: P.zeta_polynomial() |
| 3305 | 3/2*q^2 - 1/2*q |
| 3306 | """ |
| 3307 | q = polygen(QQ, 'q') |
| 3308 | g = sum(q**len(ch) for ch in self.chains()) |
| 3309 | n = g.degree() |
| 3310 | f = g[max(n, 1)] |
| 3311 | while n > 1: |
| 3312 | f = (q - n)*f |
| 3313 | n = n - 1 |
| 3314 | f = g[n] + f/n |
| 3315 | return f |
| 3316 | |
| 3317 | |
| 3318 | def remove_top_and_bottom(self): |
| 3319 | r""" |
| 3320 | removes the top and bottom of a bounded poset |
| 3321 | |
| 3322 | EXAMPLES:: |
| 3323 | |
| 3324 | sage: Q = Posets.DiamondPoset(5).remove_top_and_bottom() |
| 3325 | sage: Q.is_isomorphic(Posets.AntichainPoset(3)) |
| 3326 | True |
| 3327 | |
| 3328 | TESTS:: |
| 3329 | |
| 3330 | sage: P = Poset({1:[2, 3]}) |
| 3331 | sage: P.remove_top_and_bottom() |
| 3332 | Traceback (most recent call last): |
| 3333 | ... |
| 3334 | TypeError: the poset is not bounded |
| 3335 | """ |
| 3336 | if not(self.is_bounded()): |
| 3337 | raise TypeError('the poset is not bounded') |
| 3338 | return self.subposet([v for v in self |
| 3339 | if not(v in self.minimal_elements() |
| 3340 | or v in self.maximal_elements())]) |
| 3341 | |
| 3342 | |
| 3343 | def f_polynomial(self): |
| 3344 | r""" |
| 3345 | Return the f-polynomial of a bounded poset |
| 3346 | |
| 3347 | EXAMPLES:: |
| 3348 | |
| 3349 | sage: P = Posets.DiamondPoset(5) |
| 3350 | sage: P.f_polynomial() |
| 3351 | 3*q^2 + q |
| 3352 | sage: P = Poset({1:[2,3],2:[4],3:[5],4:[6],5:[7],6:[7]}) |
| 3353 | sage: P.f_polynomial() |
| 3354 | q^4 + 4*q^3 + 5*q^2 + q |
| 3355 | """ |
| 3356 | P = self.remove_top_and_bottom() |
| 3357 | q = polygen(ZZ, 'q') |
| 3358 | if self.cardinality() == 0: |
| 3359 | return q.parent().one() |
| 3360 | else: |
| 3361 | return q*sum(q**len(ch) for ch in P.chains()) |
| 3362 | |
| 3363 | |
| 3364 | def h_polynomial(self): |
| 3365 | r""" |
| 3366 | Return the h-polynomial of a bounded poset |
| 3367 | |
| 3368 | EXAMPLES:: |
| 3369 | |
| 3370 | sage: P = Posets.AntichainPoset(3).order_ideals_lattice() |
| 3371 | sage: P.h_polynomial() |
| 3372 | q^3 + 4*q^2 + q |
| 3373 | sage: P = Posets.DiamondPoset(5) |
| 3374 | sage: P.h_polynomial() |
| 3375 | 2*q^2 + q |
| 3376 | """ |
| 3377 | P = self.remove_top_and_bottom() |
| 3378 | q = polygen(ZZ, 'q') |
| 3379 | if self.cardinality() == 0: |
| 3380 | return q.parent().one() |
| 3381 | f = sum(q**len(ch) for ch in P.chains()) |
| 3382 | d = f.degree() |
| 3383 | f = (1-q)**d * q * f(q=q/(1-q)) |
| 3384 | return q.parent(f) |
| 3385 | |
| 3386 | |
| 3387 | def flag_f_polynomial(self): |
| 3388 | r""" |
| 3389 | Return the flag f-polynomial of a bounded and ranked poset |
| 3390 | |
| 3391 | EXAMPLES:: |
| 3392 | |
| 3393 | sage: P = Posets.DiamondPoset(5) |
| 3394 | sage: P.flag_f_polynomial() |
| 3395 | 3*x1*x2 + x2 |
| 3396 | |
| 3397 | sage: P = Poset({1:[2,3],2:[4],3:[5],4:[6],5:[6]}) |
| 3398 | sage: fl = P.flag_f_polynomial(); fl |
| 3399 | 2*x1*x2*x3 + 2*x1*x3 + 2*x2*x3 + x3 |
| 3400 | sage: q = polygen(ZZ,'q') |
| 3401 | sage: fl(q,q,q,q) == P.f_polynomial() |
| 3402 | True |
| 3403 | |
| 3404 | sage: P = Poset({1:[2,3,4],2:[5],3:[5],4:[5],5:[6]}) |
| 3405 | sage: P.flag_f_polynomial() |
| 3406 | 3*x1*x2*x3 + 3*x1*x3 + x2*x3 + x3 |
| 3407 | """ |
| 3408 | from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing |
| 3409 | P = self.remove_top_and_bottom() |
| 3410 | if not(self.is_ranked()): |
| 3411 | raise TypeError('the poset should be ranked') |
| 3412 | rk = P.rank_function() |
| 3413 | n = rk(P.maximal_elements()[0]) |
| 3414 | anneau = PolynomialRing(ZZ, 'x', n+3) |
| 3415 | if self.cardinality() == 0: |
| 3416 | return anneau.one() |
| 3417 | else: |
| 3418 | x = anneau.gens() |
| 3419 | return x[n+2]*sum(prod(x[1+rk(i)] for i in ch) for ch in P.chains()) |
| 3420 | |
| 3421 | |
| 3422 | def flag_h_polynomial(self): |
| 3423 | r""" |
| 3424 | Return the flag h-polynomial of a bounded and ranked poset |
| 3425 | |
| 3426 | EXAMPLES:: |
| 3427 | |
| 3428 | sage: P = Posets.DiamondPoset(5) |
| 3429 | sage: P.flag_h_polynomial() |
| 3430 | 2*x1*x2 + x2 |
| 3431 | |
| 3432 | sage: P = Poset({1:[2,3],2:[4],3:[5],4:[6],5:[6]}) |
| 3433 | sage: fl = P.flag_h_polynomial(); fl |
| 3434 | -x1*x2*x3 + x1*x3 + x2*x3 + x3 |
| 3435 | sage: q = polygen(ZZ,'q') |
| 3436 | sage: fl(q,q,q,q) == P.h_polynomial() |
| 3437 | True |
| 3438 | |
| 3439 | sage: P = Poset({1:[2,3,4],2:[5],3:[5],4:[5],5:[6]}) |
| 3440 | sage: P.flag_h_polynomial() |
| 3441 | 2*x1*x3 + x3 |
| 3442 | |
| 3443 | sage: P = posets.ChainPoset(4) |
| 3444 | sage: P.flag_h_polynomial() |
| 3445 | x3 |
| 3446 | """ |
| 3447 | from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing |
| 3448 | P = self.remove_top_and_bottom() |
| 3449 | if not(self.is_ranked()): |
| 3450 | raise TypeError('the poset should be ranked') |
| 3451 | rk = P.rank_function() |
| 3452 | n = rk(P.maximal_elements()[0]) |
| 3453 | anneau = PolynomialRing(QQ, 'x', n+3) |
| 3454 | if self.cardinality() == 0: |
| 3455 | return anneau.one() |
| 3456 | else: |
| 3457 | x = anneau.gens() |
| 3458 | return prod(1-x[k] for k in range(1, n+2))*x[n+2]*sum(prod(x[1+rk(i)]/(1-x[1+rk(i)]) for i in ch) for ch in P.chains()) |
| 3459 | |
| 3460 | |
| 3461 | def characteristic_polynomial(self): |
| 3462 | r""" |
| 3463 | Return the characteristic-polynomial of a graded poset |
| 3464 | |
| 3465 | EXAMPLES:: |
| 3466 | |
| 3467 | sage: P = Posets.DiamondPoset(5) |
| 3468 | sage: P.characteristic_polynomial() |
| 3469 | q^2 - 3*q + 2 |
| 3470 | sage: P = Poset({1:[2,3],2:[4],3:[5],4:[6],5:[6],6:[7]}) |
| 3471 | sage: P.characteristic_polynomial() |
| 3472 | q^4 - 2*q^3 + q |
| 3473 | """ |
| 3474 | if not(self.is_ranked()): |
| 3475 | raise TypeError('the poset should be ranked') |
| 3476 | rk = self.rank_function() |
| 3477 | n = rk(self.maximal_elements()[0]) |
| 3478 | x0 = self.minimal_elements()[0] |
| 3479 | q = polygen(ZZ, 'q') |
| 3480 | return sum(self.mobius_function(x0, x)*q**(n - rk(x)) for x in self) |
| 3481 | |
| 3482 | |