Language
MIND is a statically-typed, tensor-native language designed for AI and numerical computing. This page covers the core syntax and type system.
Basic Syntax
MIND uses a Rust-inspired syntax with first-class tensor support:
// Function definition
fn relu(x: Tensor<f32, N, M>) -> Tensor<f32, N, M> {
max(x, 0.0)
}
// Main entry point
fn main() {
let x: Tensor<f32, 2, 3> = [[1.0, -2.0, 3.0], [-1.0, 2.0, -3.0]];
let y = relu(x);
print(y);
}Type System
MIND features a rich type system with compile-time shape checking:
- Scalar types:
f32,f64,i32,i64,bool - Half-precision:
f16,bf16for mixed-precision training - Case-insensitive dtypes:
f32andF32are equivalent, same forbf16/BF16,i32/I32 - Tensor types:
Tensor<dtype, ...dims>with static or dynamic shapes - Generic dimensions: Use uppercase letters (
N,M,K) for polymorphic shapes - Device annotations:
@cpu,@gpufor placement control
Type Annotation Syntax
Two equivalent forms for tensor type annotations:
// Lowercase with commas (Rust-style)
let x: Tensor<f32, 2, 3> = zeros();
// Uppercase with bracket dims (ML-style)
let y: Tensor<F32, [N, M]> = zeros();
// Opaque tensor (no shape annotation)
fn relu(x: tensor<f32>) -> tensor<f32> { max(x, 0.0) }Tensor Literals
// 1D tensor let v: Tensor<f32, 3> = [1.0, 2.0, 3.0]; // 2D tensor (matrix) let m: Tensor<f32, 2, 3> = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]; // Random initialization let w: Tensor<f32, 784, 128> = randn(); // Zeros/ones let zeros: Tensor<f32, 10, 10> = zeros(); let ones: Tensor<i32, 5> = ones();
Functions
// Regular function
fn add(a: Tensor<f32, N>, b: Tensor<f32, N>) -> Tensor<f32, N> {
a + b
}
// Differentiable function
@differentiable
fn loss(pred: Tensor<f32, N>, target: Tensor<f32, N>) -> f32 {
mean((pred - target) ** 2)
}
// Generic over dtype
fn identity<T>(x: Tensor<T, N, M>) -> Tensor<T, N, M> {
x
}Operators
MIND supports arithmetic, comparison, and logical operators on both scalars and tensors:
| Category | Operators | Notes |
|---|---|---|
| Arithmetic | + - * / | Element-wise on tensors, broadcasting supported |
| Comparison | < <= > >= == != | Returns boolean tensor or scalar |
| Unary | -x | Negation for scalars and tensors |
| Assignment | = | Immutable by default, let mut for mutable |
// Comparison operators work on scalars and tensors let mask = scores > 0.5; // element-wise comparison let valid = count >= threshold; // scalar comparison let equal = pred == target; // equality check
Control Flow
// Conditionals
fn activation(x: f32, use_relu: bool) -> f32 {
if use_relu {
max(x, 0.0)
} else {
tanh(x)
}
}
// Loops (bounded for determinism)
fn sum_first_n(x: Tensor<f32, 100>, n: i32) -> f32 {
let mut acc = 0.0;
for i in 0..n {
acc = acc + x[i];
}
acc
}
// Print for debugging
print(acc);Learn More
See the full language specification at mind-spec/language.md.