Back to Skills

explore-diophantine-equations

pjt222
Updated Yesterday
4 views
17
2
17
View on GitHub
Othergeneral

About

This skill helps developers solve Diophantine equations (integer solutions) including linear equations, Pell's equations, and Pythagorean triples. It determines solvability, finds minimal solutions, and provides parametric forms. Use it for number theory problems, algorithm design, or when working with integer constraints in mathematical programming.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/explore-diophantine-equations

Copy and paste this command in Claude Code to install this skill

Documentation


name: explore-diophantine-equations description: > 探索丢番图方程:线性丢番图方程(扩展 Euclid 算法)、Pell 方程 (连分数法)、勾股方程(参数化解)和高次方程(Fermat 大定理及 相关结果)。涵盖可解性判定、解的参数化和求最小正整数解。 license: MIT allowed-tools: Read Grep Glob WebFetch WebSearch metadata: author: Philipp Thoss version: "1.0" domain: number-theory complexity: intermediate language: natural tags: number-theory, diophantine-equations, pell-equation, pythagorean-triples, fermat locale: zh-CN source_locale: en source_commit: 6f65f316 translator: claude-sonnet-4-6 translation_date: 2026-03-16

探索丢番图方程

系统求解要求整数解的丢番图方程,涵盖线性方程、Pell 方程、勾股方程和高次方程。

适用场景

  • 求解线性丢番图方程 ax + by = c 的整数解
  • 使用连分数法求解 Pell 方程 x^2 - Dy^2 = 1
  • 生成和分析勾股数组 (a, b, c) 满足 a^2 + b^2 = c^2
  • 分析高次丢番图方程的可解性
  • 将实际问题转化为丢番图方程

输入

  • 必需:丢番图方程的陈述
  • 可选:解的约束(正整数、非负整数、某范围内)
  • 可选:是否需要所有解的参数化或仅特定解
  • 可选:应用上下文

步骤

第 1 步:分类方程并判定可解性

确定方程类型和解的存在性:

  1. 线性丢番图方程 ax + by = c:
    • 有解当且仅当 gcd(a, b) | c
    • 如果有解,则有无穷多解
  2. Pell 方程 x^2 - Dy^2 = 1(D 为非完全平方正整数):
    • 总是有非平凡解
    • 最小正解可通过 sqrt(D) 的连分数展开求得
  3. 负 Pell 方程 x^2 - Dy^2 = -1:
    • 不一定有解——取决于 D 的性质
    • 有解当且仅当 sqrt(D) 的连分数周期长度为奇数
  4. 勾股方程 x^2 + y^2 = z^2:
    • 所有本原解(gcd(x,y,z) = 1)由参数化给出
  5. Fermat 方程 x^n + y^n = z^n(n ≥ 3):
    • 无正整数解(Fermat 大定理,Wiles 1995 年证明)
  6. 一般二次丢番图方程:可使用 Hasse-Minkowski 定理等工具分析。

预期结果: 方程已分类,可解性条件已确定或证明无解。

失败处理: 如果方程不属于标准类型,尝试通过变量替换或模运算论证将其转化为已知类型。模运算是证明无解的强大工具。

第 2 步:求解方程

根据方程类型求解:

  1. 线性丢番图方程
    • 使用扩展 Euclid 算法找 ax + by = gcd(a,b) 的特解 (x_0, y_0)
    • 缩放得到 ax + by = c 的特解:x_0' = x_0 * c/gcd(a,b)
    • 通解:x = x_0' + (b/d)t, y = y_0' - (a/d)t,t 为任意整数
    • 对于正整数解,求 t 的范围使 x > 0 且 y > 0
  2. Pell 方程
    • 计算 sqrt(D) 的连分数展开 [a_0; a_1, a_2, ..., a_k, ...]
    • 找到周期长度 k
    • 如果 k 为偶数,第 k-1 个渐近分数 p_(k-1)/q_(k-1) 给出最小解
    • 如果 k 为奇数,第 2k-1 个渐近分数给出最小解
    • 所有解由递推生成:(x_(n+1), y_(n+1)) = (x_1 * x_n + D * y_1 * y_n, x_1 * y_n + y_1 * x_n)
  3. 勾股数组
    • 本原勾股数组参数化:对互素的 m > n > 0(一奇一偶)
    • a = m^2 - n^2, b = 2mn, c = m^2 + n^2
    • 一般勾股数组为本原数组的倍数

