python3 <<'PY' import math a=0.25; b=1.0/12 def G(t,y3): y1=3*t-2.0/3 if y1<-1e-14 or y1>b+1e-14 or y3<-1e-14 or y3>a+1e-14: return -1 al=2*a+2*b-y1-t mu1=a+b-y1; mu2=b+a-t; nu1=a+b r1=mu1/al; r2=mu2/al; s1=nu1/al; s3=1-s1 A=al*(math.sqrt(max(0,a*r1*s1))+math.sqrt(max(0,b*r1*s3))+math.sqrt(max(0,b*r2*s1))+math.sqrt(max(0,a*r2*s3))) beta=a+b-y3 B=math.sqrt(beta)*(b+math.sqrt(max(0,a*(a-y3)))) gam=y1+t+y3 C=math.sqrt(gam)*(math.sqrt(max(0,b*y1))+math.sqrt(max(0,a*t))+math.sqrt(max(0,a*y3))) return A+B+C def opty3(t): lo=0.0; hi=a gr=(math.sqrt(5)-1)/2 for _ in range(100): c=hi-gr*(hi-lo); d=lo+gr*(hi-lo) if G(t,c)best: best=g; arg=(t,y3) print("rough",best,arg) # refine around arg using ternary on t with inner y3 opt center=arg[0]; w=0.002 lo=max(tlo,center-w); hi=min(thi,center+w) for _ in range(80): m1=lo+(hi-lo)/3; m2=hi-(hi-lo)/3 if G(m1,opty3(m1))