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 Overview

Sys2DSL (System 2 Domain-Specific Language) is a constrained language designed for knowledge representation and querying. Its key properties:

Natural Language "Dogs are mammals" "Fire causes smoke" "Is a cat an animal?" LLM Translation (Chat mode) Optional Sys2DSL ASSERT Dog IS_A Mammal ASSERT Fire CAUSES Smoke ASK "Cat IS_A Animal?" Engine Geometry ops Direct (Raw CLI)

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.

Grammar Structure

Sys2DSL commands follow a consistent grammar. The full syntax reference is in the Syntax Guide.

Command Types

CommandSyntaxPurpose
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

Relation Types

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.

Parser

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.

Parsing Stages

  1. Tokenization – Split input into tokens (keywords, identifiers, operators)
  2. Syntax validation – Verify token sequence matches grammar rules
  3. AST construction – Build tree representation of command
  4. Semantic validation – Check relation compatibility, identifier validity
// 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" }
}

Error Handling

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"
                       ^^^^^^^^^

Fact Encoder

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.

AST Node S: Dog R: IS_A O: Animal Get Vectors v(Dog), v(Animal) Get Permutation π(IS_A) Permute Object π(IS_A)(v(Animal)) Combine v(Dog) + π(v(Animal)) Encoded Fact

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.

Encoding Formula

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])

Query Compiler

The Query Compiler transforms ASK commands into retrieval and reasoning operations. It determines the query type, identifies required concepts, and prepares the execution plan.

Query Types

PatternTypeOperation
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

Benefits of Sys2DSL

Testability

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

Auditability

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

Reproducibility

The deterministic grammar ensures that replaying the same command sequence always produces identical results—essential for debugging and verification.

Related Documentation