nx_sum_first_n.nx source
↩ module page · 30 lines · 917 B
1// nx_sum_first_n.nx -- AUTO-GENERATED from shape `scalar_accumulator_n`.
2//
3// Shape: takes a count `n`, runs `n` iterations of STEP, returns the
4// final accumulator value. INIT is the starting accumulator; STEP
5// is the per-iteration update expression (may reference `acc`, `n`,
6// and the loop variable `i`).
7//
8// genealogy_id: synthesized_from_corpus
9// lineage_id: scalar_accumulator_n
10// license: public_domain
11// complexity: O(n)
12
13// nx_safety_envelope:
14// intended_use: AUTO_APPLIED -- primitive-specific tuning queued
15// sil_target: SIL1
16// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail]
17// verdict: NOT_YET_EVALUATED
18
19import "nx_syscalls.nx"
20import "nx_tier.nx"
21
22func nx_sum_first_n(n: nx_int) -> nx_int {
23 var acc: nx_int = 0
24 var i: nx_int = 0
25 while i < n {
26 acc = acc + i
27 i = i + 1
28 }
29 return acc
30}