kappalogic 0.9.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.
Files changed (31) hide show
  1. kappalogic-0.9.0/LICENSE +201 -0
  2. kappalogic-0.9.0/PKG-INFO +114 -0
  3. kappalogic-0.9.0/README.md +104 -0
  4. kappalogic-0.9.0/kappalogic/__init__.py +59 -0
  5. kappalogic-0.9.0/kappalogic/applications.py +88 -0
  6. kappalogic-0.9.0/kappalogic/bridge.py +42 -0
  7. kappalogic-0.9.0/kappalogic/core.py +118 -0
  8. kappalogic-0.9.0/kappalogic/electronic_structure.py +93 -0
  9. kappalogic-0.9.0/kappalogic/field_theory.py +67 -0
  10. kappalogic-0.9.0/kappalogic/funcs.py +38 -0
  11. kappalogic-0.9.0/kappalogic/heat.py +62 -0
  12. kappalogic-0.9.0/kappalogic/info_theory.py +40 -0
  13. kappalogic-0.9.0/kappalogic/kernels.py +59 -0
  14. kappalogic-0.9.0/kappalogic/quantum_well.py +92 -0
  15. kappalogic-0.9.0/kappalogic/search.py +94 -0
  16. kappalogic-0.9.0/kappalogic/spacetime.py +29 -0
  17. kappalogic-0.9.0/kappalogic/stat_mech.py +46 -0
  18. kappalogic-0.9.0/kappalogic/theory.py +87 -0
  19. kappalogic-0.9.0/kappalogic/topology.py +36 -0
  20. kappalogic-0.9.0/kappalogic.egg-info/PKG-INFO +114 -0
  21. kappalogic-0.9.0/kappalogic.egg-info/SOURCES.txt +29 -0
  22. kappalogic-0.9.0/kappalogic.egg-info/dependency_links.txt +1 -0
  23. kappalogic-0.9.0/kappalogic.egg-info/requires.txt +1 -0
  24. kappalogic-0.9.0/kappalogic.egg-info/top_level.txt +1 -0
  25. kappalogic-0.9.0/pyproject.toml +14 -0
  26. kappalogic-0.9.0/setup.cfg +4 -0
  27. kappalogic-0.9.0/tests/test_kappalogic.py +86 -0
  28. kappalogic-0.9.0/tests/test_v02_features.py +126 -0
  29. kappalogic-0.9.0/tests/test_v04_crossdomain.py +79 -0
  30. kappalogic-0.9.0/tests/test_v05_bridge_dft.py +70 -0
  31. kappalogic-0.9.0/tests/test_v07_theory.py +63 -0
