0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ワーキングメモリが一杯にならないために

Last updated at Posted at 2025-12-24

infoviewに頼れ/りたくないとき、showを置く。
過剰にshowを置いた事例。やりすぎかもしれないけれども、クリスタルクリア、ブレインフレンドリー。
死んだ木に書かれたコードはここまでしてくれないと初学者には大変。
geminiによれば、すでにゴールがFalseならshow False、そうでないならexfalsoがよい。
なお、直接 left : P -> Falseとできればよいものの、それはできない様子。

-- de morgan
example (P Q : Prop) : ¬ (P  Q)  ¬ P  ¬ Q := by
  constructor
  --^ splitting iff into `mp` (modus ponens) and `mpr` (modus ponens reversed)
  case mp =>
    show ¬ (P  Q)  ¬ P  ¬ Q
    intro (h : ¬ (P  Q))
    show ¬ P  ¬ Q
    constructor -- splitting ∧ into `left` and `right`
    case left =>
      show P  False
      intro (p : P)
      show False
      exact (
        (h        : ¬ (P  Q))
        (Or.inl p :    P  Q)
        : False
      )
    case right =>
      show Q  False
      intro (q : Q)
      show False
      exact (
        (h        : ¬ (P  Q))
        (Or.inr q :    P  Q)
        : False
      )
  case mpr =>
    show (¬ P  ¬ Q)  ((P  Q)  False)
    intro (h : ¬ P  ¬ Q)
    show ((P  Q)  False)
    intro (h : P  Q)
    show False
    cases h with
    | inl p => exact ((h.left  : P  False) (p : P) : False)
    | inr q => exact ((h.right : Q  False) (q : Q) : False)

次の例では、mp枝のゴールはQだけどexfalsoshow Falseよりというということだと思う。
なお、mprhave+exactで型を明示したパターン。showguard_target=\_sとの使い分けはまだ見えてこない。
また、contradictionはコンテキスト依存がexactより強いということらしく、脱コンテキストを目指すならexactの方が好ましいらしい(なぜかleanにはあまり強くないcopilot談)。

-- material conditional
example (P Q : Prop) : (¬ P  Q)  (P  Q) := by
  constructor
  case mp =>
    show¬ P  Q  (P  Q)
    intro h
    intro p
    cases h with
    | inl np => -- this term always results in False
      exfalso -- because we have both P and ¬ P
      exact (np p)
    | inr q => exact q
  case mpr =>
    have goal : (P  Q)  ¬ P  Q := by
      intro h
      by_cases h : P
      case pos => exact (Or.inr (h h : Q) : ¬ P  Q)
      case neg => exact (Or.inl (h : ¬ P)  : ¬ P  Q)
    exact goal

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?