Module logic

Module logic 

Source
Expand description

TensorLogic: Neuro-symbolic reasoning via tensor operations (Domingos, 2025) TensorLogic: Neuro-Symbolic Reasoning via Tensor Operations

This module implements the TensorLogic paradigm (Domingos, 2025), unifying neural and symbolic reasoning through tensor operations. All logical operations are expressed as Einstein summations, enabling:

  • Differentiable inference: Backpropagation through logical reasoning
  • Dual-mode operation: Boolean (guaranteed correctness) or Continuous (learnable)
  • Knowledge graph reasoning: RESCAL factorization and embedding space queries

§Toyota Way Principles

  • Jidoka: Boolean mode guarantees no hallucinations (output ⊆ derivable facts)
  • Poka-Yoke: Type-safe mode selection prevents accidental mixing
  • Genchi Genbutsu: Explicit tensor equations for auditability

§Example

use aprender::logic::{LogicMode, logical_join, logical_project};

// Family tree reasoning: Grandparent = Parent @ Parent
let parent = vec![
    vec![0.0, 1.0, 0.0],  // Alice is parent of Bob
    vec![0.0, 0.0, 1.0],  // Bob is parent of Charlie
    vec![0.0, 0.0, 0.0],  // Charlie has no children
];

let grandparent = logical_join(&parent, &parent, LogicMode::Boolean);
// grandparent[0][2] = 1.0 (Alice is grandparent of Charlie)

§References

  • Domingos, P. (2025). “Tensor Logic: The Language of AI.” arXiv:2510.12269
  • Nickel, M. et al. (2011). “RESCAL: A Three-Way Model for Collective Learning”
  • Bordes, A. et al. (2013). “TransE: Translating Embeddings for Multi-relational Data”

Structs§

BilinearScorer
Bilinear scorer for knowledge graph completion
EmbeddingSpace
Embedding space for knowledge graph reasoning
ProgramBuilder
Builder for constructing TensorPrograms fluently
RelationMatrix
Relation matrix wrapper (for type-safe access)
RescalFactorizer
RESCAL Tensor Factorization for predicate invention
TensorProgram
A TensorProgram is an executable collection of facts and rules

Enums§

Equation
An equation defines how to compute a derived tensor
LogicMode
Logic mode determines how operations handle intermediate values
Nonlinearity
Nonlinearity functions for attention and activation

Functions§

apply_nonlinearity
Apply nonlinearity function to tensor
apply_nonlinearity_with_mask
Apply nonlinearity with optional mask
apply_nonlinearity_with_temperature
Apply nonlinearity with temperature parameter
logical_join
Logical join (AND): Combines two relations via matrix multiplication
logical_negation
Logical negation (NOT): Negates tensor values
logical_project
Logical projection (∃): Existential quantification over a dimension
logical_select
Logical selection (WHERE): Filters tensor by condition
logical_union
Logical union (OR): Combines two tensors via logical OR