// SPDX-License-Identifier: Apache-2.0 ; specs/widgets/tc-half-adder.t27 -- lesson 7 of the course "The ternary machine" (specs/course/ternary-computing.t27) ; Source of truth for public/widgets/tc-half-adder/ (gHashTag/trinity): scripts/widget-pages-from-spec.mjs compiles this ; file, checks its constants, evaluates the tests below and writes the page; the page hands every constant to ; tool.js as window.T27_WIDGET. tool.js draws through ../ternary-kit.js and computes nothing: every number comes ; from public/widgets/tc-half-adder/logic.js, the fn bodies of the gHashTag/t27 spec in logic.t27, compiled to wasm. ; ASCII only (L3), English only (LANG-EN). ; phi^2 + 1/phi^2 = 3 | TRINITY module widget_tc_half_adder; pub const KIND : str = "widget-tool"; pub const ID : str = "tc-half-adder"; pub const TITLE : str = "The half adder: two trits in, a sum and a carry out"; pub const DESCRIPTION : str = "Pick two trits. The half adder writes their sum as a sum trit plus three times a carry trit; all nine cases below."; pub const IMAGE_ALT : str = "Half adder card: +1 + +1 = 2, written as a carry of +1 and a sum of -1, since 3 - 1 = 2. All nine input pairs are shown with their carry and sum; only two of them carry."; pub const HOOK : str = "In ternary, 1 + 1 is not 10 but +-: carry one, write minus one."; pub const CATEGORY : str = "compiler"; pub const DATA_SOURCES : [2]str = ["gHashTag/t27 specs/ternary/trits.t27 (t27#8979): every value on the page is its fn bodies, compiled to wasm (logic.js), with 18 tests and 4108 runtime asserts", "D. Knuth, The Art of Computer Programming, vol. 2, section 4.1: balanced ternary"]; pub const READS_LOCAL_FILES : bool = false; pub const SENDS_NOTHING : bool = true; pub const K_CARD_WIDTH : u16 = 1200; pub const K_CARD_HEIGHT : u16 = 630; pub const SAY_LOADING : str = "Loading"; pub const SAY_CARRY : str = "carry"; pub const SAY_SUM : str = "sum"; pub const SAY_EQ : str = "{0} = 3 x {1} + {2}"; pub const SAY_CASES : str = "All 9 cases: inputs, carry, sum"; pub const SAY_SOURCE : str = "Logic: t27 spec ternary/trits.t27, compiled"; test the_card_is_the_share_size { assert K_CARD_WIDTH == 1200; assert K_CARD_HEIGHT == 630; assert K_CARD_WIDTH * 21 == K_CARD_HEIGHT * 40; } test the_widget_starts_where_its_card_says { assert SENDS_NOTHING == true; assert READS_LOCAL_FILES == false; }