"""Directed shifted B mass with the q-prime prefix and local product computed exactly. Use for small z and logN panels; all calls are independent of the distribution-error method. """ from functools import lru_cache from decimal import Decimal as D,ROUND_FLOOR import numpy as np from numeric_center import M,P,EG,K0,PI,ex,ln,eps,dh,dec,U10,dir_log1p_ratio from numeric_base import PR,upfloat,dnfloat,fu,fd,guard CUT=250000 @lru_cache(None) def prefix(): # Outward bounds from correctly rounded Decimal, shared by all subsequent evaluations. lp=np.asarray([dnfloat(ln(D(int(p)))) for p in PR]) weights=fu(1./PR.astype(float));return lp,weights @lru_cache(maxsize=1000) def center(l0,l1,be,et,nv=160,nu=1200): logs,recip=prefix();a=be*l0;uhi=1-2*et zlo=ex(a);it=int(np.searchsorted(PR,int((zlo-guard(zlo)).to_integral_value(rounding=ROUND_FLOOR)),side='left')) nq=len(PR)-it;ufi=fd(logs[it:]/upfloat(l1)) start=max(be,ln(D(CUT))/l1) if start0 parts[hit]=fu(q[hit]/s[hit]);tot=fu(np.sum(fu(parts*ww))*(1+4e-16*len(x))) sm+=(cdf(v)-cdf(v-D(1)/nv))*D.from_float(float(tot)) return sm+guard(sm) @lru_cache(maxsize=1000) def local_v(z): v=D(1) for pp in PR: p=int(pp) if p>=z:break if p>2:v*=D(p-2)/(p-1) return v def main(l0,l1,b,be='.09',et='.334'): l0,l1,b,be,et=map(dec,(l0,l1,b,be,et)) assert 45<=l0<=l1 and et>=D(1)/3 and et<=D('.37') and ex(et*l0)>CUT z=be*l0;y=et*l0;dqt=dh(max(ln(D(CUT)),z));dq=dh(z);dy=dh(y) top=1-2*et;st=max(be,ln(D(CUT))/l1) jq=max(D(0),ln((1-st-et)/et)/(1-st)) if st=20 else max(K0,ex(D('.000003')+2*ex(-y/2)/y+D('.000006836')/y)) assert ex(y)>=1090697 if ex(be*l1)D('.5'):coeff*=(1+1/(ex(z)-2))**(1/be) return U10(coeff*mass),U10(mass),U10(conv)