kauri 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kauri-1.0.0/LICENSE +201 -0
- kauri-1.0.0/PKG-INFO +221 -0
- kauri-1.0.0/README.md +186 -0
- kauri-1.0.0/kauri/__init__.py +19 -0
- kauri-1.0.0/kauri/bck/__init__.py +28 -0
- kauri-1.0.0/kauri/bck/bck.py +119 -0
- kauri-1.0.0/kauri/bck_impl/__init__.py +4 -0
- kauri-1.0.0/kauri/bck_impl/bck_impl.py +101 -0
- kauri-1.0.0/kauri/bseries.py +296 -0
- kauri-1.0.0/kauri/cem/__init__.py +43 -0
- kauri-1.0.0/kauri/cem/cem.py +126 -0
- kauri-1.0.0/kauri/cem_impl/__init__.py +5 -0
- kauri-1.0.0/kauri/cem_impl/cem_impl.py +109 -0
- kauri-1.0.0/kauri/display.py +445 -0
- kauri-1.0.0/kauri/generic_algebra.py +78 -0
- kauri-1.0.0/kauri/gentrees.py +62 -0
- kauri-1.0.0/kauri/maps.py +323 -0
- kauri-1.0.0/kauri/rk.py +660 -0
- kauri-1.0.0/kauri/rk_methods.py +284 -0
- kauri-1.0.0/kauri/trees.py +1467 -0
- kauri-1.0.0/kauri/utils.py +215 -0
- kauri-1.0.0/kauri.egg-info/PKG-INFO +221 -0
- kauri-1.0.0/kauri.egg-info/SOURCES.txt +26 -0
- kauri-1.0.0/kauri.egg-info/dependency_links.txt +1 -0
- kauri-1.0.0/kauri.egg-info/requires.txt +6 -0
- kauri-1.0.0/kauri.egg-info/top_level.txt +1 -0
- kauri-1.0.0/setup.cfg +4 -0
- kauri-1.0.0/setup.py +30 -0
kauri-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
kauri-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kauri
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Algebraic manipulation of non-planar rooted trees in Python
|
|
5
|
+
Home-page: https://github.com/daniil-shmelev/kauri
|
|
6
|
+
Author: Daniil Shmelev
|
|
7
|
+
Author-email: daniil.shmelev23@imperial.ac.uk
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Win32 (MS Windows)
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Operating System :: MacOS
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: Unix
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: matplotlib
|
|
21
|
+
Requires-Dist: plotly
|
|
22
|
+
Requires-Dist: numpy
|
|
23
|
+
Requires-Dist: scipy
|
|
24
|
+
Requires-Dist: sympy
|
|
25
|
+
Requires-Dist: tqdm
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: description
|
|
30
|
+
Dynamic: description-content-type
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
Dynamic: requires-dist
|
|
34
|
+
Dynamic: summary
|
|
35
|
+
|
|
36
|
+
<p align="center">
|
|
37
|
+
<img src="docs/_static/logo.png" width="350">
|
|
38
|
+
</p>
|
|
39
|
+
|
|
40
|
+
Kauri is a Python package for symbolic and algebraic manipulation of rooted trees,
|
|
41
|
+
often used in the study of B-series, Runge-Kutta methods, and backward error analysis. It implements Hopf algebraic structures and provides tools for symbolic computation and visualization.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
pip install kauri
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Documentation
|
|
50
|
+
|
|
51
|
+
Full documentation is available at [https://kauri.readthedocs.io](https://kauri.readthedocs.io)
|
|
52
|
+
|
|
53
|
+
## Functionalities
|
|
54
|
+
|
|
55
|
+
The main goal of the kauri package is to provide implementations of:
|
|
56
|
+
|
|
57
|
+
- The Butcher-Connes-Kreimer (BCK) Hopf algebra of (un)labelled non-planar rooted trees [[Connes & Kreimer, 1999](#reference)],
|
|
58
|
+
used for the analysis of B-series and Runge-Kutta schemes
|
|
59
|
+
- The Calaque, Ebrahimi-Fard and Manchon (CEM) Hopf algebra [[Calaque, Ebrahimi-Fard & Manchon, 2011](#reference)],
|
|
60
|
+
used for backward error analysis of B-series and Runge-Kutta schemes
|
|
61
|
+
- Evaluation and manipulation of Runge-Kutta schemes, including symbolic expressions for elementary weights functions
|
|
62
|
+
and order conditions
|
|
63
|
+
- Evaluation and symbolic manipulation of truncated B-series over unlabelled trees.
|
|
64
|
+
|
|
65
|
+
## Simple Examples
|
|
66
|
+
|
|
67
|
+
### Unlabelled BCK coproduct
|
|
68
|
+
```python
|
|
69
|
+
import kauri as kr
|
|
70
|
+
import kauri.bck as bck
|
|
71
|
+
|
|
72
|
+
t = kr.Tree([[], [[]]])
|
|
73
|
+
cp = bck.coproduct(t)
|
|
74
|
+
kr.display(cp)
|
|
75
|
+
```
|
|
76
|
+
Output:
|
|
77
|
+
|
|
78
|
+
<img src="docs/_static/example1.png" width="600">
|
|
79
|
+
|
|
80
|
+
### Labelled BCK antipode
|
|
81
|
+
```python
|
|
82
|
+
import kauri as kr
|
|
83
|
+
import kauri.bck as bck
|
|
84
|
+
|
|
85
|
+
t = kr.Tree([[[3],2],[1],0])
|
|
86
|
+
s = bck.antipode(t)
|
|
87
|
+
kr.display(s)
|
|
88
|
+
```
|
|
89
|
+
Output:
|
|
90
|
+
|
|
91
|
+
<img src="docs/_static/example2.png" width="500">
|
|
92
|
+
|
|
93
|
+
### Runge-Kutta order conditions
|
|
94
|
+
```python
|
|
95
|
+
import kauri as kr
|
|
96
|
+
|
|
97
|
+
t = kr.Tree([[],[]])
|
|
98
|
+
print(kr.rk_order_cond(t, s = 3, explicit = True))
|
|
99
|
+
```
|
|
100
|
+
Output:
|
|
101
|
+
```
|
|
102
|
+
a10**2*b1 + b2*(a20 + a21)**2 - 1/3
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Truncated B-series of RK4
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
import kauri as kr
|
|
109
|
+
import sympy as sp
|
|
110
|
+
import numpy as np
|
|
111
|
+
import matplotlib.pyplot as plt
|
|
112
|
+
|
|
113
|
+
y1 = sp.symbols('y1')
|
|
114
|
+
y = sp.Matrix([y1])
|
|
115
|
+
f = sp.Matrix([y1 ** 2])
|
|
116
|
+
|
|
117
|
+
m = kr.rk4.elementary_weights_map()
|
|
118
|
+
bs = kr.BSeries(y, f, weights = m, order = 5)
|
|
119
|
+
print(bs.series())
|
|
120
|
+
|
|
121
|
+
t = np.linspace(0, 0.9, 100)
|
|
122
|
+
true = [1 / (1 - x) for x in t]
|
|
123
|
+
plt.plot(t, true, linestyle="--", color="black")
|
|
124
|
+
plt.plot(t, [bs([1], h) for h in t], color = 'firebrick')
|
|
125
|
+
plt.show()
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## The BCK Hopf Algebra
|
|
129
|
+
|
|
130
|
+
The Butcher-Connes-Kreimer Hopf algebra of (un)labelled non-planar rooted trees [[Connes & Kreimer, 1999](#reference)], is given by
|
|
131
|
+
$(\mathcal{H}, \Delta_{BCK},\mu,\varepsilon_{BCK}, \emptyset, S_{BCK})$, where<br>
|
|
132
|
+
- $\mathcal{H}$ is the set of all linear combinations of forests of (un)labelled trees
|
|
133
|
+
- Multiplication $\mu$ is defined as the commutative juxtaposition of trees
|
|
134
|
+
- Comultiplication $\Delta_{BCK}$ is defined by
|
|
135
|
+
```math
|
|
136
|
+
\Delta_{BCK}(t) = t \otimes \emptyset + \emptyset \otimes t + \sum_{s \subset t} s \otimes [t\setminus s]
|
|
137
|
+
```
|
|
138
|
+
where the sum is over proper rooted subtrees $s$ of $t$, and $[t\setminus s]$ is the product of all branches formed when
|
|
139
|
+
$s$ is erased from $t$.
|
|
140
|
+
- The unit $\emptyset$ is the empty tree
|
|
141
|
+
- The counit $\varepsilon_{BCK}$ is given by $\varepsilon(\tau) = 1$ if $\tau = \emptyset$ and $0$ otherwise
|
|
142
|
+
- The antipode $S_{BCK}$ is defined by
|
|
143
|
+
```math
|
|
144
|
+
S_{BCK}(t) = -t - \sum_{s \subset t} S([t \setminus s])s, \quad S_{BCK}(\bullet) = -\bullet
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Given two maps $f,g : \mathcal{H} \to \mathcal{H}$, we define their product map by
|
|
148
|
+
```math
|
|
149
|
+
(f\cdot g)(\tau) = \mu \circ (f \otimes g) \circ \Delta(\tau).
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## The CEM Hopf Algebra
|
|
153
|
+
|
|
154
|
+
The Calaque, Ebrahimi-Fard and Manchon (CEM) [[Calaque, Ebrahimi-Fard & Manchon, 2011](#reference)] Hopf algebra
|
|
155
|
+
$(\widetilde{H}, \Delta_{CEM}, \mu, \varepsilon_{CEM}, \bullet, S_{CEM})$ is defined as follows.
|
|
156
|
+
|
|
157
|
+
- $\widetilde{H}$ is the space of non-empty unlabelled trees, defined as
|
|
158
|
+
$\widetilde{H} = H / J$ where $H$ is the space of unlabelled non-planar rooted trees and
|
|
159
|
+
$J$ is the ideal generated by $\bullet - \emptyset$.
|
|
160
|
+
- The unit is the single-node tree, $\bullet$.
|
|
161
|
+
- The counit map is defined by $\varepsilon_{CEM}(\bullet) = 1$,
|
|
162
|
+
$\varepsilon_{CEM}(t) = 0$ for all $\bullet \neq t \in \widetilde{H}$.
|
|
163
|
+
- Multiplication $\mu : \widetilde{H} \otimes \widetilde{H} \to \widetilde{H}$ is defined as the
|
|
164
|
+
commutative juxtaposition of two forests.
|
|
165
|
+
- Comultiplication $\Delta : \widetilde{H} \to \widetilde{H} \otimes \widetilde{H}$ is defined as
|
|
166
|
+
|
|
167
|
+
```math
|
|
168
|
+
\Delta_{CEM}(t) = \sum_{s \subset t} s \otimes t / s
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
where the sum runs over all possible subforests $s$ of $t$, and
|
|
172
|
+
$t / s$ is the tree obtained by contracting each connected component of
|
|
173
|
+
$s$ onto a vertex [[Calaque, Ebrahimi-Fard & Manchon, 2011](#reference)].
|
|
174
|
+
- The antipode $S_{CEM}$ is defined by $S_{CEM}(\bullet) = \bullet$ and
|
|
175
|
+
|
|
176
|
+
```math
|
|
177
|
+
S_{CEM}(t) = -t - \sum_{t, \bullet \neq s \subset t} S_{CEM}(s) \,\, t / s.
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Truncated B-series
|
|
181
|
+
|
|
182
|
+
Consider an ODE of the form
|
|
183
|
+
```math
|
|
184
|
+
\frac{dy}{ds} = f(y)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Given a weights function $\varphi$, the associated truncated B-Series is
|
|
188
|
+
|
|
189
|
+
```math
|
|
190
|
+
B_h(\varphi, y_0) := \sum_{|t| \leq n} \frac{h^{|t|}}{\sigma(t)} \varphi(t) F(t)(y_0),
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
where the sum runs over all trees of order at most $n$, $\sigma(t)$ is the symmetry factor
|
|
194
|
+
of a tree, and $F(t)(y_0)$ are the elementary differentials, defined recursively on trees by:
|
|
195
|
+
|
|
196
|
+
```math
|
|
197
|
+
F(\emptyset) = y,
|
|
198
|
+
```
|
|
199
|
+
```math
|
|
200
|
+
F(\bullet) = f(y),
|
|
201
|
+
```
|
|
202
|
+
```math
|
|
203
|
+
F([t_1, t_2, \ldots, t_k])(y) = f^{(k)}(y)(F(t_1)(y), F(t_2)(y), \ldots, F(t_k)(y)).
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Citation
|
|
207
|
+
|
|
208
|
+
```bibtex
|
|
209
|
+
@misc{shmelev2025kauri,
|
|
210
|
+
title={Kauri: Algebraic manipulation of non-planar rooted trees in Python},
|
|
211
|
+
author={Shmelev, Daniil},
|
|
212
|
+
year={2025},
|
|
213
|
+
howpublished={\url{https://github.com/daniil-shmelev/kauri}}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## References
|
|
218
|
+
<a name="reference"></a>
|
|
219
|
+
- Connes, A., & Kreimer, D. (1999). *Hopf algebras, renormalization and noncommutative geometry*. In *Quantum field theory: perspective and prospective* (pp. 59–109). Springer.
|
|
220
|
+
- Calaque, D., Ebrahimi-Fard, K., & Manchon, D. (2011). Two interacting Hopf algebras of trees: A Hopf-algebraic approach to composition and substitution of B-series. Advances in Applied Mathematics, 47(2), 282–308. Elsevier.
|
|
221
|
+
- Beyer, T., & Hedetniemi, S. M. (1980). *Constant time generation of rooted trees*. In *SIAM Journal on Computing 9.4* (pp. 706-712)
|
kauri-1.0.0/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/_static/logo.png" width="350">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
Kauri is a Python package for symbolic and algebraic manipulation of rooted trees,
|
|
6
|
+
often used in the study of B-series, Runge-Kutta methods, and backward error analysis. It implements Hopf algebraic structures and provides tools for symbolic computation and visualization.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
pip install kauri
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Documentation
|
|
15
|
+
|
|
16
|
+
Full documentation is available at [https://kauri.readthedocs.io](https://kauri.readthedocs.io)
|
|
17
|
+
|
|
18
|
+
## Functionalities
|
|
19
|
+
|
|
20
|
+
The main goal of the kauri package is to provide implementations of:
|
|
21
|
+
|
|
22
|
+
- The Butcher-Connes-Kreimer (BCK) Hopf algebra of (un)labelled non-planar rooted trees [[Connes & Kreimer, 1999](#reference)],
|
|
23
|
+
used for the analysis of B-series and Runge-Kutta schemes
|
|
24
|
+
- The Calaque, Ebrahimi-Fard and Manchon (CEM) Hopf algebra [[Calaque, Ebrahimi-Fard & Manchon, 2011](#reference)],
|
|
25
|
+
used for backward error analysis of B-series and Runge-Kutta schemes
|
|
26
|
+
- Evaluation and manipulation of Runge-Kutta schemes, including symbolic expressions for elementary weights functions
|
|
27
|
+
and order conditions
|
|
28
|
+
- Evaluation and symbolic manipulation of truncated B-series over unlabelled trees.
|
|
29
|
+
|
|
30
|
+
## Simple Examples
|
|
31
|
+
|
|
32
|
+
### Unlabelled BCK coproduct
|
|
33
|
+
```python
|
|
34
|
+
import kauri as kr
|
|
35
|
+
import kauri.bck as bck
|
|
36
|
+
|
|
37
|
+
t = kr.Tree([[], [[]]])
|
|
38
|
+
cp = bck.coproduct(t)
|
|
39
|
+
kr.display(cp)
|
|
40
|
+
```
|
|
41
|
+
Output:
|
|
42
|
+
|
|
43
|
+
<img src="docs/_static/example1.png" width="600">
|
|
44
|
+
|
|
45
|
+
### Labelled BCK antipode
|
|
46
|
+
```python
|
|
47
|
+
import kauri as kr
|
|
48
|
+
import kauri.bck as bck
|
|
49
|
+
|
|
50
|
+
t = kr.Tree([[[3],2],[1],0])
|
|
51
|
+
s = bck.antipode(t)
|
|
52
|
+
kr.display(s)
|
|
53
|
+
```
|
|
54
|
+
Output:
|
|
55
|
+
|
|
56
|
+
<img src="docs/_static/example2.png" width="500">
|
|
57
|
+
|
|
58
|
+
### Runge-Kutta order conditions
|
|
59
|
+
```python
|
|
60
|
+
import kauri as kr
|
|
61
|
+
|
|
62
|
+
t = kr.Tree([[],[]])
|
|
63
|
+
print(kr.rk_order_cond(t, s = 3, explicit = True))
|
|
64
|
+
```
|
|
65
|
+
Output:
|
|
66
|
+
```
|
|
67
|
+
a10**2*b1 + b2*(a20 + a21)**2 - 1/3
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Truncated B-series of RK4
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import kauri as kr
|
|
74
|
+
import sympy as sp
|
|
75
|
+
import numpy as np
|
|
76
|
+
import matplotlib.pyplot as plt
|
|
77
|
+
|
|
78
|
+
y1 = sp.symbols('y1')
|
|
79
|
+
y = sp.Matrix([y1])
|
|
80
|
+
f = sp.Matrix([y1 ** 2])
|
|
81
|
+
|
|
82
|
+
m = kr.rk4.elementary_weights_map()
|
|
83
|
+
bs = kr.BSeries(y, f, weights = m, order = 5)
|
|
84
|
+
print(bs.series())
|
|
85
|
+
|
|
86
|
+
t = np.linspace(0, 0.9, 100)
|
|
87
|
+
true = [1 / (1 - x) for x in t]
|
|
88
|
+
plt.plot(t, true, linestyle="--", color="black")
|
|
89
|
+
plt.plot(t, [bs([1], h) for h in t], color = 'firebrick')
|
|
90
|
+
plt.show()
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## The BCK Hopf Algebra
|
|
94
|
+
|
|
95
|
+
The Butcher-Connes-Kreimer Hopf algebra of (un)labelled non-planar rooted trees [[Connes & Kreimer, 1999](#reference)], is given by
|
|
96
|
+
$(\mathcal{H}, \Delta_{BCK},\mu,\varepsilon_{BCK}, \emptyset, S_{BCK})$, where<br>
|
|
97
|
+
- $\mathcal{H}$ is the set of all linear combinations of forests of (un)labelled trees
|
|
98
|
+
- Multiplication $\mu$ is defined as the commutative juxtaposition of trees
|
|
99
|
+
- Comultiplication $\Delta_{BCK}$ is defined by
|
|
100
|
+
```math
|
|
101
|
+
\Delta_{BCK}(t) = t \otimes \emptyset + \emptyset \otimes t + \sum_{s \subset t} s \otimes [t\setminus s]
|
|
102
|
+
```
|
|
103
|
+
where the sum is over proper rooted subtrees $s$ of $t$, and $[t\setminus s]$ is the product of all branches formed when
|
|
104
|
+
$s$ is erased from $t$.
|
|
105
|
+
- The unit $\emptyset$ is the empty tree
|
|
106
|
+
- The counit $\varepsilon_{BCK}$ is given by $\varepsilon(\tau) = 1$ if $\tau = \emptyset$ and $0$ otherwise
|
|
107
|
+
- The antipode $S_{BCK}$ is defined by
|
|
108
|
+
```math
|
|
109
|
+
S_{BCK}(t) = -t - \sum_{s \subset t} S([t \setminus s])s, \quad S_{BCK}(\bullet) = -\bullet
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Given two maps $f,g : \mathcal{H} \to \mathcal{H}$, we define their product map by
|
|
113
|
+
```math
|
|
114
|
+
(f\cdot g)(\tau) = \mu \circ (f \otimes g) \circ \Delta(\tau).
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## The CEM Hopf Algebra
|
|
118
|
+
|
|
119
|
+
The Calaque, Ebrahimi-Fard and Manchon (CEM) [[Calaque, Ebrahimi-Fard & Manchon, 2011](#reference)] Hopf algebra
|
|
120
|
+
$(\widetilde{H}, \Delta_{CEM}, \mu, \varepsilon_{CEM}, \bullet, S_{CEM})$ is defined as follows.
|
|
121
|
+
|
|
122
|
+
- $\widetilde{H}$ is the space of non-empty unlabelled trees, defined as
|
|
123
|
+
$\widetilde{H} = H / J$ where $H$ is the space of unlabelled non-planar rooted trees and
|
|
124
|
+
$J$ is the ideal generated by $\bullet - \emptyset$.
|
|
125
|
+
- The unit is the single-node tree, $\bullet$.
|
|
126
|
+
- The counit map is defined by $\varepsilon_{CEM}(\bullet) = 1$,
|
|
127
|
+
$\varepsilon_{CEM}(t) = 0$ for all $\bullet \neq t \in \widetilde{H}$.
|
|
128
|
+
- Multiplication $\mu : \widetilde{H} \otimes \widetilde{H} \to \widetilde{H}$ is defined as the
|
|
129
|
+
commutative juxtaposition of two forests.
|
|
130
|
+
- Comultiplication $\Delta : \widetilde{H} \to \widetilde{H} \otimes \widetilde{H}$ is defined as
|
|
131
|
+
|
|
132
|
+
```math
|
|
133
|
+
\Delta_{CEM}(t) = \sum_{s \subset t} s \otimes t / s
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
where the sum runs over all possible subforests $s$ of $t$, and
|
|
137
|
+
$t / s$ is the tree obtained by contracting each connected component of
|
|
138
|
+
$s$ onto a vertex [[Calaque, Ebrahimi-Fard & Manchon, 2011](#reference)].
|
|
139
|
+
- The antipode $S_{CEM}$ is defined by $S_{CEM}(\bullet) = \bullet$ and
|
|
140
|
+
|
|
141
|
+
```math
|
|
142
|
+
S_{CEM}(t) = -t - \sum_{t, \bullet \neq s \subset t} S_{CEM}(s) \,\, t / s.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Truncated B-series
|
|
146
|
+
|
|
147
|
+
Consider an ODE of the form
|
|
148
|
+
```math
|
|
149
|
+
\frac{dy}{ds} = f(y)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Given a weights function $\varphi$, the associated truncated B-Series is
|
|
153
|
+
|
|
154
|
+
```math
|
|
155
|
+
B_h(\varphi, y_0) := \sum_{|t| \leq n} \frac{h^{|t|}}{\sigma(t)} \varphi(t) F(t)(y_0),
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
where the sum runs over all trees of order at most $n$, $\sigma(t)$ is the symmetry factor
|
|
159
|
+
of a tree, and $F(t)(y_0)$ are the elementary differentials, defined recursively on trees by:
|
|
160
|
+
|
|
161
|
+
```math
|
|
162
|
+
F(\emptyset) = y,
|
|
163
|
+
```
|
|
164
|
+
```math
|
|
165
|
+
F(\bullet) = f(y),
|
|
166
|
+
```
|
|
167
|
+
```math
|
|
168
|
+
F([t_1, t_2, \ldots, t_k])(y) = f^{(k)}(y)(F(t_1)(y), F(t_2)(y), \ldots, F(t_k)(y)).
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Citation
|
|
172
|
+
|
|
173
|
+
```bibtex
|
|
174
|
+
@misc{shmelev2025kauri,
|
|
175
|
+
title={Kauri: Algebraic manipulation of non-planar rooted trees in Python},
|
|
176
|
+
author={Shmelev, Daniil},
|
|
177
|
+
year={2025},
|
|
178
|
+
howpublished={\url{https://github.com/daniil-shmelev/kauri}}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## References
|
|
183
|
+
<a name="reference"></a>
|
|
184
|
+
- Connes, A., & Kreimer, D. (1999). *Hopf algebras, renormalization and noncommutative geometry*. In *Quantum field theory: perspective and prospective* (pp. 59–109). Springer.
|
|
185
|
+
- Calaque, D., Ebrahimi-Fard, K., & Manchon, D. (2011). Two interacting Hopf algebras of trees: A Hopf-algebraic approach to composition and substitution of B-series. Advances in Applied Mathematics, 47(2), 282–308. Elsevier.
|
|
186
|
+
- Beyer, T., & Hedetniemi, S. M. (1980). *Constant time generation of rooted trees*. In *SIAM Journal on Computing 9.4* (pp. 706-712)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Algebraic manipulation of rooted trees for the analysis of B-series and Runge-Kutta schemes.
|
|
3
|
+
"""
|
|
4
|
+
from .trees import Tree, Forest, ForestSum, TensorProductSum
|
|
5
|
+
from .maps import Map, ident, sign, exact_weights, omega
|
|
6
|
+
from .display import display
|
|
7
|
+
from .gentrees import trees_of_order, trees_up_to_order
|
|
8
|
+
from .rk import RK, rk_symbolic_weight, rk_order_cond
|
|
9
|
+
|
|
10
|
+
from .rk_methods import (euler, heun_rk2, midpoint, kutta_rk3, heun_rk3,
|
|
11
|
+
ralston_rk3, rk4, ralston_rk4, nystrom_rk5, backward_euler,
|
|
12
|
+
implicit_midpoint, crank_nicolson, gauss6, radau_iia, lobatto6)
|
|
13
|
+
|
|
14
|
+
from .bseries import BSeries, elementary_differential
|
|
15
|
+
|
|
16
|
+
from .trees import EMPTY_TREE, EMPTY_FOREST, EMPTY_FOREST_SUM, ZERO_FOREST_SUM
|
|
17
|
+
|
|
18
|
+
import kauri.bck
|
|
19
|
+
import kauri.cem
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The ``kauri.bck`` sub-package implements the Butcher-Connes-Kreimer (BCK) :cite:`connes1999hopf` Hopf algebra
|
|
3
|
+
:math:`(H, \\Delta_{BCK}, \\mu, \\varepsilon_{BCK}, \\emptyset, S_{BCK})`, defined as follows.
|
|
4
|
+
|
|
5
|
+
- :math:`H` is the set of all non-planar rooted trees.
|
|
6
|
+
- The unit :math:`\\emptyset` is the empty forest.
|
|
7
|
+
- The counit map is defined by :math:`\\varepsilon_{BCK}(\\emptyset) = 1`,
|
|
8
|
+
:math:`\\varepsilon_{BCK}(t) = 0` for all :math:`\\emptyset \\neq t \\in H`.
|
|
9
|
+
- Multiplication :math:`\\mu : H \\otimes H \\to H` is defined as the
|
|
10
|
+
commutative juxtaposition of two forests.
|
|
11
|
+
- Comultiplication :math:`\\Delta : H \\to H \\otimes H` is defined as
|
|
12
|
+
|
|
13
|
+
.. math::
|
|
14
|
+
|
|
15
|
+
\\Delta_{BCK}(t) = t \\otimes \\emptyset + \\emptyset \\otimes t + \\sum_{s \\subset t} [t \\setminus s] \\otimes s
|
|
16
|
+
|
|
17
|
+
where the sum runs over all proper rooted subtrees :math:`s` of :math:`t`, and :math:`[t \\setminus s]`
|
|
18
|
+
is the forest of all trees remaining after erasing :math:`s` from :math:`t`.
|
|
19
|
+
- The antipode :math:`S_{BCK}` is defined by :math:`S_{BCK}(\\bullet) = -\\bullet` and
|
|
20
|
+
|
|
21
|
+
.. math::
|
|
22
|
+
|
|
23
|
+
S_{BCK}(t) = -t - \\sum_{s \\subset t} (-1)^{n(t \\setminus s)} S_{BCK}([t \\setminus s]) s,
|
|
24
|
+
|
|
25
|
+
where :math:`n(t \\setminus s)` is the number of trees in the forest :math:`[t \\setminus s]`.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
from .bck import antipode, counit, coproduct, map_power, map_product
|