Variable: Constraint
@kortexya/reasoninglayer / Constraint
Variable: Constraint
constConstraint:object
Defined in: src/builders/constraint.ts:57
Builders for the chainer’s homoiconic meta-constraints. Each function
returns a single TermInputArg representing one constraint term — drop
the result into a clause body or rule antecedents.
Type Declaration
equation()
readonlyequation(result,op,left,right):TermInputArg
State that result = left op right. Selects the chainer sort by op:
+ → plus_constraint, - → minus_constraint, * →
times_constraint, / → div_constraint. The chainer reads each
operand as either a Reference variable or a numeric literal, and can
run forward, reverse, or verify depending on which operands are
bound.
Parameters
result
Result variable or value (z).
op
Arithmetic operator.
left
Left operand (x).
right
Right operand (y).
Returns
The appropriate arithmetic-constraint term.
has()
readonlyhas(variable,feature,target):TermInputArg
State that a variable’s feature equals a target. The chainer unifies the variable’s feature value with the target.
Important: the chainer’s feature_constraint only unifies
term-references with term-references. The variable’s feature on the
persisted side must itself be a Value::Reference. Comparing against
literals (e.g. has('?N', 'name', 'S') where name is stored as a
plain string) silently returns zero solutions — that’s a chainer
design constraint, not a builder bug.
Parameters
variable
string
The owning variable (e.g. '?Edge').
feature
string
The feature name (e.g. 'src').
target
The target — typically another variable ('?Src')
or an existing term referenced by its UUID via '!<uuid>'.
Returns
A feature_constraint term.
intRange()
readonlyintRange(variable,min,max):TermInputArg
Constrain a variable to be an integer in the inclusive range
[min, max]. Required before the chainer’s labeling step can assign
a concrete value via Constraint.solveFor.
Parameters
variable
string
Variable name to constrain.
min
number
Lower bound (inclusive).
max
number
Upper bound (inclusive).
Returns
An fd_domain_constraint term.
solveFor()
readonlysolveFor(…variables):TermInputArg
Search for concrete integer assignments to the listed variables that satisfy every other constraint mentioning them. Place this at the END of a clause body — it’s the labeling/search step that turns a constraint network into solutions.
Parameters
variables
…string[]
Variable names to assign.
Returns
An fd_labeling_constraint term.
typeOf()
readonlytypeOf(variable,sortUuid):TermInputArg
State that a variable is a term of a given sort. The chainer enumerates every persisted term of that sort via backtracking.
Parameters
variable
string
Variable name (e.g. '?E') or pre-built variable Ψ-term.
sortUuid
string
UUID of the target sort (resolve from
client.inference.getMetaSorts() or your own createSort response).
Returns
A sort_constraint term.
where()
readonlywhere(left,op,right):TermInputArg
State a boolean comparison between two operands. The chainer residuates the constraint until both sides are bound; when they are, the comparison must hold or the proof branch fails.
Parameters
left
Left operand — variable, literal number, or term ref.
op
Comparison operator.
right
Right operand.
Returns
A guard_constraint term.
Remarks
These wrap the underlying meta-sort names (sort_constraint,
feature_constraint, guard_constraint, plus_constraint, etc.) and
use the exact feature keys the chainer reads. Hand-rolled psi('...')
calls with guessed keys silently fail — use these builders instead.
Example
import { Constraint, psi } from '@kortexya/reasoninglayer';
// "?E is a term of sort flow_edge_constraint, with edges leaving X"const body = [ Constraint.typeOf('?E', flowEdgeSortUuid), Constraint.has('?E', 'src', '?X'), Constraint.has('?E', 'dst', '?Y'), Constraint.has('?E', 'cap', '?C'), Constraint.intRange('?Amount', 1, 100), Constraint.where('?Amount', '<=', '?C'), Constraint.solveFor('?Amount'),];