{
  "schema_version": "ocme-derivation-reader-v1",
  "guide_id": "derivation-mko-topological-ordering-dag-01",
  "mko_id": "mko-topological-ordering-dag",
  "title": {
    "zh-Hant": "三頂點DAG的全部排列與Kahn trace",
    "en": "All permutations and a Kahn trace for a three-vertex DAG"
  },
  "contract": {
    "schema_version": "ocme-derivation-guide-v0.1",
    "guide_id": "derivation-mko-topological-ordering-dag-01",
    "source": {
      "mko_id": "mko-topological-ordering-dag",
      "commit": "b1b2f1dcf8c50d67a93fe52d95f8eef7b3abba9f",
      "sha256": "826499909e9a38a23996ab91062cdf86e73a350078b0b11c2a5fb8828d12e5f9",
      "english_sha256": "3063e85d7b49e8d03329c2cbf2fe9c9b69db6122f1ad297fcebacdb7df784a96"
    },
    "mode": "worked_example",
    "audience_prerequisites": [
      "work"
    ],
    "goal": {
      "zh-Hant": "完整列valid orders並核source-removal invariant。",
      "en": "List every valid order and audit source-removal invariants."
    },
    "givens": [
      {
        "id": "G1",
        "statement": {
          "zh-Hant": "V={0,1,2}，E={(0,2),(1,2)}；Kahn每步選最小zero-indegree頂點。",
          "en": "V={0,1,2}, E={(0,2),(1,2)}; Kahn selects the least zero-indegree vertex at each step."
        }
      }
    ],
    "steps": [
      {
        "id": "S01",
        "uses": [
          "G1",
          "work"
        ],
        "before_tex": "\\text{all permutations of }V",
        "after_tex": "012,021,102,120,201,210",
        "relation": "implies",
        "rule": "work",
        "conditions": [],
        "explanation": {
          "zh-Hant": "3!個候選各含每頂點一次。",
          "en": "All3! candidates contain each vertex once."
        },
        "reverse_audit": {
          "kind": "premise_audit",
          "required_ids": [
            "G1",
            "work"
          ],
          "explanation": {
            "zh-Hant": "有重複或漏點的序列不在候選集合。",
            "en": "Sequences with duplicates or omissions are excluded."
          }
        },
        "leaf_basis": "work"
      },
      {
        "id": "S02",
        "uses": [
          "G1",
          "S01",
          "work"
        ],
        "before_tex": "012,102",
        "after_tex": "\\operatorname{pos}(0)<\\operatorname{pos}(2),\\quad\\operatorname{pos}(1)<\\operatorname{pos}(2)",
        "relation": "implies",
        "rule": "work",
        "conditions": [],
        "explanation": {
          "zh-Hant": "兩個排列都把0、1放2之前，全部邊尊重。",
          "en": "Both orders place0 and 1 before 2, respecting every edge."
        },
        "reverse_audit": {
          "kind": "premise_audit",
          "required_ids": [
            "G1",
            "S01",
            "work"
          ],
          "explanation": {
            "zh-Hant": "必須核兩條邊而非只核0→2。",
            "en": "Both edges, not only0-to2, must be checked."
          }
        },
        "leaf_basis": "work"
      },
      {
        "id": "S03",
        "uses": [
          "G1",
          "S02",
          "work"
        ],
        "before_tex": "021,120",
        "after_tex": "021\\text{ violates }1\\to2;\\quad120\\text{ violates }0\\to2",
        "relation": "implies",
        "rule": "work",
        "conditions": [],
        "explanation": {
          "zh-Hant": "兩個候選各有明確反向邊。",
          "en": "Each candidate has an explicit violated edge."
        },
        "reverse_audit": {
          "kind": "premise_audit",
          "required_ids": [
            "G1",
            "S02",
            "work"
          ],
          "explanation": {
            "zh-Hant": "它們失敗不代表原圖有圈。",
            "en": "Their failure does not make the original graph cyclic."
          }
        },
        "leaf_basis": "work"
      },
      {
        "id": "S04",
        "uses": [
          "G1",
          "S03",
          "work"
        ],
        "before_tex": "201,210",
        "after_tex": "\\text{both violate }0\\to2\\text{ since2 precedes0}",
        "relation": "implies",
        "rule": "work",
        "conditions": [],
        "explanation": {
          "zh-Hant": "最後兩案也無效，六排列分類完成。",
          "en": "The final two cases fail too, completing all six permutations."
        },
        "reverse_audit": {
          "kind": "premise_audit",
          "required_ids": [
            "G1",
            "S03",
            "work"
          ],
          "explanation": {
            "zh-Hant": "valid orders恰012與102，非唯一。",
            "en": "The valid orders are exactly012 and 102, so they are not unique."
          }
        },
        "leaf_basis": "work"
      },
      {
        "id": "S05",
        "uses": [
          "G1",
          "S04",
          "work"
        ],
        "before_tex": "d^-(0,1,2)=(0,0,2)",
        "after_tex": "\\text{Kahn chooses }0;\\quad\\text{remaining indegrees }(1:0,2:1)",
        "relation": "implies",
        "rule": "work",
        "conditions": [],
        "explanation": {
          "zh-Hant": "刪source0及其out邊後更新2的indegree。",
          "en": "Delete source0 and its outgoing edge, updating2's indegree."
        },
        "reverse_audit": {
          "kind": "premise_audit",
          "required_ids": [
            "G1",
            "S04",
            "work"
          ],
          "explanation": {
            "zh-Hant": "記錄剩餘圖indegree，不沿用初始值。",
            "en": "Track indegrees in the remaining graph, not initial values."
          }
        },
        "leaf_basis": "work"
      },
      {
        "id": "S06",
        "uses": [
          "G1",
          "S05",
          "work"
        ],
        "before_tex": "\\text{remaining }\\{1,2\\},\\quad d^-=(0,1)",
        "after_tex": "\\text{choose }1,\\text{ then }2;\\quad\\text{output }012",
        "relation": "implies",
        "rule": "work",
        "conditions": [],
        "explanation": {
          "zh-Hant": "刪1釋放2成source，再刪2，全部頂點輸出。",
          "en": "Removing1 releases2 as a source; then delete2, outputting every vertex."
        },
        "reverse_audit": {
          "kind": "premise_audit",
          "required_ids": [
            "G1",
            "S05",
            "work"
          ],
          "explanation": {
            "zh-Hant": "每次刪source，已輸出prefix不會違反incoming edge。",
            "en": "Each source deletion keeps the output prefix free of violated incoming edges."
          }
        },
        "leaf_basis": "work"
      },
      {
        "id": "S07",
        "uses": [
          "G1",
          "S06",
          "work"
        ],
        "before_tex": "H:\\ E_H=\\{(0,1),(1,2),(2,0)\\}",
        "after_tex": "d^-_H=(1,1,1),\\quad0\\to1\\to2\\to0\\text{ is a cycle}",
        "relation": "implies",
        "rule": "work",
        "conditions": [],
        "explanation": {
          "zh-Hant": "另一圖若無source但有剩餘頂點，明列directed cycle witness。",
          "en": "For the separate graph with no source and remaining vertices, supply an explicit directed cycle."
        },
        "reverse_audit": {
          "kind": "premise_audit",
          "required_ids": [
            "G1",
            "S06",
            "work"
          ],
          "explanation": {
            "zh-Hant": "不能把Kahn停止本身當未展開的cycle證書。",
            "en": "Do not leave the cycle certificate implicit in Kahn stopping."
          }
        },
        "leaf_basis": "work"
      },
      {
        "id": "S08",
        "uses": [
          "G1",
          "S07",
          "work"
        ],
        "before_tex": "\\operatorname{Orders}(G)=\\{012,102\\}",
        "after_tex": "G\\text{ is a DAG and Kahn returns }012",
        "relation": "implies",
        "rule": "work",
        "conditions": [],
        "explanation": {
          "zh-Hant": "有效order的positions沿每邊嚴增，故不可能閉圈。",
          "en": "Positions strictly increase along edges of a valid order, ruling out a directed cycle."
        },
        "reverse_audit": {
          "kind": "premise_audit",
          "required_ids": [
            "G1",
            "S07",
            "work"
          ],
          "explanation": {
            "zh-Hant": "零頂點圖有一個empty order；非empty edgeless圖有全部排列。",
            "en": "A zero-vertex graph has one empty order; a nonempty edgeless graph has every permutation."
          }
        },
        "leaf_basis": "work"
      }
    ],
    "result": {
      "zh-Hant": "全部valid orders為012、102；lex-first Kahn輸出012，原圖DAG。",
      "en": "All valid orders are 012,102; lex-first Kahn outputs012 and the graph is a DAG."
    },
    "negative_controls": [
      {
        "claim": {
          "zh-Hant": "021無效所以圖有cycle。",
          "en": "Invalid021 means the graph has a cycle."
        },
        "expected": "reject",
        "reason": {
          "zh-Hant": "012是完整valid order。",
          "en": "012 is a complete valid order."
        }
      },
      {
        "claim": {
          "zh-Hant": "此圖topological order唯一。",
          "en": "This graph has a unique topological order."
        },
        "expected": "reject",
        "reason": {
          "zh-Hant": "012與102皆合法。",
          "en": "Both012 and 102 are valid."
        }
      },
      {
        "claim": {
          "zh-Hant": "Kahn刪0後2立即成source。",
          "en": "Removing0 immediately makes2 a source."
        },
        "expected": "reject",
        "reason": {
          "zh-Hant": "尚有1→2，所以剩餘indegree為1。",
          "en": "The edge1-to2 remains, leaving indegree1."
        }
      }
    ],
    "status": "candidate",
    "gaps": [],
    "verification": {
      "structure": "checked_local_script",
      "mathematics": "candidate_argument",
      "formalization": "not_formalized"
    },
    "rule_glossary": [
      {
        "id": "mko_definition",
        "kind": "cited",
        "statement": {
          "zh-Hant": "candidate ordering須是全部vertices的permutation，逐edge驗pos(u)<pos(v)。小型graph完整枚舉所有valid orders；Kahn程序每步選lexicographically first zero-indegree source、刪除並記錄invariant。若無source但尚有vertices，輸出explicit directed cycle witness。multiple orders與empty-edge保留；invalid candidate不等於graph有cycle，亦不與topological-space混同。",
          "en": "A candidate ordering must be a permutation of all vertices and must place u before v for every edge u→v. For a small graph enumerate all valid orders. Kahn source removal chooses the lexically first zero-indegree vertex at each step and retains the trace. If no source exists while vertices remain, give an explicit directed cycle. Multiple orders and edgeless graphs are allowed; a zero-vertex graph has one empty order. One invalid candidate does not show the graph is cyclic. These graph orders are not topological-space notions."
        },
        "source": {
          "mko_id": "mko-topological-ordering-dag",
          "sha256": "826499909e9a38a23996ab91062cdf86e73a350078b0b11c2a5fb8828d12e5f9",
          "commit": "b1b2f1dcf8c50d67a93fe52d95f8eef7b3abba9f"
        }
      },
      {
        "id": "work",
        "kind": "prerequisite",
        "statement": {
          "zh-Hant": "拓撲排列為全頂點permutation且每有向邊u→v滿足pos(u)<pos(v)；Kahn刪zero-indegree source並更新剩餘圖。 DAG沒有directed cycle；topological order為全頂點permutation，且每邊起點位置嚴格先於終點。",
          "en": "A topological order is a full vertex permutation with pos(u)<pos(v) for every edge u-to-v; Kahn removes a zero-indegree source and updates the residual graph. A DAG has no directed cycle; a topological order is a full vertex permutation placing each edge's source strictly before its target."
        }
      }
    ],
    "revision_log": [],
    "numeric_checks": [
      {
        "id": "N01",
        "lhs": "factorial(3)",
        "rhs": "6"
      },
      {
        "id": "N02",
        "lhs": "2-1",
        "rhs": "1"
      }
    ]
  },
  "presentation": {
    "md_scope": {
      "zh-Hant": "finite graph orders，不混同拓撲空間。",
      "en": "Finite graph orders, not topological spaces."
    },
    "md_symbols": [
      [
        "V,E",
        "完整頂點與邊集合",
        "complete vertex and edge sets"
      ],
      [
        "pos",
        "排列位置",
        "order position"
      ]
    ],
    "md_error_controls": [
      {
        "title": "六排列 / Six permutations",
        "zh": "3!候選各出現一次且給edge證據。",
        "en": "Each of the 3! candidates appears once, with edge evidence for its validity or failure."
      },
      {
        "title": "剩餘圖 / Residual graph",
        "zh": "每步刪outgoing edges再更新indegree。",
        "en": "Delete outgoing edges and update indegrees at every step."
      }
    ],
    "md_open_items": []
  },
  "revision": {
    "id": "ocme-new142-reader-adoption-20261021",
    "collection": "coverage-20261021",
    "source_commit": "b1b2f1dcf8c50d67a93fe52d95f8eef7b3abba9f",
    "adopted_source_sha256": "75e458baf0ea665f57f182f5f2532425a1c004b4b86bffc40d16191b5e5c83e3",
    "original_source_sha256": "28d6cd464a04e9680e5cb6230b6ecb75b0de6ea8867e0fa97d61121a6898906c",
    "owner_adopted": true,
    "bilingual_sync": "complete_source_bound",
    "formal_Lean": "NOT_RUN",
    "reader_review": "142_of_142_source_bound",
    "wording_review": "original_Lead_decisions_resolved",
    "glossary_reader_paraphrases": [],
    "independent_AI_concurrence": "SCOPED_LEAD_AND_BILINGUAL_CONTEXT_REVIEW",
    "issue_ids": [
      "BR142-P081",
      "BR142-S227",
      "BR142-S226",
      "BR142-S223",
      "BR142-S225"
    ],
    "parent_manifest_sha256": "d29f4cae8229ebd24f60d496cb1d3cd4ad8c0a4dca9d44daab0c3245c544283a",
    "scope": "Owner-adopted reader revision. Lead and bilingual review concern the recorded text and premises; no new universal or Lean proof, canonical promotion or historical-label rewrite."
  }
}
