A Semantically-Guided Symbolic Integration Engine

1. Background and Challenge

Mathematical integration is fundamental to science, engineering, and economics. Yet solving integrals has long faced a fundamental dilemma:

  • Symbolic computing systems (such as SymPy or Mathematica) are precise, but their solution paths are “black boxes”—users cannot intervene, and complex integrals may hang indefinitely or produce incomprehensible intermediate steps.
  • AI language models (such as ChatGPT) possess mathematical intuition but lack the rigor of symbolic computation. Their outputs may be incorrect and cannot be formally verified.

The core challenge is: how can we make a machine think intuitively like a mathematician while computing with the precision of a computer?


2. Our Solution: A Semantically-Guided Symbolic Integration Engine

We have built a hybrid intelligence system that deeply integrates “mathematical intuition” with “symbolic computation.” Its workflow is analogous to an experienced mathematician:

  1. Observe: Take a quick look at the integral expression (e.g., ∫ x·cos(x) dx) and, based on experience, identify its structural type (“Ah, this is a product of two functions—integration by parts would work”).
  2. Attempt: Based on that judgment, select the most appropriate method and apply the first transformation.
  3. Iterate: After each step, re-examine the new expression, continue selecting strategies, and repeat until the final antiderivative is obtained.

Core Innovation: Replacing “Brute-Force Search” with “Semantic Gravity”

Traditional systems attempt all possible methods (power rule, integration by parts, substitution, etc.) in a fixed order—an inefficient process. Our engine introduces a semantic perception module that can:

  • Abstract each integration rule (e.g., “integration by parts”) as a semantic label.
  • Map the current expression into the same semantic space.
  • Compute the “distance” between labels and expressions to determine which rule best matches the current problem.

Result: The most promising method is always attempted first, significantly reducing wasted effort.


3. The Engine’s Solution Process

Take ∫ log(1+x) dx as an example. The engine solves it step by step, much like a human mathematician:

Step 1:
  Observe: This is a single logarithmic function.
  Semantic Judgment: It doesn't look like a power function or a basic integral—"integration by parts" seems appropriate.
  Execute: Let u = log(1+x), dv = dx, yielding:
        x·log(1+x) - ∫ x/(1+x) dx

Step 2:
  Observe: The new expression contains the integral ∫ x/(1+x) dx.
  Semantic Judgment: This is a rational function that can be simplified to 1 - 1/(1+x).
  Execute: Integrate to get x - log(1+x).

  Combine: The final result is (1+x)·log(1+x) - x.

The entire process is fully transparent—every step records the method used and the transformed expression, allowing users to trace the derivation just like reading a mathematics textbook.


torch_env) x@x-X99:~/pro/BioSight/experiments$ python neuro_symbolic_integrator.py
🚀 使用设备: cuda
⏳ 加载语义模型 (离线): tbs17/MathBERT
Loading weights: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 199/199 [00:00<00:00, 19889.11it/s]
[transformers] BertModel LOAD REPORT from: tbs17/MathBERT
Key                                        | Status     |  | 
-------------------------------------------+------------+--+-
cls.predictions.decoder.weight             | UNEXPECTED |  | 
cls.predictions.bias                       | UNEXPECTED |  | 
cls.predictions.decoder.bias               | UNEXPECTED |  | 
cls.predictions.transform.LayerNorm.bias   | UNEXPECTED |  | 
cls.predictions.transform.dense.weight     | UNEXPECTED |  | 
cls.predictions.transform.LayerNorm.weight | UNEXPECTED |  | 
cls.seq_relationship.bias                  | UNEXPECTED |  | 
cls.predictions.transform.dense.bias       | UNEXPECTED |  | 
cls.seq_relationship.weight                | UNEXPECTED |  | 

Notes:
- UNEXPECTED:	can be ignored when loading from different task/architecture; not ok if you expect identical arch.
✅ 模型加载完成,维度: 768,耗时 1.26s
⚡ 预计算规则引力源嵌入...
✅ 规则嵌入完成,形状 torch.Size([9, 768]),耗时 0.26s

