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.

⊘

Assigns a value to a binding, field, or assignable expression.

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

Glyph Hadamard divide: identical-shape elementwise division on tensors.

Syntax: <expression> ⊘ <expression>

Category#

tensor

Examples#

radix/corpus/reference/operator-group/circled-divide/arithmetic-int-division.fab (canonical · operator-group)#

Tensor division semantics: floored integer ⊘, / and %, exact ÷ into float, IEEE float division by zero.

# =============================================================================
# Tensor division semantics — floored integer and IEEE float division.
# =============================================================================
#
# What this teaches:
#   • Integer division rounds toward negative infinity: `⊘`, `/` and `%` on a
#     `ti32` tensor all take the floor, so -7 / 2 is -4 and -7 % 2 is 1, not
#     the truncating -3 / -1 that C-style division would give.
#   • `÷` is exact division: an integer tensor divided by an integer scalar or
#     tensor widens to f64 and never truncates.
#   • Float division by zero is bare IEEE — `x / 0.0` yields `inf`, `-inf` or
#     `nan` rather than trapping; the glyph `⊘` and the slash agree because
#     both lower to the same bare f32/f64 hardware division.
#
# EXPECTED stdout:
#   [-4, 3, 3, -4]
#   [-4, 3, -4, 3]
#   [1, 1, 1, 1]
#   [-1, -1, -1, -1]
#   [-3.5, 3.5, -3.5, 3.5]
#   [-3.5, 3.5, 3.5, -3.5]
#   [inf, -inf, NaN]
#   [inf, -inf, NaN]
#
# See also: tensor, arithmetic, ⊘, ÷, %
# =============================================================================

main {
    let ti32[4] a ← [-7, 7, -7, 7] ↦ tensor<i32, [4]>
    let ti32[4] b ← [2, 2, -2, -2] ↦ tensor<i32, [4]>
    let ti32[4] floored ← a ⊘ b
    print floored.flatten()
    let ti32[4] by_scalar ← a / 2
    print by_scalar.flatten()
    let ti32[4] remainder ← a % 2
    print remainder.flatten()
    let ti32[4] negative_remainder ← a % -2
    print negative_remainder.flatten()
    let tensor<f64, [4]> exact_widened ← a ÷ 2
    print exact_widened.flatten()
    let tensor<f64, [4]> exact_elementwise ← a ÷ b
    print exact_elementwise.flatten()
    let tf32[3] edge ← [1.0, -1.0, 0.0] ↦ tensor<f32, [3]>
    let tf32[3] zeroes ← [0.0, 0.0, 0.0] ↦ tensor<f32, [3]>
    let tf32[3] glyph_edge ← edge ⊘ zeroes
    print glyph_edge.flatten()
    let tf32[3] scalar_edge ← edge / 0.0
    print scalar_edge.flatten()
}

Expected output:

[-4, 3, 3, -4]
[-4, 3, -4, 3]
[1, 1, 1, 1]
[-1, -1, -1, -1]
[-3.5, 3.5, -3.5, 3.5]
[-3.5, 3.5, 3.5, -3.5]
[inf, -inf, NaN]
[inf, -inf, NaN]

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

Glyph Hadamard divide: identical-shape elementwise division on tensors.

# =============================================================================
# ⊘ — glyph Hadamard divide (identical-shape elementwise division).
# =============================================================================
#
# What this teaches:
#   • Hadamard divide — `a ⊘ b` divides elementwise under the same
#     identical-shape contract as `a ⊙ b`; it is the glyph spelling of the
#     tensor `divisio` method twin and the existing TensorDiv MIR operation.
#   • This is not broadcasting — mismatched static shapes reject at typecheck,
#     just as they do for `⊙`.
#   • Device posture — `⊘` remains fail-closed until its first device
#     consumer, matching the `⊗` family posture: it waits for that consumer
#     rather than claiming an unproved device recipe.
#
# EXPECTED stdout:
#   [2.0, 2.0, 3.0, 4.0]
#
# See also: tensor, arithmetic, ⊙, ⊘
# =============================================================================

fn hadamard_divide(tensor<f32, [2, 2]> numerator, tensor<f32, [2, 2]> denominator) → tensor<f32, [2, 2]> {
    return numerator ⊘ denominator
}

main {
    let list<f32> flat_numerator ← [2.0, 4.0, 9.0, 16.0]
    let list<f32> flat_denominator ← [1.0, 2.0, 3.0, 4.0]
    mut tf32[2, 2] numerator ← flat_numerator ↦ tensor<f32, [2, 2]>
    mut tf32[2, 2] denominator ← flat_denominator ↦ tensor<f32, [2, 2]>
    let tf32[2, 2] result ← hadamard_divide(numerator, denominator)
    print result.flatten()
}

Expected output:

[2.0, 2.0, 3.0, 4.0]