Skip to content

Commit 4a415e9

Browse files
docs: 添加中文文档并更新英文README
添加详细的中文文档README_zh.md,介绍库的核心功能和使用方法 更新英文README,简化内容并链接到中文文档
1 parent e7ddc5c commit 4a415e9

File tree

2 files changed

+215
-84
lines changed

2 files changed

+215
-84
lines changed

README.md

Lines changed: 33 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,60 @@
11
# SPG (Spin Point Groups) Library
22

3-
SPG is a Lean 4 library for analyzing Spin Point Groups, Magnetic Point Groups (MPGs), and symmetry breaking phenomena in condensed matter physics. It provides tools to define magnetic symmetries, generate group closures, and verify physical properties such as allowed electric polarization.
3+
> [中文文档 (Chinese Documentation)](README_zh.md)
44
5-
## Installation
5+
SPG is a Lean 4 library designed for exact algebraic analysis of magnetic point groups and their representations in condensed matter physics.
66

7-
Add the following dependency to your `lakefile.lean`:
7+
Unlike numerical tools (Python/MATLAB), SPG operates entirely over the field of rational numbers (``), ensuring that all symmetry checks, invariant generations, and "forbidden term" classifications are mathematically exact and decidable.
88

9-
```lean
10-
require SPG from git
11-
"https://github.com/tsurumi-yizhou/SPG.git"
12-
```
9+
## Key Features
1310

14-
Then update dependencies:
11+
* **Exact Algebra**: No floating-point errors. Matrices and coefficients are ``.
12+
* **Invariant Analysis**: Automated solving of linear equations to find allowed k·p Hamiltonian terms (e.g., checking for altermagnetism).
13+
* **Symmetry Breaking**: Calculate Magnetic Point Groups (MPG) from a given magnetic order parameter.
14+
* **Physical Properties**: Verify macroscopic properties like allowed electric polarization or net magnetization.
1515

16-
```bash
17-
lake update
18-
```
16+
## Quick Start
1917

20-
## Usage Guide
18+
### Installation
2119

22-
This section demonstrates how to use the library to analyze magnetic symmetries.
20+
Add to your `lakefile.lean`:
2321

24-
### 1. Import Modules
22+
```lean
23+
require SPG from git
24+
"https://github.com/tsurumi-yizhou/SPG.git"
25+
```
2526

26-
Import the main library to access all core functionalities:
27+
### Example: Checking Altermagnetism
2728

2829
```lean
2930
import SPG
3031
3132
open SPG
3233
open SPG.Interface
3334
open SPG.Algebra
34-
open SPG.Physics
35+
open SPG.Physics.Hamiltonian
3536
open SPG.Geometry.SpatialOps
36-
```
3737
38-
### 2. Define Group Generators
38+
-- Define a group generator: C4z * TimeReversal
39+
def g_C4z_T : SPGElement := Op[mat_4_z, ^-1]
40+
def g_C2x : SPGElement := Op[mat_2_x, ^1]
41+
def g_Inv : SPGElement := Op[mat_inv, ^1]
3942
40-
Use the `Op[spatial, spin]` syntax to define group elements.
41-
* `^1`: Identity spin operation (non-magnetic).
42-
* `^-1`: Time-reversal operation (spin flip).
43+
-- Generate the full group
44+
def my_group : List SPGElement := generate_group [g_C4z_T, g_C2x, g_Inv]
4345
44-
```lean
45-
-- Example: 4-fold rotoinversion along z (non-magnetic)
46-
def g1 : SPGElement := Op[mat_4bar_z, ^1]
47-
48-
-- Example: 2-fold rotation along x combined with time-reversal
49-
def g2 : SPGElement := Op[mat_2_x, ^-1]
46+
-- Check if d-wave spin splitting (kx^2 - ky^2)σz is allowed
47+
-- This is the hallmark of d-wave altermagnetism
48+
def p_dwave : Poly := (kx * kx) - (ky * ky)
49+
#eval isInvariantHam my_group (singleTerm p_dwave .z)
5050
```
5151

