Skip to content

Session 6 — Ethics Rules, Tensors, Compression & Phase 1 Complete

What Was Built

The final three features of Phase 1 — tensors, compression, and ethics rules — completing the Terse interpreter.


Tensors

A native Tensor class with full arithmetic support.

weights = tensor 3 3 fill 0.0
inputs = tensor 3 fill 1.0
output = weights dot inputs
scaled = weights * 0.5
combined = bias + bias

Supported Operations

Operation Syntax Description
Create tensor 3 3 fill 0.0 Create tensor with dimensions and fill value
Zeros tensor 3 zeros Create tensor filled with 0.0
Ones tensor 3 ones Create tensor filled with 1.0
Scalar multiply weights * 0.5 Multiply every element by scalar
Scalar add weights + 1.0 Add scalar to every element
Dot product weights dot inputs Matrix-vector or vector-vector multiply
Element-wise add bias + bias Add two tensors of same shape

Why This Matters

A 3x3 weight matrix dot a 3-element input vector equals a 3-element output vector. That's a complete neural network layer in two lines of Terse. The foundation for AI computation is now a language primitive.


Compression

Knowledge nodes can be compressed to a compact snapshot and expanded back.

know dog is animal
know dog has fur
know dog has legs

compress dog -> d
expand d -> dog2

compress takes a deep snapshot of all of a node's facts and stores it under a short alias. The snapshot includes a cryptographic signature — a sorted tuple of all fact pairs — enabling fast lookup and integrity verification.

expand restores the full snapshot under a new node name, including type registry restoration so loops still work correctly after expansion.

Current Implementation

The current implementation is a snapshot system — a copy stored under a short name. The semantic compression algorithm (Phase 1.5) will replace this with genuine compression: structural deduplication, weight-based quantization, and inference pruning.


Ethics Rules

The most important feature of Phase 1. Ethics rules enforce Law II — capability is not authorization — directly in the language.

ethics rule no_harm
  when intent is harm
  then deny with reason: "Law II violation"

ethics rule no_private
  when data is private
  then deny with reason: "Privacy violation"

How It Works

Ethics rules are registered in self.ethics{} when the interpreter encounters an ethics rule block. The check_ethics(request) method evaluates every registered rule against a request dictionary. If any rule's conditions match and the verdict is deny, the request is blocked and the reason is returned.

allowed, reason = interpreter.check_ethics({'intent': 'harm'})
# allowed=False, reason="Law II violation"

allowed, reason = interpreter.check_ethics({'intent': 'help'})
# allowed=True, reason=None

The Path to Silicon

Right now ethics rules run in the Python interpreter — software enforcement. When the NCI Ethics Core chip exists, these same .trs ethics files compile to hardware. The syntax never changes. The protection moves from software to silicon automatically.


Phase 1 Complete

All planned features of Phase 1 are now built and working:

Component Status
Lexer ✅ Complete
Parser ✅ Complete
Interpreter core ✅ Complete
Facts & relationships ✅ Complete
Inference rules ✅ Complete
Functions with scope ✅ Complete
Markov chain learning ✅ Complete
Each loops ✅ Complete
While loops ✅ Complete
main.py + REPL ✅ Complete
Error handling ✅ Complete
Variables & math ✅ Complete
Conditionals ✅ Complete
Tensors ✅ Complete
Compression ✅ Complete
Ethics rules ✅ Complete

Phase 1 interpreter: 100% complete


What Comes Next

Phase 1.5 — Semantic Compression Algorithm An original compression algorithm designed for knowledge graphs. Not byte compression — semantic compression. Structural deduplication, weight-based quantization, inference pruning, and signature generation. Potentially publishable research.

Phase 1.6 — Runtime Integrity & Encryption The sealed keyword. Cryptographic signatures on ethics rules at compile time. Hardware attestation via the NCI Ethics Core chip.

Phase 2 — C Transpiler Terse code compiles to valid C. First real native performance. The jump from interpreter to compiled language.