// SPDX-License-Identifier: Apache-2.0 ; specs/widgets/tc-why-three.t27 -- lesson 1 of the course "The ternary machine" (specs/course/ternary-computing.t27) ; Source of truth for public/widgets/tc-why-three/ (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-why-three/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_why_three; pub const KIND : str = "widget-tool"; pub const ID : str = "tc-why-three"; pub const TITLE : str = "Why three: what a number costs in each base"; pub const DESCRIPTION : str = "Pick a range of numbers. Every base pays digits times states per digit; base 3 pays least, bases 2 and 4 tie behind it."; pub const IMAGE_ALT : str = "Why three card: writing every number up to 999,999 costs 39 in base 3 (13 digits of 3 states), 40 in bases 2 and 4, 60 in base 10. The curve b / ln b bottoms out at e = 2.718, with 3 the closest whole base."; pub const HOOK : str = "A million costs 39 in base 3 and 40 in binary. The cheapest base is e; the cheapest whole one is 3."; pub const CATEGORY : str = "compiler"; pub const DATA_SOURCES : [2]str = ["gHashTag/t27 specs/ternary/radix_economy.t27 (t27#8979): every value on the page is its fn bodies, compiled to wasm (logic.js), with 3 tests", "B. Hayes, Third Base, American Scientist 89(6), 2001: radix economy and why 3 is the cheapest whole base"]; 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_NUMBERS : [5]u32 = [100, 1000, 999999, 1000000, 100000000]; pub const K_MAX_BASE : u32 = 10; pub const K_START : u8 = 2; pub const SAY_PICK : str = "Numbers up to"; pub const SAY_NUMBERS : [5]str = ["100", "1,000", "999,999", "1,000,000", "100,000,000"]; pub const SAY_BASE : str = "base {0}"; pub const SAY_COST : str = "{0} x {1} = {2}"; pub const SAY_BEST : str = "cheapest: base {0}, cost {1}"; pub const SAY_RULE : str = "Cost = digits x states per digit. A digit that tells more states apart is dearer, but fewer of them are needed."; pub const SAY_CURVE_TITLE : str = "Per-digit price over a long range: b / ln b"; pub const SAY_CURVE_AXIS : str = "b / ln b"; pub const SAY_CURVE : str = "b / ln b is {0} at 3 and {1} at 2 and 4; the minimum is e = 2.718."; pub const SAY_SOURCE : str = "Logic: t27 spec ternary/radix_economy.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_MAX_BASE == 10; assert K_NUMBERS[2] == 999999; assert K_START < 5; }