Stdlib module math/modular.vitl

This page is a wiki-style reference for one concrete stdlib file. It explains what the file owns, where it fits in the family, and how to decide whether this is the right surface to depend on.

Visual portrait of math/modular.vitl
Wiki-style portrait for math/modular.vitl.

Family: math

Kind: public stdlib surface

Page style: this reference follows the same “encyclopedic card + portrait + usage contract” logic as the keyword pages, but for stdlib modules.

Summary

Overview

FieldValue
Pathmath/modular.vitl
Familymath
Kindpublic stdlib surface
Line count415
Declared procedures47
Declared forms/picks2

`math/modular.vitl` is a public stdlib surface inside the `math` family. It should be read as one focused slice of the broader family responsibility: Arithmetic, algebra, comparison, calculus, geometry, modular arithmetic, number theory, probability, statistics, matrix, and vector helpers.

Purpose

This file should be chosen because of responsibility, not because its name “sounds close enough”. Inside the math family, it carries one focused part of the contract and keeps that responsibility separate from neighboring concerns.

  • A scoring engine can compute aggregates in `math` while keeping I/O and transport elsewhere.
  • A statistics or matrix chapter should explain the workflow around the computation, not just a single formula.

Taxonomy

Think of this page as a generated encyclopedia entry rather than a hand-written tutorial. The goal is to show what kind of module this is, how dense it is, and what reading strategy makes sense before depending on it.

  • Large algorithm surface: this file exposes many procedures and likely acts as a domain toolkit rather than a single thin wrapper.
  • Owns domain vocabulary: the module declares data shapes in addition to executable helpers, so its types are part of the contract.
  • Has tuning constants: part of the module behavior is controlled by named constants that document default precision, limits, or policy.
  • Minimal top-level dependencies: the module reads as mostly self-contained from its opening declarations.
  • Explicit export surface: the file ends with visible export declarations instead of relying only on implicit namespace discovery.

Implementation profile

This profile is inferred directly from the source text. It does not replace reading the file, but it tells you quickly whether the module is mostly declarative, loop-heavy, branch-heavy, or organized around many small exits.

SignalCountWhat it suggests
if17Branching density and local decision-making.
while13Loop-heavy or iterative implementation style.
for0Collection-style traversal at source level.
match0Variant-driven branching or grammar-style decoding.
let66Local state and intermediate value density.
give62Number of explicit exit points and result shaping.

Top-level API inventory

SurfaceItems
Proceduresabs_int, min_int, max_int, mod_is_valid, mod_norm, mod_is_zero, mod_equal, are_congruent, mod_add, mod_sub, mod_neg, mod_double
FormsEgcdResult, Crt2Result
Picksnone declared at top level
ConstantsMOD_INVALID
Exports*

Imported surfaces

This file does not advertise a top-level `use` surface in its opening declarations. That often means it is either self-contained or an aggregation layer.

Position in family

This file is module 11 of 21 in the math family when ordered by path. By procedure count it ranks 15, and by line count it ranks 13. Those ranks are useful as rough signals of breadth, not as quality judgments.

Declaration map

The declaration map turns raw source into a scan-friendly catalog. It is useful when the file is large enough that a reader wants to orient by kinds of surfaces first.

