// SPDX-License-Identifier: Apache-2.0 ; specs/widgets/tc-two-bits.t27 -- lesson 13 of the course "The ternary machine" (specs/course/ternary-computing.t27) ; Source of truth for public/widgets/tc-two-bits/ (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-two-bits/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_two_bits; pub const KIND : str = "widget-tool"; pub const ID : str = "tc-two-bits"; pub const TITLE : str = "A trit in two bits, and the code nobody uses"; pub const DESCRIPTION : str = "Binary hardware stores a trit in two bits: -1 as 00, 0 as 01, +1 as 10. The fourth code, 11, means nothing: a quarter of the codes are wasted."; pub const IMAGE_ALT : str = "Two bits per trit card: -1 stored as 00, 0 as 01, +1 as 10, the way the hardware specs pack trits, and 11 crossed out as unused. The two bits carry 1.585 bits of information: 79.25 percent used."; pub const HOOK : str = "Two bits hold four codes, a trit needs three. Store trits that way and a fifth of the memory carries nothing."; pub const CATEGORY : str = "compiler"; pub const DATA_SOURCES : [1]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"]; 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_TRIT : str = "Trit"; pub const SAY_CODE : str = "{0} is stored as {1}"; pub const SAY_HOLDS : str = "holds {0}"; pub const SAY_UNUSED : str = "unused"; pub const SAY_WHY : str = "One trit carries log2(3) = 1.585 bits, so two bits are 79 percent used."; pub const SAY_USE : str = "bits that carry information: {0}%"; 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; }