@@ -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.
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.4
2
+ Name: kappalogic
3
+ Version: 0.9.0
4
+ Summary: tanh(x/xi)ベースの擬連続論理ゲート・比較演算子ライブラリ
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: numpy
9
+ Dynamic: license-file
10
+
11
+ # kappalogic (v0.9)
12
+
13
+ `kappa(x/ξ)`(デフォルトは`tanh`、`erf`/`algebraic`にも切り替え可能)を
14
+ 基本ブロックにして、離散的な論理演算・比較演算・場合分けを「実数上の
15
+ 滑らかな式」として書き直すためのライブラリ。
16
+
17
+ 開発の経緯・迷った点・見つけたことの詳しい記録は `dev_notes.md` を参照
18
+ (こちらは要約と現状の参照用)。
19
+
20
+ ```bash
21
+ pip install -e .
22
+ ```
23
+
24
+ ## 構成
25
+
26
+ | モジュール | 内容 |
27
+ |---|---|
28
+ | `core.py` | sgn/reg/AND/OR/XOR/比較演算子など基本ゲート、n項融合版`AND_n`/`OR_n` |
29
+ | `funcs.py` | int/par(整数・奇偶判定)、max/min/clamp |
30
+ | `kernels.py` | `tanh`/`erf`/`algebraic`カーネルの切り替え |
31
+ | `applications.py` | クロネッカーのデルタ、コラッツ漸化式、板チョコのPoisson源項 |
32
+ | `heat.py` | ξと拡散時間tの対応、熱核によるソフトな一致度報酬 |
33
+ | `search.py` | 勾配ベース探索専用の"softモード"とアニーリング解法(`anneal_solve`, `l2_penalty`) |
34
+ | `quantum_well.py` | 有限区間の熱核・無限井戸型ポテンシャルの量子プロパゲータ(鏡像法) |
35
+ | `field_theory.py` | φ^4理論のキンクソリトン(sgnが厳密解であることの証明付き) |
36
+ | `stat_mech.py` | 熱核による分配関数、SUSY QMのWitten指数(McKean-Singer型) |
37
+ | `info_theory.py` | de Bruijnの恒等式(熱拡散のエントロピー変化率とフィッシャー情報量) |
38
+ | `topology.py` | モース理論によるオイラー標数の計算 |
39
+ | `spacetime.py` | 光円錐の指示関数 |
40
+ | `bridge.py` | Σ(離散和)と∫(連続積分)の橋渡し、階乗とΓ関数 |
41
+ | `electronic_structure.py` | フェルミ・ディラック占有数=sgn(x,2kT)、DFTの電子スメアリング |
42
+ | `theory.py` | reg/AND系の勾配構造の厳密な命題群(証明付き) |
43
+ | `examples/` | 実行できるデモ4本 |
44
+
45
+ ## 使用例
46
+
47
+ ```python
48
+ from kappalogic import gt, AND, par, collatz_sequence, choc_bar_source
49
+ from kappalogic import xi_of_time, heat_step_profile, anneal_solve, soft_gt, l2_penalty
50
+ from kappalogic import kink_profile, kink_energy_exact, fermi_occupation
51
+
52
+ gt(5, 3) # 1.0
53
+ kink_energy_exact(xi=1.0) # 4/3 (ソリトンの厳密な質量)
54
+ fermi_occupation(eps=0.3, mu=0.5, kT=0.1) # フェルミ・ディラック分布と機械精度で一致
55
+ ```
56
+
57
+ ## 検証済みの主な結果
58
+
59
+ **v0.1で見つかった原案のバグ3件(修正済み、回帰テストあり)**
60
+ - `(A>B)`,`(A<B)`: `reg()`が符号を2乗で消すため、実際には`(A≠B)`と同じ値になっていた
61
+ - `par(x)`: 偶数で`-1`を返していた(`int(x)-int(x/2)`に修正)
62
+ - コラッツ漸化式: 「ステップ番号の偶奇」でなく「値自体の偶奇」で分岐するよう修正
63
+
64
+ **検証済みの技術的な発見**
65
+ - `kernel="erf"`が階段状初期条件の熱拡散の厳密解と一致(有限差分と誤差5.7e-5)
66
+ - 有限区間の熱核・無限井戸型ポテンシャルの量子プロパゲータが鏡像法+εプリスクリプションで固有関数展開と機械精度(diff~1e-13)で一致
67
+ - SUSY QMのWitten指数がβ=0.01〜10で厳密に1.000000(McKean-Singer型)
68
+ - de Bruijnの恒等式(熱拡散のエントロピー変化率=フィッシャー情報量)が誤差1e-10で一致
69
+ - モース理論によるオイラー標数がトーラス(0)・球面(2)で教科書通り
70
+ - フェルミ・ディラック分布が`sgn(x,2kT)`と機械精度で一致(DFTの電子スメアリングと同一構造)
71
+ - Σ_{n=0}^N n! と∫_0^{N+1}(floor(x))!dxが相対誤差6e-5で一致
72
+ - キンクソリトン`tanh(x/ξ)`がφ^4理論のEOMを厳密に(sympyの記号微分で)満たし、厳密エネルギー`E=4/(3ξ)`を導出
73
+ - `AND_n`融合とnaive foldの不一致は「途中の部分積がξと同スケールになったとき」に起きることを2万件のランダム試行で99.95%の精度で特定(`fusion_is_safe`)
74
+
75
+ ## 先行研究との関係(誠実な位置づけ)
76
+
77
+ 要素技術のほとんどは既存研究の再発明である:
78
+
79
+ | このライブラリの要素 | 対応する既存研究 |
80
+ |---|---|
81
+ | tanhベースの滑らかな指示関数 | 相分離理論(Allen-Cahn方程式、拡散界面法、1979年〜) |
82
+ | reg/ANDの勾配消失 | van Krieken et al. (2022, *Artificial Intelligence*)が命題として証明済み |
83
+ | 論理ゲート×連続緩和×アニーリング | Petersen et al. (2022, NeurIPS)、実装ライブラリ`difflogic`も既存 |
84
+ | ξ(t)=2√(Dt)のアニーリングスケジュール | 拡散モデルの"Variance Exploding SDE"と数学的に同一 |
85
+ | Dirac delta/Heaviside の微分可能な近似 | Smoothing methods for AD、mollifier理論、SPHカーネルとして既に成熟 |
86
+ | フェルミ・ディラック占有数=sgn(x,2kT) | DFT計算の電子スメアリング手法(実務で広く使われる既存技法) |
87
+
88
+ **見つけた本物の区別**: 標準的なt-norm(van Krieken論文の分析対象)は
89
+ 真偽度[0,1]の範囲で単調だが、`reg(x)=tanh(x/xi)^2`は任意の実数を
90
+ 受け取り「0か非0か」を判定する非単調な"検出器"であり、t-normの
91
+ 枠組みには存在しない。むしろmollifier/AD平滑化の系譜に近い。この
92
+ 2つの研究コミュニティを明示的に繋いだ文献は検索した範囲では見当たらなかった。
93
+ 新規性を主張できるとすれば、この細い糸のみ(詳細はdev_notes.md)。
94
+
95
+ ## 率直な限界(誇張しないための注記)
96
+
97
+ - hardモード(reg/AND/OR)は離散的な場合分けをif文なしで解析式に埋め込む
98
+ 用途には向くが、**それ自体を勾配降下の目的関数にしてNP完全問題を
99
+ 解くのには向かない**(勾配消失のため)。
100
+ - softモード+アニーリングは「うまくいく場合がある局所探索の補助」で
101
+ あって、P=NPを覆すようなものではない。
102
+ - 個々の要素技術はほぼ全て先行研究があり(一部はより厳密な形で)、
103
+ 「大発見」と呼べる新定理・新予想は今のところ出ていない。
104
+
105
+ ## テスト・サンプル実行
106
+
107
+ ```bash
108
+ pytest tests/ -v # 110 tests
109
+
110
+ python examples/heat_equation_demo.py
111
+ python examples/karnaugh_fusion_benchmark.py
112
+ python examples/sat_3var_demo.py
113
+ python examples/infinite_well_demo.py
114
+ ```
@@ -0,0 +1,104 @@
1
+ # kappalogic (v0.9)
2
+
3
+ `kappa(x/ξ)`(デフォルトは`tanh`、`erf`/`algebraic`にも切り替え可能)を
4
+ 基本ブロックにして、離散的な論理演算・比較演算・場合分けを「実数上の
5
+ 滑らかな式」として書き直すためのライブラリ。
6
+
7
+ 開発の経緯・迷った点・見つけたことの詳しい記録は `dev_notes.md` を参照
8
+ (こちらは要約と現状の参照用)。
9
+
10
+ ```bash
11
+ pip install -e .
12
+ ```
13
+
14
+ ## 構成
15
+
16
+ | モジュール | 内容 |
17
+ |---|---|
18
+ | `core.py` | sgn/reg/AND/OR/XOR/比較演算子など基本ゲート、n項融合版`AND_n`/`OR_n` |
19
+ | `funcs.py` | int/par(整数・奇偶判定)、max/min/clamp |
20
+ | `kernels.py` | `tanh`/`erf`/`algebraic`カーネルの切り替え |
21
+ | `applications.py` | クロネッカーのデルタ、コラッツ漸化式、板チョコのPoisson源項 |
22
+ | `heat.py` | ξと拡散時間tの対応、熱核によるソフトな一致度報酬 |
23
+ | `search.py` | 勾配ベース探索専用の"softモード"とアニーリング解法(`anneal_solve`, `l2_penalty`) |
24
+ | `quantum_well.py` | 有限区間の熱核・無限井戸型ポテンシャルの量子プロパゲータ(鏡像法) |
25
+ | `field_theory.py` | φ^4理論のキンクソリトン(sgnが厳密解であることの証明付き) |
26
+ | `stat_mech.py` | 熱核による分配関数、SUSY QMのWitten指数(McKean-Singer型) |
27
+ | `info_theory.py` | de Bruijnの恒等式(熱拡散のエントロピー変化率とフィッシャー情報量) |
28
+ | `topology.py` | モース理論によるオイラー標数の計算 |
29
+ | `spacetime.py` | 光円錐の指示関数 |
30
+ | `bridge.py` | Σ(離散和)と∫(連続積分)の橋渡し、階乗とΓ関数 |
31
+ | `electronic_structure.py` | フェルミ・ディラック占有数=sgn(x,2kT)、DFTの電子スメアリング |
32
+ | `theory.py` | reg/AND系の勾配構造の厳密な命題群(証明付き) |
33
+ | `examples/` | 実行できるデモ4本 |
34
+
35
+ ## 使用例
36
+
37
+ ```python
38
+ from kappalogic import gt, AND, par, collatz_sequence, choc_bar_source
39
+ from kappalogic import xi_of_time, heat_step_profile, anneal_solve, soft_gt, l2_penalty
40
+ from kappalogic import kink_profile, kink_energy_exact, fermi_occupation
41
+
42
+ gt(5, 3) # 1.0
43
+ kink_energy_exact(xi=1.0) # 4/3 (ソリトンの厳密な質量)
44
+ fermi_occupation(eps=0.3, mu=0.5, kT=0.1) # フェルミ・ディラック分布と機械精度で一致
45
+ ```
46
+
47
+ ## 検証済みの主な結果
48
+
49
+ **v0.1で見つかった原案のバグ3件(修正済み、回帰テストあり)**
50
+ - `(A>B)`,`(A<B)`: `reg()`が符号を2乗で消すため、実際には`(A≠B)`と同じ値になっていた
51
+ - `par(x)`: 偶数で`-1`を返していた(`int(x)-int(x/2)`に修正)
52
+ - コラッツ漸化式: 「ステップ番号の偶奇」でなく「値自体の偶奇」で分岐するよう修正
53
+
54
+ **検証済みの技術的な発見**
55
+ - `kernel="erf"`が階段状初期条件の熱拡散の厳密解と一致(有限差分と誤差5.7e-5)
56
+ - 有限区間の熱核・無限井戸型ポテンシャルの量子プロパゲータが鏡像法+εプリスクリプションで固有関数展開と機械精度(diff~1e-13)で一致
57
+ - SUSY QMのWitten指数がβ=0.01〜10で厳密に1.000000(McKean-Singer型)
58
+ - de Bruijnの恒等式(熱拡散のエントロピー変化率=フィッシャー情報量)が誤差1e-10で一致
59
+ - モース理論によるオイラー標数がトーラス(0)・球面(2)で教科書通り
60
+ - フェルミ・ディラック分布が`sgn(x,2kT)`と機械精度で一致(DFTの電子スメアリングと同一構造)
61
+ - Σ_{n=0}^N n! と∫_0^{N+1}(floor(x))!dxが相対誤差6e-5で一致
62
+ - キンクソリトン`tanh(x/ξ)`がφ^4理論のEOMを厳密に(sympyの記号微分で)満たし、厳密エネルギー`E=4/(3ξ)`を導出
63
+ - `AND_n`融合とnaive foldの不一致は「途中の部分積がξと同スケールになったとき」に起きることを2万件のランダム試行で99.95%の精度で特定(`fusion_is_safe`)
64
+
65
+ ## 先行研究との関係(誠実な位置づけ)
66
+
67
+ 要素技術のほとんどは既存研究の再発明である:
68
+
69
+ | このライブラリの要素 | 対応する既存研究 |
70
+ |---|---|
71
+ | tanhベースの滑らかな指示関数 | 相分離理論(Allen-Cahn方程式、拡散界面法、1979年〜) |
72
+ | reg/ANDの勾配消失 | van Krieken et al. (2022, *Artificial Intelligence*)が命題として証明済み |
73
+ | 論理ゲート×連続緩和×アニーリング | Petersen et al. (2022, NeurIPS)、実装ライブラリ`difflogic`も既存 |
74
+ | ξ(t)=2√(Dt)のアニーリングスケジュール | 拡散モデルの"Variance Exploding SDE"と数学的に同一 |
75
+ | Dirac delta/Heaviside の微分可能な近似 | Smoothing methods for AD、mollifier理論、SPHカーネルとして既に成熟 |
76
+ | フェルミ・ディラック占有数=sgn(x,2kT) | DFT計算の電子スメアリング手法(実務で広く使われる既存技法) |
77
+
78
+ **見つけた本物の区別**: 標準的なt-norm(van Krieken論文の分析対象)は
79
+ 真偽度[0,1]の範囲で単調だが、`reg(x)=tanh(x/xi)^2`は任意の実数を
80
+ 受け取り「0か非0か」を判定する非単調な"検出器"であり、t-normの
81
+ 枠組みには存在しない。むしろmollifier/AD平滑化の系譜に近い。この
82
+ 2つの研究コミュニティを明示的に繋いだ文献は検索した範囲では見当たらなかった。
83
+ 新規性を主張できるとすれば、この細い糸のみ(詳細はdev_notes.md)。
84
+
85
+ ## 率直な限界(誇張しないための注記)
86
+
87
+ - hardモード(reg/AND/OR)は離散的な場合分けをif文なしで解析式に埋め込む
88
+ 用途には向くが、**それ自体を勾配降下の目的関数にしてNP完全問題を
89
+ 解くのには向かない**(勾配消失のため)。
90
+ - softモード+アニーリングは「うまくいく場合がある局所探索の補助」で
91
+ あって、P=NPを覆すようなものではない。
92
+ - 個々の要素技術はほぼ全て先行研究があり(一部はより厳密な形で)、
93
+ 「大発見」と呼べる新定理・新予想は今のところ出ていない。
94
+
95
+ ## テスト・サンプル実行
96
+
97
+ ```bash
98
+ pytest tests/ -v # 110 tests
99
+
100
+ python examples/heat_equation_demo.py
101
+ python examples/karnaugh_fusion_benchmark.py
102
+ python examples/sat_3var_demo.py
103
+ python examples/infinite_well_demo.py
104
+ ```
@@ -0,0 +1,59 @@
1
+ from .core import (
2
+ sgn, reg, NOT, AND, OR, NAND, NOR, XOR, XNOR, AND_n, OR_n,
3
+ eq, neq, gt, lt, ge, le, DEFAULT_XI, DEFAULT_KERNEL,
4
+ )
5
+ from .funcs import intf, par, maxf, minf, clamp
6
+ from .applications import (
7
+ kronecker_delta, levi_civita, dirac_delta_integral,
8
+ line_intersection_y, collatz_step, collatz_sequence,
9
+ choc_bar_source,
10
+ )
11
+ from .kernels import KERNELS, apply_kernel
12
+ from .heat import xi_of_time, time_of_xi, heat_step_profile, heat_kernel_gaussian, gaussian_match
13
+ from .quantum_well import (
14
+ box_heat_kernel, box_heat_kernel_eigen,
15
+ infinite_well_propagator, infinite_well_propagator_eigen,
16
+ )
17
+ from .search import soft_gt, soft_eq, soft_or, soft_and, anneal_solve, numeric_grad, l2_penalty
18
+ from .field_theory import kink_profile, kink_eom_residual, kink_energy_exact, topological_charge
19
+ from .stat_mech import box_partition_function, box_partition_function_exact, witten_index_toy
20
+ from .info_theory import (
21
+ gaussian_variance, differential_entropy_gaussian,
22
+ fisher_information_gaussian, de_bruijn_check,
23
+ )
24
+ from .topology import morse_index, euler_characteristic
25
+ from .spacetime import inside_lightcone, future_lightcone
26
+ from .bridge import floor_smooth, sum_via_integral, gamma_via_riemann_sum
27
+ from .electronic_structure import (
28
+ fermi_occupation, tight_binding_chain_energies,
29
+ find_chemical_potential, total_energy_smeared,
30
+ tight_binding_dos_continuum, continuum_filling, continuum_energy, continuum_find_mu,
31
+ )
32
+ from .theory import max_gradient_location, max_gradient_value, is_single_passing_at_zero, fusion_is_safe
33
+
34
+ __all__ = [
35
+ "sgn", "reg", "NOT", "AND", "OR", "NAND", "NOR", "XOR", "XNOR", "AND_n", "OR_n",
36
+ "eq", "neq", "gt", "lt", "ge", "le", "DEFAULT_XI", "DEFAULT_KERNEL",
37
+ "intf", "par", "maxf", "minf", "clamp",
38
+ "kronecker_delta", "levi_civita", "dirac_delta_integral",
39
+ "line_intersection_y", "collatz_step", "collatz_sequence",
40
+ "choc_bar_source",
41
+ "KERNELS", "apply_kernel",
42
+ "xi_of_time", "time_of_xi", "heat_step_profile", "heat_kernel_gaussian", "gaussian_match",
43
+ "box_heat_kernel", "box_heat_kernel_eigen",
44
+ "infinite_well_propagator", "infinite_well_propagator_eigen",
45
+ "soft_gt", "soft_eq", "soft_or", "soft_and", "anneal_solve", "numeric_grad", "l2_penalty",
46
+ "kink_profile", "kink_eom_residual", "kink_energy_exact", "topological_charge",
47
+ "box_partition_function", "box_partition_function_exact", "witten_index_toy",
48
+ "gaussian_variance", "differential_entropy_gaussian",
49
+ "fisher_information_gaussian", "de_bruijn_check",
50
+ "morse_index", "euler_characteristic",
51
+ "inside_lightcone", "future_lightcone",
52
+ "floor_smooth", "sum_via_integral", "gamma_via_riemann_sum",
53
+ "fermi_occupation", "tight_binding_chain_energies",
54
+ "find_chemical_potential", "total_energy_smeared",
55
+ "tight_binding_dos_continuum", "continuum_filling", "continuum_energy", "continuum_find_mu",
56
+ "max_gradient_location", "max_gradient_value", "is_single_passing_at_zero", "fusion_is_safe",
57
+ ]
58
+
59
+ __version__ = "0.9.0"
@@ -0,0 +1,88 @@
1
+ """
2
+ kappalogic.applications
3
+ =========================
4
+ 応用19〜20の実例。
5
+
6
+ 注意 (実装時に見つかった原設計の誤り):
7
+ 応用20のコラッツ漸化式
8
+ f(x+1) = (f(x)/2)*int(x/2) + (3f(x)+1)*int((x+1)/2)
9
+ は "ステップ番号 x" の偶奇で分岐しているが、コラッツ写像は
10
+ 本来 "現在の値 f(x)" の偶奇で分岐すべきものなので、この式は
11
+ 数値検証の結果、2ステップ目から真の数列と一致しないことを確認した
12
+ (例: n0=27 -> 真の値82 に対しこの式は13.5を返す)。
13
+ 本実装では par(f(x)) (修正済みの奇偶判定) を使って
14
+ f(x+1) = (f(x)/2)*(1-par(f(x))) + (3f(x)+1)*par(f(x))
15
+ と書き換え、n0=27 (111ステップ、最大値9232) を含む多数の初期値で
16
+ 真のコラッツ数列と完全一致することを確認済み。
17
+ """
18
+ import numpy as np
19
+ from .core import eq, gt, lt, AND
20
+ from .funcs import par
21
+
22
+
23
+ def kronecker_delta(i, j, xi=1e-3):
24
+ """delta_ij = (i=j)"""
25
+ return eq(i, j, xi)
26
+
27
+
28
+ def levi_civita(i, j, k, xi=1e-3):
29
+ """epsilon_ijk = sgn((i-j)(j-k)(k-i)) ※重複指標では0になる"""
30
+ from .core import sgn
31
+ return sgn((i - j) * (j - k) * (k - i), xi)
32
+
33
+
34
+ def dirac_delta_integral(f, a, xs, weights):
35
+ """
36
+ ∫ f(x) delta(x-a) dx = f(x)(x=a) の離散近似。
37
+ xs, weights: 数値積分用の分点と重み (例: 台形則の点と幅)
38
+ """
39
+ xs = np.asarray(xs, dtype=float)
40
+ fx = np.asarray([f(x) for x in xs])
41
+ return np.sum(fx * eq(xs, a) * weights)
42
+
43
+
44
+ def line_intersection_y(a, b, c, d, x):
45
+ """
46
+ 2直線 y=ax+b, y=cx+d の交点のy座標を
47
+ ((ax+b)=(cx+d)) という等式インジケータで表現した式の値。
48
+ (本来は交点のxを解いて代入するのが素直だが、
49
+ "式の中に方程式の解を埋め込む" という応用19の考え方の例として、
50
+ xを動かしたときに交点近傍だけ1になることを確認するデモ)
51
+ """
52
+ return eq(a * x + b, c * x + d)
53
+
54
+
55
+ def collatz_step(fx, xi=1e-3):
56
+ """
57
+ 修正済みコラッツ漸化式: f(x)の偶奇で分岐(元式のバグを修正)。
58
+ f(x+1) = (f(x)/2)(1-par(f(x))) + (3f(x)+1)(par(f(x)))
59
+ """
60
+ p = par(fx)
61
+ return (fx / 2) * (1 - p) + (3 * fx + 1) * p
62
+
63
+
64
+ def collatz_sequence(n0, max_steps=1000):
65
+ """collatz_step を繰り返し適用して数列を生成 (n=1で停止)"""
66
+ seq = [float(n0)]
67
+ fx = float(n0)
68
+ for _ in range(max_steps):
69
+ if abs(fx - 1) < 1e-6:
70
+ break
71
+ fx = float(collatz_step(fx))
72
+ seq.append(fx)
73
+ return seq
74
+
75
+
76
+ def choc_bar_source(x, y, z, a, b, c, rho, xi=1e-3):
77
+ """
78
+ 密度rho, 幅a x 奥行b x 高さc の直方体(板チョコ)が作る
79
+ ポアソン方程式の右辺: 4*pi*rho * (箱の内部なら1、外なら0)
80
+ """
81
+ inside = AND(
82
+ AND(lt(x, a / 2, xi), lt(y, b / 2, xi), xi),
83
+ AND(lt(z, c / 2, xi),
84
+ AND(gt(x, -a / 2, xi), AND(gt(y, -b / 2, xi), gt(z, -c / 2, xi), xi), xi),
85
+ xi),
86
+ xi,
87
+ )
88
+ return 4 * np.pi * rho * inside
@@ -0,0 +1,42 @@
1
+ """
2
+ kappalogic.bridge
3
+ ====================
4
+ Σ(離散和)と∫(連続積分)の橋渡し。
5
+
6
+ floor(x) = sum_{k=1}^{K} Theta(x-k) (x>0, K>=floor(x)で十分) という
7
+ 初等的な恒等式を、このライブラリのgt(符号保存版の大小比較)の総和として
8
+ 実装する。これにより
9
+ sum_{n=0}^{N} f(n) = integral_0^{N+1} f(floor(x)) dx
10
+ という初等解析の恒等式を、gtゲートの総和で明示的に構成できる。
11
+
12
+ n!とGamma関数(Γ(n+1)=∫_0^∞ t^n e^{-t} dt = n!、オイラー積分)の
13
+ 数値実験で、Σ(離散和)→∫(オイラー積分)→n!(階乗)の一致を検証済み
14
+ (相対誤差~1e-11、中点則で十分な精度)。
15
+ """
16
+ import numpy as np
17
+ import math
18
+ from .core import gt, DEFAULT_XI
19
+
20
+
21
+ def floor_smooth(x, K=50, xi=DEFAULT_XI):
22
+ """floor(x) = sum_{k=1}^{K} gt(x,k) の近似(x>0, K>=想定される最大値+1)。"""
23
+ return sum(gt(x, k, xi) for k in range(1, K + 1))
24
+
25
+
26
+ def sum_via_integral(f, N, xi=DEFAULT_XI, n_points=200000):
27
+ """
28
+ sum_{n=0}^{N} f(n) を integral_0^{N+1} f(floor_smooth(x)) dx として
29
+ 数値積分で計算する(Σ->∫の橋渡しの実演)。fは整数引数を取る関数。
30
+ """
31
+ xs = np.linspace(0, N + 1, n_points)
32
+ fx = np.array([f(int(round(floor_smooth(x, K=N + 2, xi=xi)))) for x in xs])
33
+ return np.trapezoid(fx, xs)
34
+
35
+
36
+ def gamma_via_riemann_sum(n, dt=0.01, t_max=200):
37
+ """
38
+ Gamma(n+1) = integral_0^inf t^n e^{-t} dt を中点則のリーマン和で近似する。
39
+ dt->0でn!(math.factorial(n))に収束することを確認済み(相対誤差~1e-11@dt=0.1)。
40
+ """
41
+ ts = np.arange(dt / 2, t_max, dt)
42
+ return np.sum(ts ** n * np.exp(-ts)) * dt