Introduction

The core philosophy of DeepSeek Harness (DSH) is “everything is a plugin.” During model inference development, developers often need to handle expanding logical expressions, enumerating truth tables, converting canonical forms, and minimizing logic functions. Manual calculation can easily lead to errors in applying De Morgan’s laws or drawing Karnaugh maps. dsh-boolean is a Boolean algebra toolbox designed for DSH. It parses propositional logic expressions and provides complete truth tables, minimum sum-of-products, and canonical form conversions without relying on an external runtime environment.

Installation and Activation

Installing this plugin requires ensuring that the system pnpm is in PATH. Run the following command in the terminal:

dsh plugin --profile web add github:TYEclipse/dsh-boolean

After installation is complete, restart the profile session (or start a new session). The five tools provided by the plugin will be registered as tools and can be invoked by the Agent.

Core Features

This plugin includes the following core capabilities:

  1. Truth table enumeration: Supports complete truth tables for up to 8 variables (256 rows), including results, minterm/maxterm indices, flags such as tautology, contradiction, and satisfiability, and canonical DNF and CNF strings.
  2. Logic evaluation: Evaluates the expression under a given assignment. If a variable is not listed in trueVars or falseVars, an error is reported instead of silently defaulting.
  3. Equivalence check: Compares the results of two expressions across all rows. If they are not equivalent, it reports the number of differing rows and provides a specific counterexample.
  4. Canonical conversion: Converts an expression to NNF (negation normal form), DNF (disjunctive normal form), CNF (conjunctive normal form), and gate networks using only NAND or only NOR.
  5. Minimization: Uses the Quine-McCluskey algorithm to minimize the expression to the minimum sum of products, supporting optional “don’t-care” terms.

Expression Syntax

The plugin supports the following operators:

Meaning Symbol Word Unicode
NOT (prefix) ! not ¬
AND & and ∧
XOR ^ xor ⊕
OR \| or ∨
IMPLIES -> => implies →
IFF <-> <=> iff ↔
  • Variables must be single letters a–z (uppercase letters are normalized to lowercase).
  • Operator precedence: NOT > AND > XOR > OR > IMPLIES > IFF.
  • Binary operators are left-associative. XOR, IMPLIES, and IFF are converted to canonical NOT/AND/OR forms during parsing.

Typical Usage

The following examples show how to invoke these tools:

1. Generate a Truth Table

View the truth table for a ^ b and its canonical forms:

truth_table { expr: "a ^ b" }

Sample output:

rows: m0(00)=0, m1(01)=1, m2(10)=1, m3(11)=0
minterms [1,2]  DNF = (!a & b) | (a & !b)
maxterms [0,3]  CNF = (a | b) & (!a | !b)

2. Logic Evaluation

Evaluate the result of a -> (b | c) under a specific assignment:

logic_eval { expr: "a -> (b | c)", trueVars: ["a"], falseVars: ["b","c"] }

Sample output:

a -> (b | c) with a=true, b=false, c=false = false

3. Equivalence Check

Verify De Morgan’s law !(a | b) == !a & !b:

logic_equiv { exprA: "!(a | b)", exprB: "!a & !b" }

Sample output:

equivalent: !(a | b) == !a & !b (all 4 rows agree)

4. Canonical Form Conversion

Convert !(a & b) to NNF and a & b to a NAND-only network form:

logic_convert { expr: "!(a & b)", operation: "nnf" }  # 结果: !a | !b
logic_convert { expr: "a & b",   operation: "nand" }  # 结果: NAND(NAND(a,b),NAND(a,b))

5. Logic Minimization

Minimize ((a & b) | (a & c)) | (b & c) and optimize using don’t-care terms:

logic_minimize { expr: "((a & b) | (a & c)) | (b & c)" }
# 结果: a & b | a & c | b & c (3 terms, 6 literals, proven minimum, unique)

logic_minimize { expr: "a & !b & c | a & !b & !c", dontCare: [6, 7] }
# 结果: a (1 term, 1 literal; the prime implicant covers m[4,5] and the don't-cares dc[6,7])

Notes

  1. Variable limit: The truth table tool has a maximum of 8 variables (256 rows). NNF/NAND/NOR conversions are structural rewrites and have no variable limit.
  2. Evaluation requirements: logic_eval requires every variable in the expression to appear in trueVars or falseVars; none can be omitted.
  3. Gate network output syntax: Output uses function-call syntax, such as NAND(a,b) or NOR(a,b). NOT(x) is written as NAND(x,x) or NOR(x,x). The input syntax does not accept gate names; conversion is required first.
  4. Special results: logic_minimize returns an empty string for a constant false function and 1 for a constant true function.
  5. License: This plugin follows the MIT License, and the source code is available for public review.