algorithm-design

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Algorithm Design

算法设计

Formalize methods into algorithm pseudocode and system architecture diagrams.
将方法形式化为算法伪代码和系统架构图。

Input

输入

  • $0
    — Method description or implementation to formalize
  • $0$
    — 待形式化的方法描述或实现代码

References

参考资料

  • Algorithm and diagram templates:
    ~/.claude/skills/algorithm-design/references/algorithm-templates.md
  • 算法与图表模板:
    ~/.claude/skills/algorithm-design/references/algorithm-templates.md

Workflow

工作流程

Step 1: Formalize the Algorithm

步骤1:形式化算法

  1. Define clear inputs and outputs
  2. Identify the main loop / recursive structure
  3. Specify all parameters and their types
  4. Write step-by-step pseudocode
  1. 定义明确的输入和输出
  2. 识别主循环/递归结构
  3. 明确所有参数及其类型
  4. 编写分步伪代码

Step 2: Generate LaTeX Pseudocode

步骤2:生成LaTeX伪代码

Use
algorithm
+
algpseudocode
environments:
latex
\begin{algorithm}[t]
\caption{Method Name}
\label{alg:method}
\begin{algorithmic}[1]
\Require Input $x$, parameters $\theta$
\Ensure Output $y$
\State Initialize ...
\For{$t = 1$ to $T$}
    \State $z_t \gets f(x_t; \theta)$
    \If{convergence criterion met}
        \State \textbf{break}
    \EndIf
\EndFor
\State \Return $y$
\end{algorithmic}
\end{algorithm}
使用
algorithm
+
algpseudocode
环境:
latex
\begin{algorithm}[t]
\caption{Method Name}
\label{alg:method}
\begin{algorithmic}[1]
\Require Input $x$, parameters $\theta$
\Ensure Output $y$
\State Initialize ...
\For{$t = 1$ to $T$}
    \State $z_t \gets f(x_t; \theta)$
    \If{convergence criterion met}
        \State \textbf{break}
    \EndIf
\EndFor
\State \Return $y$
\end{algorithmic}
\end{algorithm}

Step 3: Generate UML Diagrams (Mermaid)

步骤3:生成UML图(Mermaid)

Class Diagram

类图

mermaid
classDiagram
    class Model {
        +forward(x: Tensor) Tensor
        +train_step(batch) float
    }
mermaid
classDiagram
    class Model {
        +forward(x: Tensor) Tensor
        +train_step(batch) float
    }

Sequence Diagram

序列图

mermaid
sequenceDiagram
    participant M as Main
    participant D as DataLoader
    M->>D: load_data()
    D-->>M: batches
mermaid
sequenceDiagram
    participant M as Main
    participant D as DataLoader
    M->>D: load_data()
    D-->>M: batches

Step 4: Verify Consistency

步骤4:验证一致性

  • Every pseudocode step must map to a code module
  • Every class in the UML must exist in the implementation
  • Parameter names must match between pseudocode and code
  • 伪代码的每一步都必须对应到一个代码模块
  • UML中的每个类都必须在实现代码中存在
  • 伪代码与代码中的参数名称必须一致

Rules

规则

  • Use standard algorithmic notation (not code syntax)
  • Number lines for easy reference
  • Include complexity analysis as a comment or proposition
  • Use
    \Require
    /
    \Ensure
    for inputs/outputs
  • Keep pseudocode at the right abstraction level — not too detailed, not too vague
  • 使用标准算法符号(而非代码语法)
  • 为代码行编号以便于引用
  • 将复杂度分析作为注释或命题包含在内
  • 使用
    \Require
    /
    \Ensure
    声明输入/输出
  • 保持伪代码在合适的抽象层次——既不过于详细,也不过于模糊

Related Skills

相关技能

  • Upstream: atomic-decomposition, math-reasoning
  • Downstream: experiment-code, paper-writing-section
  • See also: symbolic-equation
  • 上游技能:atomic-decomposition, math-reasoning
  • 下游技能:experiment-code, paper-writing-section
  • 另见:symbolic-equation