
(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 4 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}
(FPCore (t l k) :precision binary64 (if (<= (* l l) 5e+122) (* (* l (/ (/ 2.0 k) (* k t))) (/ (/ l (sin k)) (tan k))) (* 2.0 (* (pow (/ l k) 2.0) (/ (cos k) (* t (pow (sin k) 2.0)))))))
double code(double t, double l, double k) {
double tmp;
if ((l * l) <= 5e+122) {
tmp = (l * ((2.0 / k) / (k * t))) * ((l / sin(k)) / tan(k));
} else {
tmp = 2.0 * (pow((l / k), 2.0) * (cos(k) / (t * pow(sin(k), 2.0))));
}
return tmp;
}
real(8) function code(t, l, k)
real(8), intent (in) :: t
real(8), intent (in) :: l
real(8), intent (in) :: k
real(8) :: tmp
if ((l * l) <= 5d+122) then
tmp = (l * ((2.0d0 / k) / (k * t))) * ((l / sin(k)) / tan(k))
else
tmp = 2.0d0 * (((l / k) ** 2.0d0) * (cos(k) / (t * (sin(k) ** 2.0d0))))
end if
code = tmp
end function
public static double code(double t, double l, double k) {
double tmp;
if ((l * l) <= 5e+122) {
tmp = (l * ((2.0 / k) / (k * t))) * ((l / Math.sin(k)) / Math.tan(k));
} else {
tmp = 2.0 * (Math.pow((l / k), 2.0) * (Math.cos(k) / (t * Math.pow(Math.sin(k), 2.0))));
}
return tmp;
}
def code(t, l, k): tmp = 0 if (l * l) <= 5e+122: tmp = (l * ((2.0 / k) / (k * t))) * ((l / math.sin(k)) / math.tan(k)) else: tmp = 2.0 * (math.pow((l / k), 2.0) * (math.cos(k) / (t * math.pow(math.sin(k), 2.0)))) return tmp
function code(t, l, k) tmp = 0.0 if (Float64(l * l) <= 5e+122) tmp = Float64(Float64(l * Float64(Float64(2.0 / k) / Float64(k * t))) * Float64(Float64(l / sin(k)) / tan(k))); else tmp = Float64(2.0 * Float64((Float64(l / k) ^ 2.0) * Float64(cos(k) / Float64(t * (sin(k) ^ 2.0))))); end return tmp end
function tmp_2 = code(t, l, k) tmp = 0.0; if ((l * l) <= 5e+122) tmp = (l * ((2.0 / k) / (k * t))) * ((l / sin(k)) / tan(k)); else tmp = 2.0 * (((l / k) ^ 2.0) * (cos(k) / (t * (sin(k) ^ 2.0)))); end tmp_2 = tmp; end
code[t_, l_, k_] := If[LessEqual[N[(l * l), $MachinePrecision], 5e+122], N[(N[(l * N[(N[(2.0 / k), $MachinePrecision] / N[(k * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(l / N[Sin[k], $MachinePrecision]), $MachinePrecision] / N[Tan[k], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Power[N[(l / k), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Cos[k], $MachinePrecision] / N[(t * N[Power[N[Sin[k], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\ell \cdot \ell \leq 5 \cdot 10^{+122}:\\
\;\;\;\;\left(\ell \cdot \frac{\frac{2}{k}}{k \cdot t}\right) \cdot \frac{\frac{\ell}{\sin k}}{\tan k}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left({\left(\frac{\ell}{k}\right)}^{2} \cdot \frac{\cos k}{t \cdot {\sin k}^{2}}\right)\\
\end{array}
\end{array}
if (*.f64 l l) < 4.99999999999999989e122Initial program 34.4%
associate-*l*34.4%
associate-*l*34.4%
associate-/r*33.8%
associate-/r/33.3%
*-commutative33.3%
times-frac34.6%
+-commutative34.6%
associate--l+46.7%
metadata-eval46.7%
+-rgt-identity46.7%
times-frac54.8%
Simplified54.8%
Taylor expanded in t around 0 90.4%
unpow290.4%
Simplified90.4%
associate-*l/90.4%
associate-*l*94.6%
Applied egg-rr94.6%
associate-*l/94.5%
*-commutative94.5%
associate-*l*96.8%
Simplified96.8%
associate-*l/96.8%
Applied egg-rr96.8%
expm1-log1p-u80.5%
expm1-udef63.6%
associate-/l*63.6%
Applied egg-rr63.6%
expm1-def80.5%
expm1-log1p95.1%
associate-/r/96.8%
times-frac95.1%
*-commutative95.1%
associate-*r/90.9%
*-commutative90.9%
times-frac96.9%
associate-*r/96.9%
associate-/r*96.8%
Simplified96.8%
if 4.99999999999999989e122 < (*.f64 l l) Initial program 31.5%
associate-*l*31.5%
associate-*l*31.5%
associate-/r*31.5%
associate-/r/31.5%
*-commutative31.5%
times-frac31.7%
+-commutative31.7%
associate--l+32.8%
metadata-eval32.8%
+-rgt-identity32.8%
times-frac32.8%
Simplified32.8%
Taylor expanded in t around 0 56.7%
unpow256.7%
Simplified56.7%
associate-*l/56.7%
associate-*l*60.1%
Applied egg-rr60.1%
associate-*l/60.1%
*-commutative60.1%
associate-*l*73.1%
Simplified73.1%
associate-*l/73.1%
Applied egg-rr73.1%
Taylor expanded in l around 0 57.6%
*-commutative57.6%
times-frac56.9%
unpow256.9%
unpow256.9%
times-frac94.5%
unpow294.5%
*-commutative94.5%
Simplified94.5%
Final simplification96.0%
(FPCore (t l k) :precision binary64 (* (* l (/ (/ 2.0 k) (* k t))) (/ (/ l (sin k)) (tan k))))
double code(double t, double l, double k) {
return (l * ((2.0 / k) / (k * t))) * ((l / sin(k)) / tan(k));
}
real(8) function code(t, l, k)
real(8), intent (in) :: t
real(8), intent (in) :: l
real(8), intent (in) :: k
code = (l * ((2.0d0 / k) / (k * t))) * ((l / sin(k)) / tan(k))
end function
public static double code(double t, double l, double k) {
return (l * ((2.0 / k) / (k * t))) * ((l / Math.sin(k)) / Math.tan(k));
}
def code(t, l, k): return (l * ((2.0 / k) / (k * t))) * ((l / math.sin(k)) / math.tan(k))
function code(t, l, k) return Float64(Float64(l * Float64(Float64(2.0 / k) / Float64(k * t))) * Float64(Float64(l / sin(k)) / tan(k))) end
function tmp = code(t, l, k) tmp = (l * ((2.0 / k) / (k * t))) * ((l / sin(k)) / tan(k)); end
code[t_, l_, k_] := N[(N[(l * N[(N[(2.0 / k), $MachinePrecision] / N[(k * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(l / N[Sin[k], $MachinePrecision]), $MachinePrecision] / N[Tan[k], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\ell \cdot \frac{\frac{2}{k}}{k \cdot t}\right) \cdot \frac{\frac{\ell}{\sin k}}{\tan k}
\end{array}
Initial program 33.4%
associate-*l*33.4%
associate-*l*33.4%
associate-/r*33.0%
associate-/r/32.7%
*-commutative32.7%
times-frac33.5%
+-commutative33.5%
associate--l+41.7%
metadata-eval41.7%
+-rgt-identity41.7%
times-frac46.8%
Simplified46.8%
Taylor expanded in t around 0 78.2%
unpow278.2%
Simplified78.2%
associate-*l/78.2%
associate-*l*82.0%
Applied egg-rr82.0%
associate-*l/82.0%
*-commutative82.0%
associate-*l*88.2%
Simplified88.2%
associate-*l/88.2%
Applied egg-rr88.2%
expm1-log1p-u65.0%
expm1-udef53.1%
associate-/l*53.1%
Applied egg-rr53.1%
expm1-def65.0%
expm1-log1p87.1%
associate-/r/88.2%
times-frac87.1%
*-commutative87.1%
associate-*r/79.7%
*-commutative79.7%
times-frac88.2%
associate-*r/88.2%
associate-/r*89.0%
Simplified89.0%
Final simplification89.0%
(FPCore (t l k) :precision binary64 (* (/ l k) (* (/ l k) (/ 2.0 (* k (* k t))))))
double code(double t, double l, double k) {
return (l / k) * ((l / k) * (2.0 / (k * (k * t))));
}
real(8) function code(t, l, k)
real(8), intent (in) :: t
real(8), intent (in) :: l
real(8), intent (in) :: k
code = (l / k) * ((l / k) * (2.0d0 / (k * (k * t))))
end function
public static double code(double t, double l, double k) {
return (l / k) * ((l / k) * (2.0 / (k * (k * t))));
}
def code(t, l, k): return (l / k) * ((l / k) * (2.0 / (k * (k * t))))
function code(t, l, k) return Float64(Float64(l / k) * Float64(Float64(l / k) * Float64(2.0 / Float64(k * Float64(k * t))))) end
function tmp = code(t, l, k) tmp = (l / k) * ((l / k) * (2.0 / (k * (k * t)))); end
code[t_, l_, k_] := N[(N[(l / k), $MachinePrecision] * N[(N[(l / k), $MachinePrecision] * N[(2.0 / N[(k * N[(k * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\ell}{k} \cdot \left(\frac{\ell}{k} \cdot \frac{2}{k \cdot \left(k \cdot t\right)}\right)
\end{array}
Initial program 33.4%
associate-*l*33.4%
associate-*l*33.4%
associate-/r*33.0%
associate-/r/32.7%
*-commutative32.7%
times-frac33.5%
+-commutative33.5%
associate--l+41.7%
metadata-eval41.7%
+-rgt-identity41.7%
times-frac46.8%
Simplified46.8%
Taylor expanded in t around 0 78.2%
unpow278.2%
Simplified78.2%
associate-*l/78.2%
associate-*l*82.0%
Applied egg-rr82.0%
associate-*l/82.0%
*-commutative82.0%
associate-*l*88.2%
Simplified88.2%
Taylor expanded in k around 0 69.3%
Taylor expanded in k around 0 70.1%
Final simplification70.1%
(FPCore (t l k) :precision binary64 (/ (* 2.0 (* (/ l k) (/ l k))) (* k (* k t))))
double code(double t, double l, double k) {
return (2.0 * ((l / k) * (l / k))) / (k * (k * t));
}
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 * ((l / k) * (l / k))) / (k * (k * t))
end function
public static double code(double t, double l, double k) {
return (2.0 * ((l / k) * (l / k))) / (k * (k * t));
}
def code(t, l, k): return (2.0 * ((l / k) * (l / k))) / (k * (k * t))
function code(t, l, k) return Float64(Float64(2.0 * Float64(Float64(l / k) * Float64(l / k))) / Float64(k * Float64(k * t))) end
function tmp = code(t, l, k) tmp = (2.0 * ((l / k) * (l / k))) / (k * (k * t)); end
code[t_, l_, k_] := N[(N[(2.0 * N[(N[(l / k), $MachinePrecision] * N[(l / k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(k * N[(k * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2 \cdot \left(\frac{\ell}{k} \cdot \frac{\ell}{k}\right)}{k \cdot \left(k \cdot t\right)}
\end{array}
Initial program 33.4%
associate-*l*33.4%
associate-*l*33.4%
associate-/r*33.0%
associate-/r/32.7%
*-commutative32.7%
times-frac33.5%
+-commutative33.5%
associate--l+41.7%
metadata-eval41.7%
+-rgt-identity41.7%
times-frac46.8%
Simplified46.8%
Taylor expanded in t around 0 78.2%
unpow278.2%
Simplified78.2%
associate-*l/78.2%
associate-*l*82.0%
Applied egg-rr82.0%
Taylor expanded in k around 0 61.5%
unpow261.5%
unpow261.5%
times-frac70.5%
Simplified70.5%
Final simplification70.5%
herbie shell --seed 2023257
(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))))