This page groups the syntax, tensor-logic primitives, static checks, and algebraic semantics. Read it as the specification layer: what a TensorLang program can say before we discuss evidence, backends, or model workflows.
TensorLang programs are S-expressions describing modules, domains, typed tensors, sparse COO tensors, named-axis equations, semirings, joins, projections, fixed points, properties, trainable tensor fragments, and dynamical systems. The surface is intentionally minimal so that semantics and tooling stay legible.
(module examples.family (tensorlang "1.5") (domain Person (size 4) (labels "alice" "bob" "carol" "dave")) (tensor parent (type Bool) (shape Person Person) (data (row 0 1 0 0) (row 0 0 1 0) (row 0 0 0 1) (row 0 0 0 0))))
(semiring bool-or-and (type Bool) (zero false) (one true) (add or) (mul and) (order subset)) (def ancestor (type Bool) (shape Person Person) (expr (fixpoint A (type Bool) (shape Person Person) (semiring bool-or-and) (init parent) (step (or parent (semiring-einsum bool-or-and "Src Mid, Mid Dst -> Src Dst" A parent))) (max-steps 8))))
(sparse-tensor user_role (type Bool) (shape User Role) (coords (row "alice" "reviewer") (row "bob" "admin"))) (def user_role_action (type Bool) (shape User Role Action) (expr (join "User Role, Role Action -> User Role Action" user_role role_action))) (def can_do (type Bool) (shape User Action) (expr (project user_role_action "User" "Action"))) (def gathered_embedding (type F64) (shape Sample Feature) (expr (embedding entity_embedding entity_ids))) (def accumulated_updates (type F64) (shape Entity Feature) (expr (scatter-add entity_ids sample_updates Entity)))
(module examples.dynamics (tensorlang "1.5") (domain State (size 2) (labels "r0" "r1")) (domain Input (size 1) (labels "u0")) (system TinyReservoir (time continuous (dt 0.1) (steps 3)) (state x (type F64) (shape State) (init (data 0.1 -0.1))) (input u (type F64) (shape Input) (data 1.0)) (param W (type F64) (shape State State) (data (row 0.0 1.0) (row -1.0 0.0))) (dynamics (= dx/dt (tanh (+ (einsum "ij,j->i" W x) u))))))
TensorLang now has a direct language layer for the tensor-logic idea: relations as sparse Boolean tensors, Datalog-like rules as joins and projections, and embedding workflows as gather/scatter tensor operations.
Readable specs such as "Sample Feature, Entity Feature -> Sample Entity" normalize to compact einsum labels while preserving declared output shapes.
Relations and embeddings can be declared by coordinates, with domain labels accepted in coordinate rows.
Finite Bool relation joins are explicit tensor expressions and also lower into relational-algebra plans.
Projection existentially OR-reduces omitted Bool axes, matching the relation view of Datalog-style rules.
I64 ID tensors select rows or slices from numeric tables while keeping TensorLang shape metadata.
Numeric updates accumulate into an output domain, connecting indexed examples back to tensor state.
tl check examples/32_tensor_logic_primitives.tl tl eval examples/32_tensor_logic_primitives.tl can_do --pretty tl lower-relalg examples/32_tensor_logic_primitives.tl user_role_action tl infer examples/32_tensor_logic_primitives.tl accumulated_updates
This is TensorLang's independent tensor-logic-inspired surface, not a compatibility claim for the Tensor Logic paper. The implemented subset is intentionally concrete: named axes, finite Bool relations, sparse COO literals, joins, projections, gather, and scatter-add in the reference evaluator and static checker.
TensorLang's front-end performs structural and algebraic checks ahead of any backend lowering. The intent is to catch shape, dtype, semiring, and recursion mistakes statically.
The same einsum expression can mean matrix multiplication, a join, a shortest path, or a max-product computation, depending on the declared semiring.
Relational algebra lowering reuses the same einsum machinery. In the v1.6 finite Bool subset, both semiring-einsum and explicit named-axis join/project lower into plans that can run through in-memory or SQLite reference backends and export to SQL, Datalog, or TypeDB/TypeQL-style text.