Pepguy commited on
Commit
45a0163
Β·
verified Β·
1 Parent(s): 609dc98

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +678 -703
app.js CHANGED
@@ -1,8 +1,8 @@
1
- /**
2
  * axl_dataset_server.js
3
  * ══════════════════════════════════════════════════════════════════════════════
4
  * AXL Dataset Generation Server (Node.js/Express version)
5
- * Generates UCE training samples via AWS Bedrock + synthetic math injection.
6
  * Returns JSON for download. Tracks domain diversity across requests.
7
  *
8
  * Endpoints:
@@ -70,7 +70,7 @@ const bedrockClient = new BedrockRuntimeClient({
70
  async function callBedrock(prompt, maxTokens = 18000) {
71
  const command = new ConverseCommand({
72
  modelId: BEDROCK_MODEL_ID,
73
- messages: [{ role: "user", content: [{ text: prompt }] }],
74
  inferenceConfig: {
75
  maxTokens: maxTokens,
76
  temperature: 0.9,
@@ -112,12 +112,10 @@ encoder. AXL is what survives after domain is stripped away.
112
  Declares an abstraction level. Everything inside a scope inherits
113
  its level tag. Scopes are numbered β€” lower is more fundamental.
114
 
115
-
116
  SCOPE <name> [level: <int>]
117
  ...contents...
118
  END SCOPE
119
 
120
-
121
  Example levels (not hardcoded, user defined):
122
  - level 0 = most fundamental (quantum, bits)
123
  - level 1 = composed structures (atoms, bytes)
@@ -132,7 +130,6 @@ A thing that exists within a scope. Has fields, states, and
132
  existence conditions. An entity does not exist unless its
133
  REQUIRES clause is satisfied.
134
 
135
-
136
  ENTITY <name>
137
  FIELD <name>: <type> [BOUND <range>] [CONSERVES] [DISCRETE]
138
  STATE <name>: REQUIRES <condition>
@@ -140,7 +137,6 @@ ENTITY <name>
140
  DERIVES FROM <entity_list>
141
  END ENTITY
142
 
143
-
144
  **FIELD** β€” a measurable or logical property of the entity
145
  **CONSERVES** β€” this field cannot change across any TRANSFORM
146
  **DISCRETE** β€” field only takes integer or enumerated values
@@ -153,28 +149,24 @@ Axiom declaration. Taken as true without derivation.
153
  The foundation everything else builds on.
154
  Multiple ASSUMEs compound β€” all must hold simultaneously.
155
 
156
-
157
  ASSUME <statement>
158
  ASSUME <entity> EXISTS
159
  ASSUME <field> EQUALS <value>
160
  ASSUME <relationship> HOLDS
161
 
162
-
163
  ---
164
 
165
  ### 4. BOUND
166
  Hard constraint on a field or relationship.
167
  Nothing outside a BOUND can exist in this scope.
168
 
169
-
170
- BOUND <field> WITHIN [<min>, <max>]
171
  BOUND <field> ABOVE <value>
172
  BOUND <field> BELOW <value>
173
  BOUND <field> EQUALS <value> # exact, no freedom
174
- BOUND <entity> COUNT WITHIN [<min>, <max>]
175
  BOUND <a> FORBIDS <b> # mutual exclusion
176
 
177
-
178
  ---
179
 
180
  ### 5. TEND
@@ -182,27 +174,23 @@ Soft objective. The system pulls toward this but does not
182
  require it. Multiple TENDs create competing pressures that
183
  produce equilibrium β€” emergence happens here.
184
 
185
-
186
  TEND <field> MIN # pull toward minimum
187
  TEND <field> MAX # pull toward maximum
188
  TEND <field> TOWARD <value> # pull toward specific value
189
  TEND <system> STABLE # resist perturbation
190
  TEND <field> FOLLOW <other_field> # track another field
191
 
192
-
193
  ---
194
 
195
  ### 6. OBJECTIVE
196
  Hard optimization target. Unlike TEND, this must be satisfied
197
  for the scope to be considered resolved.
198
 
199
-
200
  OBJECTIVE <name>
201
  OPTIMIZE <field> [MIN | MAX | EQUAL <value>]
202
  SUBJECT TO <constraint_list>
203
  END OBJECTIVE
204
 
205
-
206
  ---
207
 
208
  ### 7. DERIVE
@@ -210,14 +198,12 @@ Declares that something follows necessarily from other things.
210
  If the sources hold, the derived thing must hold.
211
  This is the upward propagation engine.
212
 
213
-
214
  DERIVE <entity | field | state>
215
  FROM <source_list>
216
  WHEN <condition>
217
  BY <transform_name>
218
  END DERIVE
219
 
220
-
221
  ---
222
 
223
  ### 8. TRANSFORM
@@ -225,7 +211,6 @@ A process that maps one configuration to another.
225
  Transforms are the edges between scope levels.
226
  They must declare what they CONSERVE and what they CHANGE.
227
 
228
-
229
  TRANSFORM <name>
230
  INPUT <entity_or_field_list>
231
  OUTPUT <entity_or_field_list>
@@ -235,7 +220,6 @@ TRANSFORM <name>
235
  PRODUCES <postcondition>
236
  END TRANSFORM
237
 
238
-
239
  ---
240
 
241
  ### 9. OBSERVE
@@ -243,12 +227,10 @@ What has been measured. This is the B value in the UCE.
243
  The system will work backwards from this to find what
244
  configuration of unknowns is consistent with it.
245
 
246
-
247
  OBSERVE <field | entity | state> EQUALS <value>
248
  OBSERVE <field> WITHIN [<min>, <max>]
249
  OBSERVE <pattern> IN <output>
250
 
251
-
252
  ---
253
 
254
  ### 10. UNKNOWN
@@ -257,11 +239,9 @@ The system navigates the abstraction domain to find
257
  values of UNKNOWNs that satisfy all constraints
258
  given the OBSERVATIONs.
259
 
260
-
261
  UNKNOWN <name>: <type> BOUND [<min>, <max>]
262
  UNKNOWN <name>: DISCRETE WITHIN <set>
263
 
264
-
265
  ---
266
 
267
  ### 11. COLLAPSE
@@ -269,27 +249,23 @@ Instruction to reduce abstraction β€” find the most concrete
269
  configuration satisfying all active constraints.
270
  This is reverse abstraction in one word.
271
 
272
-
273
  COLLAPSE <scope | entity | system>
274
  GIVEN <observation_list>
275
  FIND <unknown_list>
276
  CONFIDENCE <threshold>
277
  END COLLAPSE
278
 
279
-
280
  ---
281
 
282
  ### 12. EXPAND
283
  Opposite of COLLAPSE. Given a concrete configuration,
284
  derive upward β€” what higher-level behaviors emerge?
285
 
286
-
287
  EXPAND <entity | configuration>
288
  THROUGH <scope_list>
289
  OBSERVE_EMERGENT <property_list>
290
  END EXPAND
291
 
292
-
293
  ---
294
 
295
  ### 13. CONTRADICT
@@ -298,12 +274,10 @@ Not an error β€” a scope boundary marker.
298
  Where contradictions appear is where the interesting
299
  physics, biology, and logic lives.
300
 
301
-
302
  CONTRADICT <statement_a> WITH <statement_b>
303
  AT SCOPE <level>
304
  BOUNDARY_TYPE [SCALE | SPEED | INFORMATION | ENERGY]
305
 
306
-
307
  ---
308
 
309
  ### 14. EMERGES
@@ -312,27 +286,23 @@ but appears when lower entities compose.
312
  Emergence is not reducible to its parts in AXL β€”
313
  it must be explicitly declared.
314
 
315
-
316
  EMERGES <property>
317
  FROM COMPOSITION OF <entity_list>
318
  AT SCOPE <level>
319
  NOT PRESENT AT SCOPE <lower_level>
320
 
321
-
322
  ---
323
 
324
  ### 15. COMPOSES
325
  Declares that an entity is built from other entities.
326
  Composition respects all lower-scope constraints.
327
 
328
-
329
  COMPOSES <higher_entity>
330
  FROM <lower_entity_list>
331
  BOUND count: <range>
332
  CONSERVING <field_list>
333
  END COMPOSES
334
 
335
-
336
  ---
337
 
338
  ### 16. STEP
@@ -340,41 +310,35 @@ Sequence counter for iterative or feedback processes.
340
  Enables the system to learn groups across attempts.
341
  Critical for the mining feedback loop.
342
 
343
-
344
  STEP <n>
345
  STATE <snapshot>
346
  CANDIDATE <configuration>
347
  DELTA <change_from_previous>
348
  END STEP
349
 
350
-
351
  ---
352
 
353
  ### 17. CANDIDATE
354
  A proposed solution configuration.
355
  Multiple candidates can coexist until COLLAPSE selects.
356
 
357
-
358
  CANDIDATE <n>
359
  <field>: <value>
360
  SCORE: <objective_value>
361
  CONFIDENCE: <float 0-1>
362
  END CANDIDATE
363
 
364
-
365
  ---
366
 
367
  ### 18. UNLESS
368
  Conditional override. Higher scope can override lower scope
369
  constraints under specific conditions.
370
 
371
-
372
  UNLESS <condition>
373
  OVERRIDE <constraint>
374
  WITH <replacement>
375
  END UNLESS
376
 
377
-
378
  ---
379
 
380
  ### 19. CONSERVES
@@ -382,643 +346,21 @@ Declares an invariant across the entire system regardless
382
  of what transforms occur. Conservation laws in physics,
383
  invariants in computation, conservation of mass β€” all CONSERVES.
384
 
385
-
386
  CONSERVES <quantity> ACROSS <transform_list>
387
  CONSERVES <quantity> WITHIN SCOPE <level>
388
 
389
-
390
  ---
391
 
392
  ### 20. SAMPLE
393
  A specific observed instance used as training signal
394
  for the diffusion engine. The raw material for learning.
395
 
396
-
397
  SAMPLE <id>
398
  INPUT <configuration>
399
  OUTPUT <observed_value>
400
  STEP <n>
401
  END SAMPLE
402
-
403
-
404
- ---
405
-
406
- ## PART II β€” GRAMMAR RULES
407
-
408
-
409
- program := scope_block+
410
- scope_block := SCOPE name [level] body END SCOPE
411
- body := statement*
412
- statement := assume | entity | bound | tend | objective
413
- | derive | transform | observe | unknown
414
- | collapse | expand | contradict | emerges
415
- | composes | step | candidate | conserves
416
- | sample | unless
417
-
418
- condition := field op value | entity EXISTS | state ACTIVE
419
- | condition AND condition | condition OR condition
420
- | NOT condition
421
-
422
- range := [min, max] | {discrete_set}
423
- direction := MIN | MAX | STABLE | TOWARD value | FOLLOW field
424
- type := REAL | INTEGER | BOOLEAN | SYMBOLIC | VECTOR
425
- op := EQUALS | ABOVE | BELOW | WITHIN | FORBIDS
426
-
427
-
428
- ---
429
-
430
- ## PART III β€” DEMONSTRATIONS
431
-
432
- ---
433
-
434
- ### DEMONSTRATION 1: THE ATOM
435
- #### Encoding atomic structure from quantum scope upward
436
-
437
- axl:
438
- # ════════════════════════════════════════════════════
439
- # ATOM SYSTEM
440
- # Starting assumption: energy exists and is quantized
441
- # ════════════════════════════════════════════════════
442
-
443
- SCOPE quantum [level: 0]
444
-
445
- ASSUME energy EXISTS
446
- ASSUME energy DISCRETE # quantization axiom
447
- ASSUME charge EXISTS
448
- CONSERVES charge ACROSS ALL_TRANSFORMS
449
- CONSERVES energy ACROSS ALL_TRANSFORMS UNLESS transform EQUALS radiation
450
-
451
- ENTITY quark
452
- FIELD charge: REAL BOUND [-1, 1] DISCRETE VALUES {-2/3, -1/3, 1/3, 2/3}
453
- FIELD color: SYMBOLIC DISCRETE VALUES {red, green, blue, antired, antigreen, antiblue}
454
- FIELD mass: REAL BOUND [0.002, 4.5] # GeV
455
- STATE free: REQUIRES energy ABOVE confinement_threshold
456
- STATE confined: REQUIRES energy BELOW confinement_threshold
457
- TENDS state TOWARD confined # quarks want to be bound
458
- END ENTITY
459
-
460
- ENTITY gluon
461
- FIELD charge: BOUND [0, 0] CONSERVES
462
- FIELD color: SYMBOLIC # carries color charge
463
- TENDS quark_binding MAX # gluons maximize binding
464
- END ENTITY
465
-
466
- BOUND quark COLOR_NEUTRAL IN any_free_composite # color confinement
467
-
468
- END SCOPE
469
-
470
-
471
- SCOPE hadron [level: 1]
472
-
473
- ASSUME quantum SCOPE HOLDS # inherit all quantum rules
474
-
475
- COMPOSES proton
476
- FROM quark COUNT EQUALS 3
477
- CONFIGURATION {up, up, down} # charge = 2/3+2/3-1/3 = +1
478
- CONSERVING charge
479
- BOUND total_charge EQUALS 1
480
- BOUND color EQUALS neutral # must be colorless
481
- END COMPOSES
482
-
483
- COMPOSES neutron
484
- FROM quark COUNT EQUALS 3
485
- CONFIGURATION {up, down, down} # charge = 2/3-1/3-1/3 = 0
486
- CONSERVING charge
487
- BOUND total_charge EQUALS 0
488
- BOUND color EQUALS neutral
489
- END COMPOSES
490
-
491
- EMERGES stability
492
- FROM COMPOSITION OF {proton, neutron}
493
- AT SCOPE hadron
494
- NOT PRESENT AT SCOPE quantum
495
- # individual quarks don't have nuclear stability β€” it emerges here
496
-
497
- END SCOPE
498
-
499
-
500
- SCOPE nucleus [level: 2]
501
-
502
- ASSUME hadron SCOPE HOLDS
503
-
504
- COMPOSES nucleus
505
- FROM {proton, neutron}
506
- BOUND proton_count WITHIN [1, 118] # known elements
507
- BOUND neutron_count WITHIN [0, 177]
508
- TEND binding_energy MAX # nucleus maximizes binding
509
- TEND neutron_to_proton_ratio TOWARD 1.0 # stability tendency
510
- END COMPOSES
511
-
512
- ENTITY strong_force
513
- FIELD range: BOUND [0, 3e-15] # femtometers β€” very short range
514
- FIELD strength: REAL
515
- TENDS nucleon_separation MIN # pulls nucleons together
516
- END ENTITY
517
-
518
- ENTITY weak_force
519
- TRANSFORMS neutron INTO proton
520
- WHEN neutron_to_proton_ratio ABOVE stable_ratio
521
- PRODUCES {proton, electron, antineutrino} # beta decay
522
- CONSERVING charge
523
- CONSERVING lepton_number
524
- END ENTITY
525
-
526
- EMERGES atomic_number
527
- FROM proton COUNT
528
- AT SCOPE nucleus
529
- # proton count alone determines element identity β€” pure emergence
530
-
531
- END SCOPE
532
-
533
-
534
- SCOPE atom [level: 3]
535
-
536
- ASSUME nucleus SCOPE HOLDS
537
-
538
- ENTITY electron
539
- FIELD charge: BOUND [-1, -1] CONSERVES
540
- FIELD mass: BOUND [9.109e-31, 9.109e-31] CONSERVES
541
- FIELD spin: DISCRETE VALUES {-0.5, 0.5}
542
- FIELD orbital: DISCRETE VALUES {s, p, d, f}
543
- FIELD energy_level: INTEGER BOUND [1, 7]
544
- TENDS energy MIN # electrons seek lowest energy
545
- BOUND same_orbital_same_spin FORBIDS # Pauli exclusion principle
546
- END ENTITY
547
-
548
- COMPOSES atom
549
- FROM {nucleus, electron}
550
- BOUND electron_count EQUALS proton_count # neutral atom
551
- TEND electron ORBITAL_FILL lowest_energy_first # Aufbau principle
552
- END COMPOSES
553
-
554
- EMERGES chemical_behavior
555
- FROM valence_electron_configuration
556
- AT SCOPE atom
557
- NOT PRESENT AT SCOPE nucleus
558
- # chemistry is purely a scope 3 emergence β€” nucleus knows nothing of it
559
-
560
- EMERGES periodic_properties
561
- FROM atomic_number MODULO orbital_filling_pattern
562
- AT SCOPE atom
563
-
564
- END SCOPE
565
-
566
-
567
- # ══ COLLAPSE EXAMPLE: Given observed spectral lines, find element ══
568
-
569
- OBSERVE spectral_emission EQUALS {656nm, 486nm, 434nm, 410nm}
570
-
571
- UNKNOWN element: SYMBOLIC WITHIN periodic_table
572
- UNKNOWN atomic_number: INTEGER BOUND [1, 118]
573
- UNKNOWN electron_configuration: VECTOR
574
-
575
- COLLAPSE atom
576
- GIVEN {spectral_emission}
577
- FIND {element, atomic_number, electron_configuration}
578
- CONFIDENCE 0.95
579
- END COLLAPSE
580
-
581
- # Answer the system should derive: Hydrogen (Z=1)
582
-
583
-
584
- ---
585
-
586
- ### DEMONSTRATION 2: SHA-256 MINING
587
- #### Encoding the constraint and the intelligent nonce search
588
-
589
- axl:
590
- # ════════════════════════════════════════════════════
591
- # SHA-256 BITCOIN MINING SYSTEM
592
- # Objective: find nonce such that hash < target
593
- # The system does not know what SHA-256 is.
594
- # It knows: there is a transform, it has an output,
595
- # the output must satisfy a bound.
596
- # ════════════════════════════════════════════════════
597
-
598
- SCOPE bitfield [level: 0]
599
-
600
- ASSUME bit EXISTS
601
- ASSUME bit DISCRETE VALUES {0, 1}
602
- ENTITY bit_array
603
- FIELD length: INTEGER
604
- FIELD value: VECTOR of bit
605
- BOUND value COUNT EQUALS length
606
- END ENTITY
607
-
608
- END SCOPE
609
-
610
-
611
- SCOPE sha256_internals [level: 1]
612
-
613
- ASSUME bitfield SCOPE HOLDS
614
-
615
- ENTITY message_schedule
616
- FIELD W: VECTOR COUNT EQUALS 64 # 64 32-bit words
617
- DERIVES FROM input_block
618
- BY expansion_transform
619
- END ENTITY
620
-
621
- TRANSFORM round_function
622
- INPUT {working_vars: VECTOR COUNT 8, W_i: bit_array}
623
- OUTPUT {working_vars_next: VECTOR COUNT 8}
624
- CONSERVES bit_count
625
- CHANGES working_vars
626
- # 64 applications of this = full SHA-256
627
- # Each application: sigma, choice, majority, mod add
628
- # AXL does not encode the arithmetic β€” that's the domain encoder's job
629
- # AXL encodes only: this is a deterministic transform with known structure
630
- END TRANSFORM
631
-
632
- CONTRADICT input_a WITH input_b
633
- AT SCOPE sha256_internals
634
- BOUNDARY_TYPE INFORMATION
635
- # Two different inputs CAN produce same output (collision)
636
- # But finding one is computationally infeasible
637
- # This contradiction is the security boundary
638
-
639
- TRANSFORM sha256
640
- INPUT {message: bit_array BOUND length WITHIN [0, 2^64]}
641
- OUTPUT {digest: bit_array BOUND length EQUALS 256}
642
- CONSERVES nothing # one-way: no conservation
643
- CHANGES everything # avalanche: all output bits affected
644
- REQUIRES input EXISTS
645
- PRODUCES digest PSEUDO_RANDOM_FROM input
646
- # PSEUDO_RANDOM_FROM is the key declaration:
647
- # output is deterministic but statistically independent of input structure
648
- END TRANSFORM
649
-
650
- END SCOPE
651
-
652
-
653
- SCOPE block_header [level: 2]
654
-
655
- ASSUME sha256_internals SCOPE HOLDS
656
-
657
- ENTITY block_header
658
- FIELD version: INTEGER BOUND [1, 4]
659
- FIELD prev_hash: bit_array BOUND length EQUALS 256 # GIVEN, fixed
660
- FIELD merkle_root: bit_array BOUND length EQUALS 256 # GIVEN, fixed
661
- FIELD timestamp: INTEGER # GIVEN, approximately fixed
662
- FIELD bits: INTEGER # GIVEN, encodes target
663
- FIELD nonce: INTEGER BOUND [0, 4294967295] # UNKNOWN β€” 32 bits of freedom
664
- END ENTITY
665
-
666
- DERIVE target
667
- FROM bits
668
- BY difficulty_decode_transform
669
- # target = a 256-bit number. Valid hash must be below it.
670
- # More leading zeros in target = harder problem
671
-
672
- END SCOPE
673
-
674
-
675
- SCOPE mining [level: 3]
676
-
677
- ASSUME block_header SCOPE HOLDS
678
-
679
- TRANSFORM double_sha256
680
- INPUT {block_header}
681
- OUTPUT {hash: bit_array BOUND length EQUALS 256}
682
- BY {sha256 APPLIED_TWICE}
683
- END TRANSFORM
684
-
685
- OBJECTIVE valid_block
686
- OPTIMIZE hash MIN # minimize hash value numerically
687
- SUBJECT TO hash BELOW target # hard bound β€” must be satisfied
688
- SUBJECT TO nonce WITHIN [0, 4294967295]
689
- END OBJECTIVE
690
-
691
- # ══ HERE IS THE INTELLIGENCE LAYER ══
692
- # The nonce space has NO smooth gradient (SHA-256 destroys it)
693
- # But the SEARCH SPACE has learnable structure:
694
- # - which regions have been explored (coverage)
695
- # - step count gives sequence context
696
- # - candidate scoring gives relative ranking
697
- # This is what the UCE learns β€” not the hash, but the search
698
-
699
- UNKNOWN nonce: INTEGER BOUND [0, 4294967295]
700
-
701
- STEP 0
702
- STATE {nonce_space: unexplored}
703
- CANDIDATE 0
704
- nonce: SAMPLE uniform
705
- SCORE: UNKNOWN
706
- CONFIDENCE: 0.0
707
- END CANDIDATE
708
- END STEP
709
-
710
- STEP N
711
- STATE {
712
- explored_regions: VECTOR, # coverage map
713
- best_hash_so_far: bit_array,
714
- distance_to_target: INTEGER,
715
- step_count: N
716
- }
717
- CANDIDATE 0..50 # 50 parallel candidates
718
- nonce: DERIVES FROM {
719
- explored_regions,
720
- step_count,
721
- best_hash_so_far
722
- }
723
- # The system learns: given search history,
724
- # what nonce regions have NOT been tried
725
- # and which historically neighboring regions
726
- # produced closer hashes (within this block's structure)
727
- SCORE: distance_to_target MIN
728
- CONFIDENCE: LEARNS
729
- END CANDIDATE
730
- END STEP
731
-
732
- OBSERVE hash BELOW target # this is the termination condition
733
-
734
- COLLAPSE mining
735
- GIVEN {block_header_fixed_fields, target, search_history}
736
- FIND {nonce}
737
- CONFIDENCE 0.99
738
- END COLLAPSE
739
-
740
- # ══ WHAT THE SYSTEM LEARNS ══
741
- # Not: how to reverse SHA-256
742
- # But: how to cover the nonce space intelligently
743
- # avoiding redundant regions, clustering search
744
- # around previously productive neighborhoods
745
- # The intelligence is in the search, not the hash
746
-
747
- END SCOPE
748
-
749
-
750
- ---
751
-
752
- ### DEMONSTRATION 3: CELL DIVISION (MITOSIS)
753
- #### Encoding life as constraint satisfaction
754
-
755
- axl:
756
- # ════════════════════════════════════════════════════
757
- # CELL DIVISION SYSTEM
758
- # Life as constraints on information replication
759
- # with error correction and state machines
760
- # ════════════════════════════════════════════════════
761
-
762
- SCOPE molecular [level: 0]
763
-
764
- ASSUME molecule EXISTS
765
- ASSUME information CAN BE ENCODED IN molecule
766
- ASSUME chemical_bond EXISTS
767
- CONSERVES atom_count ACROSS chemical_reactions
768
- CONSERVES charge ACROSS chemical_reactions
769
-
770
- ENTITY nucleotide
771
- FIELD base: SYMBOLIC DISCRETE VALUES {adenine, thymine, guanine, cytosine}
772
- FIELD sugar: SYMBOLIC EQUALS deoxyribose
773
- FIELD phosphate: BOOLEAN
774
- BOUND adenine PAIRS_WITH thymine ONLY # base pairing rule
775
- BOUND guanine PAIRS_WITH cytosine ONLY
776
- END ENTITY
777
-
778
- ENTITY dna_strand
779
- FIELD sequence: VECTOR of nucleotide
780
- FIELD length: INTEGER BOUND [1, 3e9] # up to 3 billion base pairs
781
- FIELD direction: SYMBOLIC DISCRETE VALUES {5_to_3, 3_to_5}
782
- CONSERVES sequence UNLESS transform EQUALS mutation
783
- TENDS base_pair_bonds STABLE # double helix stability
784
- END ENTITY
785
-
786
- TRANSFORM base_pairing
787
- INPUT {strand_a: dna_strand, strand_b: dna_strand}
788
- OUTPUT {double_helix}
789
- REQUIRES strand_a.direction FORBIDS strand_b.direction # antiparallel
790
- REQUIRES each_base PAIRS_WITH complement
791
- CONSERVES sequence_information
792
- END TRANSFORM
793
-
794
- END SCOPE
795
-
796
-
797
- SCOPE genome [level: 1]
798
-
799
- ASSUME molecular SCOPE HOLDS
800
-
801
- ENTITY chromosome
802
- FIELD dna: dna_strand
803
- FIELD histone_proteins: VECTOR
804
- FIELD centromere_position: INTEGER
805
- FIELD telomere_length: INTEGER BOUND [0, 15000] # erosion limit
806
- TENDS compaction MAX WHEN cell_dividing EQUALS true
807
- TENDS compaction MIN WHEN cell_active EQUALS true
808
- END ENTITY
809
-
810
- ENTITY genome
811
- FIELD chromosomes: VECTOR of chromosome
812
- BOUND chromosome_count EQUALS 46 # human diploid β€” pairs of 23
813
- CONSERVES chromosome_count UNLESS transform EQUALS meiosis
814
- TENDS integrity MAX # genome resists damage
815
- END ENTITY
816
-
817
- ENTITY dna_polymerase
818
- FIELD error_rate: REAL BOUND [1e-9, 1e-9] # one error per billion bases
819
- TENDS accuracy MAX
820
- TRANSFORMS dna_strand INTO dna_strand_copy
821
- CONSERVES sequence UNLESS error_rate TRIGGERS
822
- END ENTITY
823
-
824
- EMERGES genetic_code
825
- FROM nucleotide_triplet_sequence
826
- AT SCOPE genome
827
- NOT PRESENT AT SCOPE molecular
828
- # individual nucleotides have no meaning β€” codons emerge at this level
829
-
830
- END SCOPE
831
-
832
-
833
- SCOPE cell [level: 2]
834
-
835
- ASSUME genome SCOPE HOLDS
836
-
837
- ENTITY cell
838
- FIELD genome: genome
839
- FIELD membrane: BOOLEAN EQUALS true # boundary condition
840
- FIELD atp_level: REAL BOUND [0, 1] # energy state
841
- FIELD size: REAL BOUND [minimum_viable, maximum_before_division]
842
- FIELD age: INTEGER # division counter
843
- FIELD state: SYMBOLIC DISCRETE VALUES {
844
- G1, # growth phase 1
845
- S, # synthesis (DNA replication)
846
- G2, # growth phase 2
847
- M, # mitosis (division)
848
- G0, # quiescent (resting)
849
- apoptosis # programmed death
850
- }
851
- TENDS atp_level MAX # cells maximize energy
852
- TENDS genome_integrity MAX # cells protect DNA
853
- BOUND age BELOW hayflick_limit # telomere erosion limit
854
- END ENTITY
855
-
856
- ENTITY checkpoint_protein
857
- FIELD name: SYMBOLIC DISCRETE VALUES {p53, rb, cyclin_B, cdk1}
858
- FIELD active: BOOLEAN
859
- TENDS genome_damage OBSERVE # monitors DNA integrity
860
- TRANSFORMS cell.state INTO apoptosis
861
- WHEN genome_damage ABOVE repair_threshold
862
- # p53 is the key constraint enforcer β€” if damage is too great, die
863
- END ENTITY
864
-
865
- END SCOPE
866
-
867
-
868
- SCOPE mitosis [level: 3]
869
-
870
- ASSUME cell SCOPE HOLDS
871
-
872
- # ══ TRIGGER CONDITIONS ══
873
- # Cell division is itself a constraint satisfaction problem:
874
- # divide WHEN AND ONLY WHEN all conditions hold
875
-
876
- OBJECTIVE division_trigger
877
- OPTIMIZE cell.state EQUAL M
878
- SUBJECT TO {
879
- cell.size ABOVE division_threshold,
880
- cell.atp_level ABOVE 0.7,
881
- dna_replication EQUALS complete,
882
- checkpoint_all EQUALS passed,
883
- external_growth_signal EQUALS present,
884
- cell.age BELOW hayflick_limit
885
- }
886
- # ALL conditions must hold β€” AND logic, not OR
887
- # This is why cancer is a constraint violation:
888
- # it occurs when checkpoint constraints are BROKEN
889
- END OBJECTIVE
890
-
891
- TRANSFORM prophase
892
- INPUT {cell: STATE G2}
893
- OUTPUT {cell: chromosomes_condensed, spindle_forming}
894
- REQUIRES division_trigger EQUALS satisfied
895
- CONSERVES chromosome_count
896
- CONSERVES genome_content
897
- END TRANSFORM
898
-
899
- TRANSFORM metaphase
900
- INPUT {cell: chromosomes_condensed}
901
- OUTPUT {cell: chromosomes_aligned_at_plate}
902
- REQUIRES spindle_attached_to EQUALS all_chromosomes
903
- # Checkpoint: spindle assembly checkpoint
904
- # If any chromosome unattached β€” PAUSE here
905
- BOUND unattached_chromosomes EQUALS 0
906
- UNLESS OVERRIDE apoptosis
907
- END TRANSFORM
908
-
909
- TRANSFORM anaphase
910
- INPUT {cell: chromosomes_aligned}
911
- OUTPUT {sister_chromatids: separating}
912
- CONSERVES chromosome_count_total
913
- CHANGES chromosome_location
914
- PRODUCES two_sets OF 46_chromosomes
915
- END TRANSFORM
916
-
917
- TRANSFORM telophase_and_cytokinesis
918
- INPUT {cell: chromatids_separated}
919
- OUTPUT {daughter_cell_1, daughter_cell_2}
920
- CONSERVES genome_content IN each_daughter
921
- CONSERVES organelle_distribution APPROXIMATELY
922
- PRODUCES {
923
- daughter_cell_1: IDENTICAL_GENOME_TO parent,
924
- daughter_cell_2: IDENTICAL_GENOME_TO parent
925
- }
926
- END TRANSFORM
927
-
928
- EMERGES tissue
929
- FROM COMPOSITION OF {cell COUNT ABOVE 1}
930
- AT SCOPE mitosis
931
- NOT PRESENT AT SCOPE cell
932
- # individual cells have no tissue identity β€” it emerges from composition
933
-
934
- EMERGES cancer
935
- FROM checkpoint_protein.active EQUALS false
936
- AND division_trigger SATISFIED_WITHOUT all_conditions
937
- AT SCOPE mitosis
938
- # Cancer is not a new thing β€” it is constraint violation
939
- # The cell divides when it should not because the objective
940
- # function has been corrupted
941
- CONTRADICT cancer WITH normal_division
942
- AT SCOPE mitosis
943
- BOUNDARY_TYPE INFORMATION # corrupted information in genome
944
-
945
- # ══ COLLAPSE EXAMPLE: Cancer diagnosis ══
946
-
947
- OBSERVE {
948
- cell.division_rate ABOVE normal_range,
949
- checkpoint_protein.p53 EQUALS inactive,
950
- cell.age ABOVE hayflick_limit
951
- }
952
-
953
- UNKNOWN {
954
- mutation_site: dna_strand LOCATION,
955
- checkpoint_broken: SYMBOLIC,
956
- division_trigger_violated: OBJECTIVE_CLAUSE
957
- }
958
-
959
- COLLAPSE mitosis
960
- GIVEN {abnormal_observations}
961
- FIND {mutation_site, checkpoint_broken, division_trigger_violated}
962
- CONFIDENCE 0.90
963
- END COLLAPSE
964
-
965
- END SCOPE
966
-
967
-
968
- # ════════════════════════════════════════════════════
969
- # META: THE LANGUAGE DESCRIBING ITSELF
970
- # AXL encoding its own structure
971
- # ════════════════════════════════════════════════════
972
-
973
- SCOPE axl_meta [level: 0]
974
-
975
- ASSUME symbol EXISTS
976
- ASSUME symbol CAN CARRY meaning
977
- ASSUME meaning IS RELATIVE TO scope
978
-
979
- ENTITY keyword
980
- FIELD token: SYMBOLIC
981
- FIELD semantic: SYMBOLIC
982
- FIELD abstraction_direction: DISCRETE VALUES {up, down, both, none}
983
- FIELD arity: INTEGER # how many arguments it takes
984
- END ENTITY
985
-
986
- ENTITY statement
987
- FIELD keywords: VECTOR of keyword
988
- FIELD scope_level: INTEGER
989
- DERIVES meaning FROM {keywords, scope_level, context}
990
- # Same token, different scope = different meaning
991
- # BOUND in scope 0 (physics) β‰  BOUND in scope 3 (biology)
992
- END ENTITY
993
-
994
- EMERGES program_meaning
995
- FROM COMPOSITION OF {statement COUNT ABOVE 1}
996
- AT SCOPE axl_meta
997
- NOT PRESENT AT SCOPE symbol
998
- # Individual symbols have no program meaning
999
- # Meaning emerges from composition and scope
1000
-
1001
- TEND expressiveness MAX
1002
- TEND ambiguity MIN
1003
- CONTRADICT expressiveness WITH ambiguity
1004
- AT SCOPE axl_meta
1005
- BOUNDARY_TYPE INFORMATION
1006
- # All languages face this β€” AXL resolves it via scope tagging
1007
-
1008
- END SCOPE
1009
-
1010
- ---
1011
-
1012
- ## PART IV β€” DESIGN NOTES
1013
- **On contradictions:**
1014
- Every CONTRADICT in these examples marks a real scientific boundary:
1015
- - quantum/classical = scale boundary
1016
- - cancer/normal = information boundary
1017
- - expressiveness/ambiguity = the language's own limit
1018
-
1019
- These are features, not bugs.
1020
-
1021
- `; // USER: replace in prod
1022
 
1023
  const SYSTEM_PROMPT_HEADER = `You are a dataset generator for the Universal Constraint Engine (UCE),
1024
  a domain-agnostic constraint satisfaction and optimization system.
@@ -1097,12 +439,13 @@ function _safeNorm(bRaw) {
1097
  if (!isFinite(bRaw) || isNaN(bRaw)) return 0.0;
1098
  return sign(bRaw) * Math.log1p(Math.abs(bRaw)) / SCALE_K;
1099
  }
 
 
1100
 
1101
  // ── SYNTHETIC INJECTORS ─────────────────────────────────────────────────────
1102
  function synthPhysicsSamples(n) {
1103
  let samples = [];
1104
- const templates = [["Kinetic Energy", c => 0.5 * (c[0]*100) * Math.pow(c[1]*50, 2), [[0.01,1], [0.01,1]], "Joules"],["Ohm's Law Power", c => Math.pow(c[0]*240, 2) / (c[1]*1000 + 0.001), [[0.01,1],[0.01,1]], "Watts"],
1105
- ["Gravitational PE", c => (c[0]*100) * 9.81 * (c[1]*100), [[0.01,1],[0.01,1]], "Joules"],
1106
  ["Ideal Gas PV=nRT", c => ((c[0]*10)*(c[1]*100))/((c[2]*5+0.1)*8.314), [[0.01,1],[0.01,1],[0.01,1]], "Kelvin"],["Wave Frequency", c => (c[0]*1e8) / (c[1]*10+0.001), [[0.01,1],[0.01,1]], "Hz"],["Snell Refraction", c => ((c[0]*2+1)*Math.sin(c[1]*1.5)) / ((c[2]*2+1)+0.001), [[0.01,1],[0.01,1],[0.01,1]], "dim-less"],["Centripetal Accel", c => Math.pow(c[0]*50, 2)/(c[1]*10+0.001), [[0.01,1],[0.01,1]], "m/sΒ²"],
1107
  ["Doppler Shift", c => (c[0]*1000)*(1+(c[1]*50)/(340+0.001)), [[0.01,1],[0.01,1]], "Hz"]
1108
  ];
@@ -1131,7 +474,7 @@ function synthPhysicsSamples(n) {
1131
  }
1132
 
1133
  function synthFinanceSamples(n) {
1134
- let samples = [];
1135
  const kinds =["compound_interest", "loan_payment", "portfolio_return", "options_delta"];
1136
 
1137
  for (let i = 0; i < n; i++) {
@@ -1149,7 +492,7 @@ function synthFinanceSamples(n) {
1149
  let ret =[rnd(0.02, 0.25), rnd(0.02, 0.25), rnd(0.02, 0.25)];
1150
  bRaw = w[0]*ret[0] + w[1]*ret[1] + w[2]*ret[2]; cVals = w; desc = `Portfolio weighted return: ${bRaw.toFixed(4)}`;
1151
  } else {
1152
- let S = rnd(50, 500), K = rnd(50, 500); bRaw = Math.max(0, S - K); cVals = [S/500, K/500]; desc = `Option intrinsic value: ${bRaw.toFixed(2)}`;
1153
  }
1154
  if (!isFinite(bRaw) || isNaN(bRaw)) continue;
1155
  let nVars = cVals.length;
@@ -1166,38 +509,658 @@ function synthFinanceSamples(n) {
1166
  return samples;
1167
  }
1168
 
1169
- function synthCipherSamples(n) {
1170
- let samples = [];
1171
- const kinds =["caesar","vigenere_2","vigenere_4","affine","xor_byte"];
1172
-
1173
- for (let i=0; i<n; i++) {
1174
- let kind = randchoice(kinds);
1175
- try {
1176
- let bRaw, cVals, desc;
1177
- if (kind === "caesar") {
1178
- let shift = randint(0,25), p = randint(0,25); bRaw = (p+shift)%26; cVals = [shift/25.0]; desc = `Caesar shift=${shift} plain=${p} β†’ ${bRaw|0}`;
1179
- } else if (kind === "vigenere_2") {
1180
- let k =[randint(0,25), randint(0,25)], p = [randint(0,25), randint(0,25)];
1181
- bRaw = ((p[0]+k[0])%26) + ((p[1]+k[1])%26); cVals =[k[0]/25.0, k[1]/25.0]; desc = `Vig2 key=${k}`;
1182
- } else if (kind === "vigenere_4") {
1183
- let k =[randint(0,25),randint(0,25),randint(0,25),randint(0,25)], p =[randint(0,25),randint(0,25),randint(0,25),randint(0,25)];
1184
- bRaw = k.reduce((acc, _, idx) => acc + ((p[idx]+k[idx])%26), 0); cVals = k.map(v=>v/25.0); desc = `Vig4 key=${k}`;
1185
- } else if (kind === "affine") {
1186
- let valid_a =[1,3,5,7,9,11,15,17,19,21,23,25], a_idx = randint(0,11); let a = valid_a[a_idx], b = randint(0,25), p = randint(0,25);
1187
- bRaw = (a*p+b)%26; cVals =[a_idx/11.0, b/25.0]; desc = `Affine a=${a} b=${b} plain=${p}`;
1188
- } else {
1189
- let key = randint(0,255), plain = randint(0,255); bRaw = plain ^ key; cVals =[key/255.0]; desc = `XOR key=${key} p=${plain} β†’ ${bRaw|0}`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1190
  }
1191
- let nVars = cVals.length;
1192
- samples.push({
1193
- id: crypto.randomUUID(), domain: "cryptography", subdomain: kind, sense: "EQUAL", n_vars: nVars,
1194
- vars_text: "VARS " + cVals.map((_, j) => `c${j} IN [0 1]`).join(" "), expr_text: `EXPR CIPHER_${kind.toUpperCase()}`,
1195
- sense_text: "SENSE EQUAL", b_raw: bRaw, b_norm: Number(_safeNorm(bRaw).toFixed(8)), c_values: cVals.map(v => Number(v.toFixed(6))),
1196
- mask:[...Array(nVars).fill(1), ...Array(Math.max(0, 4 - nVars)).fill(0)], candidates:[], step_count: 0,
1197
- axl_source: `SCOPE cryptography [level: 1]\n OBSERVE ${kind} EQUALS ${bRaw}\n UNKNOWN key: VECTOR BOUND [0,1]\nEND SCOPE`,
1198
- metadata: { description: desc, units: "character_code", difficulty: nVars<=2?"medium":"hard", scope_depth: 1, has_emergence: false, has_contradiction: true }
1199
- });
1200
- } catch (e) {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1201
  }
1202
  return samples;
1203
  }
@@ -1218,7 +1181,7 @@ function synthOptimizationSamples(n) {
1218
  sense: sense, n_vars: nVars, vars_text: "VARS " + cVals.map((_, j) => `c${j} IN [0 1]`).join(" "),
1219
  expr_text: "EXPR " + coeffs.map((c, j) => `${c.toFixed(3)}*c${j}`).join(" + "), sense_text: `SENSE ${sense}`,
1220
  b_raw: Number(bRaw.toFixed(6)), b_norm: Number(_safeNorm(bRaw).toFixed(8)), c_values: cVals.map(v => Number(v.toFixed(6))),
1221
- mask: Array(nVars).fill(1), candidates: [], step_count: 0,
1222
  axl_source: `SCOPE optimization[level: 2]\n OBJECTIVE OPTIMIZE f ${sense}\n SUBJECT TO c WITHIN [0,1]\nEND SCOPE`,
1223
  metadata: { description: `Linear ${sense.toLowerCase()} over ${nVars} variables`, units: "objective", difficulty: "easy", scope_depth: 1, has_emergence: false, has_contradiction: false }
1224
  });
@@ -1227,7 +1190,19 @@ function synthOptimizationSamples(n) {
1227
  return samples;
1228
  }
1229
 
1230
- const SYNTHETIC_GENERATORS = [synthPhysicsSamples, synthFinanceSamples, synthCipherSamples, synthOptimizationSamples];
 
 
 
 
 
 
 
 
 
 
 
 
1231
 
1232
  // ── FOCUS TRACKER ────────────────────────────────────────────────────────────
1233
  class FocusTracker {
@@ -1275,7 +1250,7 @@ function saveDataset() {
1275
  // ── JSON PARSER ──────────────────────────────────────────────────────────────
1276
  function parseAiResponse(text) {
1277
  let raw = text.trim();
1278
- const fences = ["```json", "```JSON", "```"];
1279
  for (let f of fences) {
1280
  if (raw.startsWith(f)) { raw = raw.slice(f.length); break; }
1281
  }
@@ -1431,7 +1406,7 @@ app.get('/dataset/download', (req, res) => {
1431
 
1432
  app.post('/dataset/clear', (req, res) => {
1433
  const count = _dataset.length;
1434
- _dataset =[];
1435
  if (fs.existsSync(DATASET_PATH)) fs.unlinkSync(DATASET_PATH);
1436
  log(`Dataset cleared β€” removed ${count} samples`, "OK");
1437
  res.json({ cleared: count });
 
1
+ /**
2
  * axl_dataset_server.js
3
  * ══════════════════════════════════════════════════════════════════════════════
4
  * AXL Dataset Generation Server (Node.js/Express version)
5
+ * Generates UCE training samples via AWS Bedrock + deep synthetic math injection.
6
  * Returns JSON for download. Tracks domain diversity across requests.
7
  *
8
  * Endpoints:
 
70
  async function callBedrock(prompt, maxTokens = 18000) {
71
  const command = new ConverseCommand({
72
  modelId: BEDROCK_MODEL_ID,
73
+ messages:[{ role: "user", content: [{ text: prompt }] }],
74
  inferenceConfig: {
75
  maxTokens: maxTokens,
76
  temperature: 0.9,
 
112
  Declares an abstraction level. Everything inside a scope inherits
113
  its level tag. Scopes are numbered β€” lower is more fundamental.
114
 
 
115
  SCOPE <name> [level: <int>]
116
  ...contents...
117
  END SCOPE
118
 
 
119
  Example levels (not hardcoded, user defined):
120
  - level 0 = most fundamental (quantum, bits)
121
  - level 1 = composed structures (atoms, bytes)
 
130
  existence conditions. An entity does not exist unless its
131
  REQUIRES clause is satisfied.
132
 
 
133
  ENTITY <name>
134
  FIELD <name>: <type> [BOUND <range>] [CONSERVES] [DISCRETE]
135
  STATE <name>: REQUIRES <condition>
 
137
  DERIVES FROM <entity_list>
138
  END ENTITY
139
 
 
140
  **FIELD** β€” a measurable or logical property of the entity
141
  **CONSERVES** β€” this field cannot change across any TRANSFORM
142
  **DISCRETE** β€” field only takes integer or enumerated values
 
149
  The foundation everything else builds on.
150
  Multiple ASSUMEs compound β€” all must hold simultaneously.
151
 
 
152
  ASSUME <statement>
153
  ASSUME <entity> EXISTS
154
  ASSUME <field> EQUALS <value>
155
  ASSUME <relationship> HOLDS
156
 
 
157
  ---
158
 
159
  ### 4. BOUND
160
  Hard constraint on a field or relationship.
161
  Nothing outside a BOUND can exist in this scope.
162
 
163
+ BOUND <field> WITHIN[<min>, <max>]
 
164
  BOUND <field> ABOVE <value>
165
  BOUND <field> BELOW <value>
166
  BOUND <field> EQUALS <value> # exact, no freedom
167
+ BOUND <entity> COUNT WITHIN[<min>, <max>]
168
  BOUND <a> FORBIDS <b> # mutual exclusion
169
 
 
170
  ---
171
 
172
  ### 5. TEND
 
174
  require it. Multiple TENDs create competing pressures that
175
  produce equilibrium β€” emergence happens here.
176
 
 
177
  TEND <field> MIN # pull toward minimum
178
  TEND <field> MAX # pull toward maximum
179
  TEND <field> TOWARD <value> # pull toward specific value
180
  TEND <system> STABLE # resist perturbation
181
  TEND <field> FOLLOW <other_field> # track another field
182
 
 
183
  ---
184
 
185
  ### 6. OBJECTIVE
186
  Hard optimization target. Unlike TEND, this must be satisfied
187
  for the scope to be considered resolved.
188
 
 
189
  OBJECTIVE <name>
190
  OPTIMIZE <field> [MIN | MAX | EQUAL <value>]
191
  SUBJECT TO <constraint_list>
192
  END OBJECTIVE
193
 
 
194
  ---
195
 
196
  ### 7. DERIVE
 
198
  If the sources hold, the derived thing must hold.
199
  This is the upward propagation engine.
200
 
 
201
  DERIVE <entity | field | state>
202
  FROM <source_list>
203
  WHEN <condition>
204
  BY <transform_name>
205
  END DERIVE
206
 
 
207
  ---
208
 
209
  ### 8. TRANSFORM
 
211
  Transforms are the edges between scope levels.
212
  They must declare what they CONSERVE and what they CHANGE.
213
 
 
214
  TRANSFORM <name>
215
  INPUT <entity_or_field_list>
216
  OUTPUT <entity_or_field_list>
 
220
  PRODUCES <postcondition>
221
  END TRANSFORM
222
 
 
223
  ---
224
 
225
  ### 9. OBSERVE
 
227
  The system will work backwards from this to find what
228
  configuration of unknowns is consistent with it.
229
 
 
230
  OBSERVE <field | entity | state> EQUALS <value>
231
  OBSERVE <field> WITHIN [<min>, <max>]
232
  OBSERVE <pattern> IN <output>
233
 
 
234
  ---
235
 
236
  ### 10. UNKNOWN
 
239
  values of UNKNOWNs that satisfy all constraints
240
  given the OBSERVATIONs.
241
 
 
242
  UNKNOWN <name>: <type> BOUND [<min>, <max>]
243
  UNKNOWN <name>: DISCRETE WITHIN <set>
244
 
 
245
  ---
246
 
247
  ### 11. COLLAPSE
 
249
  configuration satisfying all active constraints.
250
  This is reverse abstraction in one word.
251
 
 
252
  COLLAPSE <scope | entity | system>
253
  GIVEN <observation_list>
254
  FIND <unknown_list>
255
  CONFIDENCE <threshold>
256
  END COLLAPSE
257
 
 
258
  ---
259
 
260
  ### 12. EXPAND
261
  Opposite of COLLAPSE. Given a concrete configuration,
262
  derive upward β€” what higher-level behaviors emerge?
263
 
 
264
  EXPAND <entity | configuration>
265
  THROUGH <scope_list>
266
  OBSERVE_EMERGENT <property_list>
267
  END EXPAND
268
 
 
269
  ---
270
 
271
  ### 13. CONTRADICT
 
274
  Where contradictions appear is where the interesting
275
  physics, biology, and logic lives.
276
 
 
277
  CONTRADICT <statement_a> WITH <statement_b>
278
  AT SCOPE <level>
279
  BOUNDARY_TYPE [SCALE | SPEED | INFORMATION | ENERGY]
280
 
 
281
  ---
282
 
283
  ### 14. EMERGES
 
286
  Emergence is not reducible to its parts in AXL β€”
287
  it must be explicitly declared.
288
 
 
289
  EMERGES <property>
290
  FROM COMPOSITION OF <entity_list>
291
  AT SCOPE <level>
292
  NOT PRESENT AT SCOPE <lower_level>
293
 
 
294
  ---
295
 
296
  ### 15. COMPOSES
297
  Declares that an entity is built from other entities.
298
  Composition respects all lower-scope constraints.
299
 
 
300
  COMPOSES <higher_entity>
301
  FROM <lower_entity_list>
302
  BOUND count: <range>
303
  CONSERVING <field_list>
304
  END COMPOSES
305
 
 
306
  ---
307
 
308
  ### 16. STEP
 
310
  Enables the system to learn groups across attempts.
311
  Critical for the mining feedback loop.
312
 
 
313
  STEP <n>
314
  STATE <snapshot>
315
  CANDIDATE <configuration>
316
  DELTA <change_from_previous>
317
  END STEP
318
 
 
319
  ---
320
 
321
  ### 17. CANDIDATE
322
  A proposed solution configuration.
323
  Multiple candidates can coexist until COLLAPSE selects.
324
 
 
325
  CANDIDATE <n>
326
  <field>: <value>
327
  SCORE: <objective_value>
328
  CONFIDENCE: <float 0-1>
329
  END CANDIDATE
330
 
 
331
  ---
332
 
333
  ### 18. UNLESS
334
  Conditional override. Higher scope can override lower scope
335
  constraints under specific conditions.
336
 
 
337
  UNLESS <condition>
338
  OVERRIDE <constraint>
339
  WITH <replacement>
340
  END UNLESS
341
 
 
342
  ---
343
 
344
  ### 19. CONSERVES
 
346
  of what transforms occur. Conservation laws in physics,
347
  invariants in computation, conservation of mass β€” all CONSERVES.
348
 
 
349
  CONSERVES <quantity> ACROSS <transform_list>
350
  CONSERVES <quantity> WITHIN SCOPE <level>
351
 
 
352
  ---
353
 
354
  ### 20. SAMPLE
355
  A specific observed instance used as training signal
356
  for the diffusion engine. The raw material for learning.
357
 
 
358
  SAMPLE <id>
359
  INPUT <configuration>
360
  OUTPUT <observed_value>
361
  STEP <n>
362
  END SAMPLE
363
+ `;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
 
365
  const SYSTEM_PROMPT_HEADER = `You are a dataset generator for the Universal Constraint Engine (UCE),
366
  a domain-agnostic constraint satisfaction and optimization system.
 
439
  if (!isFinite(bRaw) || isNaN(bRaw)) return 0.0;
440
  return sign(bRaw) * Math.log1p(Math.abs(bRaw)) / SCALE_K;
441
  }
442
+ const fmt6 = (v) => Number(v.toFixed(6));
443
+ const fmt8 = (v) => Number(v.toFixed(8));
444
 
445
  // ── SYNTHETIC INJECTORS ─────────────────────────────────────────────────────
446
  function synthPhysicsSamples(n) {
447
  let samples = [];
448
+ const templates = [["Kinetic Energy", c => 0.5 * (c[0]*100) * Math.pow(c[1]*50, 2), [[0.01,1],[0.01,1]], "Joules"],["Ohm's Law Power", c => Math.pow(c[0]*240, 2) / (c[1]*1000 + 0.001), [[0.01,1],[0.01,1]], "Watts"],["Gravitational PE", c => (c[0]*100) * 9.81 * (c[1]*100), [[0.01,1],[0.01,1]], "Joules"],
 
449
  ["Ideal Gas PV=nRT", c => ((c[0]*10)*(c[1]*100))/((c[2]*5+0.1)*8.314), [[0.01,1],[0.01,1],[0.01,1]], "Kelvin"],["Wave Frequency", c => (c[0]*1e8) / (c[1]*10+0.001), [[0.01,1],[0.01,1]], "Hz"],["Snell Refraction", c => ((c[0]*2+1)*Math.sin(c[1]*1.5)) / ((c[2]*2+1)+0.001), [[0.01,1],[0.01,1],[0.01,1]], "dim-less"],["Centripetal Accel", c => Math.pow(c[0]*50, 2)/(c[1]*10+0.001), [[0.01,1],[0.01,1]], "m/sΒ²"],
450
  ["Doppler Shift", c => (c[0]*1000)*(1+(c[1]*50)/(340+0.001)), [[0.01,1],[0.01,1]], "Hz"]
451
  ];
 
474
  }
475
 
476
  function synthFinanceSamples(n) {
477
+ let samples =[];
478
  const kinds =["compound_interest", "loan_payment", "portfolio_return", "options_delta"];
479
 
480
  for (let i = 0; i < n; i++) {
 
492
  let ret =[rnd(0.02, 0.25), rnd(0.02, 0.25), rnd(0.02, 0.25)];
493
  bRaw = w[0]*ret[0] + w[1]*ret[1] + w[2]*ret[2]; cVals = w; desc = `Portfolio weighted return: ${bRaw.toFixed(4)}`;
494
  } else {
495
+ let S = rnd(50, 500), K = rnd(50, 500); bRaw = Math.max(0, S - K); cVals =[S/500, K/500]; desc = `Option intrinsic value: ${bRaw.toFixed(2)}`;
496
  }
497
  if (!isFinite(bRaw) || isNaN(bRaw)) continue;
498
  let nVars = cVals.length;
 
509
  return samples;
510
  }
511
 
512
+ // ─────────────────────────────────────────────────────────────────────────────
513
+ // CRYPTO INJECTORS (DEEP AXL)
514
+ // ─────────────────────────────────────────────────────────────────────────────
515
+ function synthXorSamples(n) {
516
+ const samples =[];
517
+ for (let i = 0; i < n; i++) {
518
+ const key = randint(0, 255);
519
+ const plain = randint(0, 255);
520
+ const cipher = key ^ plain;
521
+ const cVal = fmt6(key / 255.0);
522
+ const bRaw = cipher;
523
+
524
+ const keyBits = Array.from({length:8}, (_,b) => (key >> (7-b)) & 1);
525
+ const plainBits = Array.from({length:8}, (_,b) => (plain >> (7-b)) & 1);
526
+ const outBits = keyBits.map((kb, b) => kb ^ plainBits[b]);
527
+
528
+ const bitEntities = Array.from({length:8}, (_,b) =>
529
+ ` ENTITY bit_${b}\n` +
530
+ ` FIELD key_bit: DISCRETE VALUES {0, 1} EQUALS ${keyBits[b]}\n` +
531
+ ` FIELD plain_bit: DISCRETE VALUES {0, 1} EQUALS ${plainBits[b]}\n` +
532
+ ` FIELD out_bit: DISCRETE VALUES {0, 1}\n` +
533
+ ` DERIVES out_bit FROM {key_bit, plain_bit} BY xor_gate\n` +
534
+ ` END ENTITY`
535
+ ).join("\n");
536
+
537
+ const axl = [
538
+ `SCOPE xor_bit_level[level: 0]`,
539
+ ` ASSUME bit EXISTS`,
540
+ ` ASSUME bit DISCRETE VALUES {0, 1}`,
541
+ ``,
542
+ ` TRANSFORM xor_gate`,
543
+ ` INPUT {a: bit, b: bit}`,
544
+ ` OUTPUT {out: bit}`,
545
+ ` PRODUCES 0 WHEN a EQUALS b`,
546
+ ` PRODUCES 1 WHEN a NOT_EQUALS b`,
547
+ ` END TRANSFORM`,
548
+ ``,
549
+ bitEntities,
550
+ `END SCOPE`,
551
+ ``,
552
+ `SCOPE xor_byte_level [level: 1]`,
553
+ ` ASSUME xor_bit_level SCOPE HOLDS`,
554
+ ``,
555
+ ` ENTITY byte_assembler`,
556
+ ` FIELD value: INTEGER BOUND[0, 255]`,
557
+ ` DERIVES value FROM {bit_7..bit_0} BY binary_weighted_sum`,
558
+ ` END ENTITY`,
559
+ ``,
560
+ ` CONSERVES bit_count ACROSS binary_weighted_sum`,
561
+ ``,
562
+ ` ENTITY key_byte`,
563
+ ` FIELD raw: INTEGER BOUND [0, 255]`,
564
+ ` FIELD normalised: REAL BOUND[0, 1]`,
565
+ ` DERIVES normalised FROM raw BY divide_255`,
566
+ ` END ENTITY`,
567
+ ``,
568
+ ` ENTITY plain_byte`,
569
+ ` FIELD raw: INTEGER BOUND [0, 255] EQUALS ${plain}`,
570
+ ` END ENTITY`,
571
+ ``,
572
+ ` ENTITY cipher_byte`,
573
+ ` FIELD raw: INTEGER BOUND[0, 255]`,
574
+ ` DERIVES raw FROM {key_byte.raw, plain_byte.raw} BY xor_byte_transform`,
575
+ ` END ENTITY`,
576
+ ``,
577
+ ` TRANSFORM xor_byte_transform`,
578
+ ` INPUT {key: INTEGER BOUND[0,255], plain: INTEGER BOUND [0,255]}`,
579
+ ` OUTPUT {cipher: INTEGER BOUND [0,255]}`,
580
+ ` CONSERVES nothing`,
581
+ ` CHANGES cipher`,
582
+ ` PRODUCES cipher = key XOR plain # applied bit-by-bit via xor_gate`,
583
+ ` END TRANSFORM`,
584
+ ``,
585
+ ` OBSERVE cipher_byte.raw EQUALS ${cipher}`,
586
+ ` UNKNOWN key_byte.normalised: REAL BOUND [0, 1]`,
587
+ ``,
588
+ ` COLLAPSE xor_byte_level`,
589
+ ` GIVEN cipher_byte.raw`,
590
+ ` FIND key_byte.normalised`,
591
+ ` CONFIDENCE 0.99`,
592
+ ` END COLLAPSE`,
593
+ `END SCOPE`,
594
+ ].join("\n");
595
+
596
+ samples.push({
597
+ id: crypto.randomUUID(),
598
+ domain: "cryptography",
599
+ subdomain: "xor_byte",
600
+ sense: "EQUAL",
601
+ n_vars: 1,
602
+ vars_text: "VARS c0 IN [0 1]",
603
+ expr_text: `EXPR XOR plain=${plain} cipher=${cipher} key=UNKNOWN`,
604
+ sense_text: "SENSE EQUAL",
605
+ b_raw: fmt6(bRaw),
606
+ b_norm: fmt8(_safeNorm(bRaw)),
607
+ c_values: [cVal],
608
+ mask: [1],
609
+ candidates:[],
610
+ step_count: 0,
611
+ axl_source: axl,
612
+ metadata: {
613
+ description: `XOR byte cipher: plain=${plain} key=${key} β†’ cipher=${cipher}`,
614
+ units: "character_code",
615
+ difficulty: "medium",
616
+ scope_depth: 2,
617
+ has_emergence: false,
618
+ has_contradiction: true,
619
+ key_bits: keyBits,
620
+ plain_bits: plainBits,
621
+ out_bits: outBits,
622
  }
623
+ });
624
+ }
625
+ return samples;
626
+ }
627
+
628
+ function synthCaesarSamples(n) {
629
+ const samples =[];
630
+ for (let i = 0; i < n; i++) {
631
+ const msgLen = randint(1, 4);
632
+ const shift = randint(0, 25);
633
+ const plains = Array.from({length: msgLen}, () => randint(0, 25));
634
+ const ciphers = plains.map(p => (p + shift) % 26);
635
+ const cVal = fmt6(shift / 25.0);
636
+ const bRaw = ciphers.reduce((a, b) => a + b, 0);
637
+
638
+ const charEntities = plains.map((p, idx) =>
639
+ ` ENTITY char_${idx}\n` +
640
+ ` FIELD plaintext: INTEGER DISCRETE VALUES {0..25} EQUALS ${p}\n` +
641
+ ` FIELD ciphertext: INTEGER DISCRETE VALUES {0..25}\n` +
642
+ ` DERIVES ciphertext FROM {plaintext, shift} BY caesar_transform\n` +
643
+ ` END ENTITY`
644
+ ).join("\n");
645
+
646
+ const axl = [
647
+ `SCOPE alphabet_ring [level: 0]`,
648
+ ` ASSUME integer EXISTS`,
649
+ ` ASSUME modular_arithmetic HOLDS`,
650
+ ``,
651
+ ` ENTITY alphabet`,
652
+ ` FIELD size: INTEGER EQUALS 26`,
653
+ ` FIELD symbols: DISCRETE VALUES {a=0, b=1, c=2, ..., z=25}`,
654
+ ` BOUND any_char WITHIN [0, 25]`,
655
+ ` END ENTITY`,
656
+ ``,
657
+ ` TRANSFORM modular_add`,
658
+ ` INPUT {a: INTEGER, b: INTEGER, mod: INTEGER}`,
659
+ ` OUTPUT {result: INTEGER}`,
660
+ ` PRODUCES result = (a + b) % mod`,
661
+ ` CONSERVES mod`,
662
+ ` END TRANSFORM`,
663
+ `END SCOPE`,
664
+ ``,
665
+ `SCOPE caesar_char [level: 1]`,
666
+ ` ASSUME alphabet_ring SCOPE HOLDS`,
667
+ ``,
668
+ ` TRANSFORM caesar_transform`,
669
+ ` INPUT {plaintext: INTEGER BOUND [0,25], shift: INTEGER BOUND [0,25]}`,
670
+ ` OUTPUT {ciphertext: INTEGER BOUND [0,25]}`,
671
+ ` PRODUCES ciphertext = modular_add(plaintext, shift, 26)`,
672
+ ` CONSERVES alphabet_size`,
673
+ ` CHANGES character_identity`,
674
+ ` END TRANSFORM`,
675
+ ``,
676
+ ` ENTITY shift_key`,
677
+ ` FIELD raw: INTEGER BOUND [0, 25]`,
678
+ ` FIELD normalised: REAL BOUND [0, 1]`,
679
+ ` DERIVES normalised FROM raw BY divide_25`,
680
+ ` END ENTITY`,
681
+ ``,
682
+ charEntities,
683
+ `END SCOPE`,
684
+ ``,
685
+ `SCOPE caesar_message [level: 2]`,
686
+ ` ASSUME caesar_char SCOPE HOLDS`,
687
+ ``,
688
+ ` ENTITY message`,
689
+ ` FIELD plaintext: VECTOR OF INTEGER EQUALS [${plains.join(", ")}]`,
690
+ ` FIELD ciphertext: VECTOR OF INTEGER`,
691
+ ` FIELD length: INTEGER EQUALS ${msgLen}`,
692
+ ` DERIVES ciphertext FROM {plaintext, shift_key.raw} BY caesar_transform APPLIED_TO_EACH`,
693
+ ` END ENTITY`,
694
+ ``,
695
+ ` OBSERVE message.ciphertext EQUALS [${ciphers.join(", ")}]`,
696
+ ` OBSERVE SUM(message.ciphertext) EQUALS ${bRaw}`,
697
+ ` UNKNOWN shift_key.normalised: REAL BOUND [0, 1]`,
698
+ ``,
699
+ ` COLLAPSE caesar_message`,
700
+ ` GIVEN {message.plaintext, SUM(message.ciphertext)}`,
701
+ ` FIND shift_key.normalised`,
702
+ ` CONFIDENCE 0.99`,
703
+ ` END COLLAPSE`,
704
+ `END SCOPE`,
705
+ ].join("\n");
706
+
707
+ samples.push({
708
+ id: crypto.randomUUID(),
709
+ domain: "cryptography",
710
+ subdomain: "caesar",
711
+ sense: "EQUAL",
712
+ n_vars: 1,
713
+ vars_text: "VARS c0 IN [0 1]",
714
+ expr_text: `EXPR CAESAR plains=[${plains}] ciphers=[${ciphers}] shift=UNKNOWN`,
715
+ sense_text: "SENSE EQUAL",
716
+ b_raw: fmt6(bRaw),
717
+ b_norm: fmt8(_safeNorm(bRaw)),
718
+ c_values: [cVal],
719
+ mask: [1],
720
+ candidates:[],
721
+ step_count: 0,
722
+ axl_source: axl,
723
+ metadata: {
724
+ description: `Caesar cipher: shift=${shift} plains=[${plains}] β†’ ciphers=[${ciphers}]`,
725
+ units: "character_code_sum",
726
+ difficulty: msgLen > 1 ? "medium" : "easy",
727
+ scope_depth: 3,
728
+ has_emergence: false,
729
+ has_contradiction: true,
730
+ }
731
+ });
732
+ }
733
+ return samples;
734
+ }
735
+
736
+ function synthVigenereSamples(n) {
737
+ const samples =[];
738
+ for (let i = 0; i < n; i++) {
739
+ const keyLen = randint(2, 5);
740
+ const key = Array.from({length: keyLen}, () => randint(0, 25));
741
+ const plain = Array.from({length: keyLen}, () => randint(0, 25));
742
+ const cipher = plain.map((p, idx) => (p + key[idx]) % 26);
743
+ const bRaw = cipher.reduce((a, b) => a + b, 0);
744
+ const cVals = key.map(k => fmt6(k / 25.0));
745
+
746
+ const posEntities = plain.map((p, idx) =>
747
+ ` ENTITY position_${idx}\n` +
748
+ ` FIELD plaintext: INTEGER EQUALS ${p}\n` +
749
+ ` FIELD key_char: INTEGER BOUND [0, 25] # UNKNOWN\n` +
750
+ ` FIELD ciphertext: INTEGER BOUND [0, 25]\n` +
751
+ ` DERIVES ciphertext FROM {plaintext, key_char} BY modular_add_26\n` +
752
+ ` END ENTITY`
753
+ ).join("\n");
754
+
755
+ const axl =[
756
+ `SCOPE alphabet_ring [level: 0]`,
757
+ ` ASSUME integer EXISTS`,
758
+ ` TRANSFORM modular_add_26`,
759
+ ` INPUT {a: INTEGER BOUND[0,25], b: INTEGER BOUND [0,25]}`,
760
+ ` OUTPUT {result: INTEGER BOUND [0,25]}`,
761
+ ` PRODUCES result = (a + b) % 26`,
762
+ ` END TRANSFORM`,
763
+ `END SCOPE`,
764
+ ``,
765
+ `SCOPE vigenere_position [level: 1]`,
766
+ ` ASSUME alphabet_ring SCOPE HOLDS`,
767
+ posEntities,
768
+ ` EMERGES key_periodicity`,
769
+ ` FROM COMPOSITION OF {position_0..position_${keyLen-1}}`,
770
+ ` AT SCOPE vigenere_composition`,
771
+ ` END EMERGES`,
772
+ `END SCOPE`,
773
+ ``,
774
+ `SCOPE vigenere_composition [level: 2]`,
775
+ ` ASSUME vigenere_position SCOPE HOLDS`,
776
+ ``,
777
+ ` ENTITY key_vector`,
778
+ ` FIELD chars: VECTOR OF INTEGER BOUND [0, 25] # length ${keyLen}`,
779
+ ` FIELD normalised: VECTOR OF REAL BOUND [0, 1]`,
780
+ ` DERIVES normalised FROM chars BY divide_each_by_25`,
781
+ ` END ENTITY`,
782
+ ``,
783
+ ` ENTITY plaintext_vector`,
784
+ ` FIELD chars: VECTOR OF INTEGER EQUALS [${plain.join(", ")}]`,
785
+ ` END ENTITY`,
786
+ ``,
787
+ ` ENTITY ciphertext_vector`,
788
+ ` FIELD chars: VECTOR OF INTEGER`,
789
+ ` DERIVES chars FROM {plaintext_vector.chars, key_vector.chars}`,
790
+ ` BY modular_add_26 APPLIED_PAIRWISE`,
791
+ ` END ENTITY`,
792
+ ``,
793
+ ` OBSERVE ciphertext_vector.chars EQUALS[${cipher.join(", ")}]`,
794
+ ` OBSERVE SUM(ciphertext_vector.chars) EQUALS ${bRaw}`,
795
+ ``,
796
+ ` UNKNOWN key_vector.normalised: VECTOR OF REAL BOUND [0, 1] # length ${keyLen}`,
797
+ ``,
798
+ ` COLLAPSE vigenere_composition`,
799
+ ` GIVEN {plaintext_vector.chars, ciphertext_vector.chars}`,
800
+ ` FIND key_vector.normalised`,
801
+ ` CONFIDENCE 0.99`,
802
+ ` END COLLAPSE`,
803
+ `END SCOPE`,
804
+ ].join("\n");
805
+
806
+ samples.push({
807
+ id: crypto.randomUUID(),
808
+ domain: "cryptography",
809
+ subdomain: `vigenere_${keyLen}char`,
810
+ sense: "EQUAL",
811
+ n_vars: keyLen,
812
+ vars_text: Array.from({length:keyLen}, (_,j) => `c${j} IN [0 1]`).join(" "),
813
+ expr_text: `EXPR VIGENERE keyLen=${keyLen} plains=[${plain}] ciphers=[${cipher}] key=UNKNOWN`,
814
+ sense_text: "SENSE EQUAL",
815
+ b_raw: fmt6(bRaw),
816
+ b_norm: fmt8(_safeNorm(bRaw)),
817
+ c_values: cVals,
818
+ mask:[...Array(keyLen).fill(1), ...Array(Math.max(0, 4 - keyLen)).fill(0)],
819
+ candidates:[],
820
+ step_count: 0,
821
+ axl_source: axl,
822
+ metadata: {
823
+ description: `Vigenère ${keyLen}-char key=[${key}] plains=[${plain}] → [${cipher}]`,
824
+ units: "character_code_sum",
825
+ difficulty: keyLen <= 2 ? "medium" : keyLen <= 4 ? "hard" : "expert",
826
+ scope_depth: 3,
827
+ has_emergence: true,
828
+ has_contradiction: true,
829
+ }
830
+ });
831
+ }
832
+ return samples;
833
+ }
834
+
835
+ function synthAffineSamples(n) {
836
+ const VALID_A =[1,3,5,7,9,11,15,17,19,21,23,25];
837
+ const INV_A_MAP = {1:1,3:9,5:21,7:15,9:3,11:19,15:7,17:23,19:11,21:5,23:17,25:25};
838
+ const samples =[];
839
+
840
+ for (let i = 0; i < n; i++) {
841
+ const aIdx = randint(0, 11);
842
+ const a = VALID_A[aIdx];
843
+ const b = randint(0, 25);
844
+ const p = randint(0, 25);
845
+ const cipher = (a * p + b) % 26;
846
+ const aInv = INV_A_MAP[a];
847
+ const verify = ((aInv * (cipher - b)) % 26 + 26) % 26;
848
+ if (verify !== p) continue;
849
+
850
+ const cVals =[fmt6(aIdx / 11.0), fmt6(b / 25.0)];
851
+ const bRaw = cipher;
852
+
853
+ const axl = [
854
+ `SCOPE modular_arithmetic[level: 0]`,
855
+ ` ASSUME integer EXISTS`,
856
+ ``,
857
+ ` TRANSFORM modular_multiply_add`,
858
+ ` INPUT {a: INTEGER, p: INTEGER, b: INTEGER, mod: INTEGER}`,
859
+ ` OUTPUT {result: INTEGER}`,
860
+ ` PRODUCES result = (a * p + b) % mod`,
861
+ ` END TRANSFORM`,
862
+ ``,
863
+ ` TRANSFORM modular_inverse`,
864
+ ` INPUT {a: INTEGER, mod: INTEGER}`,
865
+ ` OUTPUT {a_inv: INTEGER}`,
866
+ ` REQUIRES gcd(a, mod) EQUALS 1 # invertibility condition`,
867
+ ` PRODUCES a_inv SUCH_THAT (a * a_inv) % mod EQUALS 1`,
868
+ ` END TRANSFORM`,
869
+ `END SCOPE`,
870
+ ``,
871
+ `SCOPE affine_cipher [level: 1]`,
872
+ ` ASSUME modular_arithmetic SCOPE HOLDS`,
873
+ ``,
874
+ ` ENTITY affine_key`,
875
+ ` FIELD a: INTEGER DISCRETE VALUES {1,3,5,7,9,11,15,17,19,21,23,25}`,
876
+ ` FIELD b: INTEGER BOUND [0, 25]`,
877
+ ` FIELD a_idx: INTEGER BOUND[0, 11]`,
878
+ ` FIELD a_norm: REAL BOUND[0, 1]`,
879
+ ` FIELD b_norm: REAL BOUND [0, 1]`,
880
+ ` DERIVES a FROM a_idx BY lookup_valid_a`,
881
+ ` DERIVES a_norm FROM a_idx BY divide_11`,
882
+ ` DERIVES b_norm FROM b BY divide_25`,
883
+ ` BOUND a COPRIME_TO 26`,
884
+ ` END ENTITY`,
885
+ ``,
886
+ ` ENTITY affine_transform_result`,
887
+ ` FIELD plaintext: INTEGER BOUND [0, 25] EQUALS ${p}`,
888
+ ` FIELD ciphertext: INTEGER BOUND [0, 25]`,
889
+ ` DERIVES ciphertext FROM {affine_key.a, plaintext, affine_key.b} BY modular_multiply_add`,
890
+ ` END ENTITY`,
891
+ ``,
892
+ ` ENTITY affine_inverse`,
893
+ ` FIELD a_inv: INTEGER EQUALS ${aInv}`,
894
+ ` FIELD recovery: INTEGER`,
895
+ ` DERIVES recovery FROM {a_inv, ciphertext, b} BY modular_multiply_add`,
896
+ ` END ENTITY`,
897
+ ``,
898
+ ` CONTRADICT invertible WITH non_coprime_a`,
899
+ ` AT SCOPE affine_cipher`,
900
+ ` BOUNDARY_TYPE INFORMATION`,
901
+ ` END CONTRADICT`,
902
+ ``,
903
+ ` OBSERVE affine_transform_result.ciphertext EQUALS ${cipher}`,
904
+ ` UNKNOWN affine_key.a_norm: REAL BOUND [0, 1]`,
905
+ ` UNKNOWN affine_key.b_norm: REAL BOUND [0, 1]`,
906
+ ``,
907
+ ` COLLAPSE affine_cipher`,
908
+ ` GIVEN {affine_transform_result.plaintext, affine_transform_result.ciphertext}`,
909
+ ` FIND {affine_key.a_norm, affine_key.b_norm}`,
910
+ ` CONFIDENCE 0.99`,
911
+ ` END COLLAPSE`,
912
+ `END SCOPE`,
913
+ ].join("\n");
914
+
915
+ samples.push({
916
+ id: crypto.randomUUID(),
917
+ domain: "cryptography",
918
+ subdomain: "affine",
919
+ sense: "EQUAL",
920
+ n_vars: 2,
921
+ vars_text: "VARS c0 IN [0 1] c1 IN [0 1]",
922
+ expr_text: `EXPR AFFINE a=${a}(idx=${aIdx}) b=${b} plain=${p} cipher=${cipher}`,
923
+ sense_text: "SENSE EQUAL",
924
+ b_raw: fmt6(bRaw),
925
+ b_norm: fmt8(_safeNorm(bRaw)),
926
+ c_values: cVals,
927
+ mask:[1, 1],
928
+ candidates:[],
929
+ step_count: 0,
930
+ axl_source: axl,
931
+ metadata: {
932
+ description: `Affine cipher: a=${a} b=${b} plain=${p} β†’ cipher=${cipher}, inv_a=${aInv}`,
933
+ units: "character_code",
934
+ difficulty: "hard",
935
+ scope_depth: 2,
936
+ has_emergence: false,
937
+ has_contradiction: true,
938
+ a_inverse: aInv,
939
+ coprimality_proof: `gcd(${a},26)=1`,
940
+ }
941
+ });
942
+ }
943
+ return samples;
944
+ }
945
+
946
+ function synthXorStreamSamples(n) {
947
+ const samples =[];
948
+ for (let i = 0; i < n; i++) {
949
+ const keyLen = randint(2, 4);
950
+ const msgLen = randint(keyLen, keyLen * 2);
951
+ const key = Array.from({length: keyLen}, () => randint(0, 255));
952
+ const plain = Array.from({length: msgLen}, () => randint(0, 255));
953
+ const keyStream = Array.from({length: msgLen}, (_, idx) => key[idx % keyLen]);
954
+ const cipher = plain.map((p, idx) => p ^ keyStream[idx]);
955
+ const bRaw = cipher.reduce((a,b) => a+b, 0);
956
+ const cVals = key.map(k => fmt6(k / 255.0));
957
+
958
+ const keyStreamComment = keyStream.map((k,idx) => `key[${idx%keyLen}]=${k}`).join(", ");
959
+
960
+ const axl = [
961
+ `SCOPE xor_gate [level: 0]`,
962
+ ` TRANSFORM xor_byte`,
963
+ ` INPUT {a: INTEGER BOUND [0,255], b: INTEGER BOUND [0,255]}`,
964
+ ` OUTPUT {result: INTEGER BOUND[0,255]}`,
965
+ ` PRODUCES result = a XOR b`,
966
+ ` END TRANSFORM`,
967
+ `END SCOPE`,
968
+ ``,
969
+ `SCOPE key_stream [level: 1]`,
970
+ ` ASSUME xor_gate SCOPE HOLDS`,
971
+ ``,
972
+ ` ENTITY key_block`,
973
+ ` FIELD bytes: VECTOR OF INTEGER BOUND [0,255] # length ${keyLen}`,
974
+ ` FIELD normalised: VECTOR OF REAL BOUND [0,1]`,
975
+ ` DERIVES normalised FROM bytes BY divide_each_by_255`,
976
+ ` END ENTITY`,
977
+ ``,
978
+ ` TRANSFORM key_schedule_repeating`,
979
+ ` INPUT {key: key_block, message_length: INTEGER}`,
980
+ ` OUTPUT {stream: VECTOR OF INTEGER}`,
981
+ ` PRODUCES stream[i] = key.bytes[i mod ${keyLen}]`,
982
+ ` END TRANSFORM`,
983
+ ``,
984
+ ` EMERGES key_periodicity`,
985
+ ` FROM COMPOSITION OF key_block REPEATED`,
986
+ ` AT SCOPE key_stream`,
987
+ ` NOT PRESENT AT SCOPE xor_gate`,
988
+ ` END EMERGES`,
989
+ `END SCOPE`,
990
+ ``,
991
+ `SCOPE xor_stream_cipher[level: 2]`,
992
+ ` ASSUME key_stream SCOPE HOLDS`,
993
+ ``,
994
+ ` ENTITY plaintext_msg`,
995
+ ` FIELD bytes: VECTOR OF INTEGER EQUALS[${plain.join(", ")}]`,
996
+ ` FIELD length: INTEGER EQUALS ${msgLen}`,
997
+ ` END ENTITY`,
998
+ ``,
999
+ ` ENTITY ciphertext_msg`,
1000
+ ` FIELD bytes: VECTOR OF INTEGER`,
1001
+ ` DERIVES bytes FROM {plaintext_msg.bytes, key_stream} BY xor_byte APPLIED_PAIRWISE`,
1002
+ ` END ENTITY`,
1003
+ ``,
1004
+ ` OBSERVE ciphertext_msg.bytes EQUALS [${cipher.join(", ")}]`,
1005
+ ` OBSERVE SUM(ciphertext_msg.bytes) EQUALS ${bRaw}`,
1006
+ ``,
1007
+ ` UNKNOWN key_block.normalised: VECTOR OF REAL BOUND [0,1] # length ${keyLen}`,
1008
+ ``,
1009
+ ` COLLAPSE xor_stream_cipher`,
1010
+ ` GIVEN {plaintext_msg.bytes, ciphertext_msg.bytes}`,
1011
+ ` FIND key_block.normalised`,
1012
+ ` CONFIDENCE 0.99`,
1013
+ ` END COLLAPSE`,
1014
+ `END SCOPE`,
1015
+ ].join("\n");
1016
+
1017
+ samples.push({
1018
+ id: crypto.randomUUID(),
1019
+ domain: "cryptography",
1020
+ subdomain: `xor_stream_key${keyLen}`,
1021
+ sense: "EQUAL",
1022
+ n_vars: keyLen,
1023
+ vars_text: Array.from({length:keyLen}, (_,j) => `c${j} IN[0 1]`).join(" "),
1024
+ expr_text: `EXPR XOR_STREAM keyLen=${keyLen} msgLen=${msgLen} cipherSum=${bRaw}`,
1025
+ sense_text: "SENSE EQUAL",
1026
+ b_raw: fmt6(bRaw),
1027
+ b_norm: fmt8(_safeNorm(bRaw)),
1028
+ c_values: cVals,
1029
+ mask:[...Array(keyLen).fill(1), ...Array(Math.max(0, 4 - keyLen)).fill(0)],
1030
+ candidates:[],
1031
+ step_count: 0,
1032
+ axl_source: axl,
1033
+ metadata: {
1034
+ description: `XOR stream cipher: key=[${key}] len=${msgLen} β†’ cipherSum=${bRaw}`,
1035
+ units: "byte_sum",
1036
+ difficulty: keyLen <= 2 ? "medium" : "hard",
1037
+ scope_depth: 3,
1038
+ has_emergence: true,
1039
+ has_contradiction: true,
1040
+ key_period: keyLen,
1041
+ }
1042
+ });
1043
+ }
1044
+ return samples;
1045
+ }
1046
+
1047
+ function synthNonceSearchSamples(n) {
1048
+ const samples =[];
1049
+ for (let i = 0; i < n; i++) {
1050
+ const stepCount = randint(1, 20);
1051
+ const targetZeros = randint(1, 4);
1052
+ const nonceBits = 16;
1053
+ const nonceRange = Math.pow(2, nonceBits);
1054
+
1055
+ const trueNonce = randint(0, nonceRange - 1);
1056
+ const cVal = fmt6(trueNonce / (nonceRange - 1));
1057
+
1058
+ const explored = Array.from({length: Math.min(stepCount, 5)}, () =>
1059
+ fmt6(randint(0, nonceRange-1) / (nonceRange-1))
1060
+ );
1061
+
1062
+ const stepBlocks = explored.map((nc, idx) =>[
1063
+ ` STEP ${idx}`,
1064
+ ` STATE {`,
1065
+ ` explored_fraction: ${fmt6((idx+1)/nonceRange * 100)},`,
1066
+ ` best_nonce_so_far: ${nc},`,
1067
+ ` step_count: ${idx+1}`,
1068
+ ` }`,
1069
+ ` CANDIDATE 0`,
1070
+ ` nonce_norm: ${nc}`,
1071
+ ` score: UNKNOWN`,
1072
+ ` confidence: LEARNS`,
1073
+ ` END CANDIDATE`,
1074
+ ` END STEP`,
1075
+ ].join("\n")).join("\n");
1076
+
1077
+ const axl = [
1078
+ `SCOPE nonce_space [level: 0]`,
1079
+ ` ASSUME nonce EXISTS`,
1080
+ ` ASSUME nonce DISCRETE VALUES {0..${nonceRange-1}}`,
1081
+ ``,
1082
+ ` ENTITY nonce_vector`,
1083
+ ` FIELD raw: INTEGER BOUND [0, ${nonceRange-1}]`,
1084
+ ` FIELD normalised: REAL BOUND [0, 1]`,
1085
+ ` DERIVES normalised FROM raw BY divide_${nonceRange-1}`,
1086
+ ` FIELD bits: VECTOR OF bit # ${nonceBits} bits`,
1087
+ ` DERIVES bits FROM raw BY integer_to_bits`,
1088
+ ` END ENTITY`,
1089
+ `END SCOPE`,
1090
+ ``,
1091
+ `SCOPE hash_constraint [level: 1]`,
1092
+ ` ASSUME nonce_space SCOPE HOLDS`,
1093
+ ``,
1094
+ ` TRANSFORM double_hash`,
1095
+ ` INPUT {block_header_fixed, nonce: nonce_vector}`,
1096
+ ` OUTPUT {hash: VECTOR OF bit}`,
1097
+ ` CONSERVES nothing`,
1098
+ ` CHANGES everything`,
1099
+ ` PRODUCES hash PSEUDO_RANDOM_FROM nonce`,
1100
+ ` END TRANSFORM`,
1101
+ ``,
1102
+ ` ENTITY difficulty_target`,
1103
+ ` FIELD leading_zeros: INTEGER EQUALS ${targetZeros}`,
1104
+ ` FIELD threshold: INTEGER EQUALS ${Math.floor(nonceRange / Math.pow(2, targetZeros))}`,
1105
+ ` END ENTITY`,
1106
+ ``,
1107
+ ` CONTRADICT smooth_gradient WITH hash_avalanche`,
1108
+ ` AT SCOPE hash_constraint`,
1109
+ ` BOUNDARY_TYPE INFORMATION`,
1110
+ ` END CONTRADICT`,
1111
+ `END SCOPE`,
1112
+ ``,
1113
+ `SCOPE nonce_search [level: 2]`,
1114
+ ` ASSUME hash_constraint SCOPE HOLDS`,
1115
+ ``,
1116
+ stepBlocks,
1117
+ ``,
1118
+ ` ENTITY search_state`,
1119
+ ` FIELD explored_regions: VECTOR OF REAL`,
1120
+ ` FIELD step_count: INTEGER EQUALS ${stepCount}`,
1121
+ ` FIELD best_hash_gap: REAL`,
1122
+ ` TENDS coverage MAX`,
1123
+ ` TENDS hash_gap MIN`,
1124
+ ` END ENTITY`,
1125
+ ``,
1126
+ ` OBSERVE hash BELOW difficulty_target.threshold`,
1127
+ ` UNKNOWN nonce_vector.normalised: REAL BOUND [0, 1]`,
1128
+ ``,
1129
+ ` COLLAPSE nonce_search`,
1130
+ ` GIVEN {search_state, difficulty_target}`,
1131
+ ` FIND nonce_vector.normalised`,
1132
+ ` CONFIDENCE 0.85`,
1133
+ ` END COLLAPSE`,
1134
+ `END SCOPE`,
1135
+ ].join("\n");
1136
+
1137
+ samples.push({
1138
+ id: crypto.randomUUID(),
1139
+ domain: "cryptography",
1140
+ subdomain: "nonce_search",
1141
+ sense: "MINIMIZE",
1142
+ n_vars: 1,
1143
+ vars_text: "VARS c0 IN[0 1]",
1144
+ expr_text: `EXPR NONCE_SEARCH target_zeros=${targetZeros} steps=${stepCount}`,
1145
+ sense_text: "SENSE MINIMIZE",
1146
+ b_raw: fmt6(trueNonce / (nonceRange - 1)),
1147
+ b_norm: fmt8(_safeNorm(trueNonce / (nonceRange - 1))),
1148
+ c_values: [cVal],
1149
+ mask: [1],
1150
+ candidates: explored.map(nc => [nc]),
1151
+ step_count: stepCount,
1152
+ axl_source: axl,
1153
+ metadata: {
1154
+ description: `Nonce search: target=${targetZeros} leading zeros, ${stepCount} steps explored`,
1155
+ units: "normalised_nonce",
1156
+ difficulty: targetZeros <= 2 ? "medium" : "expert",
1157
+ scope_depth: 3,
1158
+ has_emergence: false,
1159
+ has_contradiction: true,
1160
+ nonce_bits: nonceBits,
1161
+ target_zeros: targetZeros,
1162
+ }
1163
+ });
1164
  }
1165
  return samples;
1166
  }
 
1181
  sense: sense, n_vars: nVars, vars_text: "VARS " + cVals.map((_, j) => `c${j} IN [0 1]`).join(" "),
1182
  expr_text: "EXPR " + coeffs.map((c, j) => `${c.toFixed(3)}*c${j}`).join(" + "), sense_text: `SENSE ${sense}`,
1183
  b_raw: Number(bRaw.toFixed(6)), b_norm: Number(_safeNorm(bRaw).toFixed(8)), c_values: cVals.map(v => Number(v.toFixed(6))),
1184
+ mask:[...Array(nVars).fill(1), ...Array(Math.max(0, 4 - nVars)).fill(0)], candidates:[], step_count: 0,
1185
  axl_source: `SCOPE optimization[level: 2]\n OBJECTIVE OPTIMIZE f ${sense}\n SUBJECT TO c WITHIN [0,1]\nEND SCOPE`,
1186
  metadata: { description: `Linear ${sense.toLowerCase()} over ${nVars} variables`, units: "objective", difficulty: "easy", scope_depth: 1, has_emergence: false, has_contradiction: false }
1187
  });
 
1190
  return samples;
1191
  }
1192
 
1193
+ function synthCryptoSamples(n) {
1194
+ const perType = Math.ceil(n / 6);
1195
+ return[
1196
+ ...synthXorSamples(perType),
1197
+ ...synthCaesarSamples(perType),
1198
+ ...synthVigenereSamples(perType),
1199
+ ...synthAffineSamples(perType),
1200
+ ...synthXorStreamSamples(perType),
1201
+ ...synthNonceSearchSamples(perType),
1202
+ ].slice(0, n);
1203
+ }
1204
+
1205
+ const SYNTHETIC_GENERATORS =[synthPhysicsSamples, synthFinanceSamples, synthCryptoSamples, synthOptimizationSamples];
1206
 
1207
  // ── FOCUS TRACKER ────────────────────────────────────────────────────────────
1208
  class FocusTracker {
 
1250
  // ── JSON PARSER ──────────────────────────────────────────────────────────────
1251
  function parseAiResponse(text) {
1252
  let raw = text.trim();
1253
+ const fences =["```json", "```JSON", "```"];
1254
  for (let f of fences) {
1255
  if (raw.startsWith(f)) { raw = raw.slice(f.length); break; }
1256
  }
 
1406
 
1407
  app.post('/dataset/clear', (req, res) => {
1408
  const count = _dataset.length;
1409
+ _dataset =[];
1410
  if (fs.existsSync(DATASET_PATH)) fs.unlinkSync(DATASET_PATH);
1411
  log(`Dataset cleared β€” removed ${count} samples`, "OK");
1412
  res.json({ cleared: count });