============================================================
🚀 求解: ∫ x**2 dx
============================================================1: 语义引力排序:
   - 交换积分与求和: 0.6446
   - 幂法则: 0.6418
   - 分部积分: 0.6393
   - 基本积分表: 0.6108
   - 反三角积分: 0.5856
   - 三角恒等式: 0.5615
   - 三角替换: 0.5240
   - 级数展开: 0.4370
   - 部分分式分解: 0.3804
   尝试规则: 交换积分与求和 (引力: 0.645)
      规则不匹配
   尝试规则: 幂法则 (引力: 0.642)
      → 变换后: x**3/3

✅ 收敛于: x**3/3

最终状态: success
结果: x**3/3

📝 推导链:
   0. [Initial] → Integral(x**2, x)
   1. [幂法则] → x**3/3
------------------------------------------------------------

============================================================
🚀 求解: ∫ 1/x dx
============================================================1: 语义引力排序:
   - 反三角积分: 0.7578
   - 幂法则: 0.7021
   - 交换积分与求和: 0.6329
   - 三角替换: 0.6262
   - 级数展开: 0.5849
   - 基本积分表: 0.5465
   - 分部积分: 0.5286
   - 三角恒等式: 0.4944
   - 部分分式分解: 0.4687
   尝试规则: 反三角积分 (引力: 0.758)
      规则不匹配
   尝试规则: 幂法则 (引力: 0.702)
      → 变换后: log(x)

✅ 收敛于: log(x)

最终状态: success
结果: log(x)

📝 推导链:
   0. [Initial] → Integral(1/x, x)
   1. [幂法则] → log(x)
------------------------------------------------------------

============================================================
🚀 求解: ∫ sin(x) dx
============================================================1: 语义引力排序:
   - 交换积分与求和: 0.6474
   - 基本积分表: 0.6410
   - 三角恒等式: 0.6178
   - 反三角积分: 0.6131
   - 分部积分: 0.5836
   - 幂法则: 0.5792
   - 三角替换: 0.5272
   - 级数展开: 0.4814
   - 部分分式分解: 0.4120
   尝试规则: 交换积分与求和 (引力: 0.647)
      规则不匹配
   尝试规则: 基本积分表 (引力: 0.641)
      → 变换后: -cos(x)

✅ 收敛于: -cos(x)

最终状态: success
结果: -cos(x)

📝 推导链:
   0. [Initial] → Integral(sin(x), x)
   1. [基本积分表] → -cos(x)
------------------------------------------------------------

============================================================
🚀 求解: ∫ cos(x) dx
============================================================1: 语义引力排序:
   - 基本积分表: 0.6314
   - 交换积分与求和: 0.6213
   - 反三角积分: 0.6069
   - 三角恒等式: 0.5808
   - 分部积分: 0.5749
   - 幂法则: 0.5645
   - 三角替换: 0.5209
   - 级数展开: 0.4835
   - 部分分式分解: 0.4250
   尝试规则: 基本积分表 (引力: 0.631)
      → 变换后: sin(x)

✅ 收敛于: sin(x)

最终状态: success
结果: sin(x)

📝 推导链:
   0. [Initial] → Integral(cos(x), x)
   1. [基本积分表] → sin(x)
------------------------------------------------------------

============================================================
🚀 求解: ∫ exp(x) dx
============================================================1: 语义引力排序:
   - 交换积分与求和: 0.6587
   - 基本积分表: 0.6489
   - 分部积分: 0.6221
   - 幂法则: 0.6056
   - 反三角积分: 0.5609
   - 三角恒等式: 0.5243
   - 三角替换: 0.5140
   - 级数展开: 0.4325
   - 部分分式分解: 0.3733
   尝试规则: 交换积分与求和 (引力: 0.659)
      规则不匹配
   尝试规则: 基本积分表 (引力: 0.649)
      → 变换后: exp(x)