52-
### 3. Generate Group Closure
53-
54-
Use `generate_group` to compute the full group from a set of generators.
55-
56-
```lean
57-
def my_group : List SPGElement := generate_group [g1, g2]
58-
59-
-- Check group order
60-
#eval my_group.length
61-
```
62-
63-
### 4. Symmetry Breaking Analysis
64-
65-
Given a magnetic ordering vector (Neel vector), compute the Magnetic Point Group (MPG). The MPG consists of all elements in the original group that leave the magnetic vector invariant.
66-
67-
```lean
68-
def neel_vector : Vec3 := ![1, 1, 0]
69-
70-
-- Compute the Magnetic Point Group
71-
def my_mpg : List SPGElement := get_mpg my_group neel_vector
72-
73-
-- Check the size of the MPG
74-
#eval my_mpg.length
75-
```
76-
77-
### 5. Physical Property Verification
78-
79-
Verify if the resulting symmetry group allows specific physical properties, such as spontaneous polarization along the z-axis.
80-
81-
```lean
82-
-- Returns true if z-polarization is allowed, false otherwise
83-
#eval allows_z_polarization my_mpg
84-
```
85-
86-
### 6. Formal Proof
87-
88-
Physical conclusions can be formally verified using `native_decide`.
89-
90-
```lean
91-
theorem polarization_allowed :
92-
(allows_z_polarization my_mpg) = true := by
93-
native_decide
94-
```
95-
96-
## Core Modules
97-
98-
* **SPG.Interface.Notation**: Syntax definitions for `Op[...]`, `^1`, etc.
99-
* **SPG.Algebra.Group**: Algorithms for finite group generation.
100-
* **SPG.Physics.SymmetryBreaking**: Functions for MPG extraction and property verification.
101-
* **SPG.Geometry.SpatialOps**: Predefined spatial operation matrices (e.g., `mat_4bar_z`).
102-
* **SPG.Demo.Altermagnet**: Example implementation for d-wave altermagnet.
103-
104-
## Notes
52+
## Documentation
10553

106-
* **Precision**: All matrix and vector operations use `Rational` numbers (``) to ensure exact results and decidability.
107-
* **Scope**: The `generate_group` function is optimized for finite Point Groups.
54+
For a detailed guide on the physical model, implementation details, and advanced usage, please refer to the **[Chinese Documentation](README_zh.md)** (currently the most comprehensive guide).
10855

109-
## Acknowledgments
56+
## Source Code Map
11057

111-
Special thanks to **Gemini 3** for the contributions to the code structure and implementation details.
58+
* **[SPG/Algebra/Basic.lean](SPG/Algebra/Basic.lean)**: `SPGElement` definition.
59+
* **[SPG/Algebra/Actions.lean](SPG/Algebra/Actions.lean)**: Physical actions on polar/axial vectors.
60+
* **[SPG/Physics/Hamiltonian/Invariants.lean](SPG/Physics/Hamiltonian/Invariants.lean)**: Algorithms for finding invariant Hamiltonians.

