nx_theorems2_test.nx source
↩ module page · 77 lines · 3414 B
1// nx_theorems2_test.nx -- batch 2 smoke.
2
3import "syscalls.nx"
4import "nx_qed_freek.nx"
5
6func main() -> i64 {
7 // #13 Fermat's little -- 2^(7-1) = 64 mod 7 = 1.
8 if nx_th_fermat_little_check(2, 7) != 1 { return 13 }
9 if nx_th_fermat_little_check(3, 11) != 1 { return 14 }
10 // Composite check: 9 isn't prime; Fermat may still hold for some bases,
11 // but base 2: 2^8 = 256 mod 9 = 256 - 28*9 = 4 != 1.
12 if nx_th_fermat_little_check(2, 9) != 0 { return 15 }
13
14 // #14 Lagrange -- 6 divides 24, 7 does not.
15 if nx_th_lagrange_subgroup_divides(24, 6) != 1 { return 21 }
16 if nx_th_lagrange_subgroup_divides(24, 7) != 0 { return 22 }
17
18 // #15 Cantor power -- |P({})| = 1, |P({a,b,c})| = 8.
19 if nx_th_cantor_power_card(0) != 1 { return 31 }
20 if nx_th_cantor_power_card(3) != 8 { return 32 }
21 if nx_th_cantor_power_card(10) != 1024 { return 33 }
22
23 // #16 Euler totient -- phi(1)=1, phi(7)=6, phi(12)=4, phi(36)=12.
24 if nx_th_euler_phi(1) != 1 { return 41 }
25 if nx_th_euler_phi(7) != 6 { return 42 }
26 if nx_th_euler_phi(12) != 4 { return 43 }
27 if nx_th_euler_phi(36) != 12 { return 44 }
28
29 // #17 Wilson -- (5-1)! = 24, 24 mod 5 = 4 = -1 mod 5 -- prime.
30 if nx_th_wilson_check(5) != 1 { return 51 }
31 if nx_th_wilson_check(11) != 1 { return 52 }
32 if nx_th_wilson_check(9) != 0 { return 53 } // 9 composite
33
34 // #18 Triangle inequality.
35 if nx_th_triangle_ineq(3, 4) != 1 { return 61 }
36 if nx_th_triangle_ineq(-3, 5) != 1 { return 62 }
37 if nx_th_triangle_ineq(-3, -4) != 1 { return 63 }
38
39 // #19 AM-GM -- (2+8)/2 = 5, sqrt(2*8) = 4; 5 >= 4.
40 if nx_th_am_gm_check(2, 8) != 1 { return 71 }
41 if nx_th_am_gm_check(0, 0) != 1 { return 72 }
42 if nx_th_am_gm_check(5, 5) != 1 { return 73 } // equality case
43
44 // #20 Newton -- e1 = r1+r2 = 5, e2 = r1*r2 = 6, p2 = 5^2 - 12 = 13.
45 // (Verify: r1=2, r2=3 -> p2 = 4 + 9 = 13.)
46 if nx_th_newton_p2(5, 6) != 13 { return 81 }
47
48 // #21 Vieta -- roots 2, 3 -> b = -5, c = 6.
49 if nx_th_vieta_quadratic_b(2, 3) != -5 { return 91 }
50 if nx_th_vieta_quadratic_c(2, 3) != 6 { return 92 }
51
52 // #22 Heron -- 3,4,5 right triangle; area = 6; 16 * 36 = 576.
53 if nx_th_heron_area_sq_16(3, 4, 5) != 576 { return 101 }
54 // Equilateral side 6: area = 9*sqrt(3); 16 * area^2 = 16 * 243 = 3888.
55 if nx_th_heron_area_sq_16(6, 6, 6) != 3888 { return 102 }
56
57 // #23 Law of cosines -- right triangle a=3 b=4 c=5, cos C = 0
58 // (C is the angle opposite c, which is right).
59 if nx_th_law_of_cosines_check(3, 4, 5, 0) != 1 { return 111 }
60 // Equilateral 6,6,6: cos(60°) = 0.5 = 500000000 PPB.
61 // c^2 = a^2+b^2 - 2ab*0.5 = 36+36-36 = 36 = c^2. PASS.
62 if nx_th_law_of_cosines_check(6, 6, 6, 500000000) != 1 { return 112 }
63
64 // #24 Euler characteristic -- cube: V=8, E=12, F=6 -> 2.
65 if nx_th_euler_characteristic(8, 12, 6) != 2 { return 121 }
66 // Tetrahedron: V=4, E=6, F=4 -> 2.
67 if nx_th_euler_characteristic(4, 6, 4) != 2 { return 122 }
68 // Icosahedron: V=12, E=30, F=20 -> 2.
69 if nx_th_euler_characteristic(12, 30, 20) != 2 { return 123 }
70
71 // #25 IVT -- f(x) = x^3 - 2x - 5 changes sign on [1, 3].
72 // True root ~ 2.094. Integer search returns floor = 2.
73 let r: i64 = nx_th_ivt_binary_search(1, 3)
74 if r != 2 { return 131 }
75
76 return 0
77}