evaluate-boolean-expression
关于
This skill evaluates and simplifies Boolean expressions using truth tables, algebraic laws, and Karnaugh maps for up to six variables. It reduces expressions to minimal sum-of-products or product-of-sums forms and verifies logical equivalence. Use it to prepare minimized functions for gate-level implementation or to analyze digital logic.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/evaluate-boolean-expression在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Evaluate Boolean Expression
Reduce Boolean expr → minimal form. Parse → canonical, truth table, algebraic laws, K-map (≤6 vars), verify equivalent to original.
Use When
- Simplify before map to gates
- Verify 2 exprs equivalent
- Generate minimal SOP or POS
- Teach/review Boolean algebra
- Prep for design-logic-circuit
In
- Required: Boolean expr any common notation (e.g.,
A AND (B OR NOT C),A * (B + C'),A & (B | ~C)) - Required: Target form — minimal SOP, POS, or both
- Optional: Variable ordering preference for K-map
- Optional: Don't-care conditions (minterms/maxterms unspecified)
- Optional: Second expr for equivalence check
Do
Step 1: Parse + Canonical
Convert to standard internal rep.
- Tokenize: Vars (letters/short names), ops (AND, OR, NOT, XOR, NAND, NOR), parens.
- Op notation: Consistent —
*AND,+OR,'NOT,^XOR. - Var count: Unique vars. Assign bit (A=MSB, ... Z=LSB default or provided).
- Canonical SOP: Expand → sum of all minterms via
X = X*(Y + Y'). - Canonical POS: Alt → product of all maxterms via
X = X + Y*Y'.
## Normalized Expression
- **Variables**: [A, B, C, ...]
- **Variable count**: [n]
- **Original expression**: [as given]
- **Canonical SOP (minterms)**: Sigma m(i, j, k, ...)
- **Canonical POS (maxterms)**: Pi M(i, j, k, ...)
- **Don't-care set**: d(i, j, ...) [if any]
→ Expr converted canonical SOP/POS w/ all min/maxterms listed, don't-cares separated.
If err: syntax/precedence ambiguous → clarify. Standard: NOT (highest) > AND > XOR > OR (lowest). >6 vars → K-map needs Quine-McCluskey.
Step 2: Truth Table
Build complete table for behavior over all inputs.
- Rows: All 2^n combos binary order (000, 001, 010, ...).
- Eval: Sub values → compute output (0/1).
- Don't-cares: Mark
Xinstead of 0/1. - Cross-check minterms: Rows w/ output 1 match minterm list Step 1.
## Truth Table
| A | B | C | F |
|---|---|---|---|
| 0 | 0 | 0 | _ |
| 0 | 0 | 1 | _ |
| ... | ... | ... | ... |
→ Complete 2^n rows, outputs match canonical, don't-cares marked.
If err: table disagrees w/ canonical → recheck Step 1 expansion. Common: misapply De Morgan during canonical → verify each step.
Step 3: Algebraic Simplify
Reduce via Boolean identities.
- Identity/null:
A + 0 = A,A * 1 = A,A + 1 = 1,A * 0 = 0. - Idempotent:
A + A = A,A * A = A. - Complement:
A + A' = 1,A * A' = 0. - Absorption:
A + A*B = A,A * (A + B) = A. - De Morgan:
(A * B)' = A' + B',(A + B)' = A' * B'. - Distributive:
A * (B + C) = A*B + A*C,A + B*C = (A + B) * (A + C). - Consensus:
A*B + A'*C + B*C = A*B + A'*C(B*C redundant). - XOR:
A*B' + A'*B = A ^ B. - Document each step: Expr after each law, cite law.
## Algebraic Simplification Trace
1. Original: [expression]
2. Apply [law name]: [result]
3. Apply [law name]: [result]
...
n. Final algebraic form: [simplified expression]
→ Step-by-step reduction w/ law citations, converging simpler. Trace = verifiable proof.
If err: no further simplify but non-minimal → Step 4 (K-map). Algebraic ≠ guaranteed global min — depends on order.
Step 4: K-map Minimize
Provably minimal SOP/POS (≤6 vars).
- Draw: Gray code on axes.
- 2 vars: 2x2
- 3 vars: 2x4
- 4 vars: 4x4
- 5 vars: two 4x4 stacked
- 6 vars: four 4x4 stacked
- Fill: 1s (minterms), 0s (maxterms), Xs (don't-cares).
- Group adj 1s: Rectangular groups of 1, 2, 4, 8, 16, 32 (powers of 2). Wrap edges. Include don't-cares if enlarge.
- Prime implicants: Each group → product term. Constant vars appear, changing eliminated.
- Essential prime implicants: Minterms covered by only 1 PI → essential.
- Cover remaining: Fewest additional PIs (Petrick's if needed).
- Minimal expr: Combine selected PIs → minimal SOP. For POS group 0s.
## K-map Result
- **Prime implicants**: [list with covered minterms]
- **Essential prime implicants**: [list]
- **Minimal SOP**: [expression]
- **Minimal POS**: [expression, if requested]
- **Literal count**: [number of literals in minimal form]
→ Minimal SOP/POS fewest literals, all PIs documented.
If err: ambiguous (multiple minimal covers) → list all equivalent. >6 vars → Quine-McCluskey tabular or Espresso heuristic, note change.
Step 5: Verify
Confirm logical equivalence simplified vs original.
- Truth table compare: Eval simplified all 2^n → compare Step 2. Every non-don't-care row must match.
- Algebraic proof (optional): Derive original from simplified (vice versa) via Step 3 laws.
- Spot-check: All-zeros, all-ones, tricky simplification inputs.
- Document: Equivalence holds? Final minimal form.
## Equivalence Verification
- **Method**: [truth table comparison / algebraic proof / both]
- **Mismatched rows**: [none, or list row numbers]
- **Verdict**: [Equivalent / Not equivalent]
- **Final minimal expression**: [the verified result]
→ Simplified matches original all non-don't-care. Final min form clear.
If err: mismatch → trace Steps 3-4. Common: incorrect K-map grouping (non-rect / non-power-of-2), forget wrap, group 0 cell.
Check
- All vars accounted for
- Canonical SOP/POS lists correct min/maxterms
- Truth table 2^n rows correct outputs
- Don't-cares handled (in groups, not coverage req)
- Algebraic steps cite law + verifiable
- K-map Gray code both axes
- All groups rect + power-of-2
- Essential PIs identified
- Simplified matches on non-don't-care
- Final = min literals
Traps
- K-map adjacency: Leftmost/rightmost cols + top/bottom rows adjacent (wrap). Essential for largest groups.
- Non-power-of-2 groups: 3 or 5 cells. Must be 1, 2, 4, 8, 16, 32. Irregular ≠ valid product.
- Ignore don't-cares: Treating as 0s not using to enlarge. Include when reduces, but not required for coverage.
- Precedence err: Assuming AND/OR equal. Standard: NOT > AND > OR.
A + B * C≠(A + B) * C. - Stop at algebraic: Local min not global. Cross-check K-map (Quine-McCluskey >6 vars) to confirm.
- Min vs maxterm: Minterms = AND (products) in SOP. Maxterms = OR (sums) in POS. m3 3 vars = A'BC; M3 = A+B'+C'.
→
design-logic-circuit— map minimized expr → gate-levelargumentation— structured logical reasoning, shares formal logic
GitHub 仓库
相关推荐技能
executing-plans
设计该Skill用于当开发者提供完整实施计划时,以受控批次方式执行代码实现。它会先审阅计划并提出疑问,然后分批次执行任务(默认每批3个任务),并在批次间暂停等待审查。关键特性包括分批次执行、内置检查点和架构师审查机制,确保复杂系统实现的可控性。
requesting-code-review
设计该Skill可在完成任务、实现主要功能或合并代码前自动调度代码审查子代理,确保实现符合需求和计划。它支持通过指定git SHA范围进行精准的代码变更审查,帮助开发者在关键节点及时发现潜在问题。核心原则是"早审查、勤审查",适用于开发流程的各个关键阶段。
connect-mcp-server
设计这个Skill指导开发者如何将MCP服务器连接到Claude Code,支持HTTP、stdio和SSE三种传输协议。它涵盖了从安装配置到认证安全的完整流程,适用于集成GitHub、Notion、数据库等外部服务。当开发者需要添加集成、配置外部工具或提及MCP相关功能时,这个Skill能提供实用的操作指南。
web-cli-teleport
设计该Skill帮助开发者根据任务特性选择Claude Code的Web或CLI界面,并指导如何在两种环境间无缝迁移会话。它能分析任务复杂度、迭代需求等要素,推荐最优工作界面和工作流。关键特性包括会话状态管理、环境切换指导和上下文优化建议。