LineNameKindRole
1vitte/stdlib/math/modularspaceDeclares the namespace that anchors this file in the stdlib tree.
3MOD_INVALIDconstDefines a named constant reused across the module.
5EgcdResultformIntroduces a structured data shape that other procedures can exchange.
11Crt2ResultformIntroduces a structured data shape that other procedures can exchange.
17abs_intprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
24min_intprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
31max_intprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
38mod_is_validprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
42mod_normprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
53mod_is_zeroprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
57mod_equalprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
61are_congruentprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
65mod_addprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
69mod_subprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
73mod_negprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
77mod_doubleprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
81mod_mulprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
85mod_mul_safeprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
89mod_squareprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
93mod_cubeprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
98extended_gcdprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
138mod_is_unitprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
142mod_has_inverseprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
146mod_invprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
154mod_divprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
162mod_halfprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
166mod_powprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
189mod_pow2procRepresents one top-level surface in the file contract and should be read as part of the module boundary.
193mod_pow10procRepresents one top-level surface in the file contract and should be read as part of the module boundary.
197solve_linear_congruenceprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
201crt2_fullprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
227crt2procRepresents one top-level surface in the file contract and should be read as part of the module boundary.
235crtprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
257mod_factorialprocImplements a counting or probability helper inside the math boundary.
267mod_permutationsprocImplements a counting or probability helper inside the math boundary.
277mod_combinations_primeprocImplements a counting or probability helper inside the math boundary.
285mod_combinationsprocImplements a counting or probability helper inside the math boundary.
289mod_factorial_tableprocImplements a counting or probability helper inside the math boundary.
300mod_inverse_tableprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
310mod_inverse_factorial_tableprocImplements a counting or probability helper inside the math boundary.
321mod_fibonacciprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
337mod_arithmetic_sumprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
348mod_geometric_sumprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
360mod_powersprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
371mod_poly_evalprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
382mod_hash_stepprocImplements a security-sensitive transformation in the crypto boundary.
387modprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
391inv_modprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
395modular_versionprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
399modular_readyprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.
403modular_selftestprocRepresents one top-level surface in the file contract and should be read as part of the module boundary.

The table is exhaustive for top-level declarations of the selected kinds. This file declares 51 matching surfaces.

Representative signatures

