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 |