
(FPCore (F l) :precision binary64 (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))
double code(double F, double l) {
return (((double) M_PI) * l) - ((1.0 / (F * F)) * tan((((double) M_PI) * l)));
}
public static double code(double F, double l) {
return (Math.PI * l) - ((1.0 / (F * F)) * Math.tan((Math.PI * l)));
}
def code(F, l): return (math.pi * l) - ((1.0 / (F * F)) * math.tan((math.pi * l)))
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(1.0 / Float64(F * F)) * tan(Float64(pi * l)))) end
function tmp = code(F, l) tmp = (pi * l) - ((1.0 / (F * F)) * tan((pi * l))); end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision] * N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (F l) :precision binary64 (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))
double code(double F, double l) {
return (((double) M_PI) * l) - ((1.0 / (F * F)) * tan((((double) M_PI) * l)));
}
public static double code(double F, double l) {
return (Math.PI * l) - ((1.0 / (F * F)) * Math.tan((Math.PI * l)));
}
def code(F, l): return (math.pi * l) - ((1.0 / (F * F)) * math.tan((math.pi * l)))
function code(F, l) return Float64(Float64(pi * l) - Float64(Float64(1.0 / Float64(F * F)) * tan(Float64(pi * l)))) end
function tmp = code(F, l) tmp = (pi * l) - ((1.0 / (F * F)) * tan((pi * l))); end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision] * N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)
\end{array}
(FPCore (F l) :precision binary64 (if (<= (* PI l) -2e+19) (* (/ l PI) (pow PI 2.0)) (if (<= (* PI l) 1e-16) (- (* PI l) (* (/ PI F) (/ l F))) (* PI l))))
double code(double F, double l) {
double tmp;
if ((((double) M_PI) * l) <= -2e+19) {
tmp = (l / ((double) M_PI)) * pow(((double) M_PI), 2.0);
} else if ((((double) M_PI) * l) <= 1e-16) {
tmp = (((double) M_PI) * l) - ((((double) M_PI) / F) * (l / F));
} else {
tmp = ((double) M_PI) * l;
}
return tmp;
}
public static double code(double F, double l) {
double tmp;
if ((Math.PI * l) <= -2e+19) {
tmp = (l / Math.PI) * Math.pow(Math.PI, 2.0);
} else if ((Math.PI * l) <= 1e-16) {
tmp = (Math.PI * l) - ((Math.PI / F) * (l / F));
} else {
tmp = Math.PI * l;
}
return tmp;
}
def code(F, l): tmp = 0 if (math.pi * l) <= -2e+19: tmp = (l / math.pi) * math.pow(math.pi, 2.0) elif (math.pi * l) <= 1e-16: tmp = (math.pi * l) - ((math.pi / F) * (l / F)) else: tmp = math.pi * l return tmp
function code(F, l) tmp = 0.0 if (Float64(pi * l) <= -2e+19) tmp = Float64(Float64(l / pi) * (pi ^ 2.0)); elseif (Float64(pi * l) <= 1e-16) tmp = Float64(Float64(pi * l) - Float64(Float64(pi / F) * Float64(l / F))); else tmp = Float64(pi * l); end return tmp end
function tmp_2 = code(F, l) tmp = 0.0; if ((pi * l) <= -2e+19) tmp = (l / pi) * (pi ^ 2.0); elseif ((pi * l) <= 1e-16) tmp = (pi * l) - ((pi / F) * (l / F)); else tmp = pi * l; end tmp_2 = tmp; end
code[F_, l_] := If[LessEqual[N[(Pi * l), $MachinePrecision], -2e+19], N[(N[(l / Pi), $MachinePrecision] * N[Power[Pi, 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(Pi * l), $MachinePrecision], 1e-16], N[(N[(Pi * l), $MachinePrecision] - N[(N[(Pi / F), $MachinePrecision] * N[(l / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Pi * l), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\pi \cdot \ell \leq -2 \cdot 10^{+19}:\\
\;\;\;\;\frac{\ell}{\pi} \cdot {\pi}^{2}\\
\mathbf{elif}\;\pi \cdot \ell \leq 10^{-16}:\\
\;\;\;\;\pi \cdot \ell - \frac{\pi}{F} \cdot \frac{\ell}{F}\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell\\
\end{array}
\end{array}
if (*.f64 (PI.f64) l) < -2e19Initial program 64.9%
associate-*l/64.9%
*-lft-identity64.9%
Simplified64.9%
Taylor expanded in l around 0 42.8%
unpow242.8%
Simplified42.8%
add-cbrt-cube11.1%
pow311.1%
Applied egg-rr14.3%
rem-cbrt-cube46.4%
flip-+45.3%
associate-*r/45.4%
pow245.4%
*-commutative45.4%
*-commutative45.4%
swap-sqr45.4%
pow-prod-up45.4%
metadata-eval45.4%
pow245.4%
*-un-lft-identity45.4%
*-commutative45.4%
Applied egg-rr45.4%
times-frac45.3%
cancel-sign-sub-inv45.3%
distribute-rgt1-in45.3%
Simplified45.3%
Taylor expanded in F around inf 99.4%
if -2e19 < (*.f64 (PI.f64) l) < 9.9999999999999998e-17Initial program 87.4%
associate-*l/88.0%
*-un-lft-identity88.0%
associate-/r*99.6%
Applied egg-rr99.6%
Taylor expanded in l around 0 88.0%
*-commutative88.0%
unpow288.0%
times-frac99.6%
Simplified99.6%
if 9.9999999999999998e-17 < (*.f64 (PI.f64) l) Initial program 69.6%
associate-*l/69.6%
*-lft-identity69.6%
Simplified69.6%
Taylor expanded in l around 0 53.8%
unpow253.8%
Simplified53.8%
Taylor expanded in F around inf 99.6%
Final simplification99.6%
(FPCore (F l) :precision binary64 (if (or (<= (* PI l) -2e+19) (not (<= (* PI l) 1e-16))) (* PI l) (- (* PI l) (* (/ PI F) (/ l F)))))
double code(double F, double l) {
double tmp;
if (((((double) M_PI) * l) <= -2e+19) || !((((double) M_PI) * l) <= 1e-16)) {
tmp = ((double) M_PI) * l;
} else {
tmp = (((double) M_PI) * l) - ((((double) M_PI) / F) * (l / F));
}
return tmp;
}
public static double code(double F, double l) {
double tmp;
if (((Math.PI * l) <= -2e+19) || !((Math.PI * l) <= 1e-16)) {
tmp = Math.PI * l;
} else {
tmp = (Math.PI * l) - ((Math.PI / F) * (l / F));
}
return tmp;
}
def code(F, l): tmp = 0 if ((math.pi * l) <= -2e+19) or not ((math.pi * l) <= 1e-16): tmp = math.pi * l else: tmp = (math.pi * l) - ((math.pi / F) * (l / F)) return tmp
function code(F, l) tmp = 0.0 if ((Float64(pi * l) <= -2e+19) || !(Float64(pi * l) <= 1e-16)) tmp = Float64(pi * l); else tmp = Float64(Float64(pi * l) - Float64(Float64(pi / F) * Float64(l / F))); end return tmp end
function tmp_2 = code(F, l) tmp = 0.0; if (((pi * l) <= -2e+19) || ~(((pi * l) <= 1e-16))) tmp = pi * l; else tmp = (pi * l) - ((pi / F) * (l / F)); end tmp_2 = tmp; end
code[F_, l_] := If[Or[LessEqual[N[(Pi * l), $MachinePrecision], -2e+19], N[Not[LessEqual[N[(Pi * l), $MachinePrecision], 1e-16]], $MachinePrecision]], N[(Pi * l), $MachinePrecision], N[(N[(Pi * l), $MachinePrecision] - N[(N[(Pi / F), $MachinePrecision] * N[(l / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\pi \cdot \ell \leq -2 \cdot 10^{+19} \lor \neg \left(\pi \cdot \ell \leq 10^{-16}\right):\\
\;\;\;\;\pi \cdot \ell\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell - \frac{\pi}{F} \cdot \frac{\ell}{F}\\
\end{array}
\end{array}
if (*.f64 (PI.f64) l) < -2e19 or 9.9999999999999998e-17 < (*.f64 (PI.f64) l) Initial program 67.4%
associate-*l/67.4%
*-lft-identity67.4%
Simplified67.4%
Taylor expanded in l around 0 48.6%
unpow248.6%
Simplified48.6%
Taylor expanded in F around inf 99.5%
if -2e19 < (*.f64 (PI.f64) l) < 9.9999999999999998e-17Initial program 87.4%
associate-*l/88.0%
*-un-lft-identity88.0%
associate-/r*99.6%
Applied egg-rr99.6%
Taylor expanded in l around 0 88.0%
*-commutative88.0%
unpow288.0%
times-frac99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (F l) :precision binary64 (if (or (<= (* PI l) -2e+19) (not (<= (* PI l) 1e-16))) (* PI l) (* PI (- l (/ l (* F F))))))
double code(double F, double l) {
double tmp;
if (((((double) M_PI) * l) <= -2e+19) || !((((double) M_PI) * l) <= 1e-16)) {
tmp = ((double) M_PI) * l;
} else {
tmp = ((double) M_PI) * (l - (l / (F * F)));
}
return tmp;
}
public static double code(double F, double l) {
double tmp;
if (((Math.PI * l) <= -2e+19) || !((Math.PI * l) <= 1e-16)) {
tmp = Math.PI * l;
} else {
tmp = Math.PI * (l - (l / (F * F)));
}
return tmp;
}
def code(F, l): tmp = 0 if ((math.pi * l) <= -2e+19) or not ((math.pi * l) <= 1e-16): tmp = math.pi * l else: tmp = math.pi * (l - (l / (F * F))) return tmp
function code(F, l) tmp = 0.0 if ((Float64(pi * l) <= -2e+19) || !(Float64(pi * l) <= 1e-16)) tmp = Float64(pi * l); else tmp = Float64(pi * Float64(l - Float64(l / Float64(F * F)))); end return tmp end
function tmp_2 = code(F, l) tmp = 0.0; if (((pi * l) <= -2e+19) || ~(((pi * l) <= 1e-16))) tmp = pi * l; else tmp = pi * (l - (l / (F * F))); end tmp_2 = tmp; end
code[F_, l_] := If[Or[LessEqual[N[(Pi * l), $MachinePrecision], -2e+19], N[Not[LessEqual[N[(Pi * l), $MachinePrecision], 1e-16]], $MachinePrecision]], N[(Pi * l), $MachinePrecision], N[(Pi * N[(l - N[(l / N[(F * F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\pi \cdot \ell \leq -2 \cdot 10^{+19} \lor \neg \left(\pi \cdot \ell \leq 10^{-16}\right):\\
\;\;\;\;\pi \cdot \ell\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \left(\ell - \frac{\ell}{F \cdot F}\right)\\
\end{array}
\end{array}
if (*.f64 (PI.f64) l) < -2e19 or 9.9999999999999998e-17 < (*.f64 (PI.f64) l) Initial program 67.4%
associate-*l/67.4%
*-lft-identity67.4%
Simplified67.4%
Taylor expanded in l around 0 48.6%
unpow248.6%
Simplified48.6%
Taylor expanded in F around inf 99.5%
if -2e19 < (*.f64 (PI.f64) l) < 9.9999999999999998e-17Initial program 87.4%
associate-*l/88.0%
*-un-lft-identity88.0%
associate-/r*99.6%
Applied egg-rr99.6%
Taylor expanded in l around 0 88.0%
*-commutative88.0%
unpow288.0%
times-frac99.6%
Simplified99.6%
Taylor expanded in l around 0 87.5%
distribute-rgt-out--87.5%
unpow287.5%
associate-*l/88.0%
*-commutative88.0%
associate-*l/88.0%
*-commutative88.0%
distribute-rgt-out--88.0%
Simplified88.0%
Final simplification93.3%
(FPCore (F l)
:precision binary64
(let* ((t_0 (* (/ PI F) (/ (- l) F))))
(if (<= (* F F) 5e-283)
t_0
(if (<= (* F F) 5e-103)
(+ (+ (* PI l) 1.0) -1.0)
(if (<= (* F F) 1e-29) t_0 (* PI l))))))
double code(double F, double l) {
double t_0 = (((double) M_PI) / F) * (-l / F);
double tmp;
if ((F * F) <= 5e-283) {
tmp = t_0;
} else if ((F * F) <= 5e-103) {
tmp = ((((double) M_PI) * l) + 1.0) + -1.0;
} else if ((F * F) <= 1e-29) {
tmp = t_0;
} else {
tmp = ((double) M_PI) * l;
}
return tmp;
}
public static double code(double F, double l) {
double t_0 = (Math.PI / F) * (-l / F);
double tmp;
if ((F * F) <= 5e-283) {
tmp = t_0;
} else if ((F * F) <= 5e-103) {
tmp = ((Math.PI * l) + 1.0) + -1.0;
} else if ((F * F) <= 1e-29) {
tmp = t_0;
} else {
tmp = Math.PI * l;
}
return tmp;
}
def code(F, l): t_0 = (math.pi / F) * (-l / F) tmp = 0 if (F * F) <= 5e-283: tmp = t_0 elif (F * F) <= 5e-103: tmp = ((math.pi * l) + 1.0) + -1.0 elif (F * F) <= 1e-29: tmp = t_0 else: tmp = math.pi * l return tmp
function code(F, l) t_0 = Float64(Float64(pi / F) * Float64(Float64(-l) / F)) tmp = 0.0 if (Float64(F * F) <= 5e-283) tmp = t_0; elseif (Float64(F * F) <= 5e-103) tmp = Float64(Float64(Float64(pi * l) + 1.0) + -1.0); elseif (Float64(F * F) <= 1e-29) tmp = t_0; else tmp = Float64(pi * l); end return tmp end
function tmp_2 = code(F, l) t_0 = (pi / F) * (-l / F); tmp = 0.0; if ((F * F) <= 5e-283) tmp = t_0; elseif ((F * F) <= 5e-103) tmp = ((pi * l) + 1.0) + -1.0; elseif ((F * F) <= 1e-29) tmp = t_0; else tmp = pi * l; end tmp_2 = tmp; end
code[F_, l_] := Block[{t$95$0 = N[(N[(Pi / F), $MachinePrecision] * N[((-l) / F), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(F * F), $MachinePrecision], 5e-283], t$95$0, If[LessEqual[N[(F * F), $MachinePrecision], 5e-103], N[(N[(N[(Pi * l), $MachinePrecision] + 1.0), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(F * F), $MachinePrecision], 1e-29], t$95$0, N[(Pi * l), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\pi}{F} \cdot \frac{-\ell}{F}\\
\mathbf{if}\;F \cdot F \leq 5 \cdot 10^{-283}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;F \cdot F \leq 5 \cdot 10^{-103}:\\
\;\;\;\;\left(\pi \cdot \ell + 1\right) + -1\\
\mathbf{elif}\;F \cdot F \leq 10^{-29}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\pi \cdot \ell\\
\end{array}
\end{array}
if (*.f64 F F) < 5.0000000000000001e-283 or 4.99999999999999966e-103 < (*.f64 F F) < 9.99999999999999943e-30Initial program 46.8%
associate-*l/47.6%
*-lft-identity47.6%
Simplified47.6%
Taylor expanded in l around 0 38.6%
unpow238.6%
Simplified38.6%
Taylor expanded in F around 0 39.4%
mul-1-neg39.4%
associate-/l*39.4%
unpow239.4%
associate-/l*39.4%
Simplified39.4%
associate-/r/59.3%
Applied egg-rr59.3%
if 5.0000000000000001e-283 < (*.f64 F F) < 4.99999999999999966e-103Initial program 57.0%
associate-*l/57.2%
*-lft-identity57.2%
Simplified57.2%
Taylor expanded in l around 0 32.0%
unpow232.0%
Simplified32.0%
Taylor expanded in F around inf 68.4%
*-commutative68.4%
expm1-log1p-u33.1%
Applied egg-rr33.1%
expm1-udef33.3%
log1p-udef33.3%
add-exp-log68.6%
Applied egg-rr68.6%
if 9.99999999999999943e-30 < (*.f64 F F) Initial program 99.5%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
Taylor expanded in l around 0 93.7%
unpow293.7%
Simplified93.7%
Taylor expanded in F around inf 98.1%
Final simplification82.6%
(FPCore (F l) :precision binary64 (* PI l))
double code(double F, double l) {
return ((double) M_PI) * l;
}
public static double code(double F, double l) {
return Math.PI * l;
}
def code(F, l): return math.pi * l
function code(F, l) return Float64(pi * l) end
function tmp = code(F, l) tmp = pi * l; end
code[F_, l_] := N[(Pi * l), $MachinePrecision]
\begin{array}{l}
\\
\pi \cdot \ell
\end{array}
Initial program 78.2%
associate-*l/78.5%
*-lft-identity78.5%
Simplified78.5%
Taylor expanded in l around 0 69.5%
unpow269.5%
Simplified69.5%
Taylor expanded in F around inf 76.9%
Final simplification76.9%
herbie shell --seed 2023187
(FPCore (F l)
:name "VandenBroeck and Keller, Equation (6)"
:precision binary64
(- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))