Renderingen-US

intervallum

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

Clamp, materialize, and contain via conversion and continet.

Syntax:

Category#

range

Examples#

radix/corpus/intervallum/algebra.fab (canonical · type)#

Interval algebra: intersection, union, and span count.

# =============================================================================
# intervallum — Interval algebra: intersection, union, and span count
# =============================================================================
#
# What this teaches:
#   • Interval algebra: intersection, union, and span count.
#   • Related keywords: intersect, union, longitudo, none
#
# Common mistakes:
#   • Confusing `‥` (exclusive end) with `…` (inclusive end) — `0‥6` is [0,6), `0…6` is [0,6]; the wrong boundary operator changes the span.
#
# See also: intersect, union, longitudo, none
# =============================================================================

# intervallum — range algebra (intersect, union, longitudo)
#
# `intersect` / `union` return `intervallum<int> ∪ none` (none when disjoint
# or non-adjacent). `longitudo` returns discrete bound-count for int v1.
#
# EXPECTED OUTPUT:
#   none — stdout not pinned for this exemplum.

main {
    const intervallum<int> morning ← 0‥6
    const intervallum<int> afternoon ← 4‥10
    const intervallum<int> overlap ← morning.intersect(afternoon) coalesce 0‥0
    const intervallum<int> early ← 0‥5
    const intervallum<int> late ← 5‥10
    const intervallum<int> workday ← early.union(late) coalesce 0‥0
    const int overlap_span ← overlap.length()
    const int workday_span ← workday.length()
    assert overlap_span ≡ 2
    assert workday_span ≡ 10
    const intervallum<int> gap_left ← 0‥3
    const intervallum<int> gap_right ← 6‥9
    const intervallum<int> ∪ none no_union ← gap_left.union(gap_right)
    assert no_union is none
}

radix/corpus/intervallum/conversio.fab (canonical · type)#

Clamp, materialize, and contain via conversion and continet.

# =============================================================================
# intervallum — Clamp, materialize, and contain via conversion and continet
# =============================================================================
#
# What this teaches:
#   • Clamp, materialize, and contain via conversion and continet.
#   • Related keywords: ∈, ↦, list
#
# Common mistakes:
#   • Confusing `‥` (exclusive end) with `…` (inclusive end) — `15 ↦ 0‥10` clamps to 9, while `15 ↦ 0…10` clamps to 10.
#
# See also: ∈, ↦, list
# =============================================================================

# intervallum — conversion clamp, materialize, and continet
#
# Value clamp result type is bound `int` (refinement-target special case).
# Range materialize honors declared inclusivity on `‥` / `…`.
#
# EXPECTED OUTPUT:
#   none — stdout not pinned for this exemplum.

main {
    # --- value clamp (half-open interior vs inclusive endpoint) ---
    const int half ← 15 ↦ 0‥10
    const int closed ← 15 ↦ 0…10
    assert half ≡ 9
    assert closed ≡ 10

    # --- materialize to list or 1-d tensor ---
    const list<int> half_list ← 0‥10 ↦ list<int>
    const list<int> closed_list ← 0…3 ↦ list<int>
    const tensor<int, [10]> half_grid ← 0‥10 ↦ tensor<int, [10]>
    const tensor<int, [4]> closed_grid ← 0…3 ↦ tensor<int, [4]>
    const list<int> half_flat ← half_grid.flatten()
    const list<int> closed_flat ← closed_grid.flatten()
    assert half_list.length() ≡ 10
    assert closed_list.length() ≡ 4
    assert half_flat.length() ≡ 10
    assert closed_flat.length() ≡ 4

    # --- range-to-range clamp inherits target inclusivity ---
    const intervallum<int> wide ← 0‥100
    const intervallum<int> narrow ← wide ↦ 10…50
    assert narrow.length() ≡ 41

    # --- stored containment via continet (`∈` over a range tests the same containment) ---
    const intervallum<int> fines ← 0‥10
    const bool inside ← fines.contains(5)
    assert inside
}