Source code for Sullivan_MM.AlgebraPL

   1r"""
   2
   3First, consider the free graded commutative algebra :math:`\bigwedge(t_0,\dots,t_n,y_0,\dots,y_n)`, where
   4the generators :math:`t_i` have degree :math:`0`, and the generators :math:`y_j` have degree :math:`1`.
   5The differential :math:`d` is given by
   6
   7.. math::
   8
   9    \begin{array}{rcl}
  10        d(t_i) &=& y_i, \\
  11        d(y_j) &=& 0.
  12    \end{array}
  13
  14
  15The cochain algebra :math:`(A_{PL})_{n}` is defined as the quotient:
  16
  17.. math::
  18
  19    (A_{PL})_n:=\frac{\bigwedge(t_0,\dots,t_n,y_0,\dots,y_n)}{\langle\sum {t_i}-1,\sum{y_j}\rangle}.
  20
  21The implementation of this algebra has been made taking into account that this algebra is equivalent
  22to the exterior algebra :math:`Ext_y=\frac{\bigwedge(y_0,\dots,y_n)}{\langle\sum{y_j}\rangle}` with coefficients
  23in the polynomial ring :math:`R_t:=\frac{\mathbb{Q}[t_0,\dots,t_n]}{\langle\sum {t_i}-1\rangle}`:
  24
  25.. math::
  26
  27    (A_{PL})_n:=R_t \otimes Ext_y.
  28
  29For that reason, :math:`R_t` is considered the base_ring of :math:`(A_{PL})_n`.
  30
  31.. NOTE::
  32
  33    Notice that this algebra is actually isomorphic to :math:`\bigwedge(t_1,\ldots,t_n,y_1,\ldots,y_n)`. That
  34    is, the relations allow us to express :math:`t_0` in terms of :math:`t_1,\ldots, t_n` and :math:`y_0` in terms of
  35    :math:`y_1,\ldots, y_n`. After eliminating :math:`t_0,y_0`, the expression of each element is unique. However,
  36    it is sometimes more convenient to use also :math:`t_0,y_0` to write certain formulas, so we will use one
  37    expression or the other depending on the context.
  38
  39AUTHORS:
  40
  41- Carlos Alquézar (2026-05-01): initial version
  42
  43"""
  44# ****************************************************************************
  45#       Copyright (C) 2026 Carlos Alquézar <alquezar@unizar.es>
  46#
  47# This program is free software: you can redistribute it and/or modify
  48# it under the terms of the GNU General Public License as published by
  49# the Free Software Foundation, either version 2 of the License, or
  50# (at your option) any later version.
  51#                  https://www.gnu.org/licenses/
  52# ****************************************************************************
  53
  54from sage.structure.unique_representation import UniqueRepresentation, CachedRepresentation
  55from sage.misc.cachefunc import cached_method, cached_function
  56from sage.structure.parent import Parent
  57from sage.structure.element import Element
  58from sage.algebras.clifford_algebra import ExteriorAlgebra
  59from sage.misc.latex import latex
  60from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
  61from sage.rings.integer_ring import ZZ
  62from sage.rings.rational_field import QQ
  63from sage.combinat.free_module import CombinatorialFreeModule
  64from sage.sets.set import Set
  65from sage.matrix.constructor import vector, matrix, zero_matrix, identity_matrix
  66from sage.combinat.subset import powerset
  67from sage.all import cartesian_product
  68import copy
  69import itertools
  70from math import prod, factorial
  71
  72
