// SPDX-License-Identifier: Apache-2.0 ; specs/widgets/tc-sum-and-carry.t27 -- lesson 6 of the course "The ternary machine" (specs/course/ternary-computing.t27) ; Source of truth for public/widgets/tc-sum-and-carry/ (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-sum-and-carry/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_sum_and_carry; pub const KIND : str = "widget-tool"; pub const ID : str = "tc-sum-and-carry"; pub const TITLE : str = "Sum and carry: addition as two gates"; pub const DESCRIPTION : str = "The sum trit and the carry trit of a + b are two 3 x 3 tables. There are 19,683 such two-input gates in ternary and 16 in binary."; pub const IMAGE_ALT : str = "Sum and carry card: the SUM table of two trits, addition modulo 3 written as -1, 0, +1, beside the CARRY table: +1 + +1 = -1 + 3 x 1. Two-input gates: 19,683 in ternary, 16 in binary."; pub const HOOK : str = "Two trits add to a sum trit and a carry trit. Nine rows of three values give 19,683 possible gates; binary has 16."; 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 K_GATES : [2]u32 = [5, 6]; pub const K_GATE_NOT : u32 = 0; pub const SAY_PICK : str = "Gate"; pub const SAY_GATES : [2]str = ["SUM", "CARRY"]; pub const SAY_OUT : str = "out"; pub const SAY_GATE_TIPS : [2]str = ["SUM: a + b modulo 3, written as -1, 0 or +1.", "CARRY: what a + b passes to the next place."]; pub const SAY_EQ : str = "{0} + {1} = {2} + 3 x {3}"; pub const SAY_COUNT : str = "Two-input gates: {0} in ternary, {1} in binary; one-input: {2} against {3}."; 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 K_GATES[0] == 5; }