
(FPCore (t l k) :precision binary64 (/ 2.0 (* (* (* (/ (pow t 3.0) (* l l)) (sin k)) (tan k)) (+ (+ 1.0 (pow (/ k t) 2.0)) 1.0))))
double code(double t, double l, double k) {
return 2.0 / ((((pow(t, 3.0) / (l * l)) * sin(k)) * tan(k)) * ((1.0 + pow((k / t), 2.0)) + 1.0));
}
real(8) function code(t, l, k)
real(8), intent (in) :: t
real(8), intent (in) :: l
real(8), intent (in) :: k
code = 2.0d0 / (((((t ** 3.0d0) / (l * l)) * sin(k)) * tan(k)) * ((1.0d0 + ((k / t) ** 2.0d0)) + 1.0d0))
end function
public static double code(double t, double l, double k) {
return 2.0 / ((((Math.pow(t, 3.0) / (l * l)) * Math.sin(k)) * Math.tan(k)) * ((1.0 + Math.pow((k / t), 2.0)) + 1.0));
}
def code(t, l, k): return 2.0 / ((((math.pow(t, 3.0) / (l * l)) * math.sin(k)) * math.tan(k)) * ((1.0 + math.pow((k / t), 2.0)) + 1.0))
function code(t, l, k) return Float64(2.0 / Float64(Float64(Float64(Float64((t ^ 3.0) / Float64(l * l)) * sin(k)) * tan(k)) * Float64(Float64(1.0 + (Float64(k / t) ^ 2.0)) + 1.0))) end
function tmp = code(t, l, k) tmp = 2.0 / (((((t ^ 3.0) / (l * l)) * sin(k)) * tan(k)) * ((1.0 + ((k / t) ^ 2.0)) + 1.0)); end
code[t_, l_, k_] := N[(2.0 / N[(N[(N[(N[(N[Power[t, 3.0], $MachinePrecision] / N[(l * l), $MachinePrecision]), $MachinePrecision] * N[Sin[k], $MachinePrecision]), $MachinePrecision] * N[Tan[k], $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 + N[Power[N[(k / t), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(\left(\frac{{t}^{3}}{\ell \cdot \ell} \cdot \sin k\right) \cdot \tan k\right) \cdot \left(\left(1 + {\left(\frac{k}{t}\right)}^{2}\right) + 1\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (t l k) :precision binary64 (/ 2.0 (* (* (* (/ (pow t 3.0) (* l l)) (sin k)) (tan k)) (+ (+ 1.0 (pow (/ k t) 2.0)) 1.0))))
double code(double t, double l, double k) {
return 2.0 / ((((pow(t, 3.0) / (l * l)) * sin(k)) * tan(k)) * ((1.0 + pow((k / t), 2.0)) + 1.0));
}
real(8) function code(t, l, k)
real(8), intent (in) :: t
real(8), intent (in) :: l
real(8), intent (in) :: k
code = 2.0d0 / (((((t ** 3.0d0) / (l * l)) * sin(k)) * tan(k)) * ((1.0d0 + ((k / t) ** 2.0d0)) + 1.0d0))
end function
public static double code(double t, double l, double k) {
return 2.0 / ((((Math.pow(t, 3.0) / (l * l)) * Math.sin(k)) * Math.tan(k)) * ((1.0 + Math.pow((k / t), 2.0)) + 1.0));
}
def code(t, l, k): return 2.0 / ((((math.pow(t, 3.0) / (l * l)) * math.sin(k)) * math.tan(k)) * ((1.0 + math.pow((k / t), 2.0)) + 1.0))
function code(t, l, k) return Float64(2.0 / Float64(Float64(Float64(Float64((t ^ 3.0) / Float64(l * l)) * sin(k)) * tan(k)) * Float64(Float64(1.0 + (Float64(k / t) ^ 2.0)) + 1.0))) end
function tmp = code(t, l, k) tmp = 2.0 / (((((t ^ 3.0) / (l * l)) * sin(k)) * tan(k)) * ((1.0 + ((k / t) ^ 2.0)) + 1.0)); end
code[t_, l_, k_] := N[(2.0 / N[(N[(N[(N[(N[Power[t, 3.0], $MachinePrecision] / N[(l * l), $MachinePrecision]), $MachinePrecision] * N[Sin[k], $MachinePrecision]), $MachinePrecision] * N[Tan[k], $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 + N[Power[N[(k / t), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{\left(\left(\frac{{t}^{3}}{\ell \cdot \ell} \cdot \sin k\right) \cdot \tan k\right) \cdot \left(\left(1 + {\left(\frac{k}{t}\right)}^{2}\right) + 1\right)}
\end{array}
t\_m = (fabs.f64 t)
t\_s = (copysign.f64 #s(literal 1 binary64) t)
(FPCore (t_s t_m l k)
:precision binary64
(*
t_s
(if (<= t_m 6.8e-81)
(/ 2.0 (/ (/ (* k (* k (* t_m (pow (sin k) 2.0)))) (* l (cos k))) l))
(/
2.0
(*
(* (* t_m (* (/ (* t_m (sin k)) l) (/ t_m l))) (tan k))
(fma (/ k t_m) (/ k t_m) 2.0))))))t\_m = fabs(t);
t\_s = copysign(1.0, t);
double code(double t_s, double t_m, double l, double k) {
double tmp;
if (t_m <= 6.8e-81) {
tmp = 2.0 / (((k * (k * (t_m * pow(sin(k), 2.0)))) / (l * cos(k))) / l);
} else {
tmp = 2.0 / (((t_m * (((t_m * sin(k)) / l) * (t_m / l))) * tan(k)) * fma((k / t_m), (k / t_m), 2.0));
}
return t_s * tmp;
}
t\_m = abs(t) t\_s = copysign(1.0, t) function code(t_s, t_m, l, k) tmp = 0.0 if (t_m <= 6.8e-81) tmp = Float64(2.0 / Float64(Float64(Float64(k * Float64(k * Float64(t_m * (sin(k) ^ 2.0)))) / Float64(l * cos(k))) / l)); else tmp = Float64(2.0 / Float64(Float64(Float64(t_m * Float64(Float64(Float64(t_m * sin(k)) / l) * Float64(t_m / l))) * tan(k)) * fma(Float64(k / t_m), Float64(k / t_m), 2.0))); end return Float64(t_s * tmp) end
t\_m = N[Abs[t], $MachinePrecision]
t\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[t$95$s_, t$95$m_, l_, k_] := N[(t$95$s * If[LessEqual[t$95$m, 6.8e-81], N[(2.0 / N[(N[(N[(k * N[(k * N[(t$95$m * N[Power[N[Sin[k], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(l * N[Cos[k], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(N[(N[(t$95$m * N[(N[(N[(t$95$m * N[Sin[k], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * N[(t$95$m / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Tan[k], $MachinePrecision]), $MachinePrecision] * N[(N[(k / t$95$m), $MachinePrecision] * N[(k / t$95$m), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
t\_m = \left|t\right|
\\
t\_s = \mathsf{copysign}\left(1, t\right)
\\
t\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_m \leq 6.8 \cdot 10^{-81}:\\
\;\;\;\;\frac{2}{\frac{\frac{k \cdot \left(k \cdot \left(t\_m \cdot {\sin k}^{2}\right)\right)}{\ell \cdot \cos k}}{\ell}}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\left(\left(t\_m \cdot \left(\frac{t\_m \cdot \sin k}{\ell} \cdot \frac{t\_m}{\ell}\right)\right) \cdot \tan k\right) \cdot \mathsf{fma}\left(\frac{k}{t\_m}, \frac{k}{t\_m}, 2\right)}\\
\end{array}
\end{array}
if t < 6.7999999999999997e-81Initial program 37.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lift-*.f64N/A
associate-/r*N/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites22.3%
Taylor expanded in k around inf
lower-/.f64N/A
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-sin.f64N/A
lower-*.f64N/A
lower-cos.f6484.7
Applied rewrites84.7%
if 6.7999999999999997e-81 < t Initial program 70.8%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-invN/A
lift-pow.f64N/A
cube-multN/A
associate-*l*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-/.f6477.5
Applied rewrites77.5%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6491.6
Applied rewrites91.6%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
metadata-evalN/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6491.6
Applied rewrites91.6%
t\_m = (fabs.f64 t)
t\_s = (copysign.f64 #s(literal 1 binary64) t)
(FPCore (t_s t_m l k)
:precision binary64
(*
t_s
(if (<= t_m 6e+41)
(*
l
(/
(/ (* 2.0 l) (* (sin k) (* t_m (fma 2.0 (* t_m t_m) (* k k)))))
(tan k)))
(/
2.0
(*
(* (* t_m (* (/ (* t_m (sin k)) l) (/ t_m l))) (tan k))
(fma (/ k t_m) (/ k t_m) 2.0))))))t\_m = fabs(t);
t\_s = copysign(1.0, t);
double code(double t_s, double t_m, double l, double k) {
double tmp;
if (t_m <= 6e+41) {
tmp = l * (((2.0 * l) / (sin(k) * (t_m * fma(2.0, (t_m * t_m), (k * k))))) / tan(k));
} else {
tmp = 2.0 / (((t_m * (((t_m * sin(k)) / l) * (t_m / l))) * tan(k)) * fma((k / t_m), (k / t_m), 2.0));
}
return t_s * tmp;
}
t\_m = abs(t) t\_s = copysign(1.0, t) function code(t_s, t_m, l, k) tmp = 0.0 if (t_m <= 6e+41) tmp = Float64(l * Float64(Float64(Float64(2.0 * l) / Float64(sin(k) * Float64(t_m * fma(2.0, Float64(t_m * t_m), Float64(k * k))))) / tan(k))); else tmp = Float64(2.0 / Float64(Float64(Float64(t_m * Float64(Float64(Float64(t_m * sin(k)) / l) * Float64(t_m / l))) * tan(k)) * fma(Float64(k / t_m), Float64(k / t_m), 2.0))); end return Float64(t_s * tmp) end
t\_m = N[Abs[t], $MachinePrecision]
t\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[t]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[t$95$s_, t$95$m_, l_, k_] := N[(t$95$s * If[LessEqual[t$95$m, 6e+41], N[(l * N[(N[(N[(2.0 * l), $MachinePrecision] / N[(N[Sin[k], $MachinePrecision] * N[(t$95$m * N[(2.0 * N[(t$95$m * t$95$m), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Tan[k], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(N[(N[(t$95$m * N[(N[(N[(t$95$m * N[Sin[k], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision] * N[(t$95$m / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Tan[k], $MachinePrecision]), $MachinePrecision] * N[(N[(k / t$95$m), $MachinePrecision] * N[(k / t$95$m), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
t\_m = \left|t\right|
\\
t\_s = \mathsf{copysign}\left(1, t\right)
\\
t\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_m \leq 6 \cdot 10^{+41}:\\
\;\;\;\;\ell \cdot \frac{\frac{2 \cdot \ell}{\sin k \cdot \left(t\_m \cdot \mathsf{fma}\left(2, t\_m \cdot t\_m, k \cdot k\right)\right)}}{\tan k}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\left(\left(t\_m \cdot \left(\frac{t\_m \cdot \sin k}{\ell} \cdot \frac{t\_m}{\ell}\right)\right) \cdot \tan k\right) \cdot \mathsf{fma}\left(\frac{k}{t\_m}, \frac{k}{t\_m}, 2\right)}\\
\end{array}
\end{array}
if t < 5.9999999999999997e41Initial program 46.9%
lift-/.f64N/A
lift-pow.f64N/A
sqr-powN/A
lift-*.f64N/A
times-fracN/A
pow2N/A
lower-pow.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
metadata-eval59.5
Applied rewrites59.5%
Applied rewrites37.7%
Taylor expanded in t around 0
lower-*.f64N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-sin.f64N/A
+-commutativeN/A
unpow2N/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6480.4
Applied rewrites80.4%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lift-*.f64N/A
*-commutativeN/A
associate-/r*N/A
Applied rewrites82.6%
if 5.9999999999999997e41 < t Initial program 64.1%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
div-invN/A
lift-pow.f64N/A
cube-multN/A
associate-*l*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-/.f6474.0
Applied rewrites74.0%
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6490.4
Applied rewrites90.4%
lift-+.f64N/A
lift-+.f64N/A
+-commutativeN/A
associate-+l+N/A
metadata-evalN/A
lift-pow.f64N/A
unpow2N/A
lower-fma.f6490.4
Applied rewrites90.4%
Final simplification86.0%
herbie shell --seed 2024230
(FPCore (t l k)
:name "Toniolo and Linder, Equation (10+)"
:precision binary64
(/ 2.0 (* (* (* (/ (pow t 3.0) (* l l)) (sin k)) (tan k)) (+ (+ 1.0 (pow (/ k t) 2.0)) 1.0))))