Sys2DSL (System 2 Domain-Specific Language) is a minimal, uniform language where every statement encodes semantic relationships as Subject-Verb-Object triplets. All concepts, facts, and operations are represented as vectors.
Atoms, operators, facts, roles, and theories are ALL represented as hypervectors. The DSL provides human-readable syntax that compiles to vector operations.
@destination operator arg1 arg2 arg3 ...
Every statement has:
# Simple fact
@fact1 loves John Mary
# With numeric argument
@sale sell Alice Bob Car 1000
# Query with hole (unknown value)
@answer buy ?who Book ?seller ?price
# Discard result (underscore)
@_ Load $Commerce
| Token | Syntax | Purpose | Example |
|---|---|---|---|
@var |
Declaration | Create and assign variable | @f1 loves John Mary |
@var:name |
Export | Create variable and export as name | @Person:Person __Atom |
@_ |
Discard | Execute but don't store result | @_ Load $Theory |
$var |
Reference | Access existing variable | @f2 isA $John Person |
?var |
Hole | Unknown value to find | @q loves ?who Mary |
name |
Literal | Atom from vocabulary | John, loves |
# |
Comment | Ignored until end of line | # This is a comment |
Names follow a prefix convention indicating abstraction level:
| Level | Prefix | Purpose | User | Example |
|---|---|---|---|---|
| L0 | ___ |
HDC primitives | Runtime only | ___Bind |
| L1 | __ |
Structural operations | Core theory | __Atom, __Bundle |
| L2 | _ |
Semantic primitives | Knowledge engineers | _ptrans, _atrans |
| L3+ | (none) | Domain concepts | End users | Person, loves |
Theories are named collections of atoms, macros, and rules:
@TheoryName theory GEOMETRY INIT_MODE
# Atom definitions
@AtomName:AtomName __Atom
# Exported atoms
@Person:Person __Category
@Place:Place __Category
# Macros
@MyMacro:myMacro macro param1 param2
# macro body
@result __Bundle $param1 $param2
return $result
end
# Rules
@rule1 Implies (isA ?x Human) (isA ?x Mortal)
end
| Parameter | Values | Description |
|---|---|---|
| GEOMETRY | 1024, 8192, 32768, 65536 | Vector dimension in bits |
| INIT_MODE | deterministic, random |
How atoms are initialized |
Macros are reusable statement templates:
@MacroName:exportName macro param1 param2 param3
# Statements using parameters
@local1 someOp $param1 $param2
@local2 otherOp $local1 $param3
# Return value
return $local2
end
# Define macro
@DefinePerson:person macro name age occupation
@p1 isA $name Person
@p2 hasAge $name $age
@p3 hasJob $name $occupation
@result __Bundle $p1 $p2 $p3
return $result
end
# Use macro
@john person John 30 Engineer
@mary person Mary 25 Doctor
Queries use ? prefix for unknown values (holes):
# Single hole - "Who loves Mary?"
@q1 loves ?who Mary
# Multiple holes - "Who bought what from whom?"
@q2 buy ?buyer ?item ?seller
# Mixed known and unknown
@q3 sell Alice ?what Bob
QueryResult {
success: true,
bindings: {
"who": { answer: "John", similarity: 0.78, alternatives: [...] }
},
confidence: 0.78,
ambiguous: false
}
| Operation | Description |
|---|---|
___Bind A B |
XOR of two vectors |
___Bundle [A B C] |
Majority vote of vectors |
___Similarity A B |
Similarity score (0.0-1.0) |
| Operation | Description |
|---|---|
__Atom |
Create new atom |
__Bundle |
Create set/superposition |
__Role name vector |
Tag vector with semantic role |
__Category |
Define type category |
| Operation | Description | Example |
|---|---|---|
Implies A B |
If A then B | @r Implies (isA ?x Human) (isA ?x Mortal) |
And A B |
Both A and B | @c And $cond1 $cond2 |
Or A B |
Either A or B | @d Or $opt1 $opt2 |
Not A |
Negation of A | @n Not $fact |
ForAll ?x P |
Universal quantification | ForAll ?x (Implies (Human ?x) (Mortal ?x)) |
Exists ?x P |
Existential quantification | Exists ?x (loves ?x Mary) |
# Load a theory
@_ Load $TheoryName
# Create session-local fact
@myFact someRelation Subject Object
# Query knowledge base
@result query loves ?who Mary
# Prove a goal
@proof prove isA Socrates Mortal
# ============ Theory Definition ============
@Family theory 32768 deterministic
# Types
@Person:Person __Category
@Relationship:Relationship __Category
# Relation atoms
@loves:loves __Relation
@parent:parent __Relation
@sibling:sibling __Relation
# Rule: siblings share parent (using reference-based composition)
# Note: Parenthesized expressions are NOT supported.
# Complex rules are built by defining parts as separate statements.
@p1 parent ?p ?x
@p2 parent ?p ?y
@notSame Not equals ?x ?y
@siblingCond And $p1 $p2 $notSame
@siblingConc sibling ?x ?y
@siblingRule Implies $siblingCond $siblingConc
end
# ============ Session Usage ============
# Load theory
@_ Load $Family
# Add facts
@f1 parent Alice Charlie
@f2 parent Alice Diana
@f3 parent Bob Charlie
@f4 parent Bob Diana
@f5 loves Charlie Diana
# Query: Who are Charlie's siblings?
@q sibling Charlie ?who
# Result: ?who = Diana (confidence: 0.82)
| Error | Cause | Solution |
|---|---|---|
| Undefined reference: $name | Variable not in scope | Define variable first or load theory |
| Unexpected token: X | Syntax error | Check statement format |
| Theory not found: Name | Theory file missing | Verify theory path |
| Low confidence: 0.45 | Query match is weak | Refine query or add facts |