hclang 0.44.1 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2735,6 +2735,401 @@ export const HC_SOURCES = new Map([
2735
2735
  "",
2736
2736
  ].join("\n"),
2737
2737
  ],
2738
+ [
2739
+ "hc/denum.hc",
2740
+ [
2741
+ "#!/usr/bin/env hc",
2742
+ "```",
2743
+ "Denum (occurrence/figure 007.31, 007.32, 007.32b)",
2744
+ "",
2745
+ "A Denum is a constructed state of the binary Cayley–Dickson step ladder: a",
2746
+ "schema `CD[n]`, a retained application Count, and a nonnegative integer load on",
2747
+ "every signature channel. It is not a conventional number. Its conventional",
2748
+ "algebraic value is an observation, `d.observe ()`, and opposite channels stay",
2749
+ "separately counted after every operation, so `X + Opp X` is a present, nonempty",
2750
+ "Denum that merely observes as zero.",
2751
+ "",
2752
+ "`x.#n` answers a Denum of rank n for n from 0 to 5, and there is no `#n=`",
2753
+ '(see "The ranked hash" below). `Denum [rank, count, loads]` builds one directly.',
2754
+ "`Denum` is an ordinary HC class, like `Demi`; its arithmetic is the Cayley–Dickson",
2755
+ "recurrence `(a,b)(c,d) = (ac − d̄b, da + bc̄)`, computed by the one pure native",
2756
+ "seam `denum-engine` (`lib/ops/denum.ts`, over the typed reference in",
2757
+ "`lib/frames/denum.ts`), so no multiplication table is written in HC or in",
2758
+ "TypeScript. Everything else a Denum does is in this file.",
2759
+ "",
2760
+ "**Ranks and channels.** Rank n is the schema `CD[n]`, the rung of the step",
2761
+ "ladder, not the arity. Rank 0 has one unsigned channel, `e_ε`. Rank n of 1 or",
2762
+ "more has 2ⁿ channels, `±e_b` for every direction `b` of n−1 bits, positives",
2763
+ "first and then negatives, each in direction order:",
2764
+ "",
2765
+ " CD[0] e_ε",
2766
+ " CD[1] e_ε, -e_ε",
2767
+ " CD[2] e_0, e_1, -e_0, -e_1",
2768
+ " CD[3] e_00, e_01, e_10, e_11, -e_00, -e_01, -e_10, -e_11",
2769
+ " CD[4] ±e_b for b in {0,1}³ 16 channels",
2770
+ " CD[5] ±e_b for b in {0,1}⁴ 32 channels",
2771
+ "",
2772
+ "A minus names a *signature*, never a negative load: every load is a Count.",
2773
+ "`d.signatures ()` lists the native names in channel order.",
2774
+ "",
2775
+ "**State.** `d.rank`, `d.schema` (the text `CD[n]`), `d.count` (the full",
2776
+ "application Count, kept apart from the loads) and `d.loads` (one Count per",
2777
+ "channel). Anything that is not a rank from 0 to 5, a Count, and exactly the",
2778
+ "rank's number of Counts is refused with `$!!.invalid-denum`. `Denum [0, 0, [0]]`,",
2779
+ "an explicit zero-load D0, is present: it is neither the missing host that",
2780
+ "`[].#0` leaves nil nor a nonempty Denum that observes as zero.",
2781
+ "",
2782
+ "**Arithmetic.** `+`, `-` and `*` take another Denum, and only a Denum: the",
2783
+ "right operand is reconstructed from its `rank`, `count` and `loads` through the",
2784
+ "shipped constructor and must be `=` to that reconstruction, the same test `x.#n`",
2785
+ "applies to a source. A lookalike aggregate with the same fields, a Count, text",
2786
+ "or a list is `$!!.invalid-denum`. Operands of different",
2787
+ "rank are both promoted to the larger rank first (`promote`), and the result is a",
2788
+ "fresh Denum of that rank:",
2789
+ "",
2790
+ "- `a + b` adds corresponding loads and keeps opposite channels separate.",
2791
+ "- `a * b` is the ordered Cartesian product of weighted signatures: loads",
2792
+ " multiply, the signed destination is the recurrence's, and only identical full",
2793
+ " signatures aggregate. Operand order and parentheses are kept, and from",
2794
+ " rank 4 the product is not associative.",
2795
+ "- `a - b` is `a + b.opp ()`: subtraction is addition of the opposite, observed,",
2796
+ " never erased.",
2797
+ "- `d.opp ()` swaps the loads of `+e_b` and `-e_b`; a D0 is promoted to D1 first.",
2798
+ "- `d.conj ()` keeps the scalar signatures and swaps every other pair.",
2799
+ "- `d.promote k` embeds into rank k by the old-summand map, `±e_b ↦ ±e_(0b)`,",
2800
+ " keeping Count and loads and starting new channels at zero. A lower k is",
2801
+ " `$!.denum-demotion`.",
2802
+ "- `d.observe ()` is the algebraic observation: the signed coordinate of each",
2803
+ " direction, positive load minus negative load. It is a list of integers, and",
2804
+ " not the Denum.",
2805
+ "",
2806
+ "**Count.** The candidate laws of 007.32 section 6 hold for these new operations",
2807
+ "only: `C(a+b) = C(a)+C(b)`, `C(a*b) = C(a)·C(b)` and `C(Opp a) = C(a)`, and",
2808
+ "promotion and conjugation keep Count. Count is carried, never derived from the",
2809
+ "loads, and it is not the application phase `C mod arity`. `Demi` and its `+`,",
2810
+ "`-`, `*` and `./` are unchanged. This is a software construction of a supplied",
2811
+ "recurrence, not a derivation of it from bare counting.",
2812
+ "",
2813
+ "**Observers.** A Denum declares its own Count (`d.#`), Size (`d.##`, the total",
2814
+ "load) and residual (`d.###`, positive minus negative total, 0 at rank 0). Its",
2815
+ "`.####` is therefore the ordinary derived Demi of those three, which is binary",
2816
+ "and forgets the directions; `d.#n` is the Denum.",
2817
+ "",
2818
+ "**The ranked hash.** For any Frame x, `x.#n` for n from 0 to 5 answers the",
2819
+ "Denum of rank n, `nil` when x has no Count or Count zero, as `x.####` does.",
2820
+ "For an ordinary or binary host `x.#1` has the Count and the left and right",
2821
+ "loads of `x.####`. A `RotorRouter` of more than two channels is the exception:",
2822
+ "`.####` answers its channel Demi, and `.#n` does not special-case it, so it is",
2823
+ "the two-channel projection of the router's Count, Size and residual.",
2824
+ "Bare `x.#` is still the Count. The host is built from the three observers it",
2825
+ "answers, Count C, Size s and residual r: rank 0 keeps the load s, and rank",
2826
+ "n ≥ 1 puts (s+r)/2 on `e_0…0` and (s−r)/2 on `-e_0…0`, the two channels the",
2827
+ "fourth hash reads as left and right, with every other channel zero. A host's",
2828
+ "applications carry no higher signature, so none is routed to them. That is",
2829
+ "construction, and it is not promotion. A Denum instance answers `x.#n` by",
2830
+ "promotion to rank n (and `$!.denum-demotion` below its own rank), keeping Count",
2831
+ "and loads, and a forged lookalike is not recognized. A rank above 5 is",
2832
+ "`$!.denum-rank`.",
2833
+ "",
2834
+ "The class is evaluated from the compiled-in bundle the first time a ranked hash",
2835
+ "needs it, in a namespace of its own (`lib/execute/denum-prologue.ts`), so this",
2836
+ "file must not import.",
2837
+ "```",
2838
+ ".denum-state {.r (_ .0); .c (_ .1); .l (_ .2); .s (denum-engine [9, r, c, l]); [",
2839
+ " .rank r;",
2840
+ " .schema s;",
2841
+ " .count c;",
2842
+ " .loads l;",
2843
+ " .# {_^.count};",
2844
+ " .## {(_^ .loads).##};",
2845
+ " .### {denum-engine [10, (_^ .rank), (_^ .count), (_^ .loads)]};",
2846
+ " .+ {.o (_^^ .operand _); .me _^; .f (_^^ .finish);",
2847
+ " (f (denum-engine [1, (me .rank), (me .count), (me .loads), (o .rank), (o .count), (o .loads)]))};",
2848
+ " .- {.o (_^^ .operand _); .me _^; .f (_^^ .finish);",
2849
+ " (f (denum-engine [2, (me .rank), (me .count), (me .loads), (o .rank), (o .count), (o .loads)]))};",
2850
+ " .* {.o (_^^ .operand _); .me _^; .f (_^^ .finish);",
2851
+ " (f (denum-engine [3, (me .rank), (me .count), (me .loads), (o .rank), (o .count), (o .loads)]))};",
2852
+ " .promote {.k _; .me _^; .f (_^^ .finish);",
2853
+ " (f (denum-engine [6, (me .rank), (me .count), (me .loads), k]))};",
2854
+ " .opp {.u ((_ = ()) ? {1} : {0}); .me _^; .f (_^^ .finish);",
2855
+ " (u = 1) ? {(f (denum-engine [4, (me .rank), (me .count), (me .loads)]))} : {$!!.unary-observation}};",
2856
+ " .conj {.u ((_ = ()) ? {1} : {0}); .me _^; .f (_^^ .finish);",
2857
+ " (u = 1) ? {(f (denum-engine [5, (me .rank), (me .count), (me .loads)]))} : {$!!.unary-observation}};",
2858
+ " .observe {.u ((_ = ()) ? {1} : {0}); .me _^;",
2859
+ " (u = 1) ? {denum-engine [7, (me .rank), (me .count), (me .loads)]} : {$!!.unary-observation}};",
2860
+ " .signatures {.u ((_ = ()) ? {1} : {0}); .me _^;",
2861
+ " (u = 1) ? {denum-engine [8, (me .rank), (me .count), (me .loads)]} : {$!!.unary-observation}};",
2862
+ " .toText {“Denum(” (_^ .schema) “, C=” (_^ .count) “, W=” (_^ .loads) “)”}",
2863
+ " ]};",
2864
+ ".operand {.o _; .r (Denum [(o .rank), (o .count), (o .loads)]); (o = r) ? {o} : {$!!.invalid-denum}};",
2865
+ ".finish {.s _; ((s ~ ([].<>)) ? {denum-state s} : {s})};",
2866
+ ".Denum {.a _; ((a ~ ([].<>)) ? {(a .#) = 3}) ? {.s (denum-engine [0, (a .0), (a .1), (a .2)]);",
2867
+ " (s ~ ([].<>)) ? {denum-state s} : {$!!.invalid-denum}} : {$!!.invalid-denum}};",
2868
+ "```",
2869
+ "## Construction",
2870
+ "",
2871
+ "A Denum holds its schema, its Count and one load per channel. The rank-0 seed",
2872
+ "has one unsigned channel, and an explicit zero-load D0 is present",
2873
+ "```",
2874
+ "; .z (Denum [0, 0, [0]]);",
2875
+ "; [z.rank, z.schema, z.count, z.loads, z.#, z.##, z.###, “” z]",
2876
+ "# [0, “CD[0]”, 0, [0], 0, 0, 0, “Denum(CD[0], C=0, W=[0])”]",
2877
+ "```",
2878
+ "The loads are Counts, one per channel, and the Count is kept apart from them: a",
2879
+ "Denum may hold loads at Count zero, or a Count over zero loads. A rank beyond 5,",
2880
+ "a negative Count or load, a fractional load, the wrong number of loads and a",
2881
+ "non-list (a bare Count or text for the loads included) are all refused",
2882
+ "```",
2883
+ "; [“” (Denum [2, 7, [3, 2, 0, 1]]), “” (Denum [1, 0, [4, 0]]), “” (Denum [1, 5, [0, 0]])]",
2884
+ "# [“Denum(CD[2], C=7, W=[3, 2, 0, 1])”, “Denum(CD[1], C=0, W=[4, 0])”, “Denum(CD[1], C=5, W=[0, 0])”]",
2885
+ "; [Denum [6, 0, [0]], Denum [1, (0 - 1), [0, 0]], Denum [1, 0, [0, (0 - 1)]], Denum [1, 0, [0, 1.5]], Denum [2, 0, [0, 0, 0]], Denum [0, 0, [0, 0]], Denum 5, Denum [1, 0], Denum [1, 0, [0, 0], 9], Denum [0, 0, 5], Denum [1, 0, 5], Denum [0, 0, “x”]]",
2886
+ "# [$!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum]",
2887
+ "```",
2888
+ "## Signatures",
2889
+ "",
2890
+ "The native spelling has no sign bit: the direction is a bitstring of rank − 1",
2891
+ "bits, and a minus names the opposite signature. Rank 0 has only `e_ε`",
2892
+ "```",
2893
+ "; [(Denum [0, 0, [0]]).signatures (), (Denum [1, 0, [0, 0]]).signatures (), (Denum [2, 0, [0, 0, 0, 0]]).signatures ()]",
2894
+ "# [[“e_ε”], [“e_ε”, “-e_ε”], [“e_0”, “e_1”, “-e_0”, “-e_1”]]",
2895
+ "; (Denum [3, 0, [0, 0, 0, 0, 0, 0, 0, 0]]).signatures ()",
2896
+ "# [“e_00”, “e_01”, “e_10”, “e_11”, “-e_00”, “-e_01”, “-e_10”, “-e_11”]",
2897
+ "; (Denum [4, 0, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]).signatures () .# ",
2898
+ "# 16",
2899
+ "; ((Denum [5, 0, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]).signatures ()) .# ",
2900
+ "# 32",
2901
+ "```",
2902
+ "## Rank 0 and rank 1: Size and signed integers",
2903
+ "",
2904
+ "D0 adds and multiplies unsigned Size, and Counts add and multiply with it. D1",
2905
+ "has the two signatures `e_ε` and `-e_ε`, and the product of two minus signatures",
2906
+ "is the plus signature, `(-e_ε)(-e_ε) = e_ε`, while every load stays a Count",
2907
+ "```",
2908
+ "; .a (Denum [0, 2, [3]]); .b (Denum [0, 5, [4]]);",
2909
+ "; [(a + b).loads, (a + b).count, (a * b).loads, (a * b).count]",
2910
+ "# [[7], 7, [12], 10]",
2911
+ "; .p (Denum [1, 1, [1, 0]]); .m (Denum [1, 1, [0, 1]]);",
2912
+ "; [(m * m).loads, (m * p).loads, (p * m).loads, (p * p).loads]",
2913
+ "# [[1, 0], [0, 1], [0, 1], [1, 0]]",
2914
+ "; [((Denum [1, 1, [0, 2]]) * (Denum [1, 1, [0, 3]])).loads, ((Denum [1, 1, [0, 2]]) * (Denum [1, 1, [0, 3]])).observe ()]",
2915
+ "# [[6, 0], [6]]",
2916
+ "```",
2917
+ "Opposite swaps the two channels and subtraction adds the opposite. The balanced",
2918
+ "result observes as zero yet is a present, nonempty Denum with both loads",
2919
+ "```",
2920
+ "; .x (Denum [1, 1, [5, 2]]); .y (Denum [1, 1, [3, 0]]);",
2921
+ "; [x.observe (), (x.opp ()).loads, (x - y).loads, (x - y).observe (), (x - y).count]",
2922
+ "# [[3], [2, 5], [5, 5], [0], 2]",
2923
+ "; .s (Denum [1, 1, [4, 4]]);",
2924
+ "; [s.observe (), s.loads, s.#, s.##, s.###]",
2925
+ "# [[0], [4, 4], 1, 8, 0]",
2926
+ "```",
2927
+ "A D0 has no negative signature, so its opposite is promoted to D1 first",
2928
+ "```",
2929
+ "; ((Denum [0, 3, [4]]).opp ()).loads",
2930
+ "# [0, 4]",
2931
+ "; ((Denum [0, 3, [4]]).opp ()).schema",
2932
+ "# “CD[1]”",
2933
+ "```",
2934
+ "## Operands are Denums only",
2935
+ "",
2936
+ "`+`, `-` and `*` refuse a right operand that is not a Denum, even when it carries",
2937
+ "the same `rank`, `count` and `loads` fields, as `x.#n` refuses a forged source",
2938
+ "```",
2939
+ "; .dp (Denum [1, 1, [1, 0]]); .lookalike [.rank 1; .count 1; .loads [1, 0]];",
2940
+ "; [dp + lookalike, dp - lookalike, dp * lookalike, dp + [1, 1, [1, 0]], dp * 2]",
2941
+ "# [$!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum, $!!.invalid-denum]",
2942
+ "; [(dp + dp).loads, (dp * (dp + dp)).loads, (dp + (dp.opp ())).loads]",
2943
+ "# [[2, 0], [2, 0], [1, 1]]",
2944
+ "```",
2945
+ "## Rank 2: J² = −1 and the four-step cycle",
2946
+ "",
2947
+ "`e_1` is the direction bit of J. Its square is the opposite scalar `-e_0`, and",
2948
+ "the fourth power is back at `e_0`, observed",
2949
+ "```",
2950
+ "; .j (Denum [2, 1, [0, 1, 0, 0]]);",
2951
+ "; [(j * j).loads, (j * j).observe (), ((j * j) * (j * j)).loads, ((j * j) * (j * j)).observe ()]",
2952
+ "# [[0, 0, 1, 0], [-1, 0], [1, 0, 0, 0], [1, 0]]",
2953
+ "```",
2954
+ "## Rank 3: order matters",
2955
+ "",
2956
+ "With J = `e_01`, I = `e_10` and K = `e_11`, J·I = K and I·J = −K",
2957
+ "```",
2958
+ "; .J (Denum [3, 1, [0, 1, 0, 0, 0, 0, 0, 0]]); .I (Denum [3, 1, [0, 0, 1, 0, 0, 0, 0, 0]]);",
2959
+ "; [(J * I).loads, (I * J).loads]",
2960
+ "# [[0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1]]",
2961
+ "```",
2962
+ "## Rank 4: the octonion associator",
2963
+ "",
2964
+ "`(e_001 e_010) e_100` is `+e_111` and `e_001 (e_010 e_100)` is `-e_111`. The",
2965
+ "Denum keeps the parentheses, so the two groupings differ",
2966
+ "```",
2967
+ "; .o1 (Denum [4, 1, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]); .o2 (Denum [4, 1, [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]); .o4 (Denum [4, 1, [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]);",
2968
+ "; [((o1 * o2) * o4).loads, (o1 * (o2 * o4)).loads]",
2969
+ "# [[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]",
2970
+ "; [((o1 * o2) * o4).observe () = (o1 * (o2 * o4)).observe ()]",
2971
+ "# [()]",
2972
+ "```",
2973
+ "Through rank 3 the product is associative, so the same three directions in the",
2974
+ "quaternions agree",
2975
+ "```",
2976
+ "; [(J * I) * J = (J * (I * J)), ((J * I) * J).observe ()]",
2977
+ "# [<>, [0, 0, 1, 0]]",
2978
+ "```",
2979
+ "## Rank 5: sedenion zero divisors",
2980
+ "",
2981
+ "`(e_0001 + e_1010)(e_0100 − e_1111)` observes as zero though neither factor does.",
2982
+ "The product is not an empty Denum: it holds four loads, in cancelling pairs",
2983
+ "```",
2984
+ "; .u (Denum [5, 1, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]); .v (Denum [5, 1, [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]);",
2985
+ "; [u.observe (), v.observe ()]",
2986
+ "# [[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1]]",
2987
+ "; .w (u * v);",
2988
+ "; [w.observe (), w.count, w.##, w.###, w.loads]",
2989
+ "# [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 1, 4, 0, [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]]",
2990
+ "```",
2991
+ "## Promotion across the ladder",
2992
+ "",
2993
+ "Promotion embeds a lower rung into a higher one as the old summand,",
2994
+ "`±e_b ↦ ±e_(0b)`, keeping the Count and every load and starting the new channels",
2995
+ "at zero. D0 goes to the positive scalar, so the new minus channel is empty, and",
2996
+ "the map is path independent",
2997
+ "```",
2998
+ "; .t (Denum [0, 4, [6]]);",
2999
+ "; [(t.promote 1).loads, (t.promote 2).loads, ((t.promote 1).promote 2).loads = (t.promote 2).loads, (t.promote 3).count]",
3000
+ "# [[6, 0], [6, 0, 0, 0], <>, 4]",
3001
+ "; .k (Denum [1, 3, [2, 5]]);",
3002
+ "; [(k.promote 2).loads, (k.promote 3).loads, ((k.promote 2).promote 3).loads = (k.promote 3).loads, k.loads, k.rank]",
3003
+ "# [[2, 0, 5, 0], [2, 0, 0, 0, 5, 0, 0, 0], <>, [2, 5], 1]",
3004
+ "; [((Denum [2, 1, [0, 1, 0, 0]]).promote 3).loads, ((Denum [2, 1, [0, 0, 0, 1]]).promote 3).loads]",
3005
+ "# [[0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0]]",
3006
+ "```",
3007
+ "A lower rank is refused, and so is a rank above 5 or something that is not a",
3008
+ "Count. The source is never changed",
3009
+ "```",
3010
+ "; [(Denum [3, 1, [0, 0, 0, 0, 0, 0, 0, 0]]).promote 2, k.promote 6, k.promote (0 - 1), k.promote “x”]",
3011
+ "# [$!.denum-demotion, $!.denum-rank, $!.denum-rank, $!.denum-rank]",
3012
+ "```",
3013
+ "Mixed ranks promote to the larger one before the operation, and the product keeps",
3014
+ "its operand order. A rank 2 and a rank 3 Denum multiply as two rank 3 Denums",
3015
+ "```",
3016
+ "; .c2 (Denum [2, 2, [0, 1, 0, 0]]); .c3 (Denum [3, 3, [0, 0, 1, 0, 0, 0, 0, 0]]);",
3017
+ "; [(c2 * c3).schema, (c2 * c3).loads, (c3 * c2).loads, (c2 * c3).loads = ((c2.promote 3) * c3).loads, (c2 + c3).schema, (c2 + c3).count]",
3018
+ "# [“CD[3]”, [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], <>, “CD[3]”, 5]",
3019
+ "; [((c3.promote 5) * (Denum [5, 1, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])).loads = ((c3 * (Denum [3, 1, [0, 1, 0, 0, 0, 0, 0, 0]])).promote 5).loads]",
3020
+ "# [<>]",
3021
+ "```",
3022
+ "## Conjugation",
3023
+ "",
3024
+ "Conjugation fixes the scalar signatures and swaps the two channels of every",
3025
+ "other direction. It keeps the Count and the loads. A product conjugates in",
3026
+ "reverse order, observed",
3027
+ "```",
3028
+ "; .g (Denum [2, 4, [1, 2, 3, 4]]);",
3029
+ "; [(g.conj ()).loads, (g.conj ()).count, (g.conj ()).observe (), g.observe ()]",
3030
+ "# [[1, 4, 3, 2], 4, [-2, 2], [-2, -2]]",
3031
+ "; [(((J * I).conj ()).observe ()) = (((I.conj ()) * (J.conj ())).observe ()), ((Denum [0, 1, [4]]).conj ()).loads]",
3032
+ "# [<>, [4]]",
3033
+ "```",
3034
+ "## Count",
3035
+ "",
3036
+ "Count is carried and never derived from the loads. For these Denum operations",
3037
+ "it adds under `+`, multiplies under `*`, and survives the opposite, conjugation",
3038
+ "and promotion. A Count of zero may hold nonzero loads",
3039
+ "```",
3040
+ "; .e (Denum [2, 3, [1, 0, 0, 2]]); .f (Denum [2, 4, [0, 5, 1, 0]]);",
3041
+ "; [(e + f).count, (e * f).count, (e.opp ()).count, (e.conj ()).count, (e.promote 4).count, (e - f).count]",
3042
+ "# [7, 12, 3, 3, 3, 7]",
3043
+ "; .odd (Denum [2, 0, [3, 0, 0, 0]]);",
3044
+ "; [odd.count, odd.##, (odd * f).count, (odd * f).loads, (odd + f).count]",
3045
+ "# [0, 3, 0, [0, 15, 3, 0], 4]",
3046
+ "```",
3047
+ "## The ranked hash",
3048
+ "",
3049
+ "`x.#n` is the Denum of rung n for n from 0 to 5, and bare `x.#` is still the",
3050
+ "Count. A host answers its Count C, Size s and residual r, so `[1, 2, 3]` has",
3051
+ "C = 3, s = 6 and r = 2. Rank 0 keeps the one load s, rank 1 puts (s+r)/2 on",
3052
+ "`e_ε` and (s−r)/2 on `-e_ε`, which are the Demi's left and right loads, and a",
3053
+ "higher rank puts the same two on `e_0…0` and `-e_0…0`",
3054
+ "```",
3055
+ "; .xs [1, 2, 3];",
3056
+ "; [xs.#, xs.##, xs.###, “” (xs.####)]",
3057
+ "# [3, 6, 2, “Demi(3,4,2)”]",
3058
+ "; [“” (xs.#0), “” (xs.#1), “” (xs.#2)]",
3059
+ "# [“Denum(CD[0], C=3, W=[6])”, “Denum(CD[1], C=3, W=[4, 2])”, “Denum(CD[2], C=3, W=[4, 0, 2, 0])”]",
3060
+ "; [(xs.#3).loads, (xs.#4).##, (xs.#5).schema, (xs.#5).loads .#, (xs.#5).observe ()]",
3061
+ "# [[4, 0, 0, 0, 2, 0, 0, 0], 6, “CD[5]”, 32, [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]",
3062
+ "; [xs.#1.loads = xs.####.loads, xs.#1.count = xs.####.count]",
3063
+ "# [<>, <>]",
3064
+ "```",
3065
+ "A router of more than two channels keeps its channel Demi under `.####`, and",
3066
+ "`.#1` is the binary projection of the same three observers, which is what the",
3067
+ "fourth hash derives for a binary router. Both answers are pinned",
3068
+ "```",
3069
+ "; Routers <- './hc/rotor-router.hc';",
3070
+ "; .RotorRouter Routers.RotorRouter;",
3071
+ "; .r3 (RotorRouter [[5, 8], [6], [7]]); .r2 (RotorRouter [[5], [6]]);",
3072
+ "; [r3.#, r3.##, r3.###, “” r3.####, “” r3.#1, “” r3.#2, (r3.#1).count = r3.####.count]",
3073
+ "# [4, 26, 14, “Demi(4,[13, 6, 7])”, “Denum(CD[1], C=4, W=[20, 6])”, “Denum(CD[2], C=4, W=[20, 0, 6, 0])”, <>]",
3074
+ "; [“” r2.####, “” r2.#1, (r2.#1).loads = [(r2.####).left, (r2.####).right]]",
3075
+ "# [“Demi(2,5,6)”, “Denum(CD[1], C=2, W=[5, 6])”, <>]",
3076
+ "```",
3077
+ "It is construction, not promotion. Promotion of an existing Demi-shaped host",
3078
+ "adds nothing, because a host's applications carry no higher signature. Each",
3079
+ "observer is read once, and a Frame without a Count has no Denum, as it has no",
3080
+ "Demi. An empty host, zero Count and nil answer nil at every rank",
3081
+ "```",
3082
+ "; [[].#0, [].#1, [].#5, ().#2, 0.#3]",
3083
+ "# [(), (), (), (), ()]",
3084
+ "; [“”.#1, “” (“a”.#0), ({5 + 3}.#1).loads = ({5 + 3}.####).loads, ({5 + 3}.#1).count]",
3085
+ "# [(), “Denum(CD[0], C=1, W=[1])”, <>, 3]",
3086
+ "```",
3087
+ "Application to a zero Size still counts, so a Denum of zero loads can have a",
3088
+ "positive Count, and it is present. It is not the missing host",
3089
+ "```",
3090
+ "; .zs [0, 0];",
3091
+ "; [“” (zs.#0), “” (zs.#1), zs.#0 = (), (Denum [0, 0, [0]]) = ()]",
3092
+ "# [“Denum(CD[0], C=2, W=[0])”, “Denum(CD[1], C=2, W=[0, 0])”, (), ()]",
3093
+ "```",
3094
+ "A Denum answers the ranked hash by promotion of its own state, at every Count",
3095
+ "including zero, and `$!.denum-demotion` below its rank. Nothing the source",
3096
+ "declares can steer it: a lookalike aggregate with the same fields is an",
3097
+ "ordinary host and is measured like any other",
3098
+ "```",
3099
+ "; .dn (Denum [1, 0, [3, 1]]);",
3100
+ "; [“” (dn.#1), “” (dn.#3), (dn.#2).loads, (dn.#5).count, dn.#0]",
3101
+ "# [“Denum(CD[1], C=0, W=[3, 1])”, “Denum(CD[3], C=0, W=[3, 0, 0, 0, 1, 0, 0, 0])”, [3, 0, 1, 0], 0, $!.denum-demotion]",
3102
+ "; .fake [.rank 1; .count 9; .loads [3, 1]; .# {99}; .## {99}; .### {99}];",
3103
+ "; [“” (fake.#1), “” (fake.#0), fake.#]",
3104
+ "# [“Denum(CD[1], C=99, W=[99, 0])”, “Denum(CD[0], C=99, W=[99])”, 99]",
3105
+ "; [xs.#6, xs.#7, xs.#99]",
3106
+ "# [$!.denum-rank, $!.denum-rank, $!.denum-rank]",
3107
+ "```",
3108
+ "The derived hash of a Denum is the ordinary derived Demi of its three",
3109
+ "observers, which is binary and forgets directions. `d.#n` is the Denum, and its",
3110
+ "algebraic value is an observation, never the return of `#n`",
3111
+ "```",
3112
+ "; [dn.####, “” ((Denum [2, 5, [1, 2, 3, 4]]).####)]",
3113
+ "# [(), “Demi(5,3,7)”]",
3114
+ "```",
3115
+ "`Demi` keeps its own contracts. Its `+`, `-`, `*` and `./` are not Denum",
3116
+ "arithmetic, and a Denum is not a Demi",
3117
+ "```",
3118
+ "; .d (xs.####);",
3119
+ "; [“” (d + 5), “” (d * 2), “” (d ./ 3), xs.#1 + 5]",
3120
+ "# [“Demi(3,4,7)”, “Demi(3,8,4)”, “Demi(3,[2, 2, 2])”, $!!.invalid-denum]",
3121
+ "```",
3122
+ "## Syntax boundaries",
3123
+ "",
3124
+ "The ranked hash is `.#` followed directly by decimal digits. A space ends it,",
3125
+ "and `.##` and `.###` are unchanged. A plain `#` still starts a comment, and the",
3126
+ "lexer cases are pinned in `lib/frames/frame-name.test.ts`",
3127
+ "```",
3128
+ "; [xs.# 2, xs.##, xs.###, xs.##]",
3129
+ "# [6, 6, 2, 6]",
3130
+ "",
3131
+ ].join("\n"),
3132
+ ],
2738
3133
  [
2739
3134
  "hc/division.hc",
2740
3135
  [
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The Denum class, loaded from HC for the ranked hash.
3
+ *
4
+ * `x.#n` answers a Denum, and a Denum is an HC class, `Denum` in
5
+ * `hc/denum.hc` (occurrence/figure 007.32). The frames package derives the
6
+ * state natively but cannot run HC, so this module installs the constructor it
7
+ * calls (`installDenumConstructor`), exactly as `demi-prologue.ts` does for
8
+ * `.####`.
9
+ *
10
+ * The class is read from the compiled-in bundle, not through a resource root,
11
+ * so `.#n` works in a bare `evaluate`, which has no root and imports nothing.
12
+ * The file is evaluated the first time a Denum is constructed, once per
13
+ * process: its example lines are dropped and the first failure fails the whole.
14
+ * It runs in a namespace of its own, with no host bindings and no root, so it
15
+ * can read nothing but the global operators, among them the pure
16
+ * `denum-engine`, and nothing a program declares can reach it. Its outcome is
17
+ * kept, failure included, so it is never evaluated twice. A Denum requested
18
+ * while the file is still loading is `$!.denum-prologue-reentrant`.
19
+ *
20
+ * @module
21
+ */
22
+ import { EvaluationScope, Frame, FrameArray, FrameCount, FrameExpr, installDenumConstructor, } from "../frames.js";
23
+ import { HC_SOURCES } from "../bundle/hc-sources.js";
24
+ import { evaluateSourceText } from "./resource-import.js";
25
+ /** The bundled file that defines the class. */
26
+ export const DENUM_SOURCE = "hc/denum.hc";
27
+ /** The name the file declares the constructor under. */
28
+ export const DENUM_CLASS = "Denum";
29
+ let loaded;
30
+ let loading = false;
31
+ /**
32
+ * Evaluates class source in a namespace of its own, answering its `Denum` or
33
+ * the failure. Uncached: `denumClass` keeps the one result the process uses.
34
+ *
35
+ * @param source The source text, or undefined when the bundle lacks it.
36
+ * @returns The constructor, or an error.
37
+ */
38
+ export function loadDenumClass(source) {
39
+ if (source === undefined) {
40
+ return Frame.error(`$!.denum-prologue-missing ${DENUM_SOURCE}`);
41
+ }
42
+ const namespace = new FrameArray([]);
43
+ const result = evaluateSourceText(source, EvaluationScope.root(namespace));
44
+ if (result.isFailedResult() || result.observationError())
45
+ return result;
46
+ const constructor = namespace.getOwn(DENUM_CLASS);
47
+ return constructor.is.missing
48
+ ? Frame.error(`$!.denum-prologue-missing ${DENUM_CLASS}`)
49
+ : constructor;
50
+ }
51
+ /**
52
+ * The `Denum` constructor closure, evaluated from the bundle on first use.
53
+ *
54
+ * @returns The constructor, or the error that loading it answered.
55
+ */
56
+ export function denumClass() {
57
+ if (loaded)
58
+ return loaded;
59
+ if (loading)
60
+ return Frame.error("$!.denum-prologue-reentrant");
61
+ loading = true;
62
+ try {
63
+ loaded = loadDenumClass(HC_SOURCES.get(DENUM_SOURCE));
64
+ }
65
+ finally {
66
+ loading = false;
67
+ }
68
+ return loaded;
69
+ }
70
+ /**
71
+ * Constructs a Denum with the HC class: `Denum [rank, count, loads]`.
72
+ *
73
+ * @param state The rank, Count and loads, already admissible.
74
+ * @returns The new instance, or the class's failure.
75
+ */
76
+ export function constructDenum(state) {
77
+ const constructor = denumClass();
78
+ if (constructor.isFailedResult() || constructor.observationError()) {
79
+ return constructor;
80
+ }
81
+ const argument = new FrameArray([
82
+ new FrameCount(BigInt(state.rank)),
83
+ new FrameCount(state.count),
84
+ new FrameArray(state.loads.map((load) => new FrameCount(load))),
85
+ ]);
86
+ return FrameExpr.answeredValue(constructor.call(argument)).referent();
87
+ }
88
+ installDenumConstructor(constructDenum);
@@ -1,6 +1,8 @@
1
1
  import { Frame, FrameCount, FrameString, FrameSymbol, } from "../frames.js";
2
2
  // Installs the Demi class that `.####` constructs (011.20).
3
3
  import "./demi-prologue.js";
4
+ // Installs the Denum class that the ranked hash `.#n` constructs (007.32).
5
+ import "./denum-prologue.js";
4
6
  // Installs the RotorRouter class that list division answers (007.27c).
5
7
  import "./router-prologue.js";
6
8
  import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";