code wiki / _hdl_build / nx_mulchain_costcap_probe.nx
nx_mulchain_costcap_probe.nx source
↩ module page · 44 lines · 2175 B
1// nx_mulchain_costcap_probe.nx -- TEST the research claim: the tractability lever is the
2// Levin cost-cap (don't search past the depth where a chain could beat imul), NOT a cleverer
3// prune. Run the PRUNED deep search (Thurber-family reach bound) at the cost-competitive cap
4// maxL=5 over the escalated constants AND the primes that hung at depth 6/12. If depth-5 is
5// fast for everyone (finds 466/683/691=5 ops, fails-fast on 10007/1000003), the claim holds.
6// license_tier: ORIGINAL
7
8import "nx_mulchain_deep.nx"
9import "nx_syscalls.nx"
10const K_MAGIC_10007: i64 = 10007
11const K_MAGIC_1000003: i64 = 1000003
12const K_MAGIC_715827883: i64 = 715827883
13const K_MAGIC_123457: i64 = 123457
14const K_MAGIC_43691: i64 = 43691
15const K_MAGIC_2730: i64 = 2730
16
17func cp_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
18func cp_puts(s: *u8) -> i64 { sys_write(1, s, cp_slen(s)); return 0 }
19func cp_num(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 }
20
21func cp_run(c: i64) -> i64 {
22 let op: *i64 = sys_mmap(8*20) as *i64; let a: *i64 = sys_mmap(8*20) as *i64; let b: *i64 = sys_mmap(8*20) as *i64
23 return mulchain_deep_verified(c, 5, op, a, b)
24}
25
26func main() -> i64 {
27 let cs: *i64 = sys_mmap(8*16) as *i64
28 cs[0]=466; cs[1]=683; cs[2]=691; cs[3]=499; cs[4]=719
29 cs[5]=K_MAGIC_10007; cs[6]=K_MAGIC_1000003; cs[7]=K_MAGIC_715827883; cs[8]=K_MAGIC_123457; cs[9]=K_MAGIC_43691
30 cs[10]=45; cs[11]=100; cs[12]=255; cs[13]=K_MAGIC_2730; cs[14]=0; cs[15]=0
31 cp_puts("c -> deep_verified_ops @ cost-cap maxL=5 (pruned)\n" as *u8)
32 var i: i64 = 0
33 while i < 14 {
34 if cs[i] != 0 {
35 cp_puts(" c=" as *u8); cp_num(cs[i]); cp_puts(" -> " as *u8)
36 let L: i64 = cp_run(cs[i])
37 if L < 0 { cp_puts("no <=5 chain -> CEDE to imul\n" as *u8) } else { cp_num(L); cp_puts(" ops\n" as *u8) }
38 }
39 i = i + 1
40 }
41 cp_puts("done\n" as *u8)
42 sys_exit(0)
43 return 0
44}