These signatures are shown in source order so the page keeps the feel of a reference manual, not just a keyword cloud.

  • const MOD_INVALID: int = 0 (line 3)
  • form EgcdResult { (line 5)
  • form Crt2Result { (line 11)
  • proc abs_int(value: int) -> int { (line 17)
  • proc min_int(a: int, b: int) -> int { (line 24)
  • proc max_int(a: int, b: int) -> int { (line 31)
  • proc mod_is_valid(modulus: int) -> bool { (line 38)
  • proc mod_norm(value: int, modulus: int) -> int { (line 42)
  • proc mod_is_zero(value: int, modulus: int) -> bool { (line 53)
  • proc mod_equal(a: int, b: int, modulus: int) -> bool { (line 57)
  • proc are_congruent(a: int, b: int, modulus: int) -> bool { (line 61)
  • proc mod_add(a: int, b: int, modulus: int) -> int { (line 65)
  • proc mod_sub(a: int, b: int, modulus: int) -> int { (line 69)
  • proc mod_neg(a: int, modulus: int) -> int { (line 73)
  • proc mod_double(a: int, modulus: int) -> int { (line 77)
  • proc mod_mul(a: int, b: int, modulus: int) -> int { (line 81)
  • proc mod_mul_safe(a: int, b: int, modulus: int) -> int { (line 85)
  • proc mod_square(a: int, modulus: int) -> int { (line 89)

The list is intentionally capped here; the source file declares 50 matching signatures in total.

How to use this module

Start by reading the file as an ownership boundary. Ask three questions: what enters this module, what stable types or procedures it exports, and what adjacent module should stay outside of it.

  1. Read space and top-level imports first so the ownership boundary of math/modular.vitl is explicit.
  2. Scan constants before procedures; they often encode precision, limits, or policy assumptions that explain later behavior.
  3. Read declared forms and picks before algorithms so the data vocabulary is stable in your head.
  4. Traverse procedures in source order; the early helpers usually explain the naming and numeric conventions used later.
  5. Only after that compare neighbor modules, because the right boundary choice matters more than memorizing one helper name.

User example

This example is generated from the actual stdlib module surface. Its job is not to be the smallest snippet possible; its job is to show a realistic consumer-shaped file that exercises the module and mirrors the language keywords the module itself relies on.

space demo/math_modular
const SAMPLE_LABEL: string = "demo"
form UserReport {
  label: string,
  ready: bool
}
proc run_example() -> UserReport {
  let entries = mod_factorial_table(1, 1)
  let ready: bool = mod_is_valid(1)
  let failed: bool = false
  let stable: bool = ready and true
  let fallback: bool = ready or false
  let idx: int = 0
  let count: int = 0
  while idx < entries.len {
    set count = count + 1
    set idx = idx + 1
  }
  if not ready {
    give UserReport { label: "not-ready", ready: false }
  }
    give UserReport { label: "ok", ready: true }
}
export run_example

Keyword coverage

This table makes the “all keywords of the module” requirement auditable. It compares the detected Vitte keywords in the source file with the generated consumer example above.

KeywordPresent in module sourceUsed in generated user example
spaceyesyes
constyesyes
formyesyes
procyesyes
letyesyes
setyesyes
ifyesyes
whileyesyes
giveyesyes
exportyesyes
trueyesyes
falseyesyes
andyesyes
oryesyes
notyesyes

The generated snippet exercises every detected Vitte keyword used by this module.

Source shape

space vitte/stdlib/math/modular
const MOD_INVALID: int = 0
form EgcdResult {
  gcd: int,
  x: int,
  y: int
}
form Crt2Result {
  ok: bool,
  value: int,

The excerpt is not meant to replace the file. It exists to make the module recognizable at first glance, the same way a Wikipedia infobox helps the reader orient before reading the whole article.

Source landmarks

Large files are easier to retain when they have visible landmarks. When the source contains explicit section banners, they are surfaced here; otherwise the first major declarations are used as anchors.

  • Line 1: space vitte/stdlib/math/modular
  • Line 3: const MOD_INVALID: int = 0
  • Line 5: form EgcdResult {
  • Line 11: form Crt2Result {
  • Line 17: proc abs_int(value: int) -> int {
  • Line 24: proc min_int(a: int, b: int) -> int {
  • Line 31: proc max_int(a: int, b: int) -> int {
  • Line 38: proc mod_is_valid(modulus: int) -> bool {

Source organization

When a file carries its own internal chaptering, those chapters usually reveal the intended reading order better than a flat symbol list. This section reconstructs that organization from the source itself.

File surfaces

Top-level items: 52. Procedures: 47. Data surfaces: 2. Constants: 1.

First visible names: vitte/stdlib/math/modular, MOD_INVALID, EgcdResult, Crt2Result, abs_int, min_int, max_int, mod_is_valid, mod_norm, mod_is_zero

Complete API catalog

This catalog is the exhaustive file-level index for the module. It is intentionally closer to a generated encyclopedia appendix than to a tutorial summary.

Constants

LineNameSignatureRole
3MOD_INVALIDconst MOD_INVALID: int = 0Defines a named constant reused across the module.

Data surfaces

LineNameSignatureRole
5EgcdResultform EgcdResult {Introduces a structured data shape that other procedures can exchange.
11Crt2Resultform Crt2Result {Introduces a structured data shape that other procedures can exchange.

Procedures

LineNameSignatureRole
17abs_intproc abs_int(value: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
24min_intproc min_int(a: int, b: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
31max_intproc max_int(a: int, b: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
38mod_is_validproc mod_is_valid(modulus: int) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
42mod_normproc mod_norm(value: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
53mod_is_zeroproc mod_is_zero(value: int, modulus: int) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
57mod_equalproc mod_equal(a: int, b: int, modulus: int) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
61are_congruentproc are_congruent(a: int, b: int, modulus: int) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
65mod_addproc mod_add(a: int, b: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
69mod_subproc mod_sub(a: int, b: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
73mod_negproc mod_neg(a: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
77mod_doubleproc mod_double(a: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
81mod_mulproc mod_mul(a: int, b: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
85mod_mul_safeproc mod_mul_safe(a: int, b: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
89mod_squareproc mod_square(a: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
93mod_cubeproc mod_cube(a: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
98extended_gcdproc extended_gcd(a: int, b: int) -> EgcdResult {Represents one top-level surface in the file contract and should be read as part of the module boundary.
138mod_is_unitproc mod_is_unit(a: int, modulus: int) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
142mod_has_inverseproc mod_has_inverse(a: int, modulus: int) -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
146mod_invproc mod_inv(a: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
154mod_divproc mod_div(a: int, b: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
162mod_halfproc mod_half(a: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
166mod_powproc mod_pow(a: int, exp: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
189mod_pow2proc mod_pow2(exp: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
193mod_pow10proc mod_pow10(exp: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
197solve_linear_congruenceproc solve_linear_congruence(a: int, b: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
201crt2_fullproc crt2_full(a1: int, m1: int, a2: int, m2: int) -> Crt2Result {Represents one top-level surface in the file contract and should be read as part of the module boundary.
227crt2proc crt2(a1: int, m1: int, a2: int, m2: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
235crtproc crt(residues: [int], moduli: [int]) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
257mod_factorialproc mod_factorial(n: int, modulus: int) -> int {Implements a counting or probability helper inside the math boundary.
267mod_permutationsproc mod_permutations(n: int, k: int, modulus: int) -> int {Implements a counting or probability helper inside the math boundary.
277mod_combinations_primeproc mod_combinations_prime(n: int, k: int, modulus: int) -> int {Implements a counting or probability helper inside the math boundary.
285mod_combinationsproc mod_combinations(n: int, k: int, modulus: int) -> int {Implements a counting or probability helper inside the math boundary.
289mod_factorial_tableproc mod_factorial_table(n: int, modulus: int) -> [int] {Implements a counting or probability helper inside the math boundary.
300mod_inverse_tableproc mod_inverse_table(n: int, modulus: int) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
310mod_inverse_factorial_tableproc mod_inverse_factorial_table(n: int, modulus: int) -> [int] {Implements a counting or probability helper inside the math boundary.
321mod_fibonacciproc mod_fibonacci(n: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
337mod_arithmetic_sumproc mod_arithmetic_sum(first: int, step: int, count0: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
348mod_geometric_sumproc mod_geometric_sum(first: int, ratio: int, count0: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
360mod_powersproc mod_powers(base: int, count0: int, modulus: int) -> [int] {Represents one top-level surface in the file contract and should be read as part of the module boundary.
371mod_poly_evalproc mod_poly_eval(coeffs: [int], x: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
382mod_hash_stepproc mod_hash_step(hash0: int, value: int, base: int, modulus: int) -> int {Implements a security-sensitive transformation in the crypto boundary.
387modproc mod(value: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
391inv_modproc inv_mod(value: int, modulus: int) -> int {Represents one top-level surface in the file contract and should be read as part of the module boundary.
395modular_versionproc modular_version() -> string {Represents one top-level surface in the file contract and should be read as part of the module boundary.
399modular_readyproc modular_ready() -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.
403modular_selftestproc modular_selftest() -> bool {Represents one top-level surface in the file contract and should be read as part of the module boundary.

Exports

LineNameSignatureRole
415*export *Re-exports surfaces that the module wants to expose as part of its public boundary.

Integration boundaries

Within math, this file should remain focused. If a future helper changes the host boundary, scheduling boundary, or data-shape boundary, it probably belongs in a neighbor module instead of being added here by convenience.

  • Family responsibility: Arithmetic, algebra, comparison, calculus, geometry, modular arithmetic, number theory, probability, statistics, matrix, and vector helpers.
  • Family architecture role: Use `math` when the transformation itself is the feature. This family exists so algorithmic intent stays visible and testable.

Composition guidance

Choose this module when

  • Choose math/modular.vitl when the main question is owned by this module rather than by transport, storage, orchestration, or user-interface code.
  • A scoring engine can compute aggregates in `math` while keeping I/O and transport elsewhere.
  • A statistics or matrix chapter should explain the workflow around the computation, not just a single formula.

Pause before extending it when

  • Avoid extending this file when the new helper mostly changes the boundary to host I/O, runtime coordination, or foreign integration instead of staying inside math.
  • Check nearby modules such as math/algebra.vitl, math/arithmetic.vitl, math/arrays.vitl before adding convenience wrappers here.

Relationship table

This table keeps the page closer to a real encyclopedia entry: a module is easier to understand when compared with its nearest alternatives in the same family.

NeighborProceduresData surfacesWhy compare it
math/algebra.vitl140Shares the same family boundary but carries a distinct slice of responsibility.
math/arithmetic.vitl722Shares the same family boundary but carries a distinct slice of responsibility.
math/arrays.vitl832Shares the same family boundary but carries a distinct slice of responsibility.
math/calculus.vitl563Shares the same family boundary but carries a distinct slice of responsibility.
math/comparison.vitl470Shares the same family boundary but carries a distinct slice of responsibility.
math/complex.vitl490Shares the same family boundary but carries a distinct slice of responsibility.
math/geometry.vitl720Shares the same family boundary but carries a distinct slice of responsibility.
math/logic.vitl200Shares the same family boundary but carries a distinct slice of responsibility.

Neighbor modules