[docs] 73class AplN(ExteriorAlgebra, UniqueRepresentation, CachedRepresentation): 74 r""" 75 The Algebra of polynomial differential forms. 76 77 INPUT: 78 79 - ``n`` -- dimension 80 81 - ``labels`` -- (optional, default: ``t_i, y_i``); labels of the generators 82 83 .. tab:: Sage 84 85 EXAMPLES:: 86 87 sage: A = AplN(5) 88 sage: A 89 The Commutative Differential Graded Algebra (A_{PL})_{5} defined as 90 the tensor product of the Polynomial Ring QQ<t_{0},...,t_{5}> with 91 the Exterior Algebra generated by QQ<y_{0},...,y_{5}>. 92 93 The degrees of the generators are: 94 95 deg(t_i)=0 96 deg(y_j)=1 97 98 The differential 'd' is defined as: 99 100 d(t_i)=y_i 101 d(y_j)=0 102 103 sage: A.inject_variables() 104 Defining y0, y1, y2, y3, y4, y5 105 sage: R = A.base_ring() 106 sage: R.inject_variables() 107 Defining t0, t1, t2, t3, t4, t5 108 sage: p = t1*y2*y3 + t0**2*y4*y5 109 sage: p 110 t1*y2*y3 + t0^2*y4*y5 111 112 .. tab:: Raw code 113 114 EXAMPLES:: 115 116 A = AplN(5) 117 A.inject_variables() 118 R = A.base_ring() 119 R.inject_variables() 120 p = t1*y2*y3 + t0**2*y4*y5 121 122 labs = ('t2','t5','t6','y2','y5','y6') 123 A = AplN(n=2,labels=labs) 124 R = A.base_ring() 125 A.inject_variables() 126 R.inject_variables() 127 128 129 """ 130 def __init__(self, n, labels=[]): 131 r""" 132 Initialize ``self``. 133 134 INPUT: 135 136 - ``n`` -- dimension 137 138 - ``labels`` -- (optional, default: ``t_i, y_i``); labels of the generators 139 140 .. tab:: Sage 141 142 EXAMPLES:: 143 144 sage: A = AplN(5) 145 sage: A 146 The Commutative Differential Graded Algebra (A_{PL})_{5} defined as 147 the tensor product of the Polynomial Ring QQ<t_{0},...,t_{5}> with 148 the Exterior Algebra generated by QQ<y_{0},...,y_{5}>. 149 150 The degrees of the generators are: 151 152 deg(t_i)=0 153 deg(y_j)=1 154 155 The differential 'd' is defined as: 156 157 d(t_i)=y_i 158 d(y_j)=0 159 160 sage: A.inject_variables() 161 Defining y0, y1, y2, y3, y4, y5 162 sage: R = A.base_ring() 163 sage: R.inject_variables() 164 Defining t0, t1, t2, t3, t4, t5 165 sage: p = t1*y2*y3 + t0**2*y4*y5 166 sage: p 167 t1*y2*y3 + t0^2*y4*y5 168 169 170 sage: labs = ('t2','t5','t6','y2','y5','y6') 171 sage: A = AplN(n=2,labels=labs) 172 sage: R = A.base_ring() 173 sage: A.inject_variables() 174 Defining y2, y5, y6 175 sage: R.inject_variables() 176 Defining t2, t5, t6 177 178 .. tab:: Raw code 179 180 EXAMPLES:: 181 182 A = AplN(5) 183 A.inject_variables() 184 R = A.base_ring() 185 R.inject_variables() 186 p = t1*y2*y3 + t0**2*y4*y5 187 188 labs = ('t2','t5','t6','y2','y5','y6') 189 A = AplN(n=2,labels=labs) 190 R = A.base_ring() 191 A.inject_variables() 192 R.inject_variables() 193 194 """ 195 if (n < 0): 196 raise ValueError('`n` must be a non-negative integer') 197 if (labels and (not ((2 * (n + 1)) == len(labels)))): 198 raise ValueError( 199 (('`labels` must have length `' + str((n + 1))) + '`')) 200 self.n = n 201 self.name = ('Apl' + str(n)) 202 self._reduced_basis = {} 203 self._reduced_monomials = {} 204 self._multiplication_tables = {} 205 self._multiplication_table_indexes = {} 206 self._multiplication_table_sgns = {} 207 self._graded_module_endomorphisms = {} 208 if labels: 209 ts = labels[:(n + 1)] 210 ys = labels[(n + 1):] 211 self.labels = labels 212 else: 213 ts = [('t' + str(t)) for t in range((n + 1))] 214 ys = [('y' + str(t)) for t in range((n + 1))] 215 self.labels = tuple(range((n + 1))) 216 base_ring = PolynomialRing(QQ, names=ts) 217 ExteriorAlgebra.__init__(self, base_ring, names=ys) 218 219 @cached_method(do_pickle=True) 220 def _basis_indexes(self, deg): 221 r""" 222 Considering ``self`` as a graded module, and serializing the basis of all modules up to degree ``deg``, 223 this method returns the indexes corresponding to the elements of degree ``deg``. 224 225 INPUT: 226 227 - ``deg`` -- integer; 228 229 OUTPUT: a tuple of indexes with format (start, end). 230 231 .. tab:: Sage 232 233 EXAMPLES:: 234 235 """ 236 nGens = [len(self.basis(d)) for d in range((self.n + 2))] 237 cumsum = [0] 238 for g in nGens: 239 cumsum.append((cumsum[(- 1)] + g)) 240 if (deg == (self.n + 1)): 241 return (cumsum[deg], None) 242 else: 243 return (cumsum[deg], cumsum[(deg + 1)]) 244 245 @cached_method(do_pickle=True) 246 def _differential(self, p): 247 r""" 248 Return the differential of ``p``. 249 250 .. tab:: Sage 251 252 EXAMPLES:: 253 254 sage: A = AplN(5) 255 sage: R = A.base_ring() 256 sage: A.inject_variables() 257 Defining y0, y1, y2, y3, y4, y5 258 sage: R.inject_variables() 259 Defining t0, t1, t2, t3, t4, t5 260 sage: p = t0*t2*y2*y3 261 sage: p.differential() 262 t2*y0*y2*y3 263 264 .. tab:: Raw code 265 266 EXAMPLES:: 267 268 A = AplN(5) 269 R = A.base_ring() 270 A.inject_variables() 271 R.inject_variables() 272 p = t0*t2*y2*y3 273 p.differential() 274 275 """ 276 R = self.base_ring() 277 d = self.zero() 278 for term in p.terms(): 279 coeff = term.leading_coefficient() 280 mon = term.leading_monomial() 281 deriv_sum = sum([(R.derivation(t)(coeff) * y) 282 for (t, y) in zip(R.gens(), self.gens())]) 283 d += (deriv_sum * mon) 284 return d 285 286 @cached_method(do_pickle=True) 287 def _differential_matrix(self, deg_y, deg_t): 288 r""" 289 Considering ``self`` as a graded module with coefficients in a polynomial ring, 290 and serializing the basis of all modules up to degree ``deg_y`` with coefficients 291 up to degree ``deg_t``., this method returns the differential matrix as a linear map 292 between vector spaces. 293 294 INPUT: 295 296 - ``deg_t`` -- integer; maximum degree of the coefficients 297 298 - ``deg_y`` -- integer; the degree of the differential domain 299 300 OUTPUT: a matrix representing the differential as a linear map between vector spaces 301 302 .. tab:: Sage 303 304 EXAMPLES:: 305 306 sage: A = AplN(2) 307 sage: print(A.extended_basis(deg_t=2,deg_y=0,cum=True)) 308 [1, t0, t0*t1, t0*t2, t0^2, t1, t1*t2, t1^2, t2, t2^2] 309 sage: len(A.extended_basis(deg_t=2,deg_y=0,cum=True)) 310 10 311 sage: print(A.extended_basis(deg_t=1,deg_y=1,cum=True)) 312 [t0*y0, t0*y1, t0*y2, t1*y0, t1*y1, t1*y2, t2*y0, t2*y1, t2*y2, y0, y1, y2] 313 sage: len(A.extended_basis(deg_t=1,deg_y=1,cum=True)) 314 12 315 sage: m = A._differential_matrix(deg_t=1,deg_y=1) 316 sage: m.dimensions() 317 (12, 10) 318 sage: m 319 [0 0 0 0 2 0 0 0 0 0] 320 [0 0 1 0 0 0 0 0 0 0] 321 [0 0 0 1 0 0 0 0 0 0] 322 [0 0 1 0 0 0 0 0 0 0] 323 [0 0 0 0 0 0 0 2 0 0] 324 [0 0 0 0 0 0 1 0 0 0] 325 [0 0 0 1 0 0 0 0 0 0] 326 [0 0 0 0 0 0 1 0 0 0] 327 [0 0 0 0 0 0 0 0 0 2] 328 [0 1 0 0 0 0 0 0 0 0] 329 [0 0 0 0 0 1 0 0 0 0] 330 [0 0 0 0 0 0 0 0 1 0] 331 332 """ 333 extb1 = self.extended_basis( 334 deg_y=(deg_y - 1), deg_t=(deg_t + 1), cum=True) 335 extb2 = self.extended_basis(deg_y=deg_y, deg_t=deg_t, cum=True) 336 m = matrix(QQ, len(extb1), len(extb2), [g.differential()._to_extended_graded_module( 337 deg_y=deg_y, deg_t=deg_t).to_vector() for g in extb1], sparse=True) 338 return m.T 339 340 @cached_method(do_pickle=True) 341 def _free_graded_module(self, deg): 342 r""" 343 Return the graded module of ``self`` of degree ``deg`` with coefficients 344 in the polynomial ring :math:`\mathbb{Q}[t_0,\dots,t_n`. 345 346 INPUT: 347 348 - ``deg`` -- integer 349 350 OUTPUT: a CombinatorialFreeModule with coefficient in the base_ring of ``self``. 351 352 .. tab:: Sage 353 354 EXAMPLES:: 355 356 sage: A = AplN(2) 357 sage: A._free_graded_module(2) 358 Free module generated by {'y0y1', 'y0y2', 'y1y2'} over Multivariate Polynomial Ring in t0, t1, t2 over Rational Field 359 360 """ 361 R = self.base_ring() 362 gens = [str(g).replace('*', '') for g in list(self.basis(deg))] 363 return CombinatorialFreeModule(R, gens, names=gens) 364 365 @cached_method(do_pickle=True) 366 def _from_extended_graded_module(self, p, deg_y, deg_t=1, cum=False): 367 r""" 368 Returns the element of ``self`` represented by ``p``. 369 370 INPUT: 371 372 - ``p`` -- an element of the extended graded module of degrees ``deg_y`` and ``deg_t``. 373 374 - ``deg_y`` -- integer; degree of the module parent of ``p`` 375 376 - ``deg_t`` -- integer (default: `1`); 377 378 - ``cum`` -- boolean (default: `False`); If ``True``, the extended basis will be used. 379 380 OUTPUT: an element of self 381 382 .. tab:: Sage 383 384 EXAMPLES:: 385 386 sage: A = AplN(2) 387 sage: C = A._free_graded_module(2) 388 sage: p = C.an_element() 389 sage: p 390 2*y0y1 + 2*y0y2 + 3*y1y2 391 sage: p in C 392 True 393 sage: p in A 394 False 395 sage: q = A._from_extended_graded_module(p,deg_y=2, deg_t=0,cum=False) 396 sage: q 397 2*y0*y1 + 2*y0*y2 + 3*y1*y2 398 sage: q in A 399 True 400 sage: q in C 401 False 402 403 """ 404 R = self.base_ring() 405 ext_basis = self.extended_basis(deg_y, deg_t, cum) 406 return sum(((coef * gen) for (coef, gen) in zip(p.to_vector(), ext_basis))) 407 408 @cached_method(do_pickle=True) 409 def _from_graded_module(self, deg, p): 410 r""" 411 Returns the element of ``self`` represented by ``p`` on the underlying graded module. 412 413 INPUT: 414 415 - ``deg`` -- integer; degree of the module parent of ``p`` 416 417 - ``p`` -- an element of the graded module of degree ``deg``. 418 419 OUTPUT: an element of self. 420 421 .. tab:: Sage 422 423 EXAMPLES:: 424 425 sage: A = AplN(2) 426 sage: C = A._free_graded_module(2) 427 sage: p = C.an_element() 428 sage: p 429 2*y0y1 + 2*y0y2 + 3*y1y2 430 sage: p in C 431 True 432 sage: p in A 433 False 434 sage: deg = 2 435 sage: q = A._from_graded_module(deg,p) 436 sage: q 437 2*y0*y1 + 2*y0*y2 + 3*y1*y2 438 sage: q in C 439 False 440 sage: q in A 441 True 442 443 """ 444 gens = list(self.basis(deg)) 445 return sum(((coef * gen) for (coef, gen) in zip(p.to_vector(), gens))) 446 447 @cached_method(do_pickle=True) 448 def _graded_face_matrix(self, yi, deg): 449 r""" 450 Return the reduction matrix of the variable ``yi`` as a linear map 451 between the graded vector spaces of degree ``deg`` of ``self`` and 452 the graded vector space of the exterior subalgebra generated by all 453 generators of ``self`` minus ``yi``: 454 455 .. math:: 456 457 \bigwedge^deg(y_0,\dots,y_n) \longrightarrow \bigwedge^deg(y_0,\dots,\hat{y}_i,\dots,y_n) 458 459 INPUT: 460 461 - ``yi`` -- integer; 462 463 - ``deg`` -- integer; 464 465 OUTPUT: sparse matrix; 466 467 .. tab:: Sage 468 469 EXAMPLES:: 470 471 sage: A = AplN(3) 472 sage: list(A.basis(2)) 473 [y0*y1, y0*y2, y0*y3, y1*y2, y1*y3, y2*y3] 474 sage: list(A.reduced_exterior_basis(yi=0, deg=2)) 475 [y1*y2 + y1*y3, -y1*y2 + y2*y3, -y1*y3 - y2*y3, y1*y2, y1*y3, y2*y3] 476 sage: A._graded_face_matrix(yi=0,deg=2) 477 [ 1 -1 0 1 0 0] 478 [ 1 0 -1 0 1 0] 479 [ 0 1 -1 0 0 1] 480 481 """ 482 indices = self._reduction_indices(yi, deg) 483 grad_reduction_matrix = self._graded_reduction_matrix(yi, deg) 484 return grad_reduction_matrix[indices, :] 485 486 @cached_method(do_pickle=True) 487 def _graded_reduction_matrix(self, yi, deg): 488 r""" 489 490 Return the reduction matrix of the variable ``yi`` as a linear endomorphism 491 of the graded vector space of degree ``deg``. 492 493 INPUT: 494 495 - ``yi`` -- integer; 496 497 - ``deg`` -- integer; 498 499 OUTPUT: sparse matrix; 500 501 .. tab:: Sage 502 503 EXAMPLES:: 504 505 sage: A = AplN(3) 506 sage: list(A.basis(2)) 507 [y0*y1, y0*y2, y0*y3, y1*y2, y1*y3, y2*y3] 508 sage: list(A.reduced_exterior_basis(yi=0, deg=2)) 509 [y1*y2 + y1*y3, -y1*y2 + y2*y3, -y1*y3 - y2*y3, y1*y2, y1*y3, y2*y3] 510 sage: A._graded_face_matrix(yi=0,deg=2) 511 [ 1 -1 0 1 0 0] 512 [ 1 0 -1 0 1 0] 513 [ 0 1 -1 0 0 1] 514 515 516 """ 517 if (not (0 <= yi <= self.n)): 518 raise ValueError( 519 f'the reduction index must be an integer in the range {{0,{self.n}}}') 520 if (not (1 <= deg <= (self.n + 1))): 521 raise ValueError( 522 f'the degree must be an integer in the range {{1,{(self.n + 1)}}}') 523 if (deg == (self.n + 1)): 524 return zero_matrix(self.base_ring(), 1) 525 basis = self.basis(deg) 526 v = [g.reduce(yi)._to_graded_module().to_vector() for g in basis] 527 return matrix(self.base_ring(), v, sparse=True).T 528 529 @cached_method(do_pickle=True) 530 def _koszul_differential(self, p): 531 r""" 532 Return the koszul differential of `p`. 533 534 For the :math:`q`--form :math:`\omega \in (A_{PL})^q_n`: 535 536 .. math:: 537 \omega = p(\overline{t}) \;y_{j_0} \wedge\cdots\wedge y_{j_{q-1}} 538 539 the koszul differential :math:`\kappa: (A_{PL})^q_n \rightarrow (A_{PL})^{q-1}_n` is defined as 540 541 .. math:: 542 543 \kappa (\omega) = p(\overline{t}) \sum_{j=0}^{q-1}(-1)^{j}t_{i_j}y_{i_0}\wedge\cdots\wedge\hat{y_{i_j}}\wedge\cdots\wedge y_{j_{q-1}} 544 545 where :math:`p(\overline{t}) \in \mathbb{Q}[t_0,\dots,t_n]`. 546 547 Let :math:`\omega,\theta \in (A_{PL})_n`, and :math:`\omega` defined as before such that 548 :math:`q=|\omega|`, and :math:`r=|p(\overline{t})|`. Then, the koszul differential has the properties: 549 550 - :math:`\kappa \circ \kappa = 0`, 551 552 - :math:`(\kappa \circ d)(\omega) + (d \circ \kappa)(\omega) = (r+q)\omega`, 553 554 - :math:`\kappa(\omega \wedge \theta ) = \kappa(\omega) \wedge \theta + (-1)^{|\omega|} \omega \wedge \kappa (\theta)`. 555 556 INPUT: 557 558 - ``p`` -- a differential :math:`q`--form 559 560 OUTPUT: a differential :math:`(q-1)`--form. 561 562 .. tab:: Sage 563 564 EXAMPLES:: 565 566 This example illustrates the relation between the differential and koszul operators:: 567 568 sage: A = AplN(3) 569 sage: R = A.base_ring() 570 sage: A.inject_variables() 571 Defining 572 y0, y1, y2, y3 573 sage: R.inject_variables() 574 Defining 575 t0, t1, t2, t3 576 sage: p = t0 * t2 * y2 * y3 577 sage: p 578 t0*t2*y2*y3 579 sage: p.koszul().differential()+p.differential().koszul() 580 4*t0*t2*y2*y3 581 sage: (p.differential().koszul()+p.koszul().differential()).reduce(0) == (2+2)*p.reduce(0) 582 True 583 sage: p = t0*t2*y2*y3 + y1 584 sage: p.koszul().differential()+p.differential().koszul() 585 4*t0*t2*y2*y3 + y1 586 587 This example illustrates the koszul differential of a wedge of forms:: 588 589 sage: A = AplN(4) 590 sage: R = A.base_ring() 591 sage: A.inject_variables() 592 Defining y0, y1, y2, y3, y4 593 sage: R.inject_variables() 594 Defining t0, t1, t2, t3, t4 595 sage: p = t1*y2 596 sage: q = t2*y3*y4 597 sage: print(p.koszul()*q+((-1)**p.degree())*p*q.koszul().reduce(0) == (p*q).koszul().reduce(0)) 598 True 599 sage: print(p.koszul().differential()+ p.differential().koszul() == (1+1)*p) 600 True 601 sage: print(q.koszul().differential()+ q.differential().koszul() == (1+2)*q) 602 True 603 """ 604 R = self.base_ring() 605 k = self.zero() 606 for term in self(p).terms(): # (self(p) is used just in case p is of degree 0, i.e., an element of R 607 mon = term.leading_monomial() # monomial in the exterior algebra QQ<y_0,..,y_n> 608 coef = term.coefficients()[0] 609 dif = self.zero() 610 for i, (t, y) in enumerate(zip(R.gens(), self.gens())): 611 intprod = mon.interior_product(y) 612 if intprod: 613 # interior product takes into account the sign 614 dif += self(t) * intprod 615 k += coef * dif 616 return k 617 618 @cached_method(do_pickle=True) 619 def _reduce_coeff_endomorphism(self, i): 620 r""" 621 Return the endomorphism of the base_ring of ``self`` that applies 622 the relation :math:``t_i = 1-\sum_{j \neq i} t_j``. 623 624 INPUT: 625 626 - ``i`` -- integer; 627 628 OUTPUT: a endomorphism of the base_ring of ``self``. 629 630 .. tab:: Sage 631 632 EXAMPLES:: 633 634 sage: A = AplN(4) 635 sage: R = A.base_ring() 636 sage: R.inject_variables() 637 Defining t0, t1, t2, t3, t4 638 sage: hom0 = A._reduce_coeff_endomorphism(i=0) 639 sage: hom1 = A._reduce_coeff_endomorphism(i=1) 640 sage: p = t1 641 sage: hom0(p) 642 t1 643 sage: hom1(p) 644 -t0 - t2 - t3 - t4 + 1 645 sage: p = 1-t0-t1-t2-t3-t4 646 sage: hom0(p) 647 0 648 sage: hom1(p) 649 0 650 651 """ 652 R = self.base_ring() 653 gens = list(R.gens()) 654 gens.pop(i) 655 image = list(gens) 656 image.insert(i, (1 - sum(image))) 657 return R.hom(image, R) 658 659 @cached_method(do_pickle=True) 660 def _reduce_monomial(self, monomial, i, deg): 661 r""" 662 Returns the result of applying the relation :math:`y_i = -\sum_{j \neq i} y_j`. 663 664 INPUT: 665 666 - ``monomial`` -- an monomial 667 668 - ``i`` -- integer 669 670 - ``deg`` -- integer 671 672 OUTPUT: tuple; further description of the output 673 674 .. tab:: Sage 675 676 EXAMPLES:: 677 678 sage: A = AplN(5) 679 sage: R = A.base_ring() 680 sage: A.inject_variables() 681 Defining y0, y1, y2, y3, y4, y5 682 sage: R.inject_variables() 683 Defining t0, t1, t2, t3, t4, t5 684 sage: w = y1*y2 685 sage: A._reduce_monomial(w,0,2) 686 y1*y2 687 sage: A._reduce_monomial(w,1,2) 688 -y0*y2 + y2*y3 + y2*y4 + y2*y5 689 sage: w = t1*y2 690 sage: A._reduce_monomial(w,1,1) 691 t1*y2 692 sage: A._reduce_monomial(w,2,1) 693 -t1*y0 - t1*y1 - t1*y3 - t1*y4 - t1*y5 694 sage: w = y1 + y2 695 sage: A._reduce_monomial(w,2,1) 696 -y0 - y3 - y4 - y5 697 sage: w = y1 + y2*y3 698 sage: A._reduce_monomial(w,2,1) 699 y2*y3 + y1 700 sage: A._reduce_monomial(w,1,1) 701 y2*y3 - y0 - y2 - y3 - y4 - y5 702 sage: A._reduce_monomial(w,2,2) 703 -y0*y3 - y1*y3 + y3*y4 + y3*y5 + y1 704 705 """ 706 cache = self._reduced_monomials 707 if (deg not in cache): 708 cache[deg] = {} 709 if (i not in cache[deg]): 710 cache[deg][i] = {} 711 if (monomial not in cache[deg][i]): 712 red_map = self.graded_module_endomorphism(i, deg) 713 (from_idx, to_idx) = self._basis_indexes(deg) 714 v = monomial.to_vector() 715 v_part = v[from_idx:to_idx] 716 v_new_part = (red_map * v_part) 717 v_new = v[:] 718 v_new[from_idx:to_idx] = v_new_part 719 reduced = self.from_vector(v_new) 720 cache[deg][i][monomial] = reduced 721 return cache[deg][i][monomial] 722 723 @cached_method(do_pickle=True) 724 def _reduction_indices(self, yi, deg): 725 r""" 726 Returns the indices of the graded module basis of degree ``deg`` 727 corresponding to generators NOT containing ``yi``. 728 729 Equivalently, the method returns the nonzero positions of the 730 ordered graded module basis of degree ``deg`` after substituting 731 :math:`yi=0`. 732 733 INPUT: 734 735 - ``yi`` -- integer; the index of the exterior algebra generator 736 737 - ``deg`` -- integer; the degree of the graded module 738 739 OUTPUT: tuple of non-negative integers; 740 741 .. tab:: Sage 742 743 EXAMPLES:: 744 745 sage: A = AplN(3) 746 sage: list(A.basis(2)) 747 [y0*y1, y0*y2, y0*y3, y1*y2, y1*y3, y2*y3] 748 sage: A._reduction_indices(yi=1,deg=2) 749 [1, 2, 5] 750 751 """ 752 indices = [idx for idx in powerset( 753 range((self.n + 1))) if ((len(idx) == deg) and (yi not in idx))] 754 prods = [self.prod((self.gens()[i] for i in idx)) for idx in indices] 755 basis_list = list(self.basis(deg)) 756 return sorted((basis_list.index(p) for p in prods)) 757 758 def _repr_(self): 759 r""" 760 Representation of 'self'. 761 762 .. tab:: Sage 763 764 EXAMPLES:: 765 766 sage: from Sullivan_MM import * 767 sage: A = AplN(5) 768 sage: A 769 The Commutative Differential Graded Algebra (A_{PL})_{5} defined as 770 the tensor product of the Polynomial Ring QQ<t_{0},...,t_{5}> with 771 the Exterior Algebra generated by QQ<y_{0},...,y_{5}>. 772 773 The degrees of the generators are: 774 775 deg(t_i)=0 776 deg(y_j)=1 777 778 The differential 'd' is defined as: 779 780 d(t_i)=y_i 781 d(y_j)=0 782 783 """ 784 if (self.n <= 3): 785 latex_extAlgGens = latex(self.gens()).replace( 786 ' ', '').replace('\\left(', '').replace('\\right)', '') 787 latex_polRingGens = latex(self.base_ring().gens()).replace( 788 ' ', '').replace('\\left(', '').replace('\\right)', '') 789 else: 790 latex_extAlgGens = ((str(latex(self.gens()[ 791 0])) + str(',...,')) + str(latex(self.gens()[(- 1)]))).replace(' ', '') 792 latex_polRingGens = ((str(latex(self.base_ring().gens()[ 793 0])) + str(',...,')) + str(latex(self.base_ring().gens()[(- 1)]))).replace(' ', '') 794 text = """The Commutative Differential Graded Algebra (A_{PL})_{""" + str(self.n) + """} defined as 795the tensor product of the Polynomial Ring QQ<""" + latex_polRingGens + """> with 796the Exterior Algebra generated by QQ<""" + latex_extAlgGens + """>. 797 798The degrees of the generators are: 799 800 deg(t_i)=0 801 deg(y_j)=1 802 803The differential 'd' is defined as: 804 805 d(t_i)=y_i 806 d(y_j)=0 807 """ 808 return text 809 810 # def dupont_differential(self, p): 811 # dim = self.n 812 # dupdif = self.zero() 813 # for i in range((dim + 1)): 814 # dupdif += (self.dupont_operator(p, i) / (dim + 1)) 815 # return dupdif 816 @cached_method(do_pickle=True) 817 def _dupont_operator(self, p, i): 818 r""" 819 This method implements the Dupont\'s operator :math:`h_n^i: (A_{PL})^{*}_{n} \rightarrow (A_{PL})^{*-1}_{n}` 820 for the standard :math:`\Delta^n`-simplex as it is described in :cite:`cheng2008transferring` 821 (see also :cite:`dupont1976simplicial`). 822 823 Let :math:`\mathbb{K}` be a field of characteristic :math:`0` and let :math:`\Delta^n` be the 824 standard :math:`n`-simplex. Also, let 825 826 .. math:: 827 828 A_{PL}(\Delta^n) := \{A^p_{PL}(\Delta^n)\}_{p \geq 0}, 829 830 be the algebra of polynomial differential forms defined on :math:`\Delta^n`, where 831 832 .. math:: 833 834 A^p_{PL}(\Delta^n) := \{ \sigma: \Delta^n \rightarrow (A_{PL})^p_n\} 835 836 837 Notice that we can consider :math:`\Delta^n` as a set with only one element so, in this case 838 839 .. math:: 840 841 A_{PL}(\Delta^n) \cong (A_{PL})_n. 842 843 In fact, the motivation for the construction of :math:`(A_{PL})_n` was precisely to model locally 844 the algebra of polynomial differential forms on simplices and, at the same time, construct a global 845 structure satisfying the geometrical, topological and algebraic constraints. For the same reason, 846 being :math:`C^*(\Delta^n)` the simplicial cochain complex of :math:`\Delta^n`, we have: 847 848 .. math:: 849 :nowrap: 850 851 \[ 852 C^p(\Delta^n)=\Biggl\{\begin{array}{cll} 853 \mathbb{K}, &if \;\; p=n \\ 854 0, & otherwise & 855 \end{array} 856 \] 857 858 Let :math:`\int_n` be the de Rham map 859 (see :cite:`Whitney1957GeometricIT, dupont1976simplicial, felix_rational_2001`): 860 861 .. math:: 862 863 \int_n: (A_{PL})_n \rightarrow \mathbb{K} 864 865 For a subset :math:`I = \{i_0,\dots,i_p\} \subseteq \{0,\dots,n\}`, 866 with :math:`0 \leq i_0 < \cdots < i_p \leq n`, the Whitney map 867 (see :cite:`Whitney1957GeometricIT, WhitneyFormsLOHI`) 868 869 .. math:: 870 871 \mathcal{W}^I_n: \mathbb{K} \rightarrow (A_{PL})^p_n 872 873 is defined as: 874 875 .. math:: 876 877 \mathcal{W}^I_n(c) = c \cdot \sum_{j=0}^{p} (-1)^j t_{i_j} y_{i_0} \wedge \cdots \wedge \hat{y_{i_j}} 878 \wedge \cdots \wedge y_{i_p} 879 880 where :math:`\hat{}` means the term is omitted. The elements in the image of :math:`\mathcal{W}` are called 881 the `elementary differential forms` or just `Whitney forms`. 882 883 For a generic simplicial set :math:`S`, and following the work of Hassler `Whitney` 884 (see :cite:`Whitney1957GeometricIT`), `Dupont` (see :cite:`dupont1976simplicial`) constructed an 885 explicit simplicial contraction of the commutative differential graded algebra of polynomial differential forms 886 :math:`A_{PL}(S)` to :math:`C^*(S)` compatible with the intrinsic affine structure of the polynomial 887 differential forms (affine relations) and also with the wedge product of forms (up to homotopy). 888 889 This method implements step by step the description of the contraction given 890 by Cheng et al. (see :cite:`cheng2008transferring`) for the case of :math:`\Delta^n` (for the case of 891 a general simplicial set go to :meth:`.dupont_contraction`), with minor notation adaptations 892 for the sake of maintain coherence with the rest of the code. 893 894 The description given by Cheng et al. is as follows: 895 896 Let :math:`\omega \in (A_{PL})_n`. For each vertex :math:`e_i` of the :math:`n`-simplex :math:`\Delta^n`, 897 define the dilation map 898 899 .. math:: 900 901 \phi_i : [0,1] \times \Delta^n \to \Delta^n 902 903 by the formula 904 905 .. math:: 906 907 \phi_i(u,t_0, \dots, t_n) = ((1-u)t_0,\dots,(1-u)t_i+u,\dots,(1-u)t_n) . 908 909 Let 910 911 .. math:: 912 913 (\pi_i){}_*:A^*_{PL}([0,1]\times\Delta^n) \rightarrow (A_{PL})^{*-1}_n 914 915 be integration over the first factor. 916 917 The operator :math:`h_n^i`: 918 919 .. math:: 920 921 h_n^i : (A_{PL})^{*}_n \rightarrow (A_{PL})^{*-1}_n 922 923 is defined by the formula 924 925 .. math:: 926 927 h_n^i\omega = (\pi_i)_* \phi_i^* \omega. 928 929 where :math:`\phi_i^* \omega` is the pullback of :math:`\omega` respect to :math:`\phi_i`. 930 931 Let 932 933 .. math:: 934 935 \epsilon_n^i: A^*_{PL}(\Delta^n) \rightarrow \mathbb{K} 936 937 be evaluation at the vertex :math:`e_i`. The Poincar\'e Lemma states that 938 939 .. math:: 940 941 \mathbb{1}_{A} - \epsilon_n^i = d \circ h_n^i + h_n^i \circ d . 942 943 944 .. SEEALSO:: 945 946 :meth:`~AplN.Element.integral` 947 948 :meth:`.whitney_form` 949 950 :meth:`.dupont_contraction` 951 952 .. REFERENCES:: 953 954 - :cite:`Whitney1957GeometricIT` 955 956 - :cite:`dupont1976simplicial` 957 958 - :cite:`cheng2008transferring` 959 960 - :cite:`WhitneyFormsLOHI` 961 962 - :cite:`felix_rational_2001` 963 964 965 966 INPUT: 967 968 - ``p`` -- an element of ``self``. 969 970 - ``i`` -- integer; the vertex index to apply the operator 971 972 OUTPUT: an element of ``self``; 973 974 .. tab:: Sage 975 976 EXAMPLES:: 977 978 sage: A = AplN(4) 979 sage: R = A.base_ring() 980 sage: A.inject_variables() 981 Defining y0, y1, y2, y3, y4 982 sage: R.inject_variables() 983 Defining t0, t1, t2, t3, t4 984 sage: w = t0*y1*y3 985 sage: w.dif().dup(0) + w.dup(0).dif() == w 986 True 987 988 989 """ 990 def _face_coeff_endomorphism(dim): 991 """ 992 Description 993 994 """ 995 R = self.base_ring() 996 RU = u_extension_t() 997 return RU.hom(([R.zero()] + list(R.gens())), R) 998 999 def face(pol): 1000 """ 1001 Description 1002 1003 """ 1004 Au = pol.parent() 1005 dim = Au.n 1006 if (not pol.reduce(0)): 1007 return AplN((dim - 1)).zero() 1008 deg = Au(pol).degree() 1009 if (not (0 <= deg <= (dim + 1))): 1010 raise ValueError( 1011 f'the degree must be an integer in the range {{1,{(dim + 1)}}}') 1012 hom = _face(deg) 1013 baseRingFaceHom = hom['base_ring_hom'] 1014 B = AplN((dim - 1)) 1015 if (Au(pol).degree() == 0): 1016 return B(baseRingFaceHom(Au(pol).leading_coefficient())) 1017 MB = B._free_graded_module(deg) 1018 face_hom = hom['graded_module_hom'] 1019 new_element = B.zero() 1020 for term in pol.terms(): 1021 c = term.leading_coefficient() 1022 m = term.leading_monomial() 1023 v = m._to_graded_module().to_vector() 1024 vb = MB.from_vector((face_hom * v)) 1025 new_coeff = baseRingFaceHom(c) 1026 new_monomial = B._from_graded_module(deg, vb) 1027 new_element += (new_coeff * new_monomial) 1028 return new_element 1029 1030 def _face(deg): 1031 """ 1032 Description 1033 1034 """ 1035 face_idx = 0 1036 dim = (self.n + 1) 1037 if (not (0 <= deg <= (dim + 1))): 1038 raise ValueError( 1039 f'the degree must be an integer in the range {{1,{(dim + 1)}}}') 1040 baseRingFaceHom = _face_coeff_endomorphism(dim) 1041 if (deg == 0): 1042 return {'base_ring_hom': baseRingFaceHom, 'graded_module_hom': {}} 1043 A = u_extension() 1044 #B = AplN((dim - 1)) 1045 MA = A._free_graded_module(deg) 1046 #face_matrix = A._graded_face_matrix(face_idx, deg) 1047 #face_matrix = face_matrix.change_ring(QQ) 1048 idx = A._reduction_indices(face_idx, deg) 1049 m = identity_matrix(QQ, MA.dimension()) 1050 face_hom = m[idx, :] 1051 return {'base_ring_hom': baseRingFaceHom, 'graded_module_hom': face_hom} 1052 1053 def u_extension_t(): 1054 """ 1055 Description 1056 1057 """ 1058 R = self.base_ring() 1059 varnames = (['u'] + list(R.variable_names())) 1060 return PolynomialRing(QQ, names=varnames) 1061 1062 def u_extension(): 1063 """ 1064 Description 1065 1066 """ 1067 A = self 1068 R = A.base_ring() 1069 tlabels = (['u'] + list(R.variable_names())) 1070 ylabels = (['du'] + list(A.variable_names())) 1071 labels = (tlabels + ylabels) 1072 return AplN((A.n + 1), labels=tuple(labels)) 1073 1074 def dilation_map_t(i): 1075 """ 1076 Description 1077 1078 """ 1079 def inclusion(R, RU): 1080 """ 1081 Description 1082 1083 """ 1084 return R.hom(RU.gens()[1:], RU) 1085 R = self.base_ring() 1086 RU = u_extension_t() 1087 u = RU.gens()[0] 1088 inc = inclusion(R, RU) 1089 tgens = [inc(t) for t in R.gens()] 1090 image = [] 1091 for (j, t) in enumerate(tgens): 1092 if (not (i == j)): 1093 image.append([((1 - u) * t)]) 1094 else: 1095 image.append([(((1 - u) * t) + u)]) 1096 return R.hom(image, RU) 1097 1098 def dilation_map_y(i): 1099 """ 1100 Description 1101 1102 """ 1103 A = self 1104 R = A.base_ring() 1105 Au = u_extension() 1106 Ru = Au.base_ring() 1107 cols = [] 1108 for t in R.gens(): 1109 dt = Au(dilation_map_t(i)(t)).differential() 1110 cols.append(dt._to_graded_module().to_vector()) 1111 m = matrix(Ru, (len(Au.gens()) - 1), cols).T 1112 return A.lift_morphism(m, names=Au.variable_names()) 1113 1114 def dilation_map(pol, i): 1115 """ 1116 Description 1117 1118 """ 1119 A = self 1120 R = A.base_ring() 1121 Au = u_extension() 1122 Ru = Au.base_ring() 1123 dilt = dilation_map_t(i) 1124 dily = dilation_map_y(i) 1125 dilation = Au.zero() 1126 for term in pol.terms(): 1127 coef = term.coefficients()[0] 1128 mon = term.monomials()[0] 1129 dilation += (dilt(coef) * Au(dily(mon))) 1130 return dilation 1131 1132 def u_integration(pol): 1133 """ 1134 Description 1135 1136 """ 1137 Au = pol.parent() 1138 Ru = Au.base_ring() 1139 u = Ru.gens()[0] 1140 du = Au.gens()[0] 1141 intp = Au.zero() 1142 for term in pol.interior_product(du).terms(): 1143 coef = term.coefficients()[0] 1144 mon = term.monomials()[0] 1145 intcoef = (coef.integral(u).substitute(u=1) - 1146 coef.integral(u).substitute(u=0)) 1147 intp += (intcoef * mon) 1148 return intp 1149 1150 def projection(pol): 1151 """ 1152 Description 1153 1154 """ 1155 return face(pol) 1156 1157 Au = u_extension() 1158 RU = Au.base_ring() 1159 u = RU.gens()[0] 1160 di = dilation_map(p, i) 1161 inti = u_integration(di) 1162 return projection(inti) 1163 1164 @cached_method(do_pickle=True) 1165 def extended_basis(self, deg_y, deg_t=1, cum=False): 1166 r""" 1167 Considering ``self`` as a graded module, this method returns the 1168 module basis of degree ``deg_y`` with polynomial coefficients truncated 1169 by degree ``deg_t``. 1170 1171 INPUT: 1172 1173 - ``deg_y`` -- integer ; degree of the graded module of ``self``. 1174 1175 - ``deg_t`` -- integer (default: `1`); coefficient\'s degree 1176 1177 - ``cum`` -- boolean (default: `False`); If `True`, the basis takes into account 1178 polynomial coefficients up to degree ``deg_t``. Otherwise, the method returns 1179 the basis with homogeneous coefficients of degree ``deg_t``. 1180 1181 OUTPUT: tuple of monomials of ``self``; module generators of exterior degree ``deg_y``. 1182 1183 .. tab:: Sage 1184 1185 EXAMPLES:: 1186 1187 sage: A = AplN(2) 1188 sage: A.extended_basis(deg_y=1,deg_t=1,cum=False) 1189 [t0*y0, t0*y1, t0*y2, t1*y0, t1*y1, t1*y2, t2*y0, t2*y1, t2*y2] 1190 sage: A.extended_basis(deg_y=1,deg_t=1,cum=True) 1191 [t0*y0, t0*y1, t0*y2, t1*y0, t1*y1, t1*y2, t2*y0, t2*y1, t2*y2, y0, y1, y2] 1192 1193 .. tab:: Raw code 1194 1195 EXAMPLES:: 1196 1197 A = AplN(2) 1198 A.extended_basis(deg_y=1,deg_t=1,cum=False) 1199 A.extended_basis(deg_y=1,deg_t=1,cum=True) 1200 1201 1202 """ 1203 basis = [] 1204 rgens = [] 1205 R = self.base_ring() 1206 ext_basis = list(self.basis(deg_y)) 1207 if cum: 1208 basis = ext_basis 1209 t_degrees = range((deg_t + 1)) 1210 elif deg_t: 1211 t_degrees = [deg_t] 1212 else: 1213 return ext_basis 1214 for i in t_degrees: 1215 rgens += list(set([prod(l) 1216 for l in itertools.product(R.gens(), repeat=i)])) 1217 CP = cartesian_product([rgens, ext_basis]) 1218 basis += [prod(p) for p in CP] 1219 basis = list(set(basis)) 1220 basis.sort(key=str) 1221 return basis 1222 1223 @cached_method(do_pickle=True) 1224 def extended_graded_module(self, deg_y, deg_t=1, cum=False): 1225 r""" 1226 Return the extended graded module of ``self`` of degree ``deg_y`` with coefficients 1227 in the polynomial ring :math:`\mathbb{Q}[t_0,\dots,t_n]`. 1228 1229 INPUT: 1230 1231 - ``deg_y`` -- integer; degree of the graded module of ``self``. 1232 1233 - ``deg_t`` -- integer (default: `1`); coefficient\'s degree. 1234 1235 - ``cum`` -- boolean (default: `False`); If `True`, the basis takes into account 1236 polynomial coefficients up to degree ``deg_t``. Otherwise, the method returns 1237 the basis with homogeneous coefficients of degree ``deg_t``. 1238 1239 OUTPUT: a CombinatorialFreeModule with coefficient in the base_ring of ``self``. 1240 1241 .. tab:: Sage 1242 1243 EXAMPLES:: 1244 1245 sage: A = AplN(2) 1246 sage: A.extended_graded_module(deg_y=1,deg_t=1,cum=True) 1247 Free module generated by {'t0y0', 't0y1', 't0y2', 't1y0', 't1y1', 't1y2', 't2y0', 't2y1', 't2y2', 'y0', 1248 'y1', 'y2'} over Multivariate Polynomial Ring in t0, t1, t2 over Rational Field 1249 1250 """ 1251 R = self.base_ring() 1252 ext_basis = self.extended_basis(deg_y, deg_t, cum) 1253 ext_basis.sort(key=str) 1254 gens = [str(g).replace('*', '') for g in ext_basis] 1255 gens = [g.replace('^', 'e') for g in gens] 1256 return CombinatorialFreeModule(R, gens, names=gens) 1257 1258 @cached_method(do_pickle=True) 1259 def graded_module_endomorphism(self, yi, deg): 1260 r""" 1261 1262 Return the reduction matrix of the variable ``yi`` as a linear endomorphism 1263 of the graded vector space of degree ``deg``. 1264 1265 INPUT: 1266 1267 - ``yi`` -- integer; 1268 1269 - ``deg`` -- integer; 1270 1271 OUTPUT: sparse matrix; 1272 1273 .. tab:: Sage 1274 1275 EXAMPLES:: 1276 1277 sage: A = AplN(3) 1278 sage: list(A.basis(2)) 1279 [y0*y1, y0*y2, y0*y3, y1*y2, y1*y3, y2*y3] 1280 sage: list(A.reduced_exterior_basis(yi=0, deg=2)) 1281 [y1*y2 + y1*y3, -y1*y2 + y2*y3, -y1*y3 - y2*y3, y1*y2, y1*y3, y2*y3] 1282 sage: A._graded_face_matrix(yi=0,deg=2) 1283 [ 1 -1 0 1 0 0] 1284 [ 1 0 -1 0 1 0] 1285 [ 0 1 -1 0 0 1] 1286 1287 1288 """ 1289 1290 def _graded_module_endomorphism(yi, deg): 1291 """ 1292 Description 1293 1294 """ 1295 if (deg == (self.n + 1)): 1296 m = matrix(self.base_ring(), 1, [0]) 1297 else: 1298 basis = self.reduced_exterior_basis(yi, deg) 1299 m = identity_matrix(self.base_ring(), len(basis), sparse=True) 1300 (from_idx, to_idx) = self._basis_indexes(deg) 1301 for (i, gen) in enumerate(basis): 1302 v = gen.to_vector()[from_idx:to_idx] 1303 m[:, i] = v 1304 self._graded_module_endomorphisms[(yi, deg)] = m 1305 return m 1306 1307 if (not (0 <= yi <= self.n)): 1308 raise ValueError('yi must be in [0, n]') 1309 key = (yi, deg) 1310 if (key in self._graded_module_endomorphisms): 1311 return self._graded_module_endomorphisms[key] 1312 return _graded_module_endomorphism(yi, deg) 1313 1314 # def hom(self, base_imgs, gens_imgs, codomain=None): 1315 # if (codomain == None): 1316 # codomain = self 1317 # raise NotImplementedError 1318 1319 # def inject_vars(self): 1320 # self.base_ring().inject_variables() 1321 # self.inject_variables() 1322 # return None 1323 1324 # def _load_data(self, data_path='./'): 1325 # try: 1326 # data = load(((data_path + self.name) + '_data')) 1327 # except FileNotFoundError: 1328 # print('No data available.', flush=True) 1329 # return None 1330 # if data: 1331 # self._reduced_basis = data['_reduced_basis'] 1332 # self._reduced_monomials = data['_reduced_monomials'] 1333 # self._multiplication_tables = data['_multiplication_tables'] 1334 # self._multiplication_table_indexes = data['_multiplication_table_indexes'] 1335 # self._multiplication_table_sgns = data['_multiplication_table_sgns'] 1336 # self._graded_module_endomorphisms = data['_graded_module_endomorphisms'] 1337 # return None 1338 1339 # def multiplication_table(self, deg1, deg2): 1340 # key = (deg1, deg2) 1341 # if (key in self._multiplication_tables): 1342 # return self._multiplication_tables[key] 1343 # basis1 = list(self.basis(deg1)) 1344 # basis2 = list(self.basis(deg2)) 1345 # m = matrix(self, len(basis1), len(basis2), sparse=True) 1346 # for (i, a) in enumerate(basis1): 1347 # for (j, b) in enumerate(basis2): 1348 # m[(i, j)] = (a * b) 1349 # self._multiplication_tables[key] = m 1350 # return m 1351 @cached_method(do_pickle=True) 1352 def reduced_exterior_basis(self, yi, deg): 1353 r""" 1354 Returns the exterior basis of the homogeneous graded module of degree ``deg`` 1355 after applying the relation :math:`y_i = -\sum_{j \neq i} y_j`. 1356 1357 INPUT: 1358 1359 - ``yi`` -- integer; the index of the exterior algebra generator 1360 1361 - ``deg`` -- integer; the degree of the graded module 1362 1363 OUTPUT: tuple of non-negative integers; 1364 1365 .. tab:: Sage 1366 1367 EXAMPLES:: 1368 1369 sage: A = AplN(4) 1370 sage: list(A.basis(1)) 1371 [y0, y1, y2, y3, y4] 1372 sage: A.reduced_exterior_basis(yi=2, deg=1) 1373 (y0, y1, -y0 - y1 - y3 - y4, y3, y4) 1374 1375 """ 1376 def multiplication_table_indexes(deg1, deg2): 1377 """ 1378 Description 1379 """ 1380 key = (deg1, deg2) 1381 if (key in self._multiplication_table_indexes): 1382 return (self._multiplication_table_indexes[key], self._multiplication_table_sgns[key]) 1383 basis_all = list(self.basis()) 1384 deg = (deg1 + deg2) 1385 (from_idx, to_idx) = self._basis_indexes(deg) 1386 basis_deg = basis_all[from_idx:to_idx] 1387 basis1 = list(self.basis(deg1)) 1388 basis2 = list(self.basis(deg2)) 1389 m_idx = matrix(ZZ, len(basis1), len(basis2), sparse=True) 1390 m_sgn = matrix(ZZ, len(basis1), len(basis2), sparse=True) 1391 for (i, a) in enumerate(basis1): 1392 for (j, b) in enumerate(basis2): 1393 prod = (a * b) 1394 if prod.is_zero(): 1395 m_idx[(i, j)] = (- 1) 1396 else: 1397 mon = prod.monomials()[0] 1398 coeff = prod.leading_coefficient() 1399 m_idx[(i, j)] = basis_deg.index(mon) 1400 m_sgn[(i, j)] = coeff 1401 self._multiplication_table_indexes[key] = m_idx 1402 self._multiplication_table_sgns[key] = m_sgn 1403 return (m_idx, m_sgn) 1404 1405 def _reduce_exterior_basis(yi, deg): 1406 """ 1407 Description 1408 """ 1409 if (deg == 1): 1410 return self.reduced_exterior_basis(yi, 1) 1411 basis1 = list(self.reduced_exterior_basis(yi, 1)) 1412 basis2 = list(self.reduced_exterior_basis(yi, (deg - 1))) 1413 full_basis = list(self.basis(deg)) 1414 (idx_mat, sgn_mat) = multiplication_table_indexes(1, (deg - 1)) 1415 nonZero = idx_mat.find((lambda entry: (entry != (- 1)))) 1416 for (i, j) in nonZero.nonzero_positions(): 1417 if (i < j): 1418 prod = (basis1[i] * basis2[j]) 1419 full_basis[idx_mat[(i, j)]] = (sgn_mat[(i, j)] * prod) 1420 return tuple(full_basis) 1421 1422 if (not (0 <= yi <= self.n)): 1423 raise ValueError('yi must be in [0, n]') 1424 if ((yi, deg) in self._reduced_basis): 1425 return self._reduced_basis[(yi, deg)] 1426 if (deg == 0): 1427 result = self.one() 1428 elif (deg == 1): 1429 reduced = list(self.basis(1)) 1430 reduced.pop(yi) 1431 reduced.insert(yi, (- sum(reduced))) 1432 result = tuple(reduced) 1433 elif (deg == (self.n + 1)): 1434 result = self.zero() 1435 else: 1436 result = _reduce_exterior_basis(yi, deg) 1437 self._reduced_basis[(yi, deg)] = result 1438 return result 1439 1440 # def _reset_data(self): 1441 # self._reduced_basis = {} 1442 # self._reduced_monomials = {} 1443 # self._multiplication_tables = {} 1444 # self._multiplication_table_indexes = {} 1445 # self._multiplication_table_sgns = {} 1446 # self._graded_module_endomorphisms = {} 1447 # return None 1448 1449 # def _save_data(self, data_path='./'): 1450 # data = {'_reduced_basis': self._reduced_basis, '_reduced_monomials': self._reduced_monomials, '_multiplication_tables': self._multiplication_tables, 1451 # '_multiplication_table_indexes': self._multiplication_table_indexes, '_multiplication_table_sgns': self._multiplication_table_sgns, '_graded_module_endomorphisms': self._graded_module_endomorphisms} 1452 # save(data, ((data_path + self.name) + '_data')) 1453 # return None 1454 1455 # def solve_primitive(self, dp, deg_y, deg_t): 1456 # r""" 1457 # For a closed differential form, this method returns an element `q` such that 1458 # :math:`d(q)=d(p)`. 1459 # 1460 # INPUT: 1461 # 1462 # - ``dp`` -- differential form 1463 # 1464 # - ``deg_y`` -- integer; degree of `dp` 1465 # 1466 # - ``deg_t`` -- integer; maximum degree on the base_ring to look for a primitive 1467 # 1468 # OUTPUT: a differential form; 1469 # 1470 # EXAMPLES:: 1471 # 1472 # 1473 # """ 1474 # dv = dp._to_extended_graded_module(deg_y=deg_y, deg_t=deg_t).to_vector() 1475 # m = self._differential_matrix(deg_y, deg_t) 1476 # v = m.solve_right(dv) 1477 # C = self.extended_graded_module( 1478 # deg_y=(deg_y - 1), deg_t=(deg_t + 1), cum=True) 1479 # p = C.from_vector(v) 1480 # return self._from_extended_graded_module(p, deg_y=(deg_y - 1), deg_t=(deg_t + 1), cum=True) 1481 @cached_method(do_pickle=True) 1482 def whitney_form(self): 1483 r""" 1484 Returns the `elementary volume form` (also called `constant volume form`) 1485 of ``self``. The Whitney volume form on :math:`(A_{PL})_n` if a differential 1486 form of degree `n` defined as: 1487 1488 .. math:: 1489 1490 \omega_n = n! \cdot \sum_{k=0}^{n} (-1)^k t_{0} \cdot 1491 y_{0} \wedge \cdots \wedge \hat{y}_{k} \wedge \cdots \wedge y_{n} 1492 1493 OUTPUT: a differential form of degree `n`; 1494 1495 .. tab:: Sage 1496 1497 EXAMPLES:: 1498 1499 sage: A = AplN(4) 1500 sage: A.whitney_form() 1501 24*t4*y0*y1*y2*y3 - 24*t3*y0*y1*y2*y4 + 24*t2*y0*y1*y3*y4 - 24*t1*y0*y2*y3*y4 + 24*t0*y1*y2*y3*y4 1502 sage: _.reduce(0) 1503 24*y1*y2*y3*y4 1504 1505 """ 1506 n = self.n 1507 R = self.base_ring() 1508 rgens = list(R.gens()) 1509 w_form = self.zero() 1510 for i in range(len(rgens)): 1511 gens = list(self.gens()) 1512 gens.pop(i) 1513 w_form += ((((- 1) ** i) * rgens[i]) * prod(gens)) 1514 return (factorial(n) * w_form) 1515
[docs] 1516 class Element(ExteriorAlgebra.Element): 1517 r""" 1518 A polynomial differential form. 1519 """ 1520 1521 @cached_method(do_pickle=True) 1522 def _to_extended_graded_module(self, deg_y, deg_t): 1523 r""" 1524 Returns self as an element of the extended graded module defined by 1525 the parameters. 1526 1527 INPUT: 1528 1529 - ``deg_y`` -- integer; 1530 1531 - ``deg_t`` -- integer 1532 1533 OUTPUT: 1534 1535 .. tab:: Sage 1536 1537 EXAMPLES:: 1538 1539 .. SEEALSO:: 1540 1541 :meth:`.extended_graded_module` 1542 1543 """ 1544 A = self.parent() 1545 basis = A.extended_basis(deg_y=deg_y, deg_t=deg_t, cum=True) 1546 C = A.extended_graded_module(deg_y=deg_y, deg_t=deg_t, cum=True) 1547 v = vector(QQ, len(basis), sparse=True) 1548 if (not self): 1549 return sum([prod(i) for i in zip(v, C.gens())]) 1550 for term in self.terms(): 1551 y_mon = term.monomials()[0] 1552 coeff = term.coefficients()[0] 1553 for t_mon in coeff.monomials(): 1554 c = coeff.monomial_coefficient(t_mon) 1555 g_idx = basis.index((t_mon * y_mon)) 1556 v[g_idx] = c 1557 return sum([prod(i) for i in zip(v, C.gens())]) 1558 1559 @cached_method(do_pickle=True) 1560 def _to_graded_module(self): 1561 r""" 1562 Returns ``self`` as a graded module element. 1563 1564 .. tab:: Sage 1565 1566 EXAMPLES:: 1567 1568 .. SEEALSO:: 1569 1570 :meth:`._free_graded_module` 1571 1572 """ 1573 deg = self.degree() 1574 A = self.parent() 1575 C = A._free_graded_module(deg) 1576 (from_idx, to_idx) = A._basis_indexes(deg) 1577 coeffs = self.to_vector()[from_idx:to_idx] 1578 return sum([prod(i) for i in zip(coeffs, C.gens())]) 1579 1580 @cached_method(do_pickle=True) 1581 def differential(self): 1582 r""" 1583 Return the differential of `self`. 1584 1585 For the :math:`q`--form :math:`\omega \in (A_{PL})^q_n`: 1586 1587 .. math:: 1588 \omega = p(\overline{t}) \;y_{j_0} \wedge\cdots\wedge y_{j_{q-1}} 1589 1590 the differential :math:`d: (A_{PL})^q_n \rightarrow (A_{PL})^{q+1}_n` is defined as 1591 1592 .. math:: 1593 1594 d (\omega) = \sum_{j=0}^{n} \frac{\partial p(\overline{t})}{\partial t_j}y_{j}\wedge y_{i_0}\wedge\cdots\wedge y_{j_{q-1}} 1595 1596 where :math:`p(\overline{t}) \in \mathbb{Q}[t_0,\dots,t_n]`. 1597 1598 Let :math:`\omega,\theta \in (A_{PL})_n`. Then, the differential has the properties: 1599 1600 - :math:`d \circ d = 0`, 1601 1602 - :math:`d(\omega \wedge \theta ) = d(\omega) \wedge \theta + (-1)^{|\omega|} \omega \wedge d (\theta)`. 1603 1604 1605 OUTPUT: a differential :math:`(q+1)` --form. 1606 1607 .. tab:: Sage 1608 1609 EXAMPLES:: 1610 1611 sage: A = AplN(5) 1612 sage: R = A.base_ring() 1613 sage: A.inject_variables() 1614 Defining y0, y1, y2, y3, y4, y5 1615 sage: R.inject_variables() 1616 Defining t0, t1, t2, t3, t4, t5 1617 sage: p = t0*t2*y2*y3 1618 sage: p.differential() 1619 t2*y0*y2*y3 1620 1621 sage: A = AplN(5) 1622 sage: R = A.base_ring() 1623 sage: A.inject_variables() 1624 Defining y0, y1, y2, y3, y4, y5 1625 sage: R.inject_variables() 1626 Defining t0, t1, t2, t3, t4, t5 1627 sage: w = (t1*t2+t3**2)*y2*y3 1628 sage: theta = t0*y4 1629 sage: w.degree() 1630 2 1631 sage: w.differential()*theta+((-1)**2)*w*theta.differential() == (w*theta).differential() 1632 True 1633 sage: w.differential() 1634 t2*y1*y2*y3 1635 sage: w.differential().differential() 1636 0 1637 1638 .. tab:: Raw code 1639 1640 EXAMPLES:: 1641 1642 A = AplN(5) 1643 R = A.base_ring() 1644 A.inject_variables() 1645 R.inject_variables() 1646 p = t0*t2*y2*y3 1647 p.differential() 1648 1649 A = AplN(5) 1650 R = A.base_ring() 1651 A.inject_variables() 1652 R.inject_variables() 1653 w = (t1*t2+t3**2)*y2*y3 1654 theta = t0*y4 1655 w.degree() 1656 w.differential()*theta+((-1)**2)*w*theta.differential() == (w*theta).differential() 1657 w.differential() 1658 w.differential().differential() 1659 1660 1661 """ 1662 return self.parent()._differential(self) 1663 1664 # def dupont_differential(self): 1665 # return self.parent().dupont_contraction(self) 1666 @cached_method(do_pickle=True) 1667 def dif(self): 1668 r""" 1669 Alias for :meth`self.differential` 1670 """ 1671 return self.parent()._differential(self) 1672 1673 @cached_method(do_pickle=True) 1674 def dup(self,i): 1675 r""" 1676 Alias for :meth:`dupont_operator` 1677 """ 1678 return self.parent()._dupont_operator(self, i) 1679 1680 @cached_method(do_pickle=True) 1681 def dupont_operator(self, i): 1682 r""" 1683 This method implements the Dupont\'s operator :math:`h_n^i: (A_{PL})^{*}_{n} \rightarrow (A_{PL})^{*-1}_{n}` 1684 for the standard :math:`\Delta^n`-simplex as it is described in :cite:`cheng2008transferring` 1685 (see also :cite:`dupont1976simplicial`). 1686 1687 Let :math:`\mathbb{K}` be a field of characteristic :math:`0` and let :math:`\Delta^n` be the 1688 standard :math:`n`-simplex. Also, let 1689 1690 .. math:: 1691 1692 A_{PL}(\Delta^n) := \{A^p_{PL}(\Delta^n)\}_{p \geq 0}, 1693 1694 be the algebra of polynomial differential forms defined on :math:`\Delta^n`, where 1695 1696 .. math:: 1697 1698 A^p_{PL}(\Delta^n) := \{ \sigma: \Delta^n \rightarrow (A_{PL})^p_n\} 1699 1700 1701 Notice that we can consider :math:`\Delta^n` as a set with only one element so, in this case 1702 1703 .. math:: 1704 1705 A_{PL}(\Delta^n) \cong (A_{PL})_n. 1706 1707 In fact, the motivation for the construction of :math:`(A_{PL})_n` was precisely to model locally 1708 the algebra of polynomial differential forms on simplices and, at the same time, construct a global 1709 structure satisfying the geometrical, topological and algebraic constraints. For the same reason, 1710 being :math:`C^*(\Delta^n)` the simplicial cochain complex of :math:`\Delta^n`, we have: 1711 1712 .. math:: 1713 :nowrap: 1714 1715 \[ 1716 C^p(\Delta^n)=\Biggl\{\begin{array}{cll} 1717 \mathbb{K}, &if \;\; p=n \\ 1718 0, & otherwise & 1719 \end{array} 1720 \] 1721 1722 Let :math:`\int_n` be the de Rham map 1723 (see :cite:`Whitney1957GeometricIT, dupont1976simplicial, felix_rational_2001`): 1724 1725 .. math:: 1726 1727 \int_n: (A_{PL})_n \rightarrow \mathbb{K} 1728 1729 For a subset :math:`I = \{i_0,\dots,i_p\} \subseteq \{0,\dots,n\}`, 1730 with :math:`0 \leq i_0 < \cdots < i_p \leq n`, the Whitney map 1731 (see :cite:`Whitney1957GeometricIT, WhitneyFormsLOHI`) 1732 1733 .. math:: 1734 1735 \mathcal{W}^I_n: \mathbb{K} \rightarrow (A_{PL})^p_n 1736 1737 is defined as: 1738 1739 .. math:: 1740 1741 \mathcal{W}^I_n(c) = c \cdot \sum_{j=0}^{p} (-1)^j t_{i_j} y_{i_0} \wedge \cdots \wedge \hat{y_{i_j}} 1742 \wedge \cdots \wedge y_{i_p} 1743 1744 where :math:`\hat{}` means the term is omitted. The elements in the image of :math:`\mathcal{W}` are called 1745 the `elementary differential forms` or just `Whitney forms`. 1746 1747 For a generic simplicial set :math:`S`, and following the work of Hassler `Whitney` 1748 (see :cite:`Whitney1957GeometricIT`), `Dupont` (see :cite:`dupont1976simplicial`) constructed an 1749 explicit simplicial contraction of the commutative differential graded algebra of polynomial differential forms 1750 :math:`A_{PL}(S)` to :math:`C^*(S)` compatible with the intrinsic affine structure of the polynomial 1751 differential forms (affine relations) and also with the wedge product of forms (up to homotopy). 1752 1753 This method implements step by step the description of the contraction given 1754 by Cheng et al. (see :cite:`cheng2008transferring`) for the case of :math:`\Delta^n` (for the case of 1755 a general simplicial set go to :meth:`.dupont_contraction`), with minor notation adaptations 1756 for the sake of maintain coherence with the rest of the code. 1757 1758 The description given by Cheng et al. is as follows: 1759 1760 Let :math:`\omega \in (A_{PL})_n`. For each vertex :math:`e_i` of the :math:`n`-simplex :math:`\Delta^n`, 1761 define the dilation map 1762 1763 .. math:: 1764 1765 \phi_i : [0,1] \times \Delta^n \to \Delta^n 1766 1767 by the formula 1768 1769 .. math:: 1770 1771 \phi_i(u,t_0, \dots, t_n) = ((1-u)t_0,\dots,(1-u)t_i+u,\dots,(1-u)t_n) . 1772 1773 Let 1774 1775 .. math:: 1776 1777 (\pi_i){}_*:A^*_{PL}([0,1]\times\Delta^n) \rightarrow (A_{PL})^{*-1}_n 1778 1779 be integration over the first factor. 1780 1781 The operator :math:`h_n^i`: 1782 1783 .. math:: 1784 1785 h_n^i : (A_{PL})^{*}_n \rightarrow (A_{PL})^{*-1}_n 1786 1787 is defined by the formula 1788 1789 .. math:: 1790 1791 h_n^i\omega = (\pi_i)_* \phi_i^* \omega. 1792 1793 where :math:`\phi_i^* \omega` is the pullback of :math:`\omega` respect to :math:`\phi_i`. 1794 1795 Let 1796 1797 .. math:: 1798 1799 \epsilon_n^i: A^*_{PL}(\Delta^n) \rightarrow \mathbb{K} 1800 1801 be evaluation at the vertex :math:`e_i`. The Poincar\'e Lemma states that 1802 1803 .. math:: 1804 1805 \mathbb{1}_{A} - \epsilon_n^i = d \circ h_n^i + h_n^i \circ d . 1806 1807 1808 .. SEEALSO:: 1809 1810 :meth:`._dupont_operator` 1811 1812 :meth:`.integral` 1813 1814 .. REFERENCES:: 1815 1816 - :cite:`Whitney1957GeometricIT` 1817 1818 - :cite:`dupont1976simplicial` 1819 1820 - :cite:`cheng2008transferring` 1821 1822 - :cite:`WhitneyFormsLOHI` 1823 1824 - :cite:`felix_rational_2001` 1825 1826 1827 INPUT: 1828 1829 - ``p`` -- an element of ``self``. 1830 1831 - ``i`` -- integer; the vertex index to apply the operator 1832 1833 OUTPUT: an element of ``self``; 1834 1835 1836 .. tab:: Sage 1837 1838 EXAMPLES:: 1839 1840 sage: A = AplN(4) 1841 sage: R = A.base_ring() 1842 sage: A.inject_variables() 1843 Defining y0, y1, y2, y3, y4 1844 sage: R.inject_variables() 1845 Defining t0, t1, t2, t3, t4 1846 sage: w = t0*y1*y3 1847 sage: w.dup(0).dif() 1848 -1/3*t3*y0*y1 + 1/3*t1*y0*y3 + (2/3*t0 + 1/3)*y1*y3 1849 sage: w.dif().dup(0) 1850 1/3*t3*y0*y1 - 1/3*t1*y0*y3 + (1/3*t0 - 1/3)*y1*y3 1851 sage: w.dup(0).dif()+w.dif().dup(0) == w 1852 True 1853 1854 """ 1855 return self.parent()._dupont_operator(self, i) 1856 1857 @cached_method(do_pickle=True) 1858 def homogeneous_components(self): 1859 r""" 1860 Return the homogeneous components of ``self``. 1861 1862 OUTPUT: a dictionary indexed by degree. 1863 1864 .. tab:: Sage 1865 1866 EXAMPLES:: 1867 1868 sage: A = AplN(5) 1869 sage: R = A.base_ring() 1870 sage: A.inject_variables() 1871 Defining y0, y1, y2, y3, y4, y5 1872 sage: R.inject_variables() 1873 Defining t0, t1, t2, t3, t4, t5 1874 sage: p = t0*t2*y2*y3 1875 sage: p = t0*t2*y2*y3 + y1 1876 sage: p.homogeneous_components() 1877 {1: y1, 2: t0*t2*y2*y3} 1878 1879 """ 1880 if (self.is_homogeneous() and (not self.is_zero())): 1881 return {self.degree(): self} 1882 elif self.is_zero(): 1883 return {0: self} 1884 components = {} 1885 for d in range((self.parent().n + 1)): 1886 hcomp = self.homogeneous_component(d) 1887 if hcomp: 1888 components[d] = hcomp 1889 return components 1890 1891 @cached_method(do_pickle=True) 1892 def integral(self, yi=0): 1893 r""" 1894 Returns the integral of ``self``, defined as follows: 1895 1896 Let :math:`\int_{n}` be the linear map: 1897 1898 .. math:: 1899 1900 \int_{n}: (A_{PL})_{n}^{n} \rightarrow \mathbb{Q} 1901 1902 by setting 1903 1904 .. math:: 1905 :nowrap: 1906 1907 \begin{split} 1908 \int_{n}t_1^{k_1}\dots t_n^{k_n}dt_1 \wedge \dots \wedge dt_n &= \int_{0}^{1} dt_1\int_{0}^{1-t_1} dt_2 \dots\\ 1909 &\dots \int_{0}^{1-\sum\limits_{1}^{n-1}t_i}t_1^{k_1}\dots t_n^{k_n}dt_n = \\ 1910 &= \frac{k_1!k_2! \dots k_n!}{(k_1+ \dots +k_n+n)!}. 1911 \end{split} 1912 1913 1914 This map represents the integration :math:`\int_{\Delta^n}\omega` of an `n`-form 1915 :math:`\omega \in (A_{PL})^n_n` over the standard `n`-simplex :math:`\Delta^n`. 1916 For homogeneous elements :math:`\theta \in A_{PL}(p_n)` 1917 with :math:`n\neq p`, the integral is set to zero. Then, the map is extended to all :math:`(A_{PL})` 1918 by linearity. 1919 1920 INPUT: 1921 1922 - ``yi`` -- integer (optional, default: `0`); variable to reduce 1923 ``self`` before integration 1924 1925 OUTPUT: a rational number; 1926 1927 .. tab:: Sage 1928 1929 EXAMPLES:: 1930 1931 The integral of the Whitney form:: 1932 1933 sage: A = AplN(4) 1934 sage: w = A.whitney_form() 1935 sage: w 1936 24*t4*y0*y1*y2*y3 - 24*t3*y0*y1*y2*y4 + 24*t2*y0*y1*y3*y4 - 24*t1*y0*y2*y3*y4 + 24*t0*y1*y2*y3*y4 1937 sage: w.integral() 1938 1 1939 1940 The integral of a generic form of maximum degree:: 1941 1942 sage: A = AplN(4) 1943 sage: R = A.base_ring() 1944 sage: A.inject_variables() 1945 Defining y0, y1, y2, y3, y4 1946 sage: R.inject_variables() 1947 Defining t0, t1, t2, t3, t4 1948 sage: theta = (t1**2-1)*A.whitney_form() 1949 sage: theta 1950 (24*t1^2*t4 - 24*t4)*y0*y1*y2*y3 + (-24*t1^2*t3 + 24*t3)*y0*y1*y2*y4 + (24*t1^2*t2 - 24*t2)*y0*y1*y3*y4 + (-24*t1^3 + 24*t1)*y0*y2*y3*y4 + (24*t0*t1^2 - 24*t0)*y1*y2*y3*y4 1951 sage: theta.reduce(0) 1952 (24*t1^2 - 24)*y1*y2*y3*y4 1953 sage: theta.integral() 1954 -14/15 1955 sage: (factorial(4)*2)/factorial(2+4) 1956 1/15 1957 sage: (factorial(4)*2)/factorial(2+4)-1 1958 -14/15 1959 1960 The integral of an element of degree lower than the dimension of ``self.parent()``:: 1961 1962 sage: A = AplN(4) 1963 sage: R = A.base_ring() 1964 sage: A.inject_variables() 1965 Defining y0, y1, y2, y3, y4 1966 sage: R.inject_variables() 1967 Defining t0, t1, t2, t3, t4 1968 sage: theta = t1*y0 1969 sage: theta.integral() 1970 0 1971 1972 The integral of a non-homogeneous element:: 1973 1974 sage: A = AplN(4) 1975 sage: R = A.base_ring() 1976 sage: A.inject_variables() 1977 Defining y0, y1, y2, y3, y4 1978 sage: R.inject_variables() 1979 Defining t0, t1, t2, t3, t4 1980 sage: theta = t1*y0 + y1*y2 1981 sage: theta.integral() 1982 0 1983 sage: theta = t1*y0 + y1*y2 + A.whitney_form() 1984 sage: theta.integral() 1985 1 1986 1987 """ 1988 A = self.parent() 1989 voldeg = A.n 1990 if (self == A.zero()): 1991 return QQ(0) 1992 reduced_poly = self.reduce(yi) 1993 if (not reduced_poly): 1994 return QQ(0) 1995 elif not reduced_poly.is_homogeneous(): 1996 if not voldeg in reduced_poly.homogeneous_components().keys(): 1997 return QQ(0) 1998 elif (reduced_poly.degree() != voldeg): 1999 return QQ(0) 2000 #raise ValueError( 2001 #('The integral is defined for homogeneous polynomials of degree ' + str(voldeg))) 2002 coeff = reduced_poly.leading_coefficient() 2003 integrals = [] 2004 for (i, m) in enumerate(coeff.monomials()): 2005 c = coeff.coefficients()[i] 2006 num = prod([factorial(i) for i in m.degrees()]) 2007 den = factorial((sum(m.degrees()) + voldeg)) 2008 integrals += [((c * num) / den)] 2009 return (((- 1) ** yi) * sum(integrals)) 2010 2011 @cached_method(do_pickle=True) 2012 def koszul(self): 2013 r""" 2014 Return the koszul differential of `self`. 2015 2016 For the :math:`q`--form :math:`\omega \in (A_{PL})^q_n`: 2017 2018 .. math:: 2019 \omega = p(\overline{t}) \;y_{j_0} \wedge\cdots\wedge y_{j_{q-1}} 2020 2021 the koszul differential :math:`\kappa: (A_{PL})^q_n \rightarrow (A_{PL})^{q-1}_n` is defined as 2022 2023 .. math:: 2024 2025 \kappa (\omega) = p(\overline{t}) \sum_{j=0}^{q-1}(-1)^{j}t_{i_j}y_{i_0}\wedge\cdots\wedge\hat{y_{i_j}}\wedge\cdots\wedge y_{j_{q-1}} 2026 2027 where :math:`p(\overline{t}) \in \mathbb{Q}[t_0,\dots,t_n]`. 2028 2029 Let :math:`\omega,\theta \in (A_{PL})_n`, and :math:`\omega` defined as before such that 2030 :math:`q=|\omega|`, and :math:`r=|p(\overline{t})|`. Then, the koszul differential has the properties: 2031 2032 - :math:`\kappa \circ \kappa = 0`, 2033 2034 - :math:`(\kappa \circ d)(\omega) + (d \circ \kappa)(\omega) = (r+q)\omega`, 2035 2036 - :math:`\kappa(\omega \wedge \theta ) = \kappa(\omega) \wedge \theta + (-1)^{|\omega|} \omega \wedge \kappa (\theta)`. 2037 2038 2039 OUTPUT: a differential :math:`(q-1)` --form. 2040 2041 .. tab:: Sage 2042 2043 EXAMPLES:: 2044 2045 This example illustrates the relation between the cochain differential and koszul differential:: 2046 2047 sage: A = AplN(3) 2048 sage: R = A.base_ring() 2049 sage: A.inject_variables() 2050 Defining 2051 y0, y1, y2, y3 2052 sage: R.inject_variables() 2053 Defining 2054 t0, t1, t2, t3 2055 sage: p = t0 * t2 * y2 * y3 2056 sage: p 2057 t0*t2*y2*y3 2058 sage: p.koszul().differential()+p.differential().koszul() 2059 4*t0*t2*y2*y3 2060 sage: (p.differential().koszul()+p.koszul().differential()).reduce(0) == (2+2)*p.reduce(0) 2061 True 2062 2063 This example illustrates the koszul differential of a wedge of forms:: 2064 2065 sage: A = AplN(4) 2066 sage: R = A.base_ring() 2067 sage: A.inject_variables() 2068 Defining y0, y1, y2, y3, y4 2069 sage: R.inject_variables() 2070 Defining t0, t1, t2, t3, t4 2071 sage: p = t1*y2 2072 sage: q = t2*y3*y4 2073 sage: print(p.koszul()*q+((-1)**p.degree())*p*q.koszul().reduce(0) == (p*q).koszul().reduce(0)) 2074 True 2075 sage: print(p.koszul().differential()+ p.differential().koszul() == (1+1)*p) 2076 True 2077 sage: print(q.koszul().differential()+ q.differential().koszul() == (1+2)*q) 2078 True 2079 """ 2080 2081 return self.parent()._koszul_differential(self) 2082 2083 @cached_method(do_pickle=True) 2084 def reduce(self, var_idx, label_ref=False): 2085 r""" 2086 Return the reduction of ``self`` by the relations: 2087 2088 - :math:`t_i = 1-\sum_{j \neq i} t_j`, 2089 - :math:`y_i = -\sum_{j \neq i} y_j`. 2090 2091 INPUT: 2092 2093 - ``var_idx`` -- (integer or str). The index or the label of the variable to be reduced. 2094 2095 - ``label_ref`` -- boolean (default: False); If ``True``, ``var_idx`` is considered as a string. 2096 2097 OUTPUT: an element of ``self.parent()`` 2098 2099 .. tab:: Sage 2100 2101 EXAMPLES:: 2102 2103 sage: A = AplN(5) 2104 sage: R = A.base_ring() 2105 sage: A.inject_variables() 2106 Defining y0, y1, y2, y3, y4, y5 2107 sage: R.inject_variables() 2108 Defining t0, t1, t2, t3, t4, t5 2109 sage: theta = t0*y4 2110 sage: theta.reduce(0) 2111 (-t1 - t2 - t3 - t4 - t5 + 1)*y4 2112 sage: theta = t1*y0 2113 sage: theta.reduce(0) 2114 -t1*y1 - t1*y2 - t1*y3 - t1*y4 - t1*y5 2115 2116 """ 2117 A = self.parent() 2118 if (self == A.zero()): 2119 return self 2120 if label_ref: 2121 i = A.labels.index(var_idx) 2122 else: 2123 i = var_idx 2124 if (not (0 <= i <= A.n)): 2125 raise ValueError('i must be in [0, n]') 2126 hcomp = self.homogeneous_components() 2127 reducedSelf = A.zero() 2128 for (deg, p) in hcomp.items(): 2129 coeff_map = A._reduce_coeff_endomorphism(i) 2130 if (deg == 0): 2131 return A(p.map_coefficients(coeff_map)) 2132 if (p.degree() == (A.n + 1)): 2133 return A.zero() 2134 reduced_poly = p.map_coefficients(coeff_map) 2135 result = A.zero() 2136 for term in reduced_poly.terms(): 2137 coeff = term.leading_coefficient() 2138 mon = term.leading_monomial() 2139 reduced_mon = A._reduce_monomial(mon, i, deg) 2140 result += (coeff * reduced_mon) 2141 reducedSelf += result 2142 return reducedSelf
2143 2144 2145if (__name__ == '__main__'): 2146 None