
(FPCore (f) :precision binary64 (let* ((t_0 (* (/ PI 4.0) f)) (t_1 (exp t_0)) (t_2 (exp (- t_0)))) (- (* (/ 1.0 (/ PI 4.0)) (log (/ (+ t_1 t_2) (- t_1 t_2)))))))
double code(double f) {
double t_0 = (((double) M_PI) / 4.0) * f;
double t_1 = exp(t_0);
double t_2 = exp(-t_0);
return -((1.0 / (((double) M_PI) / 4.0)) * log(((t_1 + t_2) / (t_1 - t_2))));
}
public static double code(double f) {
double t_0 = (Math.PI / 4.0) * f;
double t_1 = Math.exp(t_0);
double t_2 = Math.exp(-t_0);
return -((1.0 / (Math.PI / 4.0)) * Math.log(((t_1 + t_2) / (t_1 - t_2))));
}
def code(f): t_0 = (math.pi / 4.0) * f t_1 = math.exp(t_0) t_2 = math.exp(-t_0) return -((1.0 / (math.pi / 4.0)) * math.log(((t_1 + t_2) / (t_1 - t_2))))
function code(f) t_0 = Float64(Float64(pi / 4.0) * f) t_1 = exp(t_0) t_2 = exp(Float64(-t_0)) return Float64(-Float64(Float64(1.0 / Float64(pi / 4.0)) * log(Float64(Float64(t_1 + t_2) / Float64(t_1 - t_2))))) end
function tmp = code(f) t_0 = (pi / 4.0) * f; t_1 = exp(t_0); t_2 = exp(-t_0); tmp = -((1.0 / (pi / 4.0)) * log(((t_1 + t_2) / (t_1 - t_2)))); end
code[f_] := Block[{t$95$0 = N[(N[(Pi / 4.0), $MachinePrecision] * f), $MachinePrecision]}, Block[{t$95$1 = N[Exp[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-t$95$0)], $MachinePrecision]}, (-N[(N[(1.0 / N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision] * N[Log[N[(N[(t$95$1 + t$95$2), $MachinePrecision] / N[(t$95$1 - t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision])]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\pi}{4} \cdot f\\
t_1 := e^{t\_0}\\
t_2 := e^{-t\_0}\\
-\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{t\_1 + t\_2}{t\_1 - t\_2}\right)
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (f) :precision binary64 (let* ((t_0 (* (/ PI 4.0) f)) (t_1 (exp t_0)) (t_2 (exp (- t_0)))) (- (* (/ 1.0 (/ PI 4.0)) (log (/ (+ t_1 t_2) (- t_1 t_2)))))))
double code(double f) {
double t_0 = (((double) M_PI) / 4.0) * f;
double t_1 = exp(t_0);
double t_2 = exp(-t_0);
return -((1.0 / (((double) M_PI) / 4.0)) * log(((t_1 + t_2) / (t_1 - t_2))));
}
public static double code(double f) {
double t_0 = (Math.PI / 4.0) * f;
double t_1 = Math.exp(t_0);
double t_2 = Math.exp(-t_0);
return -((1.0 / (Math.PI / 4.0)) * Math.log(((t_1 + t_2) / (t_1 - t_2))));
}
def code(f): t_0 = (math.pi / 4.0) * f t_1 = math.exp(t_0) t_2 = math.exp(-t_0) return -((1.0 / (math.pi / 4.0)) * math.log(((t_1 + t_2) / (t_1 - t_2))))
function code(f) t_0 = Float64(Float64(pi / 4.0) * f) t_1 = exp(t_0) t_2 = exp(Float64(-t_0)) return Float64(-Float64(Float64(1.0 / Float64(pi / 4.0)) * log(Float64(Float64(t_1 + t_2) / Float64(t_1 - t_2))))) end
function tmp = code(f) t_0 = (pi / 4.0) * f; t_1 = exp(t_0); t_2 = exp(-t_0); tmp = -((1.0 / (pi / 4.0)) * log(((t_1 + t_2) / (t_1 - t_2)))); end
code[f_] := Block[{t$95$0 = N[(N[(Pi / 4.0), $MachinePrecision] * f), $MachinePrecision]}, Block[{t$95$1 = N[Exp[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-t$95$0)], $MachinePrecision]}, (-N[(N[(1.0 / N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision] * N[Log[N[(N[(t$95$1 + t$95$2), $MachinePrecision] / N[(t$95$1 - t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision])]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\pi}{4} \cdot f\\
t_1 := e^{t\_0}\\
t_2 := e^{-t\_0}\\
-\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{t\_1 + t\_2}{t\_1 - t\_2}\right)
\end{array}
\end{array}
(FPCore (f) :precision binary64 (/ (/ (log (tanh (* PI (* f 0.25)))) PI) 0.25))
double code(double f) {
return (log(tanh((((double) M_PI) * (f * 0.25)))) / ((double) M_PI)) / 0.25;
}
public static double code(double f) {
return (Math.log(Math.tanh((Math.PI * (f * 0.25)))) / Math.PI) / 0.25;
}
def code(f): return (math.log(math.tanh((math.pi * (f * 0.25)))) / math.pi) / 0.25
function code(f) return Float64(Float64(log(tanh(Float64(pi * Float64(f * 0.25)))) / pi) / 0.25) end
function tmp = code(f) tmp = (log(tanh((pi * (f * 0.25)))) / pi) / 0.25; end
code[f_] := N[(N[(N[Log[N[Tanh[N[(Pi * N[(f * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] / 0.25), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\log \tanh \left(\pi \cdot \left(f \cdot 0.25\right)\right)}{\pi}}{0.25}
\end{array}
Initial program 8.9%
associate-*l/8.9%
Applied egg-rr99.4%
distribute-frac-neg99.4%
distribute-neg-frac299.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
*-commutative99.4%
Simplified99.4%
neg-mul-199.4%
associate-*r/99.4%
times-frac99.4%
metadata-eval99.4%
metadata-eval99.4%
times-frac99.4%
*-un-lft-identity99.4%
*-commutative99.4%
associate-/r*99.4%
associate-*r*99.4%
*-commutative99.4%
associate-*l*99.4%
Applied egg-rr99.4%
(FPCore (f) :precision binary64 (if (<= f 1.26) (* (- (log (/ 4.0 PI)) (log f)) (/ -4.0 PI)) (/ 0.0 (* PI -0.25))))
double code(double f) {
double tmp;
if (f <= 1.26) {
tmp = (log((4.0 / ((double) M_PI))) - log(f)) * (-4.0 / ((double) M_PI));
} else {
tmp = 0.0 / (((double) M_PI) * -0.25);
}
return tmp;
}
public static double code(double f) {
double tmp;
if (f <= 1.26) {
tmp = (Math.log((4.0 / Math.PI)) - Math.log(f)) * (-4.0 / Math.PI);
} else {
tmp = 0.0 / (Math.PI * -0.25);
}
return tmp;
}
def code(f): tmp = 0 if f <= 1.26: tmp = (math.log((4.0 / math.pi)) - math.log(f)) * (-4.0 / math.pi) else: tmp = 0.0 / (math.pi * -0.25) return tmp
function code(f) tmp = 0.0 if (f <= 1.26) tmp = Float64(Float64(log(Float64(4.0 / pi)) - log(f)) * Float64(-4.0 / pi)); else tmp = Float64(0.0 / Float64(pi * -0.25)); end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 1.26) tmp = (log((4.0 / pi)) - log(f)) * (-4.0 / pi); else tmp = 0.0 / (pi * -0.25); end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 1.26], N[(N[(N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision] - N[Log[f], $MachinePrecision]), $MachinePrecision] * N[(-4.0 / Pi), $MachinePrecision]), $MachinePrecision], N[(0.0 / N[(Pi * -0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.26:\\
\;\;\;\;\left(\log \left(\frac{4}{\pi}\right) - \log f\right) \cdot \frac{-4}{\pi}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{\pi \cdot -0.25}\\
\end{array}
\end{array}
if f < 1.26000000000000001Initial program 8.4%
Simplified99.4%
Taylor expanded in f around 0 97.9%
mul-1-neg97.9%
unsub-neg97.9%
Simplified97.9%
if 1.26000000000000001 < f Initial program 24.1%
associate-*l/24.1%
Applied egg-rr96.3%
distribute-frac-neg96.3%
distribute-neg-frac296.3%
*-commutative96.3%
distribute-rgt-neg-in96.3%
metadata-eval96.3%
*-commutative96.3%
Simplified96.3%
Applied egg-rr86.2%
*-inverses86.2%
Simplified86.2%
Final simplification97.6%
(FPCore (f) :precision binary64 (if (<= f 1.26) (/ (* -4.0 (log (/ 4.0 (* PI f)))) PI) (/ 0.0 (* PI -0.25))))
double code(double f) {
double tmp;
if (f <= 1.26) {
tmp = (-4.0 * log((4.0 / (((double) M_PI) * f)))) / ((double) M_PI);
} else {
tmp = 0.0 / (((double) M_PI) * -0.25);
}
return tmp;
}
public static double code(double f) {
double tmp;
if (f <= 1.26) {
tmp = (-4.0 * Math.log((4.0 / (Math.PI * f)))) / Math.PI;
} else {
tmp = 0.0 / (Math.PI * -0.25);
}
return tmp;
}
def code(f): tmp = 0 if f <= 1.26: tmp = (-4.0 * math.log((4.0 / (math.pi * f)))) / math.pi else: tmp = 0.0 / (math.pi * -0.25) return tmp
function code(f) tmp = 0.0 if (f <= 1.26) tmp = Float64(Float64(-4.0 * log(Float64(4.0 / Float64(pi * f)))) / pi); else tmp = Float64(0.0 / Float64(pi * -0.25)); end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 1.26) tmp = (-4.0 * log((4.0 / (pi * f)))) / pi; else tmp = 0.0 / (pi * -0.25); end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 1.26], N[(N[(-4.0 * N[Log[N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision], N[(0.0 / N[(Pi * -0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.26:\\
\;\;\;\;\frac{-4 \cdot \log \left(\frac{4}{\pi \cdot f}\right)}{\pi}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{\pi \cdot -0.25}\\
\end{array}
\end{array}
if f < 1.26000000000000001Initial program 8.4%
Simplified99.4%
Taylor expanded in f around 0 97.8%
associate-*r/97.9%
Applied egg-rr97.9%
if 1.26000000000000001 < f Initial program 24.1%
associate-*l/24.1%
Applied egg-rr96.3%
distribute-frac-neg96.3%
distribute-neg-frac296.3%
*-commutative96.3%
distribute-rgt-neg-in96.3%
metadata-eval96.3%
*-commutative96.3%
Simplified96.3%
Applied egg-rr86.2%
*-inverses86.2%
Simplified86.2%
Final simplification97.6%
(FPCore (f) :precision binary64 (if (<= f 1.26) (* (/ -4.0 PI) (log (/ 4.0 (* PI f)))) (/ 0.0 (* PI -0.25))))
double code(double f) {
double tmp;
if (f <= 1.26) {
tmp = (-4.0 / ((double) M_PI)) * log((4.0 / (((double) M_PI) * f)));
} else {
tmp = 0.0 / (((double) M_PI) * -0.25);
}
return tmp;
}
public static double code(double f) {
double tmp;
if (f <= 1.26) {
tmp = (-4.0 / Math.PI) * Math.log((4.0 / (Math.PI * f)));
} else {
tmp = 0.0 / (Math.PI * -0.25);
}
return tmp;
}
def code(f): tmp = 0 if f <= 1.26: tmp = (-4.0 / math.pi) * math.log((4.0 / (math.pi * f))) else: tmp = 0.0 / (math.pi * -0.25) return tmp
function code(f) tmp = 0.0 if (f <= 1.26) tmp = Float64(Float64(-4.0 / pi) * log(Float64(4.0 / Float64(pi * f)))); else tmp = Float64(0.0 / Float64(pi * -0.25)); end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 1.26) tmp = (-4.0 / pi) * log((4.0 / (pi * f))); else tmp = 0.0 / (pi * -0.25); end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 1.26], N[(N[(-4.0 / Pi), $MachinePrecision] * N[Log[N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.0 / N[(Pi * -0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.26:\\
\;\;\;\;\frac{-4}{\pi} \cdot \log \left(\frac{4}{\pi \cdot f}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{\pi \cdot -0.25}\\
\end{array}
\end{array}
if f < 1.26000000000000001Initial program 8.4%
Simplified99.4%
Taylor expanded in f around 0 97.8%
if 1.26000000000000001 < f Initial program 24.1%
associate-*l/24.1%
Applied egg-rr96.3%
distribute-frac-neg96.3%
distribute-neg-frac296.3%
*-commutative96.3%
distribute-rgt-neg-in96.3%
metadata-eval96.3%
*-commutative96.3%
Simplified96.3%
Applied egg-rr86.2%
*-inverses86.2%
Simplified86.2%
Final simplification97.5%
(FPCore (f) :precision binary64 (log 0.0))
double code(double f) {
return log(0.0);
}
real(8) function code(f)
real(8), intent (in) :: f
code = log(0.0d0)
end function
public static double code(double f) {
return Math.log(0.0);
}
def code(f): return math.log(0.0)
function code(f) return log(0.0) end
function tmp = code(f) tmp = log(0.0); end
code[f_] := N[Log[0.0], $MachinePrecision]
\begin{array}{l}
\\
\log 0
\end{array}
Initial program 8.9%
associate-*l/8.9%
Applied egg-rr99.4%
distribute-frac-neg99.4%
distribute-neg-frac299.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
*-commutative99.4%
Simplified99.4%
*-commutative99.4%
tanh-def-a8.9%
div-sub8.8%
associate-*l*8.8%
exp-prod8.4%
*-commutative8.4%
cosh-undef8.4%
associate-*l*8.4%
*-commutative8.4%
Applied egg-rr3.1%
+-inverses3.1%
Simplified3.1%
add-sqr-sqrt0.0%
sqrt-unprod0.7%
sqr-neg0.7%
sqrt-unprod0.7%
add-log-exp0.7%
add-sqr-sqrt0.7%
div-inv0.7%
exp-to-pow0.7%
associate-/r*0.7%
metadata-eval0.7%
Applied egg-rr0.7%
pow-base-03.1%
Simplified3.1%
(FPCore (f) :precision binary64 (/ 0.0 (* PI -0.25)))
double code(double f) {
return 0.0 / (((double) M_PI) * -0.25);
}
public static double code(double f) {
return 0.0 / (Math.PI * -0.25);
}
def code(f): return 0.0 / (math.pi * -0.25)
function code(f) return Float64(0.0 / Float64(pi * -0.25)) end
function tmp = code(f) tmp = 0.0 / (pi * -0.25); end
code[f_] := N[(0.0 / N[(Pi * -0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{\pi \cdot -0.25}
\end{array}
Initial program 8.9%
associate-*l/8.9%
Applied egg-rr99.4%
distribute-frac-neg99.4%
distribute-neg-frac299.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
*-commutative99.4%
Simplified99.4%
Applied egg-rr5.4%
*-inverses5.4%
Simplified5.4%
Final simplification5.4%
herbie shell --seed 2024180
(FPCore (f)
:name "VandenBroeck and Keller, Equation (20)"
:precision binary64
(- (* (/ 1.0 (/ PI 4.0)) (log (/ (+ (exp (* (/ PI 4.0) f)) (exp (- (* (/ PI 4.0) f)))) (- (exp (* (/ PI 4.0) f)) (exp (- (* (/ PI 4.0) f)))))))))