Skip to main content

Composing predicates

Composition is postfix (RPN) over predicate indices, using LogicToken values:

export const LogicToken = {
REF: 0,
AND: 1,
OR: 2,
NOT: 3,
} as const;

Example: (P0 AND P1) OR P2

Represent each REF with value = predicate index; boolean operators set value: 0 (unused).

logicExpression: [
{ type: LogicToken.REF, value: 0 },
{ type: LogicToken.REF, value: 1 },
{ type: LogicToken.AND, value: 0 },
{ type: LogicToken.REF, value: 2 },
{ type: LogicToken.OR, value: 0 },
],

Why postfix

The design README explains stack evaluation, avoiding precedence parsing inside the circuit (generalized-predicates/README.md — Why Postfix).

Mermaid: evaluation stack

Pass the composed logicExpression through showInputOptions on present (Show phase).