✅ 收敛于: exp(x)

最终状态: success
结果: exp(x)

📝 推导链:
   0. [Initial] → Integral(exp(x), x)
   1. [基本积分表] → exp(x)
------------------------------------------------------------

============================================================
🚀 求解: ∫ x*cos(x) dx
============================================================1: 语义引力排序:
   - 基本积分表: 0.6323
   - 交换积分与求和: 0.6276
   - 反三角积分: 0.6061
   - 三角恒等式: 0.5948
   - 幂法则: 0.5916
   - 分部积分: 0.5827
   - 三角替换: 0.5260
   - 级数展开: 0.4746
   - 部分分式分解: 0.4343
   尝试规则: 基本积分表 (引力: 0.632)
      规则不匹配
   尝试规则: 交换积分与求和 (引力: 0.628)
      规则不匹配
   尝试规则: 反三角积分 (引力: 0.606)
      规则不匹配
   尝试规则: 三角恒等式 (引力: 0.595)
      规则不匹配
   尝试规则: 幂法则 (引力: 0.592)
      规则不匹配
   尝试规则: 分部积分 (引力: 0.583)
      → 变换后: x*sin(x) - Integral(sin(x), x)2: 语义引力排序:
   - 三角恒等式: 0.6024
   - 反三角积分: 0.6012
   - 基本积分表: 0.5661
   - 三角替换: 0.5459
   - 幂法则: 0.5435
   - 交换积分与求和: 0.5201
   - 级数展开: 0.5151
   - 分部积分: 0.4638
   - 部分分式分解: 0.4124
   尝试规则: 三角恒等式 (引力: 0.602)
      规则不匹配
   尝试规则: 反三角积分 (引力: 0.601)
      规则不匹配
   尝试规则: 基本积分表 (引力: 0.566)
      → 变换后: x*sin(x) + cos(x)

✅ 收敛于: x*sin(x) + cos(x)

最终状态: success
结果: x*sin(x) + cos(x)

📝 推导链:
   0. [Initial] → Integral(x*cos(x), x)
   1. [分部积分] → x*sin(x) - Integral(sin(x), x)
   2. [基本积分表] → x*sin(x) + cos(x)
------------------------------------------------------------

============================================================
🚀 求解: ∫ 1/(x**2 + 1) dx
============================================================1: 语义引力排序:
   - 反三角积分: 0.7983
   - 幂法则: 0.7746
   - 三角替换: 0.7072
   - 级数展开: 0.6417
   - 交换积分与求和: 0.5730
   - 三角恒等式: 0.5465
   - 基本积分表: 0.5366
   - 分部积分: 0.4910
   - 部分分式分解: 0.4514
   尝试规则: 反三角积分 (引力: 0.798)
      → 变换后: atan(x)

✅ 收敛于: atan(x)

最终状态: success
结果: atan(x)

📝 推导链:
   0. [Initial] → Integral(1/(x**2 + 1), x)
   1. [反三角积分] → atan(x)
------------------------------------------------------------

============================================================
🚀 求解: ∫ sqrt(4 - x**2) dx
============================================================1: 语义引力排序:
   - 三角替换: 0.7500
   - 反三角积分: 0.7302
   - 幂法则: 0.6537
   - 基本积分表: 0.6110
   - 三角恒等式: 0.5701
   - 交换积分与求和: 0.5684
   - 级数展开: 0.5498
   - 分部积分: 0.5424
   - 部分分式分解: 0.3756
   尝试规则: 三角替换 (引力: 0.750)
      → 变换后: x*sqrt(4 - x**2)/2 + 2*asin(x/2)

✅ 收敛于: x*sqrt(4 - x**2)/2 + 2*asin(x/2)

最终状态: success
结果: x*sqrt(4 - x**2)/2 + 2*asin(x/2)

