code wiki / _hdl_build / nx_myoattach.nx

nx_myoattach.nx source

↩ module page · 405 lines · 21920 B

1// nx_myoattach.nx -- ★MUSCLE ATTACHMENTS DERIVED FROM BONE LANDMARKS, never typed. 2// 3// ★THE LAW THIS APPLIES, learned in this lane on the brow ridge: "NEVER TYPE A PLACEMENT COORDINATE 4// THAT THE PARENT ALREADY KNOWS." A muscle does not have a height; it has ATTACHMENTS -- an origin on 5// one bone and an insertion on another -- and its height is a CONSEQUENCE of where those bones are. 6// nx_myotable still carries typed per-mille stations, which means every future muscle is another 7// opportunity to type a plausible-looking number. This session already measured what that costs: the 8// biacromial breadth sat at 52% of its true value for the life of the organ because it was typed. 9// 10// ★★THE MECHANISM THAT MAKES ~700 MUSCLES REACHABLE WITHOUT 700 GUESSES: an attachment is 11// (joint_a, joint_b, t) -- a point t per-mille of the way along the bone spanning two joints that 12// nx_skelgen ALREADY EMITS. So an attachment is specified ANATOMICALLY ("the proximal third of the 13// humerus") and its coordinate is derived, at any stature, any sex, scale-free, forever. Typing stops 14// being possible for the quantity that was being got wrong. 15// 16// ⚠AND IT IS A CROSS-ARTIFACT CHECK, which is why it earns its place now rather than later: the derived 17// station and nx_myoset's typed station are two independent statements about the same muscle. This organ 18// REPORTS the disagreement per muscle. Per the lane's law, a disagreement NAMES A NUMBER TO GO LOOK UP 19// -- it does not tell you which side is wrong -- so the teeth here are on the MECHANISM and the 20// disagreements are emitted as EVIDENCE, never silently "corrected". 21// 22// nx_myoattach report <skel.dat> 23// nx_myoattach selftest <skel.dat> 24// license_tier: ORIGINAL expect_exit: 0 No hw writes (Rule 26). 25import "nx_gate_verdict.nx" 26const MA_MAGIC_2100: i64 = 2100 27const MA_MAGIC_1750: i64 = 1750 28 29const MA_MAXJ: i64 = 64 30const MA_MM: i64 = 1000 31const MA_NM: i64 = 21 32const MA_TYPED: i64 = 8 // the first 8 have typed counterparts in nx_myoset; the rest are new 33const MA_S: i64 = 8 // muscle row: o_ja, o_jb, o_t, i_ja, i_jb, i_t, peak, ACTUATED JOINT 34// ★★★THE ACTUATED-JOINT COLUMN IS WHAT MAKES ANATOMICAL VALIDITY MECHANICAL. A muscle exists to move a 35// joint, and that single declaration turns "is this attachment sane?" from a judgement into a topology 36// query: THE INSERTION MUST BE DISTAL TO THE JOINT AND THE ORIGIN PROXIMAL TO IT -- because a muscle 37// that attaches on only one side of a joint cannot move it, and a muscle that originates DISTAL to the 38// joint it crosses is anatomically impossible. Both defects this organ found by eyeball are exactly 39// that shape, so this column is what would have caught them without me reading a table. 40// ★It is also load-bearing rather than test-only: motion, FACS-style actuation and inverse dynamics all 41// need to know which muscle moves which joint. 42const MA_INVALID: i64 = 0 - 1 43// nx_skelgen joint ids 44const J_HIP: i64 = 0 45const J_L5: i64 = 1 46const J_C7: i64 = 2 47const J_ACR: i64 = 5 48const J_ELB: i64 = 6 49const J_WRI: i64 = 7 50const J_HIPJ: i64 = 9 51const J_KNEE: i64 = 10 52const J_ANK: i64 = 11 53const J_TOE: i64 = 12 54const J_HEEL: i64 = 13 55const J_ATLAS: i64 = 3 56const J_VTX: i64 = 4 57const J_HAND: i64 = 8 58 59func ma_iabs(v: i64) -> i64 { if v < 0 { return 0-v } return v } 60func ma_isdig(c: i64) -> i64 { if c >= 48 { if c <= 57 { return 1 } } return 0 } 61func ma_tok(b: *u8, n: i64, p: *i64, out: *i64) -> i64 { 62 var i: i64 = p[0] 63 var go: i64 = 1 64 while go == 1 { 65 if i >= n { go = 0 } else { 66 let c: i64 = b[i] as i64 67 var st: i64 = 0 68 if ma_isdig(c) == 1 { st = 1 } 69 if c == 45 { st = 1 } 70 if st == 1 { go = 0 } else { i = i + 1 } 71 } 72 } 73 if i >= n { p[0] = i; return 0 } 74 var sg: i64 = 1 75 if b[i] as i64 == 45 { sg = 0-1; i = i + 1 } 76 var v: i64 = 0 77 var g2: i64 = 1 78 while g2 == 1 { 79 if i >= n { g2 = 0 } else { 80 let c2: i64 = b[i] as i64 81 if ma_isdig(c2) == 1 { v = v*10 + (c2-48); i = i + 1 } else { g2 = 0 } 82 } 83 } 84 p[0] = i 85 out[0] = v*sg 86 return 1 87} 88func ma_nextline(b: *u8, n: i64, p: *i64) -> i64 { 89 var i: i64 = p[0] 90 var go: i64 = 1 91 while go == 1 { if i >= n { go = 0 } else { if b[i] as i64 == 10 { i = i+1; go = 0 } else { i = i+1 } } } 92 p[0] = i 93 return 0 94} 95// J <idx> <parent> <side> <x> <y> <z> -- we need y (and the count, to refuse a stub file) 96func ma_load(path: *u8, JY: *i64, JP: *i64) -> i64 { 97 let ln: *i64 = sys_mmap(16) as *i64 98 let buf: *u8 = sys_read_file(path, ln) 99 if buf as i64 == 0 { return 0-1 } 100 let n: i64 = ln[0] 101 let p: *i64 = sys_mmap(16) as *i64 102 let v: *i64 = sys_mmap(16) as *i64 103 p[0] = 0 104 var cnt: i64 = 0 105 var go: i64 = 1 106 while go == 1 { 107 if p[0] >= n { go = 0 } else { 108 if buf[p[0]] as i64 == 74 { 109 p[0] = p[0] + 1 110 if ma_tok(buf,n,p,v) == 1 { 111 let j: i64 = v[0] 112 if ma_tok(buf,n,p,v) == 1 { 113 let par: i64 = v[0] 114 if ma_tok(buf,n,p,v) == 1 { 115 if ma_tok(buf,n,p,v) == 1 { 116 if ma_tok(buf,n,p,v) == 1 { 117 if j >= 0 { if j < MA_MAXJ { JY[j] = v[0]; JP[j] = par; cnt = cnt + 1 } } 118 } } } } 119 } 120 } 121 ma_nextline(buf,n,p) 122 } 123 } 124 return cnt 125} 126 127// ★THE ATTACHMENT TABLE -- anatomy, not coordinates. Each attachment names the two joints whose bone it 128// sits on and how far along it lies. Read it as prose: "pectoralis major runs from 40% down the spine 129// between C7 and L5, to 20% down the humerus below the acromion." 130func ma_table(M: *i64) -> i64 { 131 var i: i64 = 0 132 // origin(ja, jb, t) insertion(ja, jb, t) peak actuates 133 M[i]=J_C7; M[i+1]=J_L5; M[i+2]=400; M[i+3]=J_ACR; M[i+4]=J_ELB; M[i+5]=200; M[i+6]=90; M[i+7]=J_ACR; i=i+MA_S // pectoralis major 134 M[i]=J_ACR; M[i+1]=J_C7; M[i+2]=0; M[i+3]=J_ACR; M[i+4]=J_ELB; M[i+5]=500; M[i+6]=70; M[i+7]=J_ACR; i=i+MA_S // deltoid: acromion -> mid humerus 135 M[i]=J_L5; M[i+1]=J_HIP; M[i+2]=500; M[i+3]=J_ACR; M[i+4]=J_ELB; M[i+5]=150; M[i+6]=80; M[i+7]=J_ACR; i=i+MA_S // latissimus dorsi 136 M[i]=J_HIP; M[i+1]=J_L5; M[i+2]=0; M[i+3]=J_L5; M[i+4]=J_C7; M[i+5]=350; M[i+6]=45; M[i+7]=J_L5; i=i+MA_S // rectus abdominis: pubis -> ribs 137 M[i]=J_ACR; M[i+1]=J_ELB; M[i+2]=0; M[i+3]=J_ELB; M[i+4]=J_WRI; M[i+5]=150; M[i+6]=60; M[i+7]=J_ELB; i=i+MA_S // biceps brachii: scapula -> radius 138 // ⚠the glute origin was stated on (L5, hip-JOINT), whose joints are BOTH at chain depth 1 -- so it 139 // was not proximal to the hip it moves. Its real origin is the ILIUM/SACRUM = the pelvis block, 140 // which is the bone (root, L5). ★The validity check below is what surfaced this. 141 M[i]=J_HIP; M[i+1]=J_L5; M[i+2]=300; M[i+3]=J_HIPJ; M[i+4]=J_KNEE; M[i+5]=300; M[i+6]=95; M[i+7]=J_HIPJ; i=i+MA_S // gluteus maximus 142 M[i]=J_HIPJ; M[i+1]=J_KNEE; M[i+2]=100; M[i+3]=J_KNEE; M[i+4]=J_ANK; M[i+5]=0; M[i+6]=85; M[i+7]=J_KNEE; i=i+MA_S // quadriceps -> patella at the knee 143 M[i]=J_KNEE; M[i+1]=J_HIPJ; M[i+2]=50; M[i+3]=J_HEEL; M[i+4]=J_ANK; M[i+5]=0; M[i+6]=55; M[i+7]=J_KNEE; i=i+MA_S // gastrocnemius: femoral condyles -> calcaneus 144 // ★★★MUSCLES 8..20, ADDED 2026-07-27. Each is stated as ANATOMY -- which bone it originates on, 145 // which it inserts on, and which joint it moves -- and NOT as a coordinate. The validity check 146 // below refuses any row whose attachments cannot actuate the joint it claims, so a mis-stated 147 // muscle fails at the gate rather than becoming a plausible number in a table. 148 M[i]=J_ATLAS;M[i+1]=J_C7; M[i+2]=200; M[i+3]=J_ACR; M[i+4]=J_ELB; M[i+5]=0; M[i+6]=75; M[i+7]=J_ACR; i=i+MA_S // trapezius: occiput/spinous -> acromion 149 M[i]=J_ACR; M[i+1]=J_ELB; M[i+2]=100; M[i+3]=J_ELB; M[i+4]=J_WRI; M[i+5]=50; M[i+6]=65; M[i+7]=J_ELB; i=i+MA_S // triceps brachii: -> olecranon 150 M[i]=J_ELB; M[i+1]=J_WRI; M[i+2]=150; M[i+3]=J_WRI; M[i+4]=J_HAND; M[i+5]=600; M[i+6]=30; M[i+7]=J_WRI; i=i+MA_S // flexor digitorum: forearm -> phalanges 151 M[i]=J_C7; M[i+1]=J_ACR; M[i+2]=200; M[i+3]=J_ATLAS;M[i+4]=J_VTX; M[i+5]=200; M[i+6]=25; M[i+7]=J_ATLAS;i=i+MA_S // sternocleidomastoid: sternum/clavicle -> mastoid 152 M[i]=J_HIP; M[i+1]=J_L5; M[i+2]=100; M[i+3]=J_L5; M[i+4]=J_C7; M[i+5]=700; M[i+6]=70; M[i+7]=J_L5; i=i+MA_S // erector spinae: sacrum/ilium -> ribs/cervical 153 M[i]=J_HIP; M[i+1]=J_L5; M[i+2]=500; M[i+3]=J_HIPJ; M[i+4]=J_KNEE; M[i+5]=150; M[i+6]=40; M[i+7]=J_HIPJ; i=i+MA_S // iliopsoas: lumbar -> lesser trochanter 154 M[i]=J_HIP; M[i+1]=J_L5; M[i+2]=50; M[i+3]=J_HIPJ; M[i+4]=J_KNEE; M[i+5]=600; M[i+6]=80; M[i+7]=J_HIPJ; i=i+MA_S // adductor magnus: pubis/ischium -> femur 155 M[i]=J_HIP; M[i+1]=J_L5; M[i+2]=350; M[i+3]=J_HIPJ; M[i+4]=J_KNEE; M[i+5]=100; M[i+6]=60; M[i+7]=J_HIPJ; i=i+MA_S // gluteus medius: ilium -> greater trochanter 156 M[i]=J_HIP; M[i+1]=J_L5; M[i+2]=0; M[i+3]=J_KNEE; M[i+4]=J_ANK; M[i+5]=150; M[i+6]=88; M[i+7]=J_KNEE; i=i+MA_S // hamstrings: ischial tuberosity -> tibia 157 M[i]=J_HIP; M[i+1]=J_L5; M[i+2]=200; M[i+3]=J_KNEE; M[i+4]=J_ANK; M[i+5]=200; M[i+6]=30; M[i+7]=J_KNEE; i=i+MA_S // sartorius: ASIS -> medial tibia 158 M[i]=J_KNEE; M[i+1]=J_ANK; M[i+2]=250; M[i+3]=J_ANK; M[i+4]=J_TOE; M[i+5]=700; M[i+6]=35; M[i+7]=J_ANK; i=i+MA_S // tibialis anterior: tibia -> medial cuneiform 159 M[i]=J_KNEE; M[i+1]=J_ANK; M[i+2]=300; M[i+3]=J_HEEL; M[i+4]=J_ANK; M[i+5]=0; M[i+6]=60; M[i+7]=J_ANK; i=i+MA_S // soleus: tibia/fibula -> calcaneus (does NOT cross the knee) 160 M[i]=J_C7; M[i+1]=J_L5; M[i+2]=100; M[i+3]=J_ACR; M[i+4]=J_ELB; M[i+5]=150; M[i+6]=40; M[i+7]=J_ACR; i=i+MA_S // teres major: scapula -> humerus 161 return 0 162} 163// ---- ★ANATOMICAL VALIDITY, as pure TOPOLOGY over the skeleton's parent chain ------------------- 164// Depth = steps from the root. Purely structural, so it works identically for spine, arm and leg and 165// never needs a "which way is proximal" sign convention that would be wrong for one of them. 166func ma_depth(JP: *i64, j: i64) -> i64 { 167 var d: i64 = 0 168 var c: i64 = j 169 var guard: i64 = 0 170 while guard < MA_MAXJ { 171 if c < 0 { return d } 172 let p: i64 = JP[c] 173 if p < 0 { return d } 174 c = p 175 d = d + 1 176 guard = guard + 1 177 } 178 return d 179} 180// ★THE TWO CONDITIONS THAT MAKE A MUSCLE ABLE TO MOVE ITS JOINT: 181// the INSERTION bone must reach DISTAL to the joint (max depth > depth(J)), and 182// the ORIGIN bone must reach PROXIMAL to it (min depth < depth(J)). 183// A muscle failing either attaches on one side only and cannot actuate anything -- which is exactly 184// what the shipped gastrocnemius (origin below its own knee) and inverted latissimus were. 185func ma_valid(JP: *i64, M: *i64, m: i64) -> i64 { 186 let dj: i64 = ma_depth(JP, M[m*MA_S+7]) 187 var omin: i64 = ma_depth(JP, M[m*MA_S]) 188 let ob: i64 = ma_depth(JP, M[m*MA_S+1]) 189 if ob < omin { omin = ob } 190 var imax: i64 = ma_depth(JP, M[m*MA_S+3]) 191 let ib: i64 = ma_depth(JP, M[m*MA_S+4]) 192 if ib > imax { imax = ib } 193 if imax <= dj { return 0 } 194 if omin >= dj { return 0 } 195 return 1 196} 197// ★DERIVE: the world height of an attachment = linear interpolation along the bone between two joints. 198// t=0 is exactly joint a, t=1000 is exactly joint b, so the endpoints are the landmarks themselves. 199func ma_point(JY: *i64, ja: i64, jb: i64, t: i64) -> i64 { 200 let a: i64 = JY[ja] 201 let b: i64 = JY[jb] 202 return a + (b - a) * t / MA_MM 203} 204func ma_origin(JY: *i64, M: *i64, m: i64) -> i64 { return ma_point(JY, M[m*MA_S], M[m*MA_S+1], M[m*MA_S+2]) } 205func ma_insert(JY: *i64, M: *i64, m: i64) -> i64 { return ma_point(JY, M[m*MA_S+3], M[m*MA_S+4], M[m*MA_S+5]) } 206// per-mille of stature, so the derived station is directly comparable to the typed one 207func ma_permil(v: i64, stature: i64) -> i64 { if stature <= 0 { return 0 } return v * MA_MM / stature } 208// the typed stations nx_myoset/nx_myotable ship, for the disagreement report 209func ma_typed_o(m: i64) -> i64 { 210 if m==0 {return 780} if m==1 {return 800} if m==2 {return 700} if m==3 {return 560} 211 if m==4 {return 745} if m==5 {return 500} if m==6 {return 430} 212 return 250 213} 214func ma_typed_i(m: i64) -> i64 { 215 if m==0 {return 700} if m==1 {return 690} if m==2 {return 560} if m==3 {return 700} 216 if m==4 {return 620} if m==5 {return 400} if m==6 {return 270} 217 return 120 218} 219func ma_name(m: i64) -> *u8 { 220 if m==0 {return "pectoralis_major" as *u8} 221 if m==1 {return "deltoid" as *u8} 222 if m==2 {return "latissimus_dorsi" as *u8} 223 if m==3 {return "rectus_abdominis" as *u8} 224 if m==4 {return "biceps_brachii" as *u8} 225 if m==5 {return "gluteus_maximus" as *u8} 226 if m==6 {return "quadriceps" as *u8} 227 if m==7 {return "gastrocnemius" as *u8} 228 if m==8 {return "trapezius" as *u8} 229 if m==9 {return "triceps_brachii" as *u8} 230 if m==10 {return "flexor_digitorum" as *u8} 231 if m==11 {return "sternocleidomastoid" as *u8} 232 if m==12 {return "erector_spinae" as *u8} 233 if m==13 {return "iliopsoas" as *u8} 234 if m==14 {return "adductor_magnus" as *u8} 235 if m==15 {return "gluteus_medius" as *u8} 236 if m==16 {return "hamstrings" as *u8} 237 if m==17 {return "sartorius" as *u8} 238 if m==18 {return "tibialis_anterior" as *u8} 239 if m==19 {return "soleus" as *u8} 240 return "teres_major" as *u8 241} 242 243func ma_report(JY: *i64, M: *i64, stature: i64) -> i64 { 244 gv_puts(" muscle derived_o typed_o d_o derived_i typed_i d_i\n" as *u8) 245 var worst: i64 = 0 246 var m: i64 = 0 247 // ⚠only the first MA_TYPED muscles have a typed counterpart to disagree with; the rest are NEW and 248 // comparing them against a value that does not exist would manufacture a disagreement. 249 // ★EVERY muscle is listed with its DERIVED stations; the "vs typed" columns appear only for those 250 // that have a counterpart in nx_myoset. A muscle with no prior value is marked NEW rather than 251 // compared against a number that does not exist. 252 while m < MA_NM { 253 let dov: i64 = ma_permil(ma_origin(JY,M,m), stature) 254 let div: i64 = ma_permil(ma_insert(JY,M,m), stature) 255 gv_puts(" " as *u8); gv_puts(ma_name(m)) 256 gv_puts(" o=" as *u8); gv_num(dov) 257 gv_puts(" i=" as *u8); gv_num(div) 258 if m < MA_TYPED { 259 let dd1: i64 = ma_iabs(dov - ma_typed_o(m)) 260 let dd2: i64 = ma_iabs(div - ma_typed_i(m)) 261 if dd1 > worst { worst = dd1 } 262 if dd2 > worst { worst = dd2 } 263 gv_puts(" typed " as *u8); gv_num(ma_typed_o(m)) 264 gv_puts("/" as *u8); gv_num(ma_typed_i(m)) 265 gv_puts(" (d " as *u8); gv_num(dd1); gv_puts("/" as *u8); gv_num(dd2); gv_puts(")" as *u8) 266 } else { 267 gv_puts(" NEW (no prior value to disagree with)" as *u8) 268 } 269 gv_puts("\n" as *u8) 270 m = m + 1 271 } 272 return worst 273} 274 275func main(argc: i64, argv: *i64) -> i64 { 276 if argc < 3 { 277 gv_puts("usage: nx_myoattach <report|selftest> <skel.dat>\n" as *u8) 278 return 2 279 } 280 let JY: *i64 = sys_mmap(MA_MAXJ*8) as *i64 281 let JP: *i64 = sys_mmap(MA_MAXJ*8) as *i64 282 var z: i64 = 0 283 while z < MA_MAXJ { JP[z] = 0-1; z = z + 1 } 284 let nj: i64 = ma_load(argv[2] as *u8, JY, JP) 285 let M: *i64 = sys_mmap(MA_NM*MA_S*8) as *i64 286 ma_table(M) 287 let ctr: *i64 = gv_ctr() 288 gv_head("nx_myoattach selftest -- attachments DERIVED from bone landmarks, never typed" as *u8) 289 // ★T0 refuse a skeleton that cannot supply the landmarks, rather than deriving from zeros 290 var t0: i64 = 0 291 if nj >= 14 { t0 = 1 } 292 gv_check("T0 the skeleton loaded with the joints this table references (>=14)" as *u8, t0, ctr) 293 if t0 == 0 { return gv_verdict("MYOATTACH" as *u8, ctr, "no skeleton" as *u8) } 294 let stature: i64 = JY[4] 295 296 // ★T1 ENDPOINTS ARE THE LANDMARKS THEMSELVES: t=0 is exactly joint a, t=1000 exactly joint b. 297 var t1: i64 = 1 298 if ma_point(JY, J_ACR, J_ELB, 0) != JY[J_ACR] { t1 = 0 } 299 if ma_point(JY, J_ACR, J_ELB, 1000) != JY[J_ELB] { t1 = 0 } 300 if ma_point(JY, J_KNEE, J_ANK, 0) != JY[J_KNEE] { t1 = 0 } 301 gv_check("T1 t=0 and t=1000 land EXACTLY on the two joints -- no coordinate is typed" as *u8, t1, ctr) 302 303 // ★T2 the midpoint is genuinely between them, so t interpolates rather than snapping 304 let mid: i64 = ma_point(JY, J_ACR, J_ELB, 500) 305 var t2: i64 = 0 306 if mid < JY[J_ACR] { if mid > JY[J_ELB] { t2 = 1 } } 307 gv_check("T2 t=500 lies strictly between the attachments (real interpolation)" as *u8, t2, ctr) 308 309 // ★★T3 SCALE-FREE, the property that makes this reusable for any subject: the per-mille station must 310 // be IDENTICAL on a skeleton of a different stature. Simulated by scaling every joint height. 311 let JY2: *i64 = sys_mmap(MA_MAXJ*8) as *i64 312 var k: i64 = 0 313 while k < MA_MAXJ { JY2[k] = JY[k] * MA_MAGIC_2100 / MA_MAGIC_1750; k = k + 1 } 314 let st2: i64 = JY2[4] 315 var t3: i64 = 1 316 var m: i64 = 0 317 while m < MA_NM { 318 let a: i64 = ma_permil(ma_origin(JY, M, m), stature) 319 let b: i64 = ma_permil(ma_origin(JY2, M, m), st2) 320 if ma_iabs(a-b) > 1 { t3 = 0 } 321 m = m + 1 322 } 323 gv_check("T3 SCALE-FREE: every derived station is the same per-mille at 1750mm and 2100mm" as *u8, t3, ctr) 324 325 // ★T4 every muscle still spans two DISTINCT heights -- a derived attachment pair that collapses 326 // would be an anatomy error introduced by the refactor 327 var t4: i64 = 1 328 m = 0 329 while m < MA_NM { 330 if ma_origin(JY,M,m) == ma_insert(JY,M,m) { t4 = 0 } 331 m = m + 1 332 } 333 gv_check("T4 every derived muscle spans two DISTINCT heights" as *u8, t4, ctr) 334 335 // ★★T5 ANTI-VACUITY: move a JOINT and the muscles attached to it MUST move. If they do not, the 336 // derivation is cosmetic and the attachments are still effectively typed. 337 let JY3: *i64 = sys_mmap(MA_MAXJ*8) as *i64 338 k = 0 339 while k < MA_MAXJ { JY3[k] = JY[k]; k = k + 1 } 340 JY3[J_ELB] = JY3[J_ELB] - 100 // shorten the upper arm 341 var moved: i64 = 0 342 var untouched: i64 = 0 343 m = 0 344 while m < MA_NM { 345 let a: i64 = ma_insert(JY, M, m) 346 let b: i64 = ma_insert(JY3, M, m) 347 if a != b { moved = moved + 1 } else { untouched = untouched + 1 } 348 m = m + 1 349 } 350 gv_puts(" perturb elbow: insertions moved=" as *u8); gv_num(moved) 351 gv_puts(" unmoved=" as *u8); gv_num(untouched); gv_puts("\n" as *u8) 352 var t5: i64 = 0 353 if moved > 0 { if untouched > 0 { t5 = 1 } } 354 gv_check("T5 ANTI-VACUITY: perturbing a joint moves ITS muscles and only those" as *u8, t5, ctr) 355 356 // ---- THE CROSS-ARTIFACT REPORT. Emitted as evidence; the teeth above are on the mechanism. 357 gv_puts("\n DERIVED vs TYPED (per-mille of stature) -- two independent statements per muscle:\n" as *u8) 358 let worst: i64 = ma_report(JY, M, stature) 359 gv_puts(" worst disagreement=" as *u8); gv_num(worst); gv_puts(" per-mille\n" as *u8) 360 // ★T6 the derivation must be in the same ballpark as the shipped data for MOST muscles -- if every 361 // muscle disagreed wildly, the attachment table would be the thing that is wrong, and this organ 362 // must not quietly replace good data with a worse derivation. 363 var agree: i64 = 0 364 m = 0 365 while m < MA_TYPED { 366 let dov: i64 = ma_permil(ma_origin(JY,M,m), stature) 367 if ma_iabs(dov - ma_typed_o(m)) <= 60 { agree = agree + 1 } 368 m = m + 1 369 } 370 gv_puts(" origins agreeing within 60 per-mille: " as *u8); gv_num(agree) 371 gv_puts(" of " as *u8); gv_num(MA_TYPED); gv_puts("\n" as *u8) 372 var t6: i64 = 0 373 if agree * 2 > MA_TYPED { t6 = 1 } 374 gv_check("T6 SANITY: the derivation agrees with the shipped data for a majority of muscles" as *u8, t6, ctr) 375 376 // ★★★T7 EVERY MUSCLE IS ANATOMICALLY VALID BY TOPOLOGY: it spans the joint it claims to move. 377 var t7: i64 = 1 378 var bad: i64 = 0 379 m = 0 380 while m < MA_NM { 381 if ma_valid(JP, M, m) == 0 { t7 = 0; bad = bad + 1 } 382 m = m + 1 383 } 384 gv_puts(" anatomically invalid muscles in the table: " as *u8); gv_num(bad); gv_puts("\n" as *u8) 385 gv_check("T7 EVERY muscle spans the joint it actuates (origin proximal, insertion distal)" as *u8, t7, ctr) 386 387 // ★★★T8 THE REFUTATION, and it is the whole reason the actuated-joint column exists: feed the 388 // checker the two defects this organ found BY EYEBALL and it must reject them mechanically. 389 let BAD: *i64 = sys_mmap(4*MA_S*8) as *i64 390 var b: i64 = 0 391 // (a) latissimus with origin and insertion SWAPPED, as the shipped typed data has them 392 BAD[b]=J_ACR; BAD[b+1]=J_ELB; BAD[b+2]=150; BAD[b+3]=J_L5; BAD[b+4]=J_HIP; BAD[b+5]=500; BAD[b+6]=80; BAD[b+7]=J_ACR; b=b+MA_S 393 // (b) gastrocnemius originating DISTAL to the knee it crosses -- on the shank, not the femur 394 BAD[b]=J_ANK; BAD[b+1]=J_KNEE; BAD[b+2]=200; BAD[b+3]=J_HEEL; BAD[b+4]=J_ANK; BAD[b+5]=0; BAD[b+6]=55; BAD[b+7]=J_KNEE; b=b+MA_S 395 // (c) a muscle attaching on ONE side of its joint only -- cannot actuate anything 396 BAD[b]=J_KNEE; BAD[b+1]=J_ANK; BAD[b+2]=100; BAD[b+3]=J_ANK; BAD[b+4]=J_HEEL; BAD[b+5]=500; BAD[b+6]=40; BAD[b+7]=J_KNEE; b=b+MA_S 397 var t8: i64 = 1 398 if ma_valid(JP, BAD, 0) != 0 { t8 = 0 } 399 if ma_valid(JP, BAD, 1) != 0 { t8 = 0 } 400 if ma_valid(JP, BAD, 2) != 0 { t8 = 0 } 401 gv_check("T8 REFUTATION: inverted, distally-originating and one-sided muscles are all REJECTED" as *u8, t8, ctr) 402 403 return gv_verdict("MYOATTACH" as *u8, ctr, 404 "attachments derived from emitted bone landmarks: scale-free, endpoint-exact, and anatomically valid by topology" as *u8) 405}