ผลรวม
Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH pack; supporting prose may still be English.
Sequential sum-reduce expression: ผลรวม ออก <tensor> ที่ [i] คงที่ s { คืน <term> }.
Syntax: ผลรวม ออก <source> ที่ [coords] คงที่ <binder> { คืน <term> }
Category#
collection
Related#
- prima
- ultima
- รายการ
Examples#
radix/corpus/lista/methodi-functionales.fab (canonical · existing-home)#
Returns the sum of numeric list elements.
# =============================================================================
# ผลรวม — Returns the sum of numeric list elements.
# =============================================================================
#
# What this teaches:
# • higher-order intrinsics for lists — `filtrata` (filter), `mappata` (map), `ลดรูป` (fold), `cumulata` (cumulate)
# • closure syntax with `∴` — inline anonymous functions for collection operations
#
# Common mistakes:
# • Omitting the initial accumulator value in ลดรูป/cumulata — both require an explicit seed argument.
#
# See also: prima, ultima, รายการ
# =============================================================================
# รายการ<T> higher-order intrinsics
#
# res.filter(T x ∴ <pred>) -- filter
# res.map(T x ∴ <expr>) -- map
# res.reduce((acc, x) ∴ <expr>, init) -- fold
# res.cumulata((acc, x) ∴ <expr>, init) -- cumulate (serial prefix scan)
#
# GRAMMAR:
# listMethod :← expr '.' ('filtrata' | 'mappata' | 'ลดรูป' | 'cumulata') '(' closure ')'
#
# EXPECTED OUTPUT:
# [2, 4]
# [2, 4, 6, 8, 10]
# 15
# [1, 3, 6, 10, 15]
#
# BACKEND: Go e2e whitelist — รายการ intrinsic methods not yet lowered for Go
# (whitelist: รายการ/methodi-functionales.fab).
main {
const list<int> res ← [1, 2, 3, 4, 5] ∷ list<int>
const list<int> pares ← res.filter(int x ∴ x % 2 ≡ 0)
const list<int> duplicata ← res.map(int x ∴ x * 2)
const int ผลรวม ← res.reduce((int collectus, int x) ∴ collectus + x, 0)
const list<int> cumulata ← res.cumulate((int collectus, int x) ∴ collectus + x, 0)
print pares
print duplicata
print ผลรวม
print cumulata
}Expected output:
[2, 4]
[2, 4, 6, 8, 10]
15
[1, 3, 6, 10, 15]
radix/corpus/summa/summa.fab (canonical · concept)#
Sequential sum-reduce expression: ผลรวม ออก <tensor> ที่ [i] คงที่ s { คืน <term> }.
# =============================================================================
# ผลรวม — one-expression sequential sum-reduce over a เทนเซอร์
# =============================================================================
#
# What this teaches:
# • Sequential fold — `ผลรวม ออก` lowers to a MIR fold over the เทนเซอร์'s
# ที่ iteration arm: a `+` accumulator seeded at zero, one term per
# element, `คืน` inside the body yields the term value.
# • Identity term — `คืน s` is the sequential spelling of `a.summa()`;
# the printed pair matches under the numeric tolerance contract.
# • Transformed term — the body may compute any numeric scalar term from
# the bound element (here `s + 1.0` per เลน).
#
# Common mistakes:
# • non-scalar terms — the term must be a numeric scalar (เศษ/numerus)
# • the distributed `เส้นใย` spelling is admitted only inside `@ เคอร์เนล`
# kernels (v1)
#
# See also: เทนเซอร์, ที่, เส้นใย
# =============================================================================
ฟังก์ชัน identity(เทนเซอร์<f32, [8]> a) → f32 {
คืน ผลรวม ออก a ที่ [i] คงที่ s {
คืน s
}
}
ฟังก์ชัน shifted(เทนเซอร์<f32, [8]> a) → f32 {
คืน ผลรวม ออก a ที่ [i] คงที่ s {
แปร f32 t ← s
t ← t + 1.0
คืน t
}
}
เริ่ม {
คงที่ รายการ<f32> flat ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
คงที่ tf32[] seed ← เซตว่าง
คงที่ tf32[8] a ← seed.สร้างจากข้อมูลแบน(flat, [8])
คงที่ f32 per_summam ← a.ผลรวม()
คงที่ f32 plicatum ← identity(a)
คงที่ f32 summam_totam ← shifted(a)
บันทึก per_summam
บันทึก plicatum
บันทึก summam_totam
}Expected output:
36.0
36.0
44.0
radix/corpus/summa/summa-combine-refusal.fab (supporting · reject)#
General-combine refusal: ผลรวม admits no identity/combine clause — the combine is sum only, pinned by a parse reject.
# =============================================================================
# ผลรวม general-combine refusal — no identity/combine clause exists.
# =============================================================================
#
# Decline row (reject reason in the comment):
# 1. general combine — the ลดรูป ruling bars overloading `ผลรวม` with a
# general combiner; there is no identity or combine clause in the
# grammar. An attempted `coniunge` tail after the binder fails at
# parse: the production expects the term block, never an operator
#
# Common mistakes:
# • expecting `ผลรวม` to spell product/min/max reduces — the combine is
# sum only; general reduce/scan heads belong to the rejection-review
# sketch, and `ลดรูป`/`cumulata` own the intrinsic family
#
# See also: ผลรวม, เส้นใย, ที่, เทนเซอร์
# =============================================================================
# 1. general combine — a combine-operator tail is not grammar; parse reject
ฟังก์ชัน product(เทนเซอร์<f32, [8]> a) → f32 {
คืน ผลรวม ออก a ที่ [i] คงที่ sconiunge '*' { คืน s }
}Expected: compilation rejects this example.
radix/corpus/summa/summa-decline.fab (supporting · reject)#
ผลรวม decline rows: เส้นใย placement outside @ เคอร์เนล, K % 32 ≠ 0 tails, and non-scalar terms fail closed.
# =============================================================================
# ผลรวม decline — placement, tail alignment, and scalar terms fail closed.
# =============================================================================
#
# Decline rows (reject reason in each comment):
# 1. placement — `เส้นใย` admits only inside an `@ เคอร์เนล` kernel;
# this host function declines: SEM010 summa_filum_requires_nucleum_kernel
# 2. tail — K = 8 is not a multiple of the 32-lane width; the v1 tail
# gate fails closed at admission:
# SEM010 summa_tail_not_aligned
# 3. non-scalar term — the term body returns a เมทริกซ์ row (a เทนเซอร์),
# not a numeric scalar: SEM010 summa_term_type_non_scalar
#
# Common mistakes:
# • expecting a partial-lane เส้นใย fold — K % W ≠ 0 is an admission
# error, never a tail loop
# • expecting list/tensor terms to combine element-wise — the term type
# must be a scalar of the element family
#
# See also: ผลรวม, เส้นใย, เคอร์เนล, ที่, เทนเซอร์
# =============================================================================
# 1. placement — เส้นใย outside @ เคอร์เนล declines
ฟังก์ชัน placement(เทนเซอร์<f32, [32]> a) → f32 {
คืน ผลรวม ออก a ที่ [i] เส้นใย f คงที่ s { คืน s }
}
# 2. tail — K = 8 not aligned to the 32-lane width declines
@ เคอร์เนล
@ สาธารณะ
ฟังก์ชัน tail(เทนเซอร์<f32, [8]> a, tf32[1] out) → เปล่า {
คงที่ f32 total ← ผลรวม ออก a ที่ [i] เส้นใย f คงที่ s { คืน s }
out[0] ← total
}
# 3. non-scalar term — a ข้อความ element is not a numeric scalar
ฟังก์ชัน non_scalar(เทนเซอร์<ข้อความ, [8]> t) → ข้อความ {
คืน ผลรวม ออก t ที่ [i] คงที่ s { คืน s }
}Expected: compilation rejects this example.