mutable struct Audit counts::Dict{String,Int} end Audit()=Audit(Dict{String,Int}()) function check!(audit::Audit, group::String, condition::Bool, detail::AbstractString="") condition || error("FAILED [$group] $detail") audit.counts[group]=get(audit.counts,group,0)+1 nothing end function rejects!(audit,group,f) rejected=false try f() catch e (e isa DomainError || e isa ArgumentError || e isa DimensionMismatch) || rethrow() rejected=true end check!(audit,group,rejected,"invalid input was accepted") end rattext(x::Rational)="$(numerator(x))/$(denominator(x))" function verify_inventory!(audit,root) ref=joinpath(root,"reference","Lean") count=0 for line in eachline(joinpath(ref,"SHA256SUMS")) isempty(strip(line)) && continue fields=split(line;limit=2) expected=fields[1]; path=strip(fields[2]) startswith(path,"*") && (path=path[2:end]) actual=bytes2hex(sha256(read(joinpath(ref,path)))) check!(audit,"source_inventory",actual==expected,path) count+=1 end entries=TOML.parsefile(joinpath(root,"THEOREMS.toml"))["theorem"] expected=Dict{String,String}() for file in sort(readdir(joinpath(ref,"Omega"))) endswith(file,".lean") || continue source=read(joinpath(ref,"Omega",file),String) prefix=file=="Ledger.lean" ? "Omega.Ledger." : "Omega." for m in eachmatch(r"(?ms)^theorem\s+([A-Za-z_][A-Za-z_0-9]*)(.*?)\s*:=",source) expected[prefix*m.captures[1]]=strip(first(split(m.match,":=";limit=2))) end end names=String[e["name"] for e in entries] check!(audit,"theorem_coverage",length(names)==147 && length(unique(names))==147,"147 unique mappings") check!(audit,"theorem_coverage",Set(names)==Set(keys(expected)),"source theorem-name equality") for e in entries check!(audit,"theorem_coverage",e["statement"]==expected[e["name"]],e["name"]*" declaration text") check!(audit,"theorem_coverage",haskey(PROOFS,e["chapter"]),e["name"]*" proof chapter") check!(audit,"theorem_coverage",!isempty(e["proof_step"]),e["name"]*" proof step") end (source_hash_entries=count,theorems=length(names)) end function verify_constants!(audit,outdir) cs=constants_enclosure(;digits=100) den=big(10)^20 pl=rational(big"161803398874989484820",den) pu=rational(big"161803398874989484821",den) pil=rational(big"314159265358979323846",den) piu=rational(big"314159265358979323847",den) check!(audit,"rational_enclosures",pl^2-pl-1<0DOMAIN_SIZE-1,"forbidden-boundary bound") check!(audit,"exact_interval",F(12343)==4196 && F(20706)==7038,"necessity witnesses") check!(audit,"modular_inverse",gcd(Q,S)==2,"gcd") check!(audit,"modular_inverse",div(Q,2)*MODULAR_INVERSE==1+big(95668581631527)*PERIOD,"integer inverse identity") check!(audit,"modular_inverse",length(unique(remainders))==DOMAIN_SIZE,"distinct first remainders") ts=extinction_thresholds(10) check!(audit,"extinction",ts==BigInt[1,3,9,27,80,236,695,2045,6016,17697,52058],"threshold recurrence") depths=zeros(Int,DOMAIN_SIZE); transitions=0;positive=0;zero=0 open(joinpath(outdir,"state_certificate.csv"),"w") do io println(io,"seed,successor,remainder,gap,extinction_depth,recovered_23_step_seed") for d in 0:DOMAIN_SIZE-1 f=successors[d+1];r=remainders[d+1] check!(audit,"finite_floor",Q*d==S*f+r && 0<=r=big(34535026732) && S*(lam.hi-q)*d0,"positive real correction") rec=encode(Q,S,23,d) restored=recover(Q,S,rec.terminal,rec.remainders) check!(audit,"canonical_ledger",restored==d && rec.terminal==0 && length(rec.remainders)==23,"23-step roundtrip") check!(audit,"canonical_ledger",admissible(Q,S,rec.terminal,rec.remainders),"generated record admissibility") check!(audit,"canonical_ledger",Q^23*d==S^23*rec.terminal+ledger_value(Q,S,rec.remainders),"ordered polynomial identity") # Reconstruct every retained state backwards, and compare with the # actual forward record. This checks the complete state trajectory. back=Vector{BigInt}(undef,24);back[24]=rec.terminal for j in 23:-1:1 numerator=S*back[j+1]+rec.remainders[j] check!(audit,"canonical_trajectory",mod(numerator,Q)==0,"reverse divisibility") back[j]=div(numerator,Q) end x=big(d);depth=0 for j in 1:23 transitions+=1 x>0 ? (positive+=1;depth+=1) : (zero+=1) check!(audit,"canonical_trajectory",x==back[j] && rho(x)==rec.remainders[j],"state/remainder equality") x=F(x) end check!(audit,"canonical_trajectory",x==back[24]==0,"terminal equality") depths[d+1]=depth for n in 0:10 # Once extinct, every further iterate is zero. The complete # recorded trajectory makes this an exact state comparison. check!(audit,"extinction",(back[n+1]==0)==(d=gap,"block $b") println(io,"$b,$(first(inds)-1),$(last(inds)-1),$(g[j]),$(first(inds)+j-2)") end end check!(audit,"census",transitions==753664 && positive==300871 && zero==452793,"transition totals") check!(audit,"census",maximum(depths)==10 && sum(depths)==300871,"extinction totals") check!(audit,"census",findall(==(10),depths).-1==collect(17697:32767),"deepest seeds") check!(audit,"census",length(unique(successors))==11140,"distinct successors") (states=DOMAIN_SIZE,transitions=transitions,positive_transitions=positive,zero_transitions=zero, maximum_depth=maximum(depths),sum_depths=sum(depths),minimum_gap=string(gap), mean_depth="300871/32768",gap_blocks=128) end function verify_precision!(audit,lam,outdir) mismatch=Int[];lastq=rational(-1) open(joinpath(outdir,"precision_sweep.csv"),"w") do io println(io,"decimal_places,numerator,denominator,mismatching_states") for p in 0:18 qp=certified_truncation(p) check!(audit,"precision",lastq<=qp<=lam.hi && qpfloor_rat(qp*d)!=F(d),0:DOMAIN_SIZE-1) check!(audit,"precision",(m==0)==(p>=8),"finite sweep precision $p") p==6 && check!(audit,"precision",m==414,"six-place count") p==7 && check!(audit,"precision",m==39 && qp==3399497//big(10)^7 && qp0 hv=admissible(A,B,rec.terminal,rec.remainders) A!=0 && check!(audit,"generic_ledger",hv,"generated admissibility") if hv restored=recover(A,B,rec.terminal,rec.remainders) check!(audit,"generic_ledger",encode(A,B,n,restored)==rec,"admissible recovery including A=0") check!(audit,"generic_ledger",big(A)^n*restored==big(B)^n*rec.terminal+ledger_value(A,B,rec.remainders),"weighted identity") end end end end # Independently enumerate image records on a provably sufficient seed range. # For |t|<=3, every valid reverse step has |d| <= (B|t|+B-1)/|A|. # Recursing this bound includes every possible admissible preimage below. candidate_count=0;valid_count=0 for A in [-3,-2,-1,1,2,3],B in 1:4,n in 0:3 bound=big(3) for _ in 1:n;bound=cld(B*bound+B-1,abs(A));end images=Dict{Tuple{BigInt,Tuple},Int}() for d in -bound:bound rec=encode(A,B,n,d);key=(rec.terminal,Tuple(rec.remainders)) images[key]=get(images,key,0)+1 end for t in -3:3, tup in Iterators.product(ntuple(_->(-1:B),n)...) candidate_count+=1;rs=BigInt[tup...] hv=admissible(A,B,t,rs) multiplicity=get(images,(big(t),Tuple(rs)),0) check!(audit,"admissible_candidates",hv==(multiplicity==1),"admissibility iff unique bounded preimage") check!(audit,"admissible_candidates",multiplicity<=1,"unique encoding") if hv valid_count+=1;x=decode_checked(A,B,t,rs) check!(audit,"admissible_candidates",encode(A,B,n,x)==(terminal=big(t),remainders=rs),"candidate re-encoding") end end end # B>0 alone is enough for the source's admissible_roundtrip, including A=0. for B in 1:4,t in -3:3,n in 0:3,tup in Iterators.product(ntuple(_->(-1:B),n)...) rs=BigInt[tup...] if admissible(0,B,t,rs) check!(audit,"zero_multiplier_admissibility",encode(0,B,n,recover(0,B,t,rs))==(terminal=big(t),remainders=rs),"A=0 weaker hypothesis") end end for A in -5:5,B in 1:5,d in -15:15,e in -8:8 check!(audit,"predecessor_inequalities",(ledger_step(A,B,d)==e)==(B*e<=A*ddecode_checked(0,3,0,BigInt[])) rejects!(audit,"input_validation",()->decode_checked(2,0,0,BigInt[])) rejects!(audit,"input_validation",()->decode_checked(2,3,0,BigInt[1])) rejects!(audit,"input_validation",()->seed_from_remainder(1)) rejects!(audit,"input_validation",()->F(-1)) # Exact probes beyond D exercise the full-period formula, without being # mislabeled as exhaustive enumeration of 500 trillion seeds. probes=BigInt[0,1,32767,32768,PERIOD-2,PERIOD-1] for d in probes check!(audit,"full_period_probes",seed_from_remainder(rho(d))==d,"full-period endpoint probe") check!(audit,"full_period_probes",rho(d+PERIOD)==rho(d),"periodicity") end (generated_cases=cases,candidate_records=candidate_count,admissible_candidates=valid_count,full_period_probes=length(probes)) end function verify_realization!(audit) scalars=0;grids=0;placements=0 for h in [rational(-3,2),rational(0),rational(1,8),rational(7,3)],y in [rational(i,7) for i in -21:21] er=scalar_encode_total(h,y);scalars+=1 check!(audit,"scalar_coordinates",scalar_decode(h,er.integer,er.residual)==y,"total scalar roundtrip") if h>0 check!(audit,"scalar_coordinates",0<=er.residual=0 ? rational(big(2)^k) : rational(1,big(2)^(-k)) for d in [0,1,2,26,12343,17697,20706,32767] y=h*d for n in 0:23 grids+=1 check!(audit,"grid_realization",y==h*iterate_state(d,n),"retained grid scale and depth") check!(audit,"grid_realization",certified_lambda_grid_step(h,y)==rational_grid_step(h,y),"certified grid interface") y=certified_lambda_grid_step(h,y) end end end frames=[ExactPlacement([0,0],[1 0;0 1]), ExactPlacement([2,-3,5],[3//5 0;4//5 0;0 1]), ExactPlacement([1,2,3,4],[0 0;1 0;0 -1;0 0])] c=variable(:c);levels=symbolic_heights() for p in frames,a in [rational(1,32768),rational(3,2),rational(32768)] marks=placed_marks(a,p);placements+=1 for i in 1:6,j in 1:6 dotp=sum((marks[i][k]-p.center[k])*(marks[j][k]-p.center[k]) for k in eachindex(p.center)) dist2=sum((marks[i][k]-marks[j][k])^2 for k in eachindex(p.center)) check!(audit,"placement_polynomials",dotp==a^2*(c^2+levels[i]*levels[j]),"placed dot product") check!(audit,"placement_polynomials",dist2==a^2*(levels[i]-levels[j])^2,"placed distance squared") end for d in [0,26,32767] rec=encode(Q,S,23,d) check!(audit,"outline_reconstruction",reconstruct_outline(a,p,rec.terminal,rec.remainders)==outline_spec(a*d,p),"retained center/frame/radius") end end rejects!(audit,"input_validation",()->ExactPlacement([0,0],[1 1;0 1])) rejects!(audit,"input_validation",()->scalar_encode(0,1)) rejects!(audit,"input_validation",()->certified_lambda_grid_step(1,1//2)) rejects!(audit,"input_validation",()->certified_lambda_grid_step(1,32768)) (scalar_examples=scalars,grid_states_at_scales=grids,placements=placements) end function verify_numerical_examples!(audit) # These are expressly illustrations, never premises of any exact certificate. count=0 setprecision(BigFloat,256) do tol=BigFloat(2)^(-180) for k in -15:15 a=k>=0 ? rational(big(2)^k) : rational(1,big(2)^(-k)) g=numerical_geometry(a);av=BigFloat(a);count+=1 check!(audit,"numerical_illustration",abs(g.G/(av*g.phi)-1)"all configured checks completed", "julia_version"=>string(VERSION),"kernel"=>string(Sys.KERNEL),"architecture"=>string(Sys.ARCH), "machine"=>Sys.MACHINE,"word_size"=>Sys.WORD_SIZE,"threads"=>Threads.nthreads(), "proof_boundary"=>"Julia exact/symbolic/finite certificates plus analytic proof text; not a Lean kernel proof", "source_inventory"=>Dict(string(k)=>v for (k,v) in pairs(inventory)), "census"=>Dict(string(k)=>v for (k,v) in pairs(census)), "generic_ledgers"=>Dict(string(k)=>v for (k,v) in pairs(ledger)), "realization"=>Dict(string(k)=>v for (k,v) in pairs(realization)), "polynomial_certificates"=>polys,"precision_mismatch_counts_p0_to_p18"=>precision, "checks_by_evidence_group"=>audit.counts,"numerical_example_count"=>numerical) open(joinpath(output_dir,"results.toml"),"w") do io; TOML.print(io,result;sorted=true);end println("Completed checks by group:") for group in sort(collect(keys(audit.counts)));println(" ",group,": ",audit.counts[group]);end println("No Julia check failed. Universal analytic inferences are documented, not kernel-checked by Julia.") result end