スキル一覧に戻る
letta-ai

prove-plus-comm

by letta-ai

A shared repository for skills.

33🍴 5📅 2026年1月24日
GitHubで見るManusで実行

SKILL.md


name: prove-plus-comm description: Guidance for proving mathematical properties in Coq using induction, specifically addition commutativity and similar arithmetic lemmas. This skill should be used when working with Coq proof assistants to complete induction proofs, fill in proof cases, or apply standard library lemmas like plus_n_O and plus_n_Sm.

Proving Addition Commutativity in Coq

Overview

This skill provides guidance for completing induction proofs in Coq, particularly proofs involving arithmetic properties like addition commutativity (n + m = m + n). It covers the workflow for understanding incomplete proofs, identifying required lemmas, and verifying correctness through compilation.

Workflow for Completing Coq Proofs

Step 1: Understand the Proof Structure

Before making any edits, read and understand the existing proof file:

  1. Identify the theorem statement and what needs to be proved
  2. Locate incomplete cases marked with admit, Admitted, or placeholder tactics
  3. Understand the induction structure (base case vs inductive case)
  4. Note which libraries are imported (e.g., Require Import Arith)

Step 2: Analyze Each Case

For induction proofs on natural numbers:

Base Case (n = 0):

  • After simpl, determine what the goal simplifies to
  • Common pattern: proving m = m + 0 requires the plus_n_O lemma
  • The plus_n_O lemma states: forall n, n = n + 0

Inductive Case (n = S n'):

  • Identify the inductive hypothesis (IH) available in context
  • After simpl, the goal typically involves S (...) on both sides
  • Common pattern: proving S (n' + m) = m + S n' requires:
    • Rewriting with the inductive hypothesis
    • Applying plus_n_Sm lemma: forall n m, S (n + m) = n + S m

Step 3: Apply Tactics

Common tactics for arithmetic proofs:

TacticUsage
simplSimplify expressions using definitions
rewrite <- lemmaRewrite goal right-to-left using lemma
rewrite -> lemmaRewrite goal left-to-right using lemma
rewrite IHnApply inductive hypothesis
reflexivityProve goal when both sides are identical
apply lemmaApply a lemma directly to the goal

Step 4: Verify with Compilation

After completing the proof:

  1. Compile the file with coqc filename.v
  2. Successful compilation produces a .vo file
  3. If compilation fails, read error messages to identify issues

Verification Strategies

Incremental Verification

Compile after each significant edit rather than completing all cases first. This prevents cascading errors and simplifies debugging.

Check Goal States

When uncertain about what a tactic produces, consider:

  • Using Show to display the current goal
  • Running Coq interactively with coqtop to step through proofs
  • Checking goal state after simpl before applying lemmas

Library Verification

Verify lemma availability before use:

  • Use Search command to find relevant lemmas: Search ((_ + 0) = _).
  • Use Print to view lemma statements: Print plus_n_O.
  • Confirm the Arith library is imported for standard arithmetic lemmas

Common Pitfalls

Direction of Rewriting

The <- and -> arrows in rewrite matter:

  • rewrite <- plus_n_O rewrites n to n + 0
  • rewrite -> plus_n_O rewrites n + 0 to n

Incorrect direction causes the tactic to fail or produce an incorrect goal.

Missing Library Imports

Standard arithmetic lemmas require Require Import Arith. Without this import, lemmas like plus_n_O and plus_n_Sm are unavailable.

Assuming Lemma Existence

Do not assume lemmas exist without verification. For non-standard proofs, explore the library using Search before relying on specific lemmas.

Coq Version Compatibility

Tactics and lemma names may differ between Coq versions. If a tactic fails unexpectedly, verify the Coq version and check documentation for version-specific syntax.

Key Lemmas for Addition Proofs

LemmaStatementUsage
plus_n_Oforall n, n = n + 0Base case: 0 + m = m simplifies to m = m + 0
plus_n_Smforall n m, S (n + m) = n + S mInductive case: relates S (n' + m) to m + S n'
plus_commforall n m, n + m = m + nThe commutativity property itself (if already proven)
plus_assocforall n m p, n + (m + p) = (n + m) + pAssociativity for rearranging terms

Example Pattern: Completing Commutativity Proof

For a proof structured as:

Theorem plus_comm : forall n m : nat, n + m = m + n.
Proof.
  intros n m.
  induction n as [| n' IHn'].
  - (* Base case: n = 0 *)
    simpl.
    (* Goal: m = m + 0 *)
    (* TODO: complete this case *)
  - (* Inductive case: n = S n' *)
    simpl.
    (* Goal: S (n' + m) = m + S n' *)
    (* IHn': n' + m = m + n' *)
    (* TODO: complete this case *)
Qed.

Base case solution:

rewrite <- plus_n_O. reflexivity.

Inductive case solution:

rewrite IHn'. rewrite plus_n_Sm. reflexivity.

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です