function out=run_upper_certificate() % UC-1.0.0: original functions/domains, outward binary64 interval certificate. here=fileparts(mfilename('fullpath')); root=fileparts(fileparts(fileparts(fileparts(fileparts(here))))); model=fullfile(root,'reports','04_models','R23-001'); base=fullfile(root,'reports','05_simulation','R23-001','runs','SIM-R3-001-he-v2'); dest=fullfile(root,'reports','05_simulation','R23-001','upper-certificate-supplement'); pub=fullfile(root,'reports','06_reports','03_endurance_simulation','SIM-R3-001'); assert(strcmp(version('-release'),'2025a')); if ~isfolder(dest),mkdir(dest);end addpath(fullfile(model,'matlab')); diary(fullfile(dest,'matlab-certificate.log')); started=char(datetime('now','TimeZone','UTC'));wholeTimer=tic; fitFile=fullfile(base,'catalog-fits.json');fit=jsondecode(fileread(fitFile)); oldFile=fullfile(pub,'upper-bound-summary.json');old=jsondecode(fileread(oldFile)); p=r23.parameters(); original=jsondecode(fileread(fullfile(base,'run-receipt-all-completed.json'))); verify_original(); cfg=struct('absolute_gap_h',.001,'scenario_time_budget_s',180,'max_nodes_per_scenario',300000, ... 'batch_size',512,'exp_positive_Taylor_degree',28,'sqrt_expansion_limit',64, ... 'seed_mass_offsets_kg',[0 -1e-8 -1e-6],'rounding','one adjacent binary64 endpoint after each basic arithmetic operation', ... 'sqrt_rule','native approximation expanded until outward-rounded square inequalities certify enclosure', ... 'exp_rule','exp(-z)=1/exp(z); positive Taylor sum and geometric tail bound, all evaluated outward', ... 'evidence_export','17 significant digits CSV with binary64 roundtrip check plus full exact MAT certificate', ... 'sqrt_scope','fail closed if endpoint square inequalities cannot be certified within expansion limit; extreme subnormals not promised', ... 'coefficient_interpretation','frozen JSON-decoded binary64 values; physical uncertainty is outside this deterministic model certificate'); for k=1:numel(fit.fc) f=fit.fc(k);assert(strcmp(f.curve_type,'exponential_specific_power')&&f.envelope_a>f.envelope_b&&f.envelope_b>0&&f.c>0); end for k=1:numel(fit.tank),assert(fit.tank(k).envelope_b>0&&all(fit.tank(k).domain>0));end q=ivSub(iv(1),iv(p.nonenergy_fraction));C=ivAdd(iv(p.payload),iv(p.buffer_mass)); K=ivDiv(ivMul(ivMul(iv(p.hydrogen_usable),iv(p.LHV)),iv(p.eta_fc)),iv(3600)); Ds=[p.diameter_22,p.diameter_28,p.diameter_30]; G=struct([]); for k=1:3 area=ivMul(ivMul(iv(p.rotor_count),[nextDown(pi),nextUp(pi)]),ivSquare(ivDiv(iv(Ds(k)),iv(2)))); profile=ivDiv(ivMul(ivMul(ivMul(ivMul(iv(p.cd_profile),iv(p.solidity)),iv(p.rho)),area),ivCube(iv(p.tip_speed))),iv(8)); z=struct('diameter_m',Ds(k),'area',area,'profile',profile,'eta',ivMul(iv(p.eta_motor),iv(p.eta_esc)), ... 'parasite',ivMul(ivMul(iv(.5),iv(p.rho)),iv(p.flat_plate))); if isempty(G),G=z;else,G(end+1)=z;end end maxFC=-Inf; for k=1:numel(fit.fc),a=fcPoint(fit.fc(k).domain(2),fit.fc(k));maxFC=max(maxFC,a(2));end maxTank=-Inf; for k=1:numel(fit.tank) t=fit.tank(k);hx=ivAdd(iv(t.envelope_a),ivMul(iv(t.envelope_b),iv(t.domain(2)))); total=ivAdd(iv(t.domain(2)),hx);maxTank=max(maxTank,total(2)); end mlo=ivDiv(C,q);mhi=ivDiv(ivAdd(ivAdd(C,iv(maxFC)),iv(maxTank)),q); massDomain=[mlo(1),mhi(2)]; B=zeros(3*numel(fit.fc)*numel(fit.tank),3);n=0; for di=1:3,for fi=1:numel(fit.fc),for ti=1:numel(fit.tank),n=n+1;B(n,:)=[di fi ti];end,end,end checks=struct('actual_power_points_checked',0,'actual_FC_points_checked',0,'actual_closure_points_checked',0, ... 'max_actual_power_enclosure_width_W',0,'basic_interval_selftests_pass',false,'original_scientific_files_unchanged',true); self_tests();checks.basic_interval_selftests_pass=true; out=struct('task_id','SIM-R3-001-UPPER-CERTIFICATE','supplement_version','UC-1.0.0', ... 'model_version','R23-HE2.0.0','catalogue_fit_SHA256',r23.sha256_file(fitFile), ... 'scope','all original 3 geometries x fitted FC families x tank families, original speed/power/empty-tank domains and mass closure', ... 'certificate_level','outward binary64 interval computation under IEEE-754 basic arithmetic; validated sqrt endpoints and Taylor remainder; not an external formal proof-assistant verification', ... 'human_wide_engineering_limit_proved',false,'settings',cfg,'mass_domain_kg',massDomain, ... 'mass_domain_derivation','M>=C/q, M<=(C+max_f mFC(Pmax)+max_t[xmax+A+B*xmax])/q; directed outward bounds', ... 'branch_count',size(B,1),'fixed',struct,'joint',struct); out.fixed=solve_case('fixed5',p.fixed_speed,old.fixed_speed_optimum); out.joint=solve_case('joint',[0,p.speed_max],old.joint_mass_speed_optimum); out.envelope_shape=shape_quantification(); out.checks=checks; out.total_elapsed_s=toc(wholeTimer); out.all_absolute_gaps_met=out.fixed.absolute_gap_h<=cfg.absolute_gap_h&&out.joint.absolute_gap_h<=cfg.absolute_gap_h; out.interpretation='Every original-domain feasible design, including any heavier design, has T<=reported global upper. Remaining mass/speed boxes contain possible maximizers; no claim of pointwise decreasing tail or unrestricted human-technology ceiling.'; r23.write_json(fullfile(dest,'summary.json'),out); r23.write_json(fullfile(dest,'settings.json'),cfg); write_parameters(); verify_original(); fprintf('UPPER_CERTIFICATE_COMPLETED gaps_met=%d fixed=[%.12g,%.12g] joint=[%.12g,%.12g]\n', ... out.all_absolute_gaps_met,out.fixed.feasible_lower_h,out.fixed.global_upper_h,out.joint.feasible_lower_h,out.joint.global_upper_h); diary('off'); source=dir(fullfile(here,'*.m'));sourceFiles=arrayfun(@(s)fullfile(s.folder,s.name),source,'UniformOutput',false); deps={fullfile(model,'matlab','+r23','power.m'),fullfile(model,'matlab','+r23','fc_mass.m'), ... fullfile(model,'matlab','+r23','parameters.m'),fullfile(model,'matlab','+r23','write_json.m'),fullfile(model,'matlab','+r23','sha256_file.m')}; inputs={fitFile,oldFile,fullfile(model,'parameters.csv'),fullfile(pub,'report-data.json'), ... fullfile(root,'reports','08_collaboration','amendments','R23-001-upper-certificate.md'), ... fullfile(root,'reports','09_reviews','R23-001-upper-certificate','mathematical-audit.md')}; files=dir(fullfile(dest,'*'));outputs={}; for k=1:numel(files),if ~files(k).isdir&&~ismember(files(k).name,{'run-receipt.json','native-launch.log'}),outputs{end+1}=fullfile(dest,files(k).name);end,end %#ok receipt=struct('task_id',out.task_id,'status','completed','all_absolute_gaps_met',out.all_absolute_gaps_met, ... 'matlab_release',version('-release'),'matlab_version',version,'computer',computer,'started_utc',started, ... 'completed_utc',char(datetime('now','TimeZone','UTC')),'randomness','none, deterministic subdivision and candidate points', ... 'script_entry','reports/04_models/R23-001/supplements/upper-certificate/run_upper_certificate.m', ... 'original_all_fit_mission_EOS_rerun',false,'original_scientific_source_and_inputs_unchanged',true, ... 'source_files',hash_files([sourceFiles(:);deps(:)]),'input_files',hash_files(inputs),'output_files',hash_files(outputs)); r23.write_json(fullfile(dest,'run-receipt.json'),receipt); function answer=solve_case(name,vDomain,seed) timer=tic;tree=zeros(cfg.max_nodes_per_scenario,17);count=size(B,1); tree(1:count,1)=(1:count)';tree(1:count,3)=(1:count)'; tree(1:count,4)=massDomain(1);tree(1:count,5)=massDomain(2); tree(1:count,6)=vDomain(1);tree(1:count,7)=vDomain(end); [ub,status,details]=box_bounds(tree(1:count,4:7),tree(1:count,3)); tree(1:count,8)=ub;tree(1:count,9)=status;tree(1:count,14:17)=details; lower=-Inf;best=struct;seedInputs=zeros(0,3); for bi=1:size(B,1),for delta=cfg.seed_mass_offsets_kg,seedInputs(end+1,:)=[seed.M_kg+delta,seed.speed_m_s,bi];end,end %#ok assert(all(seedInputs(:,1)>=massDomain(1)&seedInputs(:,1)<=massDomain(2)&seedInputs(:,2)>=vDomain(1)&seedInputs(:,2)<=vDomain(end)), ... 'Incumbent seed outside this scenario mass/speed domain.'); [lower,best]=candidate_lower(seedInputs(:,1),seedInputs(:,2),seedInputs(:,3),lower,best); assert(isfinite(lower),'No rigorously feasible seed.'); active=find(tree(1:count,9)==0);prune(); history=zeros(0,5);reason='gap_reached';iterations=0; while ~isempty(active) globalU=max(tree(active,8));gap=nextUp(globalU-lower); history(end+1,:)=[count,lower,globalU,gap,toc(timer)]; %#ok if gap<=cfg.absolute_gap_h,break;end if toc(timer)>=cfg.scenario_time_budget_s,reason='time_budget';break;end capacity=floor((cfg.max_nodes_per_scenario-count)/2); if capacity<1,reason='node_budget';break;end [~,order]=sort(tree(active,8),'descend');take=min([cfg.batch_size,numel(active),capacity]); selected=active(order(1:take));active(order(1:take))=[]; boxes=tree(selected,4:7);splitM=(boxes(:,2)-boxes(:,1))/(massDomain(2)-massDomain(1)) >= (boxes(:,4)-boxes(:,3))/max(p.speed_max,1); if numel(vDomain)==1,splitM(:)=true;end ml=boxes(:,1)+(boxes(:,2)-boxes(:,1))/2;vl=boxes(:,3)+(boxes(:,4)-boxes(:,3))/2; assert(all((splitM&ml>boxes(:,1)&mlboxes(:,3)&vlph)=2; valid=ix&status==0;if ~any(valid),continue;end flo=fcPoint(pl(valid),fc);fhi=fcPoint(ph(valid),fc);mf=[flo(:,1),fhi(:,2)]; rows=find(valid); for ti=1:numel(fit.tank) local=B(bids(rows),3)==ti;if ~any(local),continue;end jj=rows(local);tf=fit.tank(ti); mass=[boxes(jj,1),boxes(jj,2)]; x=ivDiv(ivSub(ivSub(ivSub(ivMul(q,mass),C),mf(local,:)),iv(tf.envelope_a)),ivAdd(iv(1),iv(tf.envelope_b))); xl(jj)=max(x(:,1),tf.domain(1));xh(jj)=min(x(:,2),tf.domain(2));bad=xl(jj)>xh(jj);status(jj(bad))=3; good=jj(~bad);if isempty(good),continue;end H=ivAdd(iv(tf.envelope_a),ivMul(iv(tf.envelope_b),iv(xh(good)))); noH=H(:,2)<=0;status(good(noH))=4;yes=good(~noH); if ~isempty(yes),T=ivDiv(ivMul(K,[zeros(numel(yes),1),H(~noH,2)]),iv(pl(yes)));ub(yes)=T(:,2);end end end assert(all(isfinite(ub(status==0))));detail=[pl,ph,xl,xh]; end function [lower,best]=candidate_lower(M,V,bids,lower,best) N=numel(M);P=nan(N,2);nativeP=nan(N,1); for di=1:3 ix=B(bids,1)==di;if ~any(ix),continue;end [a,b,z]=components(M(ix),V(ix),di);P(ix,:)=ivAdd(ivDiv(ivAdd(ivAdd(a,b),z),G(di).eta),iv(p.aux_power)); nativeP(ix)=r23.power(M(ix),V(ix),Ds(di),p); end assert(all(nativeP>=P(:,1)&nativeP<=P(:,2)),'Actual power function outside interval implementation.'); checks.actual_power_points_checked=checks.actual_power_points_checked+N; checks.max_actual_power_enclosure_width_W=max(checks.max_actual_power_enclosure_width_W,max(P(:,2)-P(:,1))); for fi=1:numel(fit.fc) fc=fit.fc(fi);valid=B(bids,2)==fi&P(:,1)>=fc.domain(1)&P(:,2)<=fc.domain(2); if ~any(valid),continue;end rows=find(valid);lo=fcPoint(P(valid,1),fc);hi=fcPoint(P(valid,2),fc);mf=[lo(:,1),hi(:,2)]; nativeMF=r23.fc_mass(fc,nativeP(valid));assert(all(nativeMF>=mf(:,1)&nativeMF<=mf(:,2)),'Actual FC function outside interval bounds'); checks.actual_FC_points_checked=checks.actual_FC_points_checked+numel(rows); for ti=1:numel(fit.tank) local=B(bids(rows),3)==ti;if ~any(local),continue;end jj=rows(local);tf=fit.tank(ti); x=ivDiv(ivSub(ivSub(ivSub(ivMul(q,iv(M(jj))),C),mf(local,:)),iv(tf.envelope_a)),ivAdd(iv(1),iv(tf.envelope_b))); H=ivAdd(iv(tf.envelope_a),ivMul(iv(tf.envelope_b),x)); ok=x(:,1)>=tf.domain(1)&x(:,2)<=tf.domain(2)&H(:,1)>0; TT=ivDiv(ivMul(K,H),P(jj,:)); validRows=find(ok);if isempty(validRows),continue;end nativeX=((1-p.nonenergy_fraction)*M(jj)-p.payload-p.buffer_mass-nativeMF(local)-tf.envelope_a)/(1+tf.envelope_b); assert(all(nativeX>=x(:,1)&nativeX<=x(:,2)),'Actual mass closure outside interval implementation'); checks.actual_closure_points_checked=checks.actual_closure_points_checked+numel(jj); [value,ii]=max(TT(validRows,1));j=validRows(ii); if value>lower globalj=jj(j);nativeH=tf.envelope_a+tf.envelope_b*nativeX(j); lower=value;best=struct('M_kg',M(globalj),'speed_m_s',V(globalj),'diameter_m',Ds(B(bids(globalj),1)), ... 'FC_family',fc.family,'tank_family',tf.family,'endurance_interval_h',TT(j,:), ... 'actual_function_nominal_h',nativeH*p.hydrogen_usable*p.LHV*p.eta_fc/nativeP(globalj)/3600, ... 'P_interval_W',P(globalj,:),'empty_tank_interval_kg',x(j,:),'H2_interval_kg',H(j,:), ... 'seed_or_subdivision_point_only',true); end end end end function [ind,profile,parasite]=components(M,V,di) W=ivMul(iv(M),iv(p.g));vv=iv(V); v0=ivSqrt(ivDiv(W,ivMul(ivMul(iv(2),iv(p.rho)),G(di).area))); inner=ivDiv(ivSquare(ivSquare(vv)),ivMul(iv(4),ivSquare(ivSquare(v0)))); factor=ivSqrt(ivSub(ivSqrt(ivAdd(iv(1),inner)),ivDiv(ivSquare(vv),ivMul(iv(2),ivSquare(v0))))); ind=ivMul(ivMul(ivMul(iv(p.k_induced),W),v0),factor); profile=ivMul(G(di).profile,ivAdd(iv(1),ivMul(iv(3),ivSquare(ivDiv(vv,iv(p.tip_speed)))))); parasite=ivMul(G(di).parasite,ivCube(vv)); end function mass=fcPoint(P,fc) z=ivDiv(iv(P),iv(fc.c));E=ivExpNeg(z,cfg.exp_positive_Taylor_degree); mass=ivDiv(iv(P),ivSub(iv(fc.envelope_a),ivMul(iv(fc.envelope_b),E))); end function ok=check_tree(T,L) assert(all(T(:,1)==(1:size(T,1))'));assert(sum(T(:,2)==0)==size(B,1)); split=find(T(:,9)==1); for jj=split' a=T(T(jj,10),:);b=T(T(jj,11),:);assert(a(2)==jj&&b(2)==jj&&a(3)==T(jj,3)&&b(3)==T(jj,3)); if T(jj,12)==1 assert(a(4)==T(jj,4)&&a(5)==b(4)&&b(5)==T(jj,5)&&all(a(6:7)==T(jj,6:7))&&all(b(6:7)==T(jj,6:7))); else assert(a(6)==T(jj,6)&&a(7)==b(6)&&b(7)==T(jj,7)&&all(a(4:5)==T(jj,4:5))&&all(b(4:5)==T(jj,4:5))); end end assert(all(T(T(:,9)==5,8)0&&t.a+t.b*t.domain(1)>0); x=iv(t.domain(1));oH=ivAdd(iv(t.a),ivMul(iv(t.b),x));eH=ivAdd(iv(t.envelope_a),ivMul(iv(t.b),x)); ow=ivDiv(oH,ivAdd(oH,x));ew=ivDiv(eH,ivAdd(eH,x)); os=ivDiv(iv(-t.a),ivSquare(ivAdd(iv(t.a),ivMul(ivAdd(iv(1),iv(t.b)),x)))); es=ivDiv(iv(-t.envelope_a),ivSquare(ivAdd(iv(t.envelope_a),ivMul(ivAdd(iv(1),iv(t.b)),x)))); z=struct('family',t.family,'domain_empty_kg',t.domain,'original_intercept_kg',t.a,'envelope_intercept_kg',t.envelope_a, ... 'unchanged_line_slope',t.b,'recorded_minimum_intercept_shift_kg',t.envelope_intercept_shift, ... 'max_absolute_hydrogen_change_kg',ivSub(eH,oH), ... 'max_relative_hydrogen_change_fraction',ivDiv(ivSub(eH,oH),oH), ... 'max_absolute_omega_change_percentage_points',ivMul(ivSub(ew,ow),iv(100)), ... 'max_relative_omega_change_fraction',ivDiv(ivSub(ew,ow),ow), ... 'max_absolute_omega_slope_change_per_kg',ivSub(os,es), ... 'max_relative_omega_slope_change_fraction',ivDiv(ivSub(os,es),os), ... 'location_of_maxima_empty_kg',t.domain(1), ... 'proof','For a0,h_original>0: delta-omega, relative delta-omega and positive slope reduction decrease with x; maxima are at xmin. h-line slope unchanged, omega derivative -A/[(1+B)x+A]^2 changes.', ... 'coverage_scope','recorded minimum same-slope intercept shift; unchanged original coefficients, no refitting or retuning'); if isempty(shapes.tanks),shapes.tanks=z;else,shapes.tanks(end+1)=z;end end r23.write_json(fullfile(dest,'envelope-shape.json'),shapes); end function self_tests() tiny=typecast(uint64(1),'double');assert(tiny>0&&nextUp(0)==tiny&&nextDown(0)==-tiny); assert(tiny/1==tiny,'Gradual underflow prerequisite not met.'); assert(nextUp(-tiny)==0&&nextDown(tiny)==0&&nextUp(-1)>-1&&nextDown(-1)<-1); assert(nextDown(Inf)==realmax&&nextUp(-Inf)==-realmax); subnormalFailedClosed=false;try,ivSqrt([tiny tiny]);catch,subnormalFailedClosed=true;end checks.extreme_subnormal_sqrt_failed_closed=subnormalFailedClosed; z=ivSqrt([0 0;1 1;2 2;1e-200 1e200]);assert(all(z(:,1).^2<=[0;1;2;1e-200])&&all(z(:,2).^2>=[0;1;2;1e200])); X=linspace(0,2,101)';E=ivExpNeg(iv(X),cfg.exp_positive_Taylor_degree);assert(all(exp(-X)>=E(:,1)&exp(-X)<=E(:,2))); for di=1:3 M=linspace(massDomain(1),massDomain(2),11)';V=linspace(0,p.speed_max,11)'; [a,b,z]=components(M,V,di);P=ivAdd(ivDiv(ivAdd(ivAdd(a,b),z),G(di).eta),iv(p.aux_power));actual=r23.power(M,V,Ds(di),p); assert(all(actual>=P(:,1)&actual<=P(:,2))); end end function write_parameters() settingsRows={'absolute_gap_h',cfg.absolute_gap_h,'h';'scenario_time_budget_s',cfg.scenario_time_budget_s,'s'; ... 'max_nodes_per_scenario',cfg.max_nodes_per_scenario,'1';'batch_size',cfg.batch_size,'1'; ... 'exp_positive_Taylor_degree',cfg.exp_positive_Taylor_degree,'1';'sqrt_expansion_limit',cfg.sqrt_expansion_limit,'1'; ... 'analytic_mass_domain_lo',massDomain(1),'kg';'analytic_mass_domain_hi',massDomain(2),'kg'}; rows=cell(0,5); for jj=1:numel(p.registry),a=p.registry(jj);rows(end+1,:)={a.symbol,num2str(a.value,17),a.unit,'inherited frozen model',a.source_id};end for jj=1:size(settingsRows,1),rows(end+1,:)={settingsRows{jj,1},num2str(settingsRows{jj,2},17),settingsRows{jj,3},'certificate numerical setting or outward derived bound','UC-1.0.0'};end for jj=1:numel(fit.fc) f=fit.fc(jj);for key={'a','b','c','envelope_a','envelope_b','domain'} kk=key{1};unit='W/kg';if strcmp(kk,'c')||strcmp(kk,'domain'),unit='W';end rows(end+1,:)={['FC.' f.family '.' kk],mat2str(f.(kk),17),unit,'frozen fit; no refit','catalog-fits.json'}; end end for jj=1:numel(fit.tank) f=fit.tank(jj);for key={'a','b','envelope_a','envelope_b','domain','envelope_intercept_shift'} kk=key{1};unit='kgH2';if any(strcmp(kk,{'b','envelope_b'})),unit='kgH2/kgEmpty';elseif strcmp(kk,'domain'),unit='kgEmpty';end rows(end+1,:)={['TANK.' f.family '.' kk],mat2str(f.(kk),17),unit,'frozen original fit/envelope; no retuning','catalog-fits.json'}; end end writetable(cell2table(rows,'VariableNames',{'parameter_id','value','unit','identity','source'}),fullfile(dest,'parameters.csv'),'Encoding','UTF-8'); write_exact_csv(fullfile(dest,'branches.csv'),{'branch_id','geometry_index','FC_index','tank_index'},[(1:size(B,1))',B]); end function write_exact_csv(path,headers,data) fid=fopen(path,'w','n','UTF-8');assert(fid>0);closer=onCleanup(@()fclose(fid)); fprintf(fid,'%s\n',strjoin(headers,',')); format=[repmat('%.17g,',1,size(data,2)-1) '%.17g\n'];fprintf(fid,format,data'); clear closer; reloaded=readmatrix(path,'NumHeaderLines',1); assert(isequaln(reloaded,data),'CSV numeric replay differs from exact source matrix.'); finite=isfinite(data);assert(isequal(typecast(data(finite),'uint64'),typecast(reloaded(finite),'uint64')),'CSV finite binary64 bits changed.'); end function verify_original() items=[original.source_files(:);original.input_files(:)];for jj=1:numel(items),assert(strcmp(r23.sha256_file(fullfile(root,items(jj).path)),items(jj).sha256));end assert(strcmp(r23.sha256_file(fullfile(pub,'report-data.json')),'6e9c51d39dd24bb7a9a9ff71aee42ab2011a858dbde905e8851e95c2648406fd')); end function list=hash_files(files) list=struct([]);for jj=1:numel(files),z=struct('path',strrep(erase(files{jj},[root filesep]),filesep,'/'),'sha256',r23.sha256_file(files{jj}));if isempty(list),list=z;else,list(end+1)=z;end,end end end function X=iv(x),X=[x(:),x(:)];end function C=ivAdd(A,B),C=[nextDown(A(:,1)+B(:,1)),nextUp(A(:,2)+B(:,2))];end function C=ivSub(A,B),C=[nextDown(A(:,1)-B(:,2)),nextUp(A(:,2)-B(:,1))];end function C=ivMul(A,B) v=[A(:,1).*B(:,1),A(:,1).*B(:,2),A(:,2).*B(:,1),A(:,2).*B(:,2)];C=[nextDown(min(v,[],2)),nextUp(max(v,[],2))]; end function C=ivDiv(A,B) assert(all(B(:,1)>0));C=ivMul(A,[nextDown(1./B(:,2)),nextUp(1./B(:,1))]); end function C=ivSquare(A) lo=min(A(:,1).^2,A(:,2).^2);hi=max(A(:,1).^2,A(:,2).^2);cross=A(:,1)<=0&A(:,2)>=0;lo(cross)=0; C=[nextDown(lo),nextUp(hi)];C(cross,1)=0; end function C=ivCube(A),C=ivMul(ivSquare(A),A);end function C=ivSqrt(A) assert(all(A(:,1)>=0));lo=max(nextDown(sqrt(A(:,1))),0);hi=nextUp(sqrt(A(:,2)));hi(A(:,2)==0)=0; for j=1:64,bad=lo>0&nextUp(lo.*lo)>A(:,1);if ~any(bad),break;end;lo(bad)=nextDown(lo(bad));end for j=1:64,bad=A(:,2)>0&nextDown(hi.*hi)=A(:,2)),'sqrt enclosure not verified');C=[lo,hi]; end function E=ivExpNeg(X,N) assert(all(X(:,1)>=0));term=iv(ones(size(X,1),1));S=term; for k=1:N,term=ivDiv(ivMul(term,X),iv(k));S=ivAdd(S,term);end following=ivDiv(ivMul(term,X),iv(N+1));ratio=ivDiv(iv(X(:,2)),iv(N+2));assert(all(ratio(:,2)<1)); tail=ivDiv([zeros(size(X,1),1),following(:,2)],ivSub(iv(1),ratio)); upper=nextUp(S(:,2)+tail(:,2));assert(all(S(:,1)>0));E=ivDiv(iv(ones(size(X,1),1)),[S(:,1),upper]); end function y=nextDown(x) y=x;positive=isfinite(x)&x>0;negative=isfinite(x)&x<0; if any(positive(:)),bits=typecast(x(positive),'uint64');y(positive)=typecast(bits-uint64(1),'double');end if any(negative(:)),bits=typecast(x(negative),'uint64');y(negative)=typecast(bits+uint64(1),'double');end y(x==0)=-typecast(uint64(1),'double');y(x==Inf)=realmax; end function y=nextUp(x) y=x;positive=isfinite(x)&x>0;negative=isfinite(x)&x<0; if any(positive(:)),bits=typecast(x(positive),'uint64');y(positive)=typecast(bits+uint64(1),'double');end if any(negative(:)),bits=typecast(x(negative),'uint64');y(negative)=typecast(bits-uint64(1),'double');end y(x==0)=typecast(uint64(1),'double');y(x==-Inf)=-realmax; end