// SPDX-License-Identifier: Apache-2.0
; specs/widgets/tc-detector.t27 -- lesson 26 of the course "The ternary machine" (specs/course/ternary-computing.t27)
; Source of truth for public/widgets/tc-detector/ (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-detector/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_detector;

pub const KIND : str = "widget-tool";
pub const ID : str = "tc-detector";
pub const TITLE : str = "A bar detector: one neuron, four patterns";
pub const DESCRIPTION : str = "The weights are a vertical bar. Try every input: the bar fires +1, the inverted bar -1, other shapes and noise stay at 0, with the sums listed.";
pub const IMAGE_ALT : str = "Bar detector card: the vertical-bar weights tested on five inputs: the vertical bar sums to 9 and fires +1, the inverted bar to -9 and fires -1, the horizontal bar and the diagonal sum to 1 and noise to 0: no answer.";
pub const HOOK : str = "Weights are a template: the neuron fires on what looks like them and says -1 to what looks opposite.";
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", "S. Ma and others, The Era of 1-bit LLMs: All Large Language Models are in 1.58 Bits, 2024: weights of -1, 0 and +1"];
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_PATTERNS : [45]i32 = [-1, 1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 0, 0, 1, -1, -1, 0, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1];
pub const K_W0 : [9]i32 = [-1, 1, -1, -1, 1, -1, -1, 1, -1];
pub const K_THRESHOLD : i32 = 5;
pub const SAY_PICK : str = "Input";
pub const SAY_PATTERNS : [5]str = ["vertical bar", "horizontal bar", "diagonal", "noise", "inverted bar"];
pub const SAY_TH : str = "Threshold";
pub const SAY_INPUT : str = "input (press a cell)";
pub const SAY_WEIGHTS : str = "weights: a vertical bar";
pub const SAY_PRODUCTS : str = "products";
pub const SAY_FIRE : str = "sum {0}: output {1}";
pub const SAY_TABLE : str = "Every pattern through the same neuron";
pub const SAY_ROW : str = "{0}: sum {1}, output {2}";
pub const SAY_HOW : str = "The sum counts agreements minus disagreements with the weights.";
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_THRESHOLD == 5;
}
