The Language Layer transforms structured Sys2DSL commands into operations on the Knowledge Layer. It validates syntax, builds abstract representations, and encodes parsed structures into geometric points. This layer is the bridge between human-readable commands and the mathematical operations that implement reasoning.
Specification: DS(/theory/dsl_engine) · DS(/theory/grammar) · DS(/theory/encoder)
Sys2DSL (System 2 Domain-Specific Language) is a constrained language designed for knowledge representation and querying. Its key properties:
Translation paths to Sys2DSL. The Chat Interface uses an LLM to translate natural language. The Raw CLI accepts Sys2DSL directly. Both paths produce the same structured commands that the engine executes.
Sys2DSL commands follow a consistent grammar. The full syntax reference is in the Syntax Guide.
| Command | Syntax | Purpose |
|---|---|---|
| ASSERT | ASSERT Subject RELATION Object |
Add a fact to the knowledge base |
| ASK | ASK "Subject RELATION Object?" |
Query for truth value |
| RETRACT | RETRACT Subject RELATION Object |
Remove a fact |
| THEORY_PUSH | THEORY_PUSH name="name" |
Create new theory layer |
| THEORY_POP | THEORY_POP |
Discard top theory layer |
| FACTS_MATCHING | FACTS_MATCHING pattern |
Query for matching facts |
Relations are predefined keywords that specify the semantic relationship between subject and object:
// Taxonomic relations IS_A, HAS_INSTANCE, PART_OF, HAS_PART // Causal relations CAUSES, CAUSED_BY, ENABLES, PREVENTS // Spatial relations LOCATED_IN, CONTAINS, NEAR, FAR_FROM // Temporal relations BEFORE, AFTER, DURING, OVERLAPS // Property relations HAS_PROPERTY, HAS_VALUE, HAS_ATTRIBUTE // Deontic relations PERMITS, PROHIBITS, OBLIGATES, PERMITTED_BY, PROHIBITED_BY // Similarity SIMILAR_TO, DIFFERENT_FROM
See Relations Reference for the complete list with semantics.
The DSL Parser validates syntax and produces an Abstract Syntax Tree (AST). The parser is deterministic and produces consistent output regardless of whitespace or formatting variations.
// Input: "ASSERT Dog IS_A Animal"
// Output AST:
{
type: "ASSERT",
subject: { type: "Identifier", value: "Dog" },
relation: { type: "Relation", value: "IS_A" },
object: { type: "Identifier", value: "Animal" }
}
Parse errors include line number, column, and expected vs. actual tokens:
ParseError at line 3, column 15:
Expected: RELATION keyword (IS_A, CAUSES, PART_OF, ...)
Found: "belongs_to"
Context: "ASSERT Dog belongs_to Person"
^^^^^^^^^
The Fact Encoder transforms parsed AST nodes into geometric representations. It applies relation-specific permutations and combines vectors to create encodings suitable for storage and comparison.
Fact encoding process. The encoder retrieves base vectors for subject and object, gets the relation-specific permutation, applies the permutation to the object vector, and combines with saturating addition to produce the encoded fact.
encode(S, R, O) = v(S) + π_R(v(O)) where: v(X) = base vector for concept X π_R = permutation for relation R + = saturating addition (clamped to [-127, 127])
The Query Compiler transforms ASK commands into retrieval and reasoning operations. It determines the query type, identifies required concepts, and prepares the execution plan.
| Pattern | Type | Operation |
|---|---|---|
ASK "S R O?" |
Yes/No | Inclusion check of S in O via R |
ASK "S R ?" |
What | Find all O where S R O is true |
ASK "? R O" |
Who/What | Find all S where S R O is true |
ASK "? R ?" |
List | List all facts with relation R |
Commands can be stored in files, versioned in git, and executed in CI pipelines:
# test_taxonomy.sys2dsl ASSERT Dog IS_A Mammal ASSERT Mammal IS_A Animal ASK "Dog IS_A Animal?" # Expected: TRUE_CERTAIN
Every operation is logged with its exact command, enabling complete audit trails:
2024-01-15 10:23:45 [INFO] ASSERT Dog IS_A Animal → OK 2024-01-15 10:23:46 [INFO] ASK "Dog IS_A Animal?" → TRUE_CERTAIN (0.95) 2024-01-15 10:23:47 [INFO] THEORY_PUSH name="experiment_1" → depth=1
The deterministic grammar ensures that replaying the same command sequence always produces identical results—essential for debugging and verification.