
(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 13 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}
k_m = (fabs.f64 k)
(FPCore (t l k_m)
:precision binary64
(if (<= k_m 2.55e-21)
(* (/ (+ l l) (* t (* k_m k_m))) (/ l (* k_m k_m)))
(*
(/ (* l (cos k_m)) k_m)
(/ (+ l l) (* (sin k_m) (* (sin k_m) (* k_m t)))))))k_m = fabs(k);
double code(double t, double l, double k_m) {
double tmp;
if (k_m <= 2.55e-21) {
tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m));
} else {
tmp = ((l * cos(k_m)) / k_m) * ((l + l) / (sin(k_m) * (sin(k_m) * (k_m * t))));
}
return tmp;
}
k_m = abs(k)
real(8) function code(t, l, k_m)
real(8), intent (in) :: t
real(8), intent (in) :: l
real(8), intent (in) :: k_m
real(8) :: tmp
if (k_m <= 2.55d-21) then
tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m))
else
tmp = ((l * cos(k_m)) / k_m) * ((l + l) / (sin(k_m) * (sin(k_m) * (k_m * t))))
end if
code = tmp
end function
k_m = Math.abs(k);
public static double code(double t, double l, double k_m) {
double tmp;
if (k_m <= 2.55e-21) {
tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m));
} else {
tmp = ((l * Math.cos(k_m)) / k_m) * ((l + l) / (Math.sin(k_m) * (Math.sin(k_m) * (k_m * t))));
}
return tmp;
}
k_m = math.fabs(k) def code(t, l, k_m): tmp = 0 if k_m <= 2.55e-21: tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m)) else: tmp = ((l * math.cos(k_m)) / k_m) * ((l + l) / (math.sin(k_m) * (math.sin(k_m) * (k_m * t)))) return tmp
k_m = abs(k) function code(t, l, k_m) tmp = 0.0 if (k_m <= 2.55e-21) tmp = Float64(Float64(Float64(l + l) / Float64(t * Float64(k_m * k_m))) * Float64(l / Float64(k_m * k_m))); else tmp = Float64(Float64(Float64(l * cos(k_m)) / k_m) * Float64(Float64(l + l) / Float64(sin(k_m) * Float64(sin(k_m) * Float64(k_m * t))))); end return tmp end
k_m = abs(k); function tmp_2 = code(t, l, k_m) tmp = 0.0; if (k_m <= 2.55e-21) tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m)); else tmp = ((l * cos(k_m)) / k_m) * ((l + l) / (sin(k_m) * (sin(k_m) * (k_m * t)))); end tmp_2 = tmp; end
k_m = N[Abs[k], $MachinePrecision] code[t_, l_, k$95$m_] := If[LessEqual[k$95$m, 2.55e-21], N[(N[(N[(l + l), $MachinePrecision] / N[(t * N[(k$95$m * k$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(l / N[(k$95$m * k$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(l * N[Cos[k$95$m], $MachinePrecision]), $MachinePrecision] / k$95$m), $MachinePrecision] * N[(N[(l + l), $MachinePrecision] / N[(N[Sin[k$95$m], $MachinePrecision] * N[(N[Sin[k$95$m], $MachinePrecision] * N[(k$95$m * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
k_m = \left|k\right|
\\
\begin{array}{l}
\mathbf{if}\;k\_m \leq 2.55 \cdot 10^{-21}:\\
\;\;\;\;\frac{\ell + \ell}{t \cdot \left(k\_m \cdot k\_m\right)} \cdot \frac{\ell}{k\_m \cdot k\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\ell \cdot \cos k\_m}{k\_m} \cdot \frac{\ell + \ell}{\sin k\_m \cdot \left(\sin k\_m \cdot \left(k\_m \cdot t\right)\right)}\\
\end{array}
\end{array}
if k < 2.55000000000000002e-21Initial program 41.5%
Taylor expanded in k around 0
associate-*r/N/A
lower-/.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
count-2N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
pow-sqrN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6468.4
Applied rewrites68.4%
Applied rewrites90.0%
if 2.55000000000000002e-21 < k Initial program 31.9%
Taylor expanded in t around 0
associate-*r/N/A
lower-/.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
count-2N/A
lower-+.f64N/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-sin.f6481.7
Applied rewrites81.7%
Applied rewrites91.8%
Applied rewrites94.8%
Applied rewrites94.8%
Final simplification92.6%
k_m = (fabs.f64 k) (FPCore (t l k_m) :precision binary64 (if (<= k_m 7.5e-10) (* (/ (+ l l) (* t (* k_m k_m))) (/ l (* k_m k_m))) (* (/ (* l (cos k_m)) k_m) (/ (+ l l) (* (pow (sin k_m) 2.0) (* k_m t))))))
k_m = fabs(k);
double code(double t, double l, double k_m) {
double tmp;
if (k_m <= 7.5e-10) {
tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m));
} else {
tmp = ((l * cos(k_m)) / k_m) * ((l + l) / (pow(sin(k_m), 2.0) * (k_m * t)));
}
return tmp;
}
k_m = abs(k)
real(8) function code(t, l, k_m)
real(8), intent (in) :: t
real(8), intent (in) :: l
real(8), intent (in) :: k_m
real(8) :: tmp
if (k_m <= 7.5d-10) then
tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m))
else
tmp = ((l * cos(k_m)) / k_m) * ((l + l) / ((sin(k_m) ** 2.0d0) * (k_m * t)))
end if
code = tmp
end function
k_m = Math.abs(k);
public static double code(double t, double l, double k_m) {
double tmp;
if (k_m <= 7.5e-10) {
tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m));
} else {
tmp = ((l * Math.cos(k_m)) / k_m) * ((l + l) / (Math.pow(Math.sin(k_m), 2.0) * (k_m * t)));
}
return tmp;
}
k_m = math.fabs(k) def code(t, l, k_m): tmp = 0 if k_m <= 7.5e-10: tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m)) else: tmp = ((l * math.cos(k_m)) / k_m) * ((l + l) / (math.pow(math.sin(k_m), 2.0) * (k_m * t))) return tmp
k_m = abs(k) function code(t, l, k_m) tmp = 0.0 if (k_m <= 7.5e-10) tmp = Float64(Float64(Float64(l + l) / Float64(t * Float64(k_m * k_m))) * Float64(l / Float64(k_m * k_m))); else tmp = Float64(Float64(Float64(l * cos(k_m)) / k_m) * Float64(Float64(l + l) / Float64((sin(k_m) ^ 2.0) * Float64(k_m * t)))); end return tmp end
k_m = abs(k); function tmp_2 = code(t, l, k_m) tmp = 0.0; if (k_m <= 7.5e-10) tmp = ((l + l) / (t * (k_m * k_m))) * (l / (k_m * k_m)); else tmp = ((l * cos(k_m)) / k_m) * ((l + l) / ((sin(k_m) ^ 2.0) * (k_m * t))); end tmp_2 = tmp; end
k_m = N[Abs[k], $MachinePrecision] code[t_, l_, k$95$m_] := If[LessEqual[k$95$m, 7.5e-10], N[(N[(N[(l + l), $MachinePrecision] / N[(t * N[(k$95$m * k$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(l / N[(k$95$m * k$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(l * N[Cos[k$95$m], $MachinePrecision]), $MachinePrecision] / k$95$m), $MachinePrecision] * N[(N[(l + l), $MachinePrecision] / N[(N[Power[N[Sin[k$95$m], $MachinePrecision], 2.0], $MachinePrecision] * N[(k$95$m * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
k_m = \left|k\right|
\\
\begin{array}{l}
\mathbf{if}\;k\_m \leq 7.5 \cdot 10^{-10}:\\
\;\;\;\;\frac{\ell + \ell}{t \cdot \left(k\_m \cdot k\_m\right)} \cdot \frac{\ell}{k\_m \cdot k\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\ell \cdot \cos k\_m}{k\_m} \cdot \frac{\ell + \ell}{{\sin k\_m}^{2} \cdot \left(k\_m \cdot t\right)}\\
\end{array}
\end{array}
if k < 7.49999999999999995e-10Initial program 40.6%
Taylor expanded in k around 0
associate-*r/N/A
lower-/.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
count-2N/A
lower-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
pow-sqrN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6473.6
Applied rewrites73.6%
Applied rewrites93.3%
if 7.49999999999999995e-10 < k Initial program 29.8%
Taylor expanded in t around 0
associate-*r/N/A
lower-/.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
count-2N/A
lower-+.f64N/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f64N/A
lower-sin.f6477.5
Applied rewrites77.5%
Applied rewrites93.1%
Applied rewrites94.2%
Final simplification93.8%
herbie shell --seed 2024223
(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))))