预期结果: 方程的特解和通解(或参数化),正整数解的范围(如有约束)。

失败处理: 如果连分数计算错误,通过代入 x^2 - Dy^2 验证候选解。连分数的每一步都应验证。

第 3 步:验证和分析解

确认解的正确性并进行进一步分析:

  1. 代入验证:将求得的解代入原方程确认等式成立。
  2. 完整性检查
    • 对于线性方程,验证通解公式生成的解确实覆盖所有解
    • 对于 Pell 方程,验证递推关系正确生成后续解
  3. 最小解:确认找到的是最小正解(对 Pell 方程尤其重要)。
  4. 解的性质分析
    • 解的增长率(Pell 方程的解呈指数增长)
    • 解的模式和规律
  5. 应用解释:将数学解翻译回原始问题的语境。

预期结果: 所有解经验证正确,解的结构(通解公式或参数化)已完整描述。

失败处理: 如果验证失败,重新检查计算步骤。对于 Pell 方程,确认 D 不是完全平方数(完全平方数的 Pell 方程无正整数解)。

验证清单

  • 方程类型正确分类
  • 可解性条件已验证
  • 所有解代入原方程验证正确
  • 通解公式覆盖所有解
  • 正整数解的范围正确计算(如有约束)
  • Pell 方程的最小正解正确
  • 勾股数组的本原性条件已检查

常见问题

  • 混淆 Pell 方程的两种形式:x^2 - Dy^2 = 1 和 x^2 - Dy^2 = -1 是不同的方程,后者不一定有解。
  • D 为完全平方数:当 D = k^2 时,x^2 - k^2*y^2 = (x-ky)(x+ky) = 1 只有平凡解 y = 0, x = ±1。
  • 忽略线性方程的可解性条件:ax + by = c 仅在 gcd(a,b) | c 时有解。直接使用扩展 Euclid 算法而不检查此条件可能得到非整数"解"。
  • 勾股数组参数化的条件:m 和 n 必须互素且一奇一偶,否则生成的不是本原数组。
  • 模运算论证的方向:模运算可以证明无解(如果模某个数无解,则整体无解),但不能直接证明有解。

相关技能

  • analyze-prime-numbers -- 丢番图方程的可解性常依赖于素数性质
  • solve-modular-arithmetic -- 模运算是分析丢番图方程的基本工具
  • derive-theoretical-result -- 某些丢番图方程需要理论推导来完全解决

GitHub Repository

pjt222/agent-almanac
Path: i18n/zh-CN/skills/explore-diophantine-equations
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

llamaguard

Other

LlamaGuard is Meta's 7-8B parameter model for moderating LLM inputs and outputs across six safety categories like violence and hate speech. It offers 94-95% accuracy and can be deployed using vLLM, Hugging Face, or Amazon SageMaker. Use this skill to easily integrate content filtering and safety guardrails into your AI applications.

View skill

cost-optimization

Other

This Claude Skill helps developers optimize cloud costs through resource rightsizing, tagging strategies, and spending analysis. It provides a framework for reducing cloud expenses and implementing cost governance across AWS, Azure, and GCP. Use it when you need to analyze infrastructure costs, right-size resources, or meet budget constraints.

View skill

quantizing-models-bitsandbytes

Other

This skill quantizes LLMs to 8-bit or 4-bit precision using bitsandbytes, achieving 50-75% memory reduction with minimal accuracy loss. It's ideal for running larger models on limited GPU memory or accelerating inference, supporting formats like INT8, NF4, and FP4. The skill integrates with HuggingFace Transformers and enables QLoRA training and 8-bit optimizers.

View skill

dispatching-parallel-agents

Other

This Claude Skill dispatches multiple agents to investigate and fix 3+ independent problems concurrently. It is designed for scenarios involving unrelated failures that can be resolved without shared state or dependencies. The core capability is parallel problem-solving, assigning one agent per independent problem domain to maximize efficiency.

View skill