README_zh.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# SPG (Spin Point Groups) 库
2+
3+
> [English Version](README.md)
4+
5+
这是一个基于 Lean 4 的物理计算库。它的核心目标非常明确:**用绝对精确的代数方法,解决凝聚态物理中的磁群对称性分析问题。**
6+
7+
不同于常见的数值计算代码(Python/MATLAB),这里没有浮点数,没有 `1.0000001` 这种误差。所有的矩阵、向量、系数都建立在有理数域(``)上。这意味着当你问程序“这个项是不是严格禁止的?”时,它给出的 `true` 是数学上可证明的真。
8+
9+
## 这个库解决什么问题?
10+
11+
在研究磁性材料(如反铁磁、Altermagnet)时,我们经常需要回答以下问题:
12+
13+
1. **对称性枚举**:给定了晶格结构和磁序(比如磁矩指向),这个体系到底还剩什么对称性?(求磁点群 MPG)
14+
2. **不变量分析**:在这个对称性下,哈密顿量里允许出现哪些项?(例如:是否允许 $k_x \sigma_y$ 这种自旋分裂项?是否允许 $d$-wave 形式的能带分裂?)
15+
3. **宏观物性**:这个磁结构是否允许产生净磁矩(铁磁)?是否允许产生电极化(铁电)?
16+
17+
SPG 库提供了一套自动化的工作流来回答这些问题。
18+
19+
---
20+
21+
## 核心设计:它是如何工作的?
22+
23+
要使用这个库,你只需要理解它是如何对物理世界建模的。
24+
25+
### 1. 什么是“磁群操作”?
26+
27+
在代码中,一个群元素 (`SPGElement`) 被定义为一对矩阵:
28+
29+
$$g = (R, S)$$
30+
31+
* **`spatial` (R)**: 描述原子位置如何移动的 $3 \times 3$ 矩阵(旋转、镜面、反演)。
32+
* **`spin` (S)**: 描述时间反演操作。
33+
* 在本库目前的设计中,我们只关心“是否包含时间反演”。
34+
* 因此 $S$ 只有两种取值:`I` (单位阵,无时间反演) 或 `-I` (含时间反演)。
35+
36+
这种设计对应了磁群理论中的 Corepresentation 思想。群乘法就是简单的矩阵分量相乘。
37+
38+
### 2. 物理量怎么变换?(严查事实)
39+
40+
当你对一个物理系统施加对称操作 $g$ 时,不同的物理量有不同的变法。这个库严格区分了以下几类对象,并在源码中硬编码了它们的变换规则:
41+
42+
* **极矢量 (Polar Vector)**,如位置 $r$、电场 $E$、动量 $k$:
43+
* 变换规则:$v' = R v$。
44+
* *注意*:对于动量 $k$,如果操作包含时间反演($T$),动量会反向。所以在处理 $k \cdot p$ 哈密顿量时,库会自动处理 $k \to -k$ 的变号。
45+
* **轴矢量 (Axial Vector)**,如磁矩 $M$、自旋 $\sigma$:
46+
* 变换规则:$v' = (\det R) \cdot (R v)$。
47+
* 因子 $\det R$ 保证了它们在空间反演($R=-I$)下是不变的。
48+
* *时间反演*:磁矩和自旋在时间反演下都会变号。代码中通过判断 $S$ 是否为 `-I` 来自动施加这个负号。
49+
50+
### 3. 如何寻找不变量?
51+
52+
这是本库最强大的功能。寻找“允许的哈密顿量项”本质上是在解一个巨大的线性方程组。
53+
54+
比如,你想知道是否允许 $c \cdot k_x \sigma_y$ 这样的项。库会这样做:
55+
1. 构建一个包含所有可能的 $k$ 二次项和 $\sigma$ 分量的基底空间。
56+
2. 对群里的每一个元素 $g$,计算它把基底变成了什么(比如 $k_x \to -k_y, \sigma_y \to \sigma_x$)。
57+
3. 建立方程:$g \cdot H \cdot g^{-1} = H$。
58+
4. 在有理数域上解这个线性方程组(求 Nullspace),得到所有线性独立的解。
59+
60+
---
61+
62+
## 上手指南:从零分析一个磁性体系
63+
64+
假设你正在研究一种四方晶系的反铁磁体,你想知道它是不是最近很火的 **Altermagnet**(交替磁体)。
65+
66+
### 第一步:引入库
67+
68+
```lean
69+
import SPG
70+
71+
-- 引入所有必要的命名空间
72+
open SPG
73+
open SPG.Interface -- 也就是 Op[...] 这种记号
74+
open SPG.Algebra -- 群运算
75+
open SPG.Physics.Hamiltonian -- k·p 理论相关
76+
open SPG.Geometry.SpatialOps -- 预定义的矩阵(如 mat_4_z)
77+
```
78+
79+
### 第二步:定义你的对称性
80+
81+
你需要告诉程序这个晶体有哪些对称操作。对于 D4h 这种群,通常只需要写出生成元。
82+
83+
```lean
84+
-- 定义一个包含时间反演的操作:C4z * T
85+
-- Op[ 空间矩阵, 自旋部分 ]
86+
-- ^-1 代表包含时间反演,^1 代表不包含
87+
def g_C4z_T : SPGElement := Op[mat_4_z, ^-1]
88+
89+
-- 定义普通的 C2x 旋转(不含时间反演)
90+
def g_C2x : SPGElement := Op[mat_2_x, ^1]
91+
92+
-- 定义空间反演(不含时间反演)
93+
def g_Inv : SPGElement := Op[mat_inv, ^1]
94+
```
95+
96+
### 第三步:生成群
97+
98+
程序会自动算出这几个生成元能生出的所有群元素(群闭包)。
99+
100+
```lean
101+
def my_group : List SPGElement := generate_group [g_C4z_T, g_C2x, g_Inv]
102+
#eval my_group.length -- 看看群里有多少个元素
103+
```
104+
105+
### 第四步:问物理问题
106+
107+
现在有了群,我们可以问它任何问题。
108+
109+
**问题 1:这个对称性允许 $d$-wave 的自旋分裂吗?**
110+
111+
Altermagnet 的标志性特征是允许像 $(k_x^2 - k_y^2)\sigma_z$ 这样的项。我们可以直接构建这个项并测试它是不是不变量。
112+
113+
```lean
114+
-- 定义多项式 (kx^2 - ky^2)
115+
def p_dwave : Poly := (kx * kx) - (ky * ky)
116+
117+
-- 构造哈密顿量项:多项式 * σz
118+
-- singleTerm 接受一个多项式和一个自旋分量 (.I, .x, .y, .z)
119+
def term_dwave : KPHam := singleTerm p_dwave .z
120+
121+
-- 判定!
122+
#eval isInvariantHam my_group term_dwave
123+
-- 如果输出 true,恭喜你,这是一个 Altermagnet。
124+
```
125+
126+
**问题 2:把所有允许的项都列给我看看?**
127+
128+
你可以让程序自动求解所有 2 阶以下的允许项:
129+
130+
```lean
131+
-- 求解 2 阶以内的所有矢量不变量 (Vector Invariants)
132+
-- 返回结果是按阶数分类的列表
133+
def allowed_terms := invariants_vector_by_degree_solve my_group 2
134+
135+
-- 打印出来看
136+
#eval allowed_terms
137+
```
138+
139+
### 第五步:验证宏观物性(对称性破缺)
140+
141+
假设你给这个系统加了一个沿着 $(1,1,0)$ 方向的磁场(或者磁矩指向这里),对称性会降低成什么样?
142+
143+
```lean
144+
def neel_vector : Vec3 := ![1, 1, 0]
145+
146+
-- 计算磁点群 (MPG):即原群中能保持这个磁矩不变的子群
147+
def mpg_110 : List SPGElement := get_mpg my_group neel_vector
148+
149+
-- 在这个新群下,允许产生 z 方向的铁电极化吗?
150+
-- 判据:所有元素必须保持 z 方向的极矢量不变
151+
#eval allows_z_polarization mpg_110
152+
```
153+
154+
---
155+
156+
## 源码导读
157+
158+
如果你想深入了解实现细节,可以按以下路径阅读源码(括号内是关键概念):
159+
160+
1. **[SPG/Algebra/Basic.lean](file:///home/yizhou/SPG/SPG/Algebra/Basic.lean)**
161+
* 定义了 `SPGElement` 结构体。
162+
* 你会看到矩阵是用 `Mathlib``Matrix` 定义的,元素类型锁死为 ``
163+
164+
2. **[SPG/Algebra/Actions.lean](file:///home/yizhou/SPG/SPG/Algebra/Actions.lean)**
165+
* **核心物理逻辑都在这**
166+
* `magnetic_action`: 仔细看那个 `detR`,那就是轴矢量的灵魂。
167+
* `electric_action`: 极矢量的标准变换。
168+
169+
3. **[SPG/Physics/Hamiltonian/Ham.lean](file:///home/yizhou/SPG/SPG/Physics/Hamiltonian/Ham.lean)**
170+
* 定义了 `KPHam`(k·p 哈密顿量)。
171+
* 它是如何存储的?其实就是 4 个多项式:一个标量部分(乘单位阵 $I$),三个向量部分(乘 $\sigma_x, \sigma_y, \sigma_z$)。
172+
173+
4. **[SPG/Physics/Hamiltonian/Invariants.lean](file:///home/yizhou/SPG/SPG/Physics/Hamiltonian/Invariants.lean)**
174+
* 这是最硬核的部分。
175+
* `invariants_vector_by_degree_solve`: 这里实现了把群论问题转化为线性代数问题(求 Nullspace)的算法。
176+
177+
## 局限性
178+
179+
为了保持精确性和可判定性,本库目前做了一些取舍:
180+
181+
* **只支持点群**:目前不处理平移操作(Space Groups)。
182+
* **不处理一般自旋旋转**:目前的自旋操作被锁定为“共线磁性”模型(即自旋只有翻转/不翻转,或者简单的轴向变换)。对于需要处理 Spin-Orbit Coupling 极强且涉及复杂自旋旋转的体系,可能需要扩展 `spin` 矩阵的定义。

0 commit comments

Comments
 (0)