1r"""
2The Combinatorial Laplacian and the Discrete Hodge Decomposition
3for simplicial complexes, simplicial sets, Delta complexes and Cubical complexes.
4
5The Algebraic Topological Model
6=================================================
7
8For such objects, this implementation uses the
9method ``algebraic_topological_model`` available at SAGEMATH_. The specification of the method
10for the case of a finite simplicial complex (see SS_, DC_ and CC_ for the implementation in other
11simplicial structures) is the following:
12
13.. _SAGEMATH: https://doc.sagemath.org/html/en/reference/topology/sage/topology/simplicial_complex.html#sage.topology.simplicial_complex.SimplicialComplex.algebraic_topological_model
14
15 Algebraic topological model for this simplicial complex with
16 coefficients in ``base_ring``.
17
18 The term "algebraic topological model" is defined by Pilarczyk
19 and Réal :cite:`pawereal2015`.
20
21 INPUT:
22
23 - ``base_ring`` -- coefficient ring (default: ``QQ``); must be a field
24
25 Denote by :math:`C` the chain complex associated to this simplicial
26 complex. The algebraic topological model is a chain complex
27 :math:`M` with zero differential, with the same homology as :math:`C`,
28 along with chain maps :math:`\pi: C \to M` and :math:`\iota: M \to C`
29 satisfying :math:`\iota \circ \pi = 1_M` and :math:`\pi \circ \iota` chain homotopic
30 to :math:`1_C`. The chain homotopy :math:`\phi` must satisfy
31
32 - :math:`\phi \circ \phi = 0`,
33 - :math:`\pi \circ \phi = 0`,
34 - :math:`\phi \circ \iota = 0`.
35
36 Such a chain homotopy is called a *chain contraction*.
37
38 OUTPUT: a pair consisting of
39
40 - chain contraction :math:`\phi` associated to :math:`C`, :math:`M`, :math:`\pi`, and
41 :math:`\iota`
42 - the chain complex :math:`M`
43
44 Note that from the chain contraction :math:`\phi`, one can recover the
45 chain maps :math:`\pi` and :math:`\iota` via ``phi.pi()`` and
46 ``phi.iota()``. Then one can recover :math:`C` and :math:`M` from, for
47 example, ``phi.pi().domain()`` and ``phi.pi().codomain()``,
48 respectively.
49
50An alternative definition for cochain complexes is given in :cite:`cheng2008transferring`:
51
52 Given two cochain complexes :math:`C` and :math:`M`, a contraction :math:`(\pi, \iota, \phi)`
53 from :math:`C` to :math:`M` consists of chain maps:
54
55 .. math::
56
57 \begin{array}{cc}
58 \pi:& C \rightarrow M ,\\
59 \iota:& M \rightarrow C ,
60 \end{array}
61
62 and a chain homotopy
63
64 .. math::
65
66 \phi: C^{*} \rightarrow C^{*-1},
67
68 such that
69
70 .. math::
71
72 \pi \circ \iota = \mathrm{1}_M
73
74 and
75
76 .. math::
77
78 \iota \circ \pi - \mathrm{1}_C = d_C \circ \phi + \phi \circ d_C.
79
80Such a chain homotopy provides a strong relation between the chain complexes :math:`C` and :math:`M`;
81for example, their homology groups are isomorphic.
82
83
84.. _def:combinatorial_laplacian:
85
86The Combinatorial Laplacian and the Discrete Hodge Decomposition
87=========================================================
88
89This definitions come from :cite:`dodziuk1976finite,goldberg2002combinatorial`.
90
91Let :math:`K` be a finite oriented simplicial complex, :math:`d \geq 0` be an
92integer, and :math:`\partial_d: C_d(K) \rightarrow C_{d-1}(K)`, the `boundary operator`. Then,
93
94 *Definition:* The :math:`d`-th *combinatorial Laplacian* is the linear operator
95 :math:`\Delta_d : C_d \longrightarrow C_d` given by
96
97 .. math::
98
99 \Delta_d = \partial_{d+1} \circ \partial_{d+1}^* + \partial_d^* \circ \partial_d.
100
101For convenience, we use the notations
102
103.. math::
104 \Delta_d^{\mathrm{up}} = \partial_{d+1} \circ \partial_{d+1}^*
105
106and
107
108.. math::
109
110 \Delta_d^{\mathrm{down}} = \partial_d^* \circ \partial_d,
111
112so that
113
114.. math::
115
116 \Delta_d = \Delta_d^{\mathrm{up}} + \Delta_d^{\mathrm{down}}.
117
118Now, let :math:`B_{d}` be the adjacenty matrix of dimension `d` defined by the simplicial structure of `K`.
119
120 The :math:`d`-th *Laplacian matrix* of :math:`K`, denoted :math:`L_d`, relative to some orderings of the
121 standard bases for :math:`C_d` and :math:`C_{d-1}` of :math:`K`, is the matrix representation
122 of :math:`\Delta_d`.
123
124 Observe that
125
126 .. math::
127
128 L_d = B_{d+1} B_{d+1}^T + B_d^T B_d.
129
130As above, for convenience, we use the notations
131
132.. math::
133
134 L_d^{\mathrm{up}} = B_{d+1} B_{d+1}^T
135
136and
137
138.. math::
139
140 L_d^{\mathrm{down}} = B_d^T B_d,
141
142so that
143
144.. math::
145
146 L_d = L_d^{\mathrm{up}} + L_d^{\mathrm{down}}.
147
148Relation between the `AT-model` and the combinatorial laplacian
149=========================================================
150
151Let
152
153.. math::
154 :nowrap:
155
156 \[
157 \begin{array}{rcl}
158 H_d & := & \ker{(L_d^{up})} \cap \ker{(L_d^{down})} \\
159 E_d & := & \ker{(L_d^{up})} \cap \text{Im}({L_d^{down}}) \\
160 C_d & := & \text{Im}({L_d^{up}}) \cap \ker{(L_d^{down})}
161 \end{array}
162 \]
163
164
165It is easy to see that :math:`H_d = \ker{L_d}`. The fundamental theo of discrete Hodge theory states:
166
167 For any finite simplicial complex :math:`K`, we have the orthogonal decomposition:
168
169 .. math::
170
171 C^k(K;\mathbb{K}) = H_d \oplus E_d \oplus C_d
172
173 and
174
175 .. math::
176 :nowrap:
177
178 \[
179 \begin{array}{rcl}
180 H_d & \perp & E_d \\
181 E_d & \perp & C_d \\
182 C_d & \perp & H_d
183 \end{array}
184 \]
185
186
187 Furthermore, :math:`\ker{(L_k)} \cong H^k(K; \mathbb{K})` via the natural projection.
188
189Taking into account the `AT-model`:
190
191 **Theorem:**
192
193 .. math::
194 :nowrap:
195
196 \[
197 \begin{array}{rcl}
198 H_d & \cong & \text{Im}(\iota \circ \pi) \\
199 E_d & \cong & \text{Im}{(d_C \circ \phi)} \\
200 C_d & \cong & \text{Im}{(\phi \circ d_C)}
201 \end{array}
202 \]
203
204 and
205
206 .. math::
207 :nowrap:
208
209 \[
210 \begin{array}{rcl}
211 \text{Im}(\iota \circ \pi) & \perp & \text{Im}{(d_C \circ \phi)} \\
212 \text{Im}{(d_C \circ \phi)} & \perp & \text{Im}{(\phi \circ d_C)} \\
213 \text{Im}{(\phi \circ d_C)} & \perp & \text{Im}(\iota \circ \pi)
214 \end{array}
215 \]
216
217 and
218
219 .. math::
220
221 C^k(K) = \text{Im}(\iota \circ \pi) \oplus \text{Im}{(d_C \circ \phi)} \oplus \text{Im}{(\phi \circ d_C)}
222
223.. SEEALSO::
224
225 - Finite simplicial complexes: SC_.
226
227 - Simplicial sets: SS_.
228
229 - Finite Delta-complexes: DC_.
230
231 - Finite cubical complexes: CC_.
232
233 .. _SC: https://doc.sagemath.org/html/en/reference/topology/sage/topology/simplicial_complex.html
234
235 .. _SS: https://doc.sagemath.org/html/en/reference/topology/sage/topology/simplicial_set.html
236
237 .. _DC: https://doc.sagemath.org/html/en/reference/topology/sage/topology/delta_complex.html
238
239 .. _CC: https://doc.sagemath.org/html/en/reference/topology/sage/topology/cubical_complex.html
240
241
242.. NOTE::
243
244 References:
245
246 - :cite:`dodziuk1976finite`
247
248 - :cite:`dodziuk1976remark`
249
250 - :cite:`duval2002shifted`
251
252 - :cite:`friedberg1997linear`
253
254 - :cite:`goldberg2002combinatorial`
255
256 - :cite:`Torres_2020`
257
258"""
259
260from sage.structure.unique_representation import UniqueRepresentation, CachedRepresentation
261from sage.misc.cachefunc import cached_method, cached_function
262from sage.structure.sage_object import SageObject
263from sage.matrix.constructor import matrix, zero_matrix, identity_matrix
264from sage.modules.free_module import span
265from sage.modules.free_module_element import vector, zero_vector
266from sage.rings.rational_field import QQ
267from collections import defaultdict
268
269
[docs]
270class Hodge(SageObject, UniqueRepresentation, CachedRepresentation):
271 r"""
272 This class implements the Combinatorial Laplacian and the Discrete Hodge Decomposition
273 of the cochain complex of a simplicial structure. For such decomposition, this class makes use
274 of the ``AT_model`` implementation available at SAGEMATH.
275
276 """
277
278 def __init__(self, S, base_ring=QQ):
279 r"""
280 Initialization of "self".
281
282 INPUT:
283
284 - ``S`` -- a simplicial complex, simplicial set, delta complex or cubical complex.
285
286 - ``base_ring`` -- the base ring of "self (default: QQ)
287
288 .. tab:: Sage
289
290 EXAMPLES::
291
292 sage: K = simplicial_complexes.Sphere(2)
293 sage: H = Hodge(K)
294 sage: H
295 The Discrete Hodge structure of Minimal triangulation of the 2-sphere over the base ring Rational Field
296
297 """
298 self.K = S
299 self._base_ring = base_ring
300 self.dimension = S.dimension()
301 self._laplacians = {}
302 self._harmonic_basis = {}
303 self._exact_basis = {}
304 self._coexact_basis = {}
305
306 def _repr_(self):
307 r"""
308 Default method for string representation.
309
310 .. tab:: Sage
311
312 EXAMPLES::
313
314 sage: K = simplicial_complexes.Sphere(2)
315 sage: H = Hodge(K)
316 sage: H
317 The Discrete Hodge structure of Minimal triangulation of the 2-sphere over the base ring Rational Field
318
319 """
320 return f"The Discrete Hodge structure of {self.K} over the base ring {self._base_ring}"
321
[docs]
322 def base_ring(self):
323 r"""
324 Return the base ring of "self".
325 """
326 return self._base_ring
327
328 @cached_method(do_pickle=True)
329 def boundary_operator(self, dim):
330 r"""
331 The differentials which make up the chain complex.
332
333 INPUT:
334
335 - ``dim`` -- element of the grading group (optional, default "None");
336
337
338 OUTPUT:
339
340 The differential starting in dimension ``dim`` as a sparse matrix.
341
342 .. tab:: Sage
343
344 EXAMPLES::
345
346 sage: K = simplicial_complexes.Sphere(2)
347 sage: H = Hodge(K)
348 sage: H.boundary_operator(1)
349 [-1 -1 -1 0 0 0]
350 [ 1 0 0 -1 -1 0]
351 [ 0 1 0 1 0 -1]
352 [ 0 0 1 0 1 1]
353 sage: H.boundary_operator(1) == K.chain_complex().differential(1)
354 True
355
356 """
357 ch = self.K.chain_complex(base_ring=self._base_ring)
358 return ch.differential(dim).sparse_matrix()
359
360 @cached_method(do_pickle=True)
361 def coboundary_operator(self, dim):
362 r"""
363 The differentials which make up the cochain complex.
364
365 INPUT:
366
367 - ``dim`` -- element of the grading group (optional, default "None");
368
369
370 OUTPUT:
371
372 The differential starting in dimension ``dim`` as a sparse matrix.
373
374 .. tab:: Sage
375
376 EXAMPLES::
377
378 sage: K = simplicial_complexes.Sphere(2)
379 sage: H = Hodge(K)
380 sage: H
381 The Discrete Hodge structure of Minimal triangulation of the 2-sphere over the base ring Rational Field
382 sage: H.coboundary_operator(1)
383 [ 1 -1 0 1 0 0]
384 [ 1 0 -1 0 1 0]
385 [ 0 1 -1 0 0 1]
386 [ 0 0 0 1 -1 1]
387 sage: H.coboundary_operator(1) == K.chain_complex().dual().differential(1)
388 True
389
390 """
391 ch = self.K.chain_complex(base_ring=self._base_ring).dual()
392 return ch.differential(dim).sparse_matrix()
393
394 @cached_method(do_pickle=True)
395 def coexact_basis(self, d):
396 r"""
397 The basis of the coexact (non-closed) cochain subspace of :math:`C^d(K)`.
398
399 .. tab:: Sage
400
401 EXAMPLES::
402
403 sage: K = simplicial_complexes.Sphere(2)
404 sage: H = Hodge(K)
405 sage: H.coexact_basis(1)
406 [(1, 0, -1, 0, 1, 0), (0, 1, -1, 0, 0, 1), (0, 0, 0, 1, -1, 1)]
407
408 """
409 if (d in self._coexact_basis):
410 return self._coexact_basis[d]
411 else:
412 coexact_matrix = self.coexact_matrix(d)
413 self._coexact_basis[d] = coexact_matrix.rows()
414 return self._coexact_basis[d]
415
416 @cached_method(do_pickle=True)
417 def coexact_matrix(self, d):
418 r"""
419 The coexact (non-closed) cochain subspace of :math:`C^d(K)` as a sparse matrix
420 with rows the basis of the vector subspace.
421
422 .. tab:: Sage
423
424 EXAMPLES::
425
426 sage: K = simplicial_complexes.Sphere(2)
427 sage: H = Hodge(K)
428 sage: H.coexact_basis(1)
429 [(1, 0, -1, 0, 1, 0), (0, 1, -1, 0, 0, 1), (0, 0, 0, 1, -1, 1)]
430 sage: H.coexact_matrix(1)
431 [ 1 0 -1 0 1 0]
432 [ 0 1 -1 0 0 1]
433 [ 0 0 0 1 -1 1]
434
435 """
436
437 if (d in self._coexact_basis):
438 basis = self.coexact_basis(d)
439 if len(basis):
440 return matrix(self._base_ring, len(basis), basis, sparse=True).echelon_form().sparse_matrix()
441 else:
442 ncells = len(self.K.n_cells(d))
443 return zero_matrix(self._base_ring, 0, ncells)
444 elif (d == self.K.dimension()):
445 ncells = len(self.K.n_cells(d))
446 return zero_matrix(self._base_ring, 0, ncells)
447 else:
448 # dif_matrix = self.coboundary_operator(d)
449 # if (not dif_matrix):
450 # ncells = len(self.K.n_cells(d))
451 # return zero_matrix(self._base_ring, 0, ncells)
452 (phi, M) = self.K.algebraic_topological_model()
453 #phi_matrix = phi.in_degree(d).sparse_matrix()
454 #coexacts = (phi_matrix * dif_matrix).column_space().matrix().sparse_matrix()
455 coexacts = phi.in_degree(d).row_space().matrix().sparse_matrix()
456 return coexacts
457
458 """
459 harmonic_basis = self.harmonic_basis(d)
460 if len(harmonic_basis):
461 complement_matrix = span(
462 harmonic_basis).complement().basis_matrix().sparse_matrix()
463 else:
464 complement_matrix = identity_matrix(self._base_ring,
465 len(self.K.n_cells(d)), sparse=True)
466 coex_mat = ((complement_matrix * dif.T) *
467 dif).row_space().basis_matrix().sparse_matrix()
468 return coex_mat.echelon_form().sparse_matrix()
469 """
470
471 @cached_method(do_pickle=True)
472 def exact_basis(self, d):
473 r"""
474 The basis of the exact cochain subspace of :math:`C^d(K)`.
475
476 .. tab:: Sage
477
478 EXAMPLES::
479
480 sage: K = simplicial_sets.Torus()
481 sage: H = Hodge(K)
482 sage: H.harmonic_basis(1)
483 [
484 (1, 0, 1),
485 (0, 1, 1)
486 ]
487 sage: H.exact_basis(1)
488 []
489 sage: H.coexact_basis(1)
490 [(1, 1, -1)]
491
492 """
493
494 # (phi,M) = K.algebraic_topological_model()
495 #sage: d1 = ch.differential(1)
496 #sage: d1*phi.dual().in_degree(2)
497 if (d in self._exact_basis):
498 return self._exact_basis[d]
499 else:
500 if (d == 0):
501 ncells = len(self.K.n_cells(d))
502 basis = [zero_vector(self._base_ring, ncells)]
503 else:
504 basis = self.exact_matrix(d).rows()
505 """
506 coexact_matrix_prev = self.coexact_matrix((d - 1))
507 d_prev = self.coboundary_operator((d - 1))
508 exact_matrix = (coexact_matrix_prev * d_prev.T)
509 basis = exact_matrix.echelon_form().sparse_matrix().rows()
510 """
511 self._exact_basis[d] = basis
512 return basis
513
514 @cached_method(do_pickle=True)
515 def exact_matrix(self, d):
516 r"""
517 The exact cochain subspace of :math:`C^d(K)` as a sparse matrix
518 with rows the basis of the vector subspace.
519
520 .. tab:: Sage
521
522 EXAMPLES::
523
524 sage: K = delta_complexes.KleinBottle()
525 sage: H = Hodge(K)
526 sage: [H2,E2,C2] = H.hodge_decomposition(2)
527 sage: H2
528 [0 0]
529 sage: E2
530 [ 1 1]
531 [ 1 -1]
532 sage: C2
533 []
534 sage: K.dimension()
535 2
536 sage: [H1,E1,C1] = H.hodge_decomposition(1)
537 sage: H1
538 [0 0 1]
539 sage: E1
540 []
541 sage: C1
542 [1 0 0]
543 [0 1 0]
544 sage: d1 = H.coboundary_operator(1)
545 sage: (d1*C1.T).T == E2
546 True
547
548 .. tab:: Raw code
549
550 EXAMPLES::
551
552 K = delta_complexes.KleinBottle()
553 H = Hodge(K)
554 [H2,E2,C2] = H.hodge_decomposition(2)
555 print("K.dimension()")
556 [H1,E1,C1] = H.hodge_decomposition(1)
557 d1 = H.coboundary_operator(1)
558 print((d1*C1.T).T == E2)
559 """
560
561
562 dif_matrix = self.coboundary_operator(d-1)
563 if (not dif_matrix):
564 ncells = len(self.K.n_cells(d))
565 return zero_matrix(self._base_ring, 0, ncells)
566 """
567 (phi, M) = self.K.algebraic_topological_model()
568 phi_matrix = phi.dual().in_degree(d).sparse_matrix()
569 exacts = (dif_matrix * phi_matrix).column_space().matrix().sparse_matrix()
570 return exacts
571 """
572
573 C = self.coexact_matrix(d-1)
574 return C*(dif_matrix.T) # actually, (dif_matrix * C.T).T but in this way we save a transposition
575
576 """
577 basis = self.exact_basis(d)
578 if len(basis):
579 return matrix(self._base_ring, len(basis), basis, sparse=True).echelon_form().sparse_matrix()
580 else:
581 ncells = len(self.K.n_cells(d))
582 return zero_matrix(self._base_ring, 1, ncells)
583 """
584
585 @cached_method(do_pickle=True)
586 def harmonic_basis(self, d):
587 r"""
588 The basis of the harmonic cochain subspace of :math:`C^d(K)`.
589
590 .. tab:: Sage
591
592 EXAMPLES::
593
594 sage: K = simplicial_sets.Torus()
595 sage: H = Hodge(K)
596 sage: H.harmonic_basis(1)
597 [
598 (1, 0, 1),
599 (0, 1, 1)
600 ]
601 sage: H.exact_basis(1)
602 []
603 sage: H.coexact_basis(1)
604 [(1, 1, -1)]
605
606 """
607 if (d in self._harmonic_basis):
608 return self._harmonic_basis[d]
609 else:
610 (phi, M) = self.K.algebraic_topological_model()
611 mat = (phi.iota().in_degree(d).sparse_matrix()
612 * phi.pi().in_degree(d).sparse_matrix())
613 basis = mat.row_space().basis()
614 self._harmonic_basis[d] = basis
615 return basis
616
617 @cached_method(do_pickle=True)
618 def harmonic_matrix(self, d):
619 r"""
620 The harmonic cochain subspace of :math:`C^d(K)` as a sparse matrix
621 with rows the basis of the vector subspace.
622
623 .. tab:: Sage
624
625 EXAMPLES::
626
627 sage: K = simplicial_sets.Torus()
628 sage: H = Hodge(K)
629 sage: H.harmonic_matrix(1)
630 [1 0 1]
631 [0 1 1]
632 sage: H.exact_matrix(1)
633 [0 0 0]
634 sage: H.coexact_matrix(1)
635 [ 1 1 -1]
636
637 """
638 basis = self.harmonic_basis(d)
639 if len(basis):
640 return matrix(self._base_ring, len(basis), basis, sparse=True)
641 else:
642 ncells = len(self.K.n_cells(d))
643 return zero_matrix(self._base_ring, 1, ncells)
644
[docs]
645 def hodge_cochain_decomposition(self, cochain, degree):
646 r"""
647 Returns the hodge decomposition of the cochain `c` as a sum of three components
648
649 .. math::
650
651 cochain = h + e + c
652
653 where `h` is the harmonic component, `e` is the exact component and `c` is the coexact component.
654
655 INPUT:
656
657 - ``cochain`` -- a cochain of :math:`C^d(K)` represented as a vector over the base ring.
658
659 - ``degree`` -- the degree of the cochain.
660
661 OUTPUT: a tuple `(h,e,c)` of elements of :math:`C^d(K)`
662
663 .. tab:: Sage
664
665 EXAMPLES::
666
667 sage: K = cubical_complexes.Sphere(2)
668 sage: H = Hodge(K)
669 sage: v = random_vector(QQ, len(K.n_cells(2)))
670 sage: v
671 (-1/15, 1, 1/449, 1/3, -2/5, 0)
672 sage: (h,e,c) = H.hodge_cochain_decomposition(v,2)
673 sage: v == h+c+e
674 True
675 sage: h
676 (0, 0, 0, 0, 0, 4036/2245)
677 sage: e
678 (-1/15, 1, 1/449, 1/3, -2/5, -4036/2245)
679 sage: c
680 (0, 0, 0, 0, 0, 0)
681
682
683 """
684 [H, X, Y] = self.hodge_decomposition(degree)
685 linear_system = H.stack(X.stack(Y)).T
686 coords = linear_system.solve_right(cochain)
687 hcoords = coords[:H.nrows()]
688 xcoords = coords[H.nrows():(H.nrows() + X.nrows())]
689 ycoords = coords[(- Y.nrows()):]
690 if (hcoords and H.nrows()):
691 harmonic = H.linear_combination_of_rows(hcoords)
692 else:
693 harmonic = zero_vector(self._base_ring, len(cochain))
694 if (xcoords and X.nrows()):
695 exact = X.linear_combination_of_rows(xcoords)
696 else:
697 exact = zero_vector(self._base_ring, len(cochain))
698 if (ycoords and Y.nrows()):
699 coexact = Y.linear_combination_of_rows(ycoords)
700 else:
701 coexact = zero_vector(self._base_ring, len(cochain))
702 assert (harmonic in H.row_space())
703 assert (exact in X.row_space())
704 assert (coexact in Y.row_space())
705 assert (((harmonic + exact) + coexact) == cochain)
706 return (harmonic, exact, coexact)
707
708 @cached_method(do_pickle=True)
709 def hodge_decomposition(self, dim):
710 r"""
711
712 Returns the hodge decomposition of :math:`C^dim(K)`.
713
714 INPUT:
715
716 - ``dim`` -- the degree of the cochain module.
717
718 OUTPUT: a tuple of matrices `(H,E,C)` corresponding with the harmonic, exact and coexact matrices.
719
720 .. SEEALSO::
721
722 :meth:`harmonic_matrix`
723
724 :meth:`exact_matrix`
725
726 :meth:`coexact_matrix`
727
728 .. tab:: Sage
729
730 EXAMPLES::
731
732 The hodge decomposition of the simplicial cochain complex of the 2-Sphere at degree 2:
733
734 sage: K = cubical_complexes.Sphere(2)
735 sage: H = Hodge(K)
736 sage: (H,E,C) = H.hodge_decomposition(2)
737 sage: H
738 [0 0 0 0 0 1]
739 sage: E
740 [ 1 0 0 0 0 1]
741 [ 0 1 0 0 0 -1]
742 [ 0 0 1 0 0 1]
743 [ 0 0 0 1 0 -1]
744 [ 0 0 0 0 1 1]
745 sage: C
746 []
747 sage: len(K.n_cells(2))
748 6
749
750 (TO UPDATE) Example that ilustrates the orthogonality of the decomposition:
751
752 sage: S2 = simplicial_sets.Sphere(2)
753 sage: T = simplicial_sets.Torus()
754 sage: K = S2.product(S2).product(T)
755 sage: K
756 S^2 x S^2 x Torus
757 sage: W = APLK(K)
758 sage: W
759 Algebra of Whitney Forms on S^2 x S^2 x Torus
760 sage: hodge = W.hodge()
761
762
763 .. tab:: Raw code
764
765 S2 = simplicial_sets.Sphere(2)
766 T = simplicial_sets.Torus()
767 K = S2.product(S2).product(T)
768 ch = K.chain_complex(base_ring=QQ).dual()
769 (phi,M) = K.algebraic_topological_model()
770 d1 = ch.differential(1)
771 d2 = ch.differential(2)
772 C = phi.dual().in_degree(3)*d2
773 E = d1*phi.dual().in_degree(2)
774 H = phi.dual().iota().in_degree(2)*phi.dual().pi().in_degree(2)
775 H*E == 0
776 H*C == 0
777 C*E == 0
778 E*C == 0
779
780 """
781 H = self.harmonic_matrix(dim)
782 X = self.exact_matrix(dim)
783 Y = self.coexact_matrix(dim)
784 return (H, X, Y)
785
786 @cached_method(do_pickle=True)
787 def laplacian(self, dim):
788 r"""
789 Returns the discrete laplacian of dimension ``dim``.
790
791 INPUT:
792
793 - ``dim`` -- the dimension of the cochain module.
794
795 OUTPUT: a tuple of sparse matrices `(L, Ldown, Lup)` corresponding with the laplacian, the
796 down laplacian and the up laplacian matrices.
797
798 .. tab:: Sage
799
800 EXAMPLES::
801
802 sage: K = delta_complexes.KleinBottle()
803 sage: K
804 Delta complex with 1 vertex and 7 simplices
805 sage: H = Hodge(K)
806 sage: H
807 The Discrete Hodge structure of Delta complex with 1 vertex and 7 simplices over the base ring Rational Field
808 sage: (L, Ldown, Lup) = H.laplacian(1)
809 sage: L
810 [ 2 0 0]
811 [ 0 2 -2]
812 [ 0 -2 2]
813 sage: Ldown
814 [0 0 0]
815 [0 0 0]
816 [0 0 0]
817 sage: Lup
818 [ 2 0 0]
819 [ 0 2 -2]
820 [ 0 -2 2]
821 sage: L.right_kernel().dimension() == len(H.harmonic_basis(1))
822 True
823
824 """
825 if (dim in self._laplacians):
826 return self._laplacians[dim]
827 else:
828 d_curr = self.coboundary_operator(dim)
829 d_prev = self.coboundary_operator((dim - 1))
830 L_down = (d_prev * d_prev.T)
831 L_up = (d_curr.T * d_curr)
832 L = (L_down + L_up)
833 self._laplacians[dim] = (L, L_down, L_up)
834 return (L, L_down, L_up)
835
[docs]
836 def preimage(self, cochain, degree):
837 r"""
838 Returns the coexact cochain of ``degree-1`` whose differential correspond with the
839 exact component of the given cochain.
840
841 INPUT:
842
843 - ``cochain`` -- a cochain vector
844
845 - ``degree`` -- the degree of the cochain.
846
847 OUTPUT: a cochain vector of degree ``degree-1`` whose differential corresponds with the exact component
848 of the given cochain.
849
850 .. tab:: Sage
851
852 EXAMPLES::
853
854 sage: S2 = simplicial_sets.Sphere(2)
855 sage: K = S2.product(S2)
856 sage: H = Hodge(K)
857 sage: H
858 The Discrete Hodge structure of S^2 x S^2 over the base ring Rational Field
859 sage: v = random_vector(QQ, len(K.n_cells(3)))
860 sage: (h,e,c) = H.hodge_cochain_decomposition(v,3)
861 sage: h
862 (0, 0, 0, 0, 0, 0)
863 sage: e
864 (1/12, 0, 1/12, -1/12, 0, -1/12)
865 sage: c
866 (-1/12, -2, 1/4, 1/12, -1/6, 1/12)
867 sage: y = H.preimage(v,3)
868 sage: dif = K.chain_complex(base_ring=QQ).dual().differential(2)
869 sage: dif*y == e
870 True
871
872 """
873 if (degree == 0):
874 raise ValueError(
875 'Cannot compute preimage for 0-cochains (no d_{-1})')
876 d_prev = self.coboundary_operator((degree - 1))
877 ker_matrix = d_prev.T.right_kernel_matrix()
878 M = d_prev.T.stack(ker_matrix)
879 preimage = M.T.solve_right(cochain)
880 return preimage[:len(self.K.n_cells((degree - 1)))]
881
882if (__name__ == '__main__'):
883 None