Overview
QWED-Logic is an S-expression based DSL for expressing logical constraints. It’s verified by the Z3 SMT solver for mathematical correctness.Why S-expressions? They’re unambiguous, easy to parse, and map directly to Z3 constraints.
Basic syntax
Logical operators
| Operator | Meaning | Example |
|---|---|---|
AND | Logical AND | (AND a b c) |
OR | Logical OR | (OR a b) |
NOT | Logical NOT | (NOT a) |
IMPLIES | Implication (a → b) | (IMPLIES a b) |
IFF | Biconditional (a ↔ b) | (IFF a b) |
XOR | Exclusive OR | (XOR a b) |
Examples
Comparison operators
| Operator | Meaning | Example |
|---|---|---|
EQ | Equal (=) | (EQ x 5) |
NE | Not equal (≠) | (NE x 0) |
GT | Greater than | (GT x 5) |
LT | Less than | (LT x 10) |
GE | Greater or equal (≥) | (GE x 0) |
LE | Less or equal (≤) | (LE x 100) |
Examples
Arithmetic operators
| Operator | Meaning | Example |
|---|---|---|
PLUS | Addition (+) | (PLUS x y) |
MINUS | Subtraction (-) | (MINUS x y) |
TIMES | Multiplication (*) | (TIMES x y) |
DIV | Division (/) | (DIV x y) |
MOD | Modulo (%) | (MOD x 2) |
POW | Power (^) | (POW x 2) |
ABS | Absolute value | (ABS x) |
Examples
Quantifiers
| Operator | Meaning | Example |
|---|---|---|
FORALL | For all (∀) | (FORALL (x) (GT x 0)) |
EXISTS | There exists (∃) | (EXISTS (x) (EQ x 5)) |
Examples
Special types
Boolean literals
Integer constraints
Array/list operations
Complete examples
Example 1: age validation
Example 2: budget constraint
Example 3: password rules
Example 4: scheduling constraint
Example 5: quadratic equation
Verification results
| Status | Meaning | Model |
|---|---|---|
SAT | Satisfiable — solution exists | {x: 6, y: 4} |
UNSAT | Unsatisfiable — no solution | null |
UNKNOWN | Solver timeout or undecidable | null |
Reading results
API usage
Python
CLI
HTTP API
Common patterns
Range check
Non-empty string
Mutual exclusion
At most one
Exactly one
Error handling
| Error | Cause | Fix |
|---|---|---|
PARSE_ERROR | Invalid syntax | Check parentheses matching |
UNKNOWN_OPERATOR | Typo in operator | Use valid operator names |
TYPE_ERROR | Incompatible types | Check operand types |
TIMEOUT | Constraint too complex | Simplify or set longer timeout |