"""Independent arithmetic checks for selected worked examples. Not an Android or scientific benchmark.""" from math import sqrt,log10,isclose,ceil from statistics import mean, NormalDist,median from pathlib import Path import json checks=[] def test(id,actual,expected,tol=1e-6): ok=isclose(actual,expected,rel_tol=tol,abs_tol=tol) checks.append({'id':id,'computed':actual,'expected':expected,'tolerance':tol,'passed':ok}) assert ok,(id,actual,expected) test('INV-001 reducción 250 kB',1-250000/3000000,.9167,1e-4) test('INV-001 reducción 400 kB',1-400000/3000000,.8667,1e-4) test('INV-001 PSNR',10*log10(255**2/25),34.15,.001) test('INV-002 IoU',90/(100+110-90),.75) test('INV-002 Dice',180/210,.8571,.0001) test('INV-003 PSNR 64',10*log10(255**2/64),30.07,.001) test('INV-003 PSNR 36',10*log10(255**2/36),32.57,.001) test('INV-004 RMSE',sqrt(200/3),8.16,.001) test('INV-005 exactitud',180/200,.9) test('INV-007 latencia',220+300,520) test('INV-009 interpolación',40+.25*(100-40),55) test('INV-010 F1',2*.75*.8/(.75+.8),.774,.001) test('INV-011 linealización',((.5+.055)/1.055)**2.4,.214,.001) test('INV-012 SSE',sum((v-c)**2 for v,c in [(10,11),(12,11),(80,81),(82,81)]),4) test('INV-014 ΔE76',sqrt(3**2+4**2),5) test('INV-016 sRGB',1.055*.5**(1/2.4)-.055,.735,.001) test('INV-018 contraste',(.8+.05)/(.1+.05),5.67,.001) x=2; x=(x+2/x)/2;test('INV-019 Newton 1',x,1.5);x=(x+2/x)/2;test('INV-019 Newton 2',x,1.4166667);test('INV-019 error',abs(x-sqrt(2)),.002453,.000001) test('INV-020 pérdida de precisión',(1e16+1)-1e16,0) test('INV-021 interpolación',1+2*1.5,4) test('INV-022 trapecio',(0**2+1**2)/2,.5);test('INV-022 Simpson',(0+4*.5**2+1)/6,1/3) test('INV-023 diferencia adelantada',(3.1**2-3**2)/.1,6.1);test('INV-023 diferencia central',(3.1**2-2.9**2)/.2,6) test('INV-024 SSE',sum((y-(5/6+1.5*x))**2 for x,y in [(0,1),(1,2),(2,4)]),1/6) test('INV-025 residuo 1',2*2+1-5,0);test('INV-025 residuo 2',2-1-1,0) x=4*.2*(1-.2);test('INV-026 iteración 1',x,.64);test('INV-026 iteración 2',4*x*(1-x),.9216) test('INV-030 aceleración',12/8,1.5) test('INV-031 bytes',44100*16*2*60/8,10584000) test('INV-033 bin',440/(8000/800),44) test('INV-035 ganancia',10**(6/20),1.995,.001) test('INV-036 Wh',.8*.5,.4) test('INV-037 THD',.01/1,.01) test('INV-039 SNR',10*log10(80/1),19.03,.001) test('INV-040 plazo ms',480/48000*1000,10) test('INV-041 MB',60*4/8,30) test('INV-042 tiempo',50/25,2) test('INV-044 distancia',abs(.8-.2)+abs(.2-.8),1.2) test('INV-045 PSNR',10*log10(255**2/16),36.09,.001) test('INV-046 bytes RGB',3840*2160*3,24883200) test('INV-049 rendimiento',1/.002,500) test('INV-055 sobrecoste',(3-2)/2,.5) test('INV-059 goodput',100*8/10,80) test('INV-060 goodput',200*8/25,64) test('INV-061 latencia',185-100,85) test('INV-062 buffer',2*5/8,1.25) test('INV-063 bloques',10*1024/64,160) test('INV-066 J/MB',2*20/100,.4) test('INV-067 masa molar',2*1.008+15.999,18.015) test('INV-072 promedio ponderado',10*.2+11*.8,10.8) test('INV-075 media móvil',mean([10,12,14]),12) test('INV-076 EOQ',sqrt(2*1200*10/2),109.54,.001) test('INV-079 precisión',8/20,.4);test('INV-079 sensibilidad',8/10,.8) test('INV-080 éxito',499/500,.998) test('INV-083 duración',25+5+25,55) test('INV-086 recuperación',3/4,.75) test('INV-087 reducción',(40-25)/40,.375) test('INV-089 IMC',70/1.75**2,22.86,.001) test('INV-090 media',mean([27,29,31]),29) test('INV-099 frame 60 Hz',1000/60,16.67,.001) test('INV-100 error de escala',abs(90-100)/100,.1) test('INV-105 coste de ruta',4+3,7) test('INV-107 distancia acumulada',2.4+1.6,4) p=.2;n=100;z=NormalDist().inv_cdf(.975);den=1+z*z/n;mid=(p+z*z/(2*n))/den;rad=z*sqrt(p*(1-p)/n+z*z/(4*n*n))/den test('Wilson límite inferior',mid-rad,.1334,.0001);test('Wilson límite superior',mid+rad,.2888,.0001) p1=.1;p2=.12;p=(p1+p2)/2 size=(z*sqrt(2*p*(1-p))+NormalDist().inv_cdf(.8)*sqrt(p1*(1-p1)+p2*(1-p2)))**2/(p2-p1)**2 test('Planificador A/B',ceil(size),3841) test('Kappa',(0.8-0.5)/(1-0.5),.6) test('Tasa combinada',50/300,.1667,.0001) root=Path(__file__).resolve().parents[1] output=root/'resultados'/'verificacion-ejemplos.json' output.write_text(json.dumps({'scope':'Comprobación de operaciones aritméticas de ejemplos didácticos; no resultados científicos nuevos ni validación de aplicaciones.','total':len(checks),'checks':checks},ensure_ascii=False,indent=2)+'\n',encoding='utf-8') print(f'{len(checks)} comprobaciones aritméticas correctas. {output.name}')