Skip to content

Commit 1062a79

Browse files
thomasahleclaude
andcommitted
book_layout: document the complete feature set and entry points
Module docstring now lists the full supported language (Variable, Zero, Delta all orders, Product, Rename, Sum, Function, Derivative, Expectation), the transpose-rotation rule, the three equivalent entry points, and the left/right/max_width/scale options. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018PzG3QbNtaFmABBHBG39wp
1 parent bacc986 commit 1062a79

1 file changed

Lines changed: 27 additions & 12 deletions

File tree

‎tensorgrad/extras/book_layout.py‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,33 @@
3030
(paper/chapters/tikz-styles.tex: ``copydot`` etc.), so generated code can be
3131
pasted into the book.
3232
33-
Supported today: Variable, Delta (any order), Product, Rename, Sum (top
34-
level AND as parenthesized product factors), and Function (application
35-
arrows: solid for consumed edges, densely dotted for elementwise; broadcast
36-
edges stay on the argument, as the book draws them). Transposed 2-port
37-
variables (spine forces reversed port order) are drawn rotated 180 degrees,
38-
the book's transpose convention. Unevaluated Derivative nodes render as
39-
Penrose derivative loops: a fit-ellipse around the differentiated
40-
subexpression with a dot on the boundary and labeled whiskers for the new
41-
edges (one whisker bends left; a pair bends left/right, like the book's
42-
\dloop/\dwhiskers). Nested derivatives nest their ellipses. A derivative
43-
whose new edge is contracted onward still raises NotImplementedError --
44-
simplify() first.
33+
The whole tensorgrad language is supported:
34+
35+
* **Variable / Zero** -- labelled nodes (Zero is a ``0`` node).
36+
* **Delta** (any order) -- order 2 is an identity wire, order 0 a scalar
37+
``|n|``, order >= 3 a copy-dot; a closed ring of identities is a circle.
38+
* **Product** -- contraction; shared edges become wires, the rest stubs.
39+
* **Rename** -- re-keys free edges (including swaps).
40+
* **Sum** -- top level AND as parenthesized product factors (drawn as a
41+
bracketed group with wires passing through).
42+
* **Function** -- application arrows: solid for consumed edges, densely
43+
dotted for elementwise; broadcast edges stay on the argument.
44+
* **Derivative** (unevaluated) -- a Penrose loop: a fit-ellipse around the
45+
differentiated subexpression with a boundary dot and labelled whiskers
46+
for the new edges (one bends left; a pair bends left/right, like the
47+
book's \dloop/\dwhiskers). Nested derivatives nest their ellipses. A
48+
derivative whose new edge is contracted onward raises NotImplementedError
49+
-- call simplify() first.
50+
* **Expectation** -- an ``E[.]`` fit-box around the inner subexpression.
51+
52+
A 2-port variable forced into reversed port order (a transpose, e.g. the
53+
A^T term of a gradient) is drawn rotated 180 degrees, but only when it has
54+
a free edge -- internal contraction nodes stay upright.
55+
56+
Entry points (all equivalent): ``tensorgrad.to_book_tikz(t, **opts)``,
57+
``t.to_book_tikz(**opts)``, or this module's ``to_book_tikz``. Options:
58+
``left=``/``right=`` fix a free edge's side; ``max_width=`` scales a
59+
too-wide diagram down to fit; ``scale=`` sets an explicit factor.
4560
"""
4661

4762
from __future__ import annotations

0 commit comments

Comments
 (0)