渲染zh-Hant

intervallum

Translation status: 繁體中文 reader-locale proof. Code fences render through the zh-Hant pipeline; prose is canonical Latin.

Clamp, materialize, and contain via conversio 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: inter, union, longitudo, nihil
#
# 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: inter, union, longitudo, nihil
# =============================================================================

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

main {
    const intervallum<int> morning  06
    const intervallum<int> afternoon  410
    const intervallum<int> overlap  morning.inter(afternoon) coalesce 00
    const intervallum<int> early  05
    const intervallum<int> late  510
    const intervallum<int> workday  early.union(late) coalesce 00
    const _ overlap_span  overlap.longitudo()
    const _ workday_span  workday.longitudo()
    assert overlap_span  2
    assert workday_span  10

    const intervallum<int> gap_left  03
    const intervallum<int> gap_right  69
    const _ no_union  gap_left.union(gap_right)
    assert no_union is null
}

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

Clamp, materialize, and contain via conversio and continet.

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

# intervallum — conversio clamp, materialize, and continet
#
# Value clamp result type is bound `numerus` (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 _ half  15010
    const _ closed  15010
    assert half  9
    assert closed  10

    # --- materialize to lista or 1-d tensor ---
    const list<int> half_list  010 ↦ list<int>
    const list<int> closed_list  03 ↦ list<int>
    const tensor<int, [10]> half_grid  010 ↦ tensor<int, [10]>
    const tensor<int, [4]> closed_grid  03 ↦ tensor<int, [4]>
    const list<int> half_flat  half_grid.planata()
    const list<int> closed_flat  closed_grid.planata()
    assert half_list.longitudo()  10
    assert closed_list.longitudo()  4
    assert half_flat.longitudo()  10
    assert closed_flat.longitudo()  4

    # --- range-to-range clamp inherits target inclusivity ---
    const intervallum<int> wide  0100
    const intervallum<int> narrow  wide ↦ 1050
    assert narrow.longitudo()  41

    # --- stored containment via continet (intra desugars to the same surface) ---
    const intervallum<int> fines  010
    const _ inside  fines.continet(5)
    assert inside
}