{"type": "session", "harness": "opencode", "id": "reason-0000", "name": "logic"} {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}} {"type": "message", "message": {"role": "user", "content": "Explain logic reasoning with concrete examples and common pitfalls. Include a runnable code example with its expected output."}} {"type": "message", "message": {"role": "assistant", "content": "**Propositional Logic:**\n- P ∧ Q (AND): true only if both true\n- P ∨ Q (OR): true if either true\n- ¬P (NOT): negation\n- P → Q (IF-THEN): false only if P true, Q false\n- P ↔ Q (IF AND ONLY IF): true if same truth value\n\n```python\nfrom itertools import product\n\ndef truth_table(op):\n print('P | Q | P→Q')\n for p, q in product([True, False], repeat=2):\n result = op(p, q)\n print(f'{p} | {q} | {result}')\n\ndef implies(p, q):\n return (not p) or q\n\ntruth_table(implies)\n# Output:\n# True | True | True\n# True | False | False\n# False | True | True\n# False | False | True\n```\n\n**De Morgan's Laws:**\n- ¬(P ∧ Q) = ¬P ∨ ¬Q\n- ¬(P ∨ Q) = ¬P ∧ ¬Q\n\n**Modus Ponens:** If P→Q and P, then Q.\n**Modus Tollens:** If P→Q and ¬Q, then ¬P."}}