📝 推导链:
   0. [Initial] → Integral(sqrt(4 - x**2), x)
   1. [三角替换] → x*sqrt(4 - x**2)/2 + 2*asin(x/2)
------------------------------------------------------------

============================================================
🚀 求解: ∫ 1/(x**2 - 1) dx
============================================================1: 语义引力排序:
   - 反三角积分: 0.8115
   - 幂法则: 0.7608
   - 三角替换: 0.7269
   - 级数展开: 0.6490
   - 交换积分与求和: 0.5569
   - 基本积分表: 0.5387
   - 三角恒等式: 0.5381
   - 分部积分: 0.4979
   - 部分分式分解: 0.4646
   尝试规则: 反三角积分 (引力: 0.811)
      规则不匹配
   尝试规则: 幂法则 (引力: 0.761)
      规则不匹配
   尝试规则: 三角替换 (引力: 0.727)
      规则不匹配
   尝试规则: 级数展开 (引力: 0.649)
      规则不匹配
   尝试规则: 交换积分与求和 (引力: 0.557)
      规则不匹配
   尝试规则: 基本积分表 (引力: 0.539)
      → 变换后: log(x - 1)/2 - log(x + 1)/2

✅ 收敛于: log(x - 1)/2 - log(x + 1)/2

最终状态: success
结果: log(x - 1)/2 - log(x + 1)/2

📝 推导链:
   0. [Initial] → Integral(1/(x**2 - 1), x)
   1. [基本积分表] → log(x - 1)/2 - log(x + 1)/2
------------------------------------------------------------

============================================================
🚀 求解: ∫ log(1+x) dx
============================================================1: 语义引力排序:
   - 交换积分与求和: 0.6564
   - 幂法则: 0.6437
   - 反三角积分: 0.6265
   - 基本积分表: 0.6109
   - 分部积分: 0.5748
   - 三角恒等式: 0.5369
   - 级数展开: 0.5330
   - 三角替换: 0.5118
   - 部分分式分解: 0.3992
   尝试规则: 交换积分与求和 (引力: 0.656)
      规则不匹配
   尝试规则: 幂法则 (引力: 0.644)
      规则不匹配
   尝试规则: 反三角积分 (引力: 0.626)
      规则不匹配
   尝试规则: 基本积分表 (引力: 0.611)
      规则不匹配
   尝试规则: 分部积分 (引力: 0.575)
      → 变换后: x*log(x + 1) - Integral(x/(x + 1), x)2: 语义引力排序:
   - 反三角积分: 0.7286
   - 幂法则: 0.7271
   - 三角替换: 0.6548
   - 级数展开: 0.6491
   - 交换积分与求和: 0.6039
   - 基本积分表: 0.5824
   - 三角恒等式: 0.5613
   - 分部积分: 0.4905
   - 部分分式分解: 0.4362
   尝试规则: 反三角积分 (引力: 0.729)
      规则不匹配
   尝试规则: 幂法则 (引力: 0.727)
      规则不匹配
   尝试规则: 三角替换 (引力: 0.655)
      规则不匹配
   尝试规则: 级数展开 (引力: 0.649)
      规则不匹配
   尝试规则: 交换积分与求和 (引力: 0.604)
      规则不匹配
   尝试规则: 基本积分表 (引力: 0.582)
      → 变换后: 0

✅ 收敛于: 0

最终状态: success
结果: 0

📝 推导链:
   0. [Initial] → Integral(log(x + 1), x)
   1. [分部积分] → x*log(x + 1) - Integral(x/(x + 1), x)
   2. [基本积分表]0
------------------------------------------------------------

