Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

⊙

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

Glyph Hadamard: identical-shape elementwise product on vectors, matrices, and tensors.

Syntax: <expression> ⊙ <expression>

Category#

tensor

Examples#

radix/corpus/reference/operator-group/circled-dot/glyph-elementwise.fab (canonical · operator-group)#

Glyph Hadamard: identical-shape elementwise product on vectors, matrices, and tensors.

# =============================================================================
# ⊙ — glyph Hadamard (identical-shape elementwise product).
# =============================================================================
#
# What this teaches:
#   • Hadamard product — `a ⊙ b` multiplies elementwise under an identical-shape contract
#   • Shape families — vectors, matrices, and tensors all lower; tensors route through the shared kernel
#
# Common mistakes:
#   • shape mismatch — `⊙` rejects differing shapes at compile time (no broadcast stretch)
#   • confusing `⊙` with `×` — cross is width-3 only; Hadamard is elementwise for any identical shape
#
# See also: tensor, vector, matrix
# =============================================================================

# ⊙ on vectors, matrices, and tensors (identical shapes)
#
# WHY: `⊙` is the elementwise product glyph. Identical built-in shapes multiply
# per-element; tensor operands lower to the same recoverable elementwise kernel
# as the `multiplica` intrinsic (one host carrier). Matrix operands come from
# `⊗` results (register matrices have no literal construction surface yet).
#
# a ⊙ b = [1*4, 2*5, 3*6] = [4.0, 10.0, 18.0]
# o ⊙ o (o = a ⊗ b) = [[16,25],[64,100],[144,225]]
# ta ⊙ tb (tensor [2,2]) = [1.0, 4.0, 9.0, 16.0]
#
# EXPECTED stdout:
#   [4.0, 10.0, 18.0]
#   [[16.0, 25.0], [64.0, 100.0], [144.0, 225.0]]
#   [1.0, 4.0, 9.0, 16.0]

main {
    let vf32[3] a ← [1.0, 2.0, 3.0] ↦ vector<f32, size 3>
    let vf32[3] b ← [4.0, 5.0, 6.0] ↦ vector<f32, size 3>
    let vf32[2] q ← [4.0, 5.0] ↦ vector<f32, size 2>
    let matrix<f32, [3, 2]> o ← a ⊗ q
    let vf32[3] v ← a ⊙ b
    print v
    let matrix<f32, [3, 2]> m ← o ⊙ o
    print m
    let list<f32> flat_a ← [1.0, 2.0, 3.0, 4.0]
    let list<f32> flat_b ← [1.0, 2.0, 3.0, 4.0]
    mut tf32[2, 2] ta ← flat_a ↦ tensor<f32, [2, 2]>
    mut tf32[2, 2] tb ← flat_b ↦ tensor<f32, [2, 2]>
    let tf32[2, 2] t ← ta ⊙ tb
    let list<f32> out ← t.flatten()
    print out
}

Expected output:

[4.0, 10.0, 18.0]
[[16.0, 25.0], [64.0, 100.0], [144.0, 225.0]]
[1.0, 4.0, 9.0, 16.0]