intervallum
Translation status: English reader-locale proof. Code fences render through the en pipeline; prose is canonical Latin.
Clamp, materialize, and contain via conversio and continet.
Syntax:
Category#
range
Related#
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 ← 0‥6
const intervallum<int> afternoon ← 4‥10
const intervallum<int> overlap ← morning.inter(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 _ overlap_span ← overlap.longitudo()
const _ workday_span ← workday.longitudo()
assert overlap_span ≡ 2
assert workday_span ≡ 10
const intervallum<int> gap_left ← 0‥3
const intervallum<int> gap_right ← 6‥9
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 ← 15 ↦ 0‥10
const _ closed ← 15 ↦ 0…10
assert half ≡ 9
assert closed ≡ 10
# --- materialize to lista 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.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 ← 0‥100
const intervallum<int> narrow ← wide ↦ 10…50
assert narrow.longitudo() ≡ 41
# --- stored containment via continet (intra desugars to the same surface) ---
const intervallum<int> fines ← 0‥10
const _ inside ← fines.continet(5)
assert inside
}