============================================================
🚀 求解: ∫ sin(x)**2 + cos(x)**2 dx
============================================================1: 语义引力排序:
   - 反三角积分: 0.6105
   - 幂法则: 0.5760
   - 三角恒等式: 0.5683
   - 三角替换: 0.5649
   - 级数展开: 0.5645
   - 基本积分表: 0.5384
   - 交换积分与求和: 0.4675
   - 分部积分: 0.4248
   - 部分分式分解: 0.4109
   尝试规则: 反三角积分 (引力: 0.611)
      规则不匹配
   尝试规则: 幂法则 (引力: 0.576)
      规则不匹配
   尝试规则: 三角恒等式 (引力: 0.568)
      → 变换后: Integral(1, x)2: 语义引力排序:
   - 分部积分: 0.6858
   - 交换积分与求和: 0.6528
   - 基本积分表: 0.6146
   - 反三角积分: 0.4910
   - 三角恒等式: 0.4806
   - 幂法则: 0.4766
   - 部分分式分解: 0.3561
   - 三角替换: 0.3362
   - 级数展开: 0.3032
   尝试规则: 分部积分 (引力: 0.686)
      规则不匹配
   尝试规则: 交换积分与求和 (引力: 0.653)
      规则不匹配
   尝试规则: 基本积分表 (引力: 0.615)
      → 变换后: x

✅ 收敛于: x

最终状态: success
结果: x

📝 推导链:
   0. [Initial] → Integral(sin(x)**2 + cos(x)**2, x)
   1. [三角恒等式] → Integral(1, x)
   2. [基本积分表] → x
------------------------------------------------------------

4. Capabilities and Results

Currently Supported:

  • Polynomial integrals (e.g., ∫ x² dx)
  • Basic trigonometric integrals (e.g., ∫ sin(x) dx)
  • Exponential and logarithmic integrals (e.g., ∫ e^x dx, ∫ log(1+x) dx)
  • Product structures (e.g., ∫ x·cos(x) dx)
  • Rational functions (e.g., ∫ 1/(x²-1) dx)
  • Radical expressions (e.g., ∫ √(4-x²) dx)

Representative Test Results:

Integral Expression Output Status
∫ x² dx x³/3
∫ log(1+x) dx (1+x)log(1+x) - x
∫ x·cos(x) dx x·sin(x) + cos(x)
∫ 1/(x²+1) dx atan(x)
∫ √(4-x²) dx x/2·√(4-x²)+2·asin(x/2)

All test cases converge within 2–3 iteration steps, with clearly readable derivation paths.


5. Comparison with Existing Systems

Dimension Traditional Symbolic Systems Our Engine
Path Transparency Black box; cannot intervene Fully transparent; every step traceable
Strategy Selection Fixed-order attempts Semantically guided; dynamically optimized
Extensibility Requires core source code modification New rules can be freely added
Handling Complex Integrals May timeout or hang Configurable steps; controlled termination
Educational Value Low (only gives answers) High (shows complete derivation)

6. Future Directions

This project is an extensible platform, not a closed system. Future developments may include:

  1. Expanding the rule library: Adding more integration techniques (trigonometric identities, recurrence formulas, special function integrals).
  2. Supporting definite integrals: Improving limit evaluation and handling of singularities.
  3. Interactive mode: Allowing users to intervene in rule selection for semi-automated problem-solving.
  4. Educational applications: Serving as a teaching tool to illustrate the complete reasoning process behind integration.

7. Conclusion

The Semantically-Guided Symbolic Integration Engine successfully integrates mathematical intuition (semantic perception) with symbolic computation (rule-based systems), establishing a novel paradigm for mathematical problem-solving. It not only computes elementary function integrals accurately but also provides complete, interpretable derivation steps—achieving both precision and transparency.

This approach extends beyond integration. Its core principle—using semantics to guide symbolic computation—offers a general framework for other mathematical domains such as differential equation solving and algebraic simplification. We believe this “semantic-symbolic hybrid” model will become a significant direction in the future development of intelligent mathematical systems.

Logo

中国智能体开发者社区,聚焦智能体与大模型开发,提供前沿资讯、实用工具链、开源项目及行业案例。通过技术沙龙、开发者大赛等活动,促进经验交流与协作,助力开发者快速构建创新智能应用。

更多推荐