
(FPCore (w0 M D h l d) :precision binary64 (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))
double code(double w0, double M, double D, double h, double l, double d) {
return w0 * sqrt((1.0 - (pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
real(8) function code(w0, m, d, h, l, d_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_1
code = w0 * sqrt((1.0d0 - ((((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l))))
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
return w0 * Math.sqrt((1.0 - (Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
def code(w0, M, D, h, l, d): return w0 * math.sqrt((1.0 - (math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))))
function code(w0, M, D, h, l, d) return Float64(w0 * sqrt(Float64(1.0 - Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))))) end
function tmp = code(w0, M, D, h, l, d) tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l)))); end
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (w0 M D h l d) :precision binary64 (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))
double code(double w0, double M, double D, double h, double l, double d) {
return w0 * sqrt((1.0 - (pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
real(8) function code(w0, m, d, h, l, d_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_1
code = w0 * sqrt((1.0d0 - ((((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l))))
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
return w0 * Math.sqrt((1.0 - (Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
def code(w0, M, D, h, l, d): return w0 * math.sqrt((1.0 - (math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))))
function code(w0, M, D, h, l, d) return Float64(w0 * sqrt(Float64(1.0 - Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l))))) end
function tmp = code(w0, M, D, h, l, d) tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l)))); end
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}
\end{array}
(FPCore (w0 M D h l d) :precision binary64 (let* ((t_0 (* (* M D) (/ 0.5 d)))) (* w0 (sqrt (- 1.0 (* t_0 (/ h (/ l t_0))))))))
double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = (M * D) * (0.5 / d);
return w0 * sqrt((1.0 - (t_0 * (h / (l / t_0)))));
}
real(8) function code(w0, m, d, h, l, d_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_1
real(8) :: t_0
t_0 = (m * d) * (0.5d0 / d_1)
code = w0 * sqrt((1.0d0 - (t_0 * (h / (l / t_0)))))
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = (M * D) * (0.5 / d);
return w0 * Math.sqrt((1.0 - (t_0 * (h / (l / t_0)))));
}
def code(w0, M, D, h, l, d): t_0 = (M * D) * (0.5 / d) return w0 * math.sqrt((1.0 - (t_0 * (h / (l / t_0)))))
function code(w0, M, D, h, l, d) t_0 = Float64(Float64(M * D) * Float64(0.5 / d)) return Float64(w0 * sqrt(Float64(1.0 - Float64(t_0 * Float64(h / Float64(l / t_0)))))) end
function tmp = code(w0, M, D, h, l, d) t_0 = (M * D) * (0.5 / d); tmp = w0 * sqrt((1.0 - (t_0 * (h / (l / t_0))))); end
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(N[(M * D), $MachinePrecision] * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]}, N[(w0 * N[Sqrt[N[(1.0 - N[(t$95$0 * N[(h / N[(l / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(M \cdot D\right) \cdot \frac{0.5}{d}\\
w0 \cdot \sqrt{1 - t_0 \cdot \frac{h}{\frac{\ell}{t_0}}}
\end{array}
\end{array}
Initial program 79.6%
Simplified79.2%
frac-times79.6%
*-commutative79.6%
expm1-log1p-u63.3%
expm1-udef63.3%
Applied egg-rr79.6%
add-exp-log63.3%
log1p-udef63.3%
expm1-udef63.3%
expm1-log1p-u79.6%
associate-*l/84.4%
associate-/l*84.8%
associate-*l*84.4%
Applied egg-rr84.4%
*-un-lft-identity84.4%
unpow284.4%
times-frac85.2%
*-commutative85.2%
associate-*r*83.4%
*-commutative83.4%
*-commutative83.4%
associate-*r*84.8%
*-commutative84.8%
Applied egg-rr84.8%
associate-*l/84.8%
*-lft-identity84.8%
Simplified84.8%
associate-/r/86.3%
associate-*r*84.8%
associate-*r*87.0%
Applied egg-rr87.0%
Final simplification87.0%
(FPCore (w0 M D h l d)
:precision binary64
(let* ((t_0 (* M (* D (/ 0.5 d)))))
(if (or (<= (/ h l) (- INFINITY)) (not (<= (/ h l) -2e-238)))
(+ w0 (* -0.125 (* w0 (/ (* h (pow (/ D (/ d M)) 2.0)) l))))
(* w0 (sqrt (- 1.0 (* t_0 (* (/ h l) t_0))))))))
double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = M * (D * (0.5 / d));
double tmp;
if (((h / l) <= -((double) INFINITY)) || !((h / l) <= -2e-238)) {
tmp = w0 + (-0.125 * (w0 * ((h * pow((D / (d / M)), 2.0)) / l)));
} else {
tmp = w0 * sqrt((1.0 - (t_0 * ((h / l) * t_0))));
}
return tmp;
}
public static double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = M * (D * (0.5 / d));
double tmp;
if (((h / l) <= -Double.POSITIVE_INFINITY) || !((h / l) <= -2e-238)) {
tmp = w0 + (-0.125 * (w0 * ((h * Math.pow((D / (d / M)), 2.0)) / l)));
} else {
tmp = w0 * Math.sqrt((1.0 - (t_0 * ((h / l) * t_0))));
}
return tmp;
}
def code(w0, M, D, h, l, d): t_0 = M * (D * (0.5 / d)) tmp = 0 if ((h / l) <= -math.inf) or not ((h / l) <= -2e-238): tmp = w0 + (-0.125 * (w0 * ((h * math.pow((D / (d / M)), 2.0)) / l))) else: tmp = w0 * math.sqrt((1.0 - (t_0 * ((h / l) * t_0)))) return tmp
function code(w0, M, D, h, l, d) t_0 = Float64(M * Float64(D * Float64(0.5 / d))) tmp = 0.0 if ((Float64(h / l) <= Float64(-Inf)) || !(Float64(h / l) <= -2e-238)) tmp = Float64(w0 + Float64(-0.125 * Float64(w0 * Float64(Float64(h * (Float64(D / Float64(d / M)) ^ 2.0)) / l)))); else tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(t_0 * Float64(Float64(h / l) * t_0))))); end return tmp end
function tmp_2 = code(w0, M, D, h, l, d) t_0 = M * (D * (0.5 / d)); tmp = 0.0; if (((h / l) <= -Inf) || ~(((h / l) <= -2e-238))) tmp = w0 + (-0.125 * (w0 * ((h * ((D / (d / M)) ^ 2.0)) / l))); else tmp = w0 * sqrt((1.0 - (t_0 * ((h / l) * t_0)))); end tmp_2 = tmp; end
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(M * N[(D * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[N[(h / l), $MachinePrecision], (-Infinity)], N[Not[LessEqual[N[(h / l), $MachinePrecision], -2e-238]], $MachinePrecision]], N[(w0 + N[(-0.125 * N[(w0 * N[(N[(h * N[Power[N[(D / N[(d / M), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(w0 * N[Sqrt[N[(1.0 - N[(t$95$0 * N[(N[(h / l), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := M \cdot \left(D \cdot \frac{0.5}{d}\right)\\
\mathbf{if}\;\frac{h}{\ell} \leq -\infty \lor \neg \left(\frac{h}{\ell} \leq -2 \cdot 10^{-238}\right):\\
\;\;\;\;w0 + -0.125 \cdot \left(w0 \cdot \frac{h \cdot {\left(\frac{D}{\frac{d}{M}}\right)}^{2}}{\ell}\right)\\
\mathbf{else}:\\
\;\;\;\;w0 \cdot \sqrt{1 - t_0 \cdot \left(\frac{h}{\ell} \cdot t_0\right)}\\
\end{array}
\end{array}
if (/.f64 h l) < -inf.0 or -2e-238 < (/.f64 h l) Initial program 80.3%
Simplified79.5%
Taylor expanded in D around 0 55.7%
expm1-log1p-u51.8%
expm1-udef51.8%
associate-*r*52.6%
pow-prod-down66.3%
*-commutative66.3%
Applied egg-rr66.3%
expm1-def66.3%
expm1-log1p71.0%
associate-*r*74.0%
*-commutative74.0%
times-frac71.1%
associate-/l*71.7%
Simplified71.7%
associate-*r/76.8%
add-sqr-sqrt66.5%
pow266.5%
sqrt-div32.0%
unpow232.0%
sqrt-prod20.3%
add-sqr-sqrt32.8%
sqrt-div32.9%
unpow232.9%
sqrt-prod19.2%
add-sqr-sqrt38.0%
Applied egg-rr38.0%
expm1-log1p-u35.4%
expm1-udef35.4%
associate-*r/32.5%
*-commutative32.5%
associate-/r/32.5%
unpow-prod-down32.5%
*-commutative32.5%
pow232.5%
add-sqr-sqrt79.3%
Applied egg-rr79.3%
expm1-def79.3%
expm1-log1p84.2%
associate-*l/88.7%
*-rgt-identity88.7%
associate-*r/88.7%
associate-*l*89.4%
associate-*r/89.4%
*-rgt-identity89.4%
*-commutative89.4%
*-commutative89.4%
associate-/l*88.7%
Simplified88.7%
if -inf.0 < (/.f64 h l) < -2e-238Initial program 78.8%
Simplified78.8%
frac-times78.8%
*-commutative78.8%
expm1-log1p-u50.4%
expm1-udef50.4%
Applied egg-rr78.8%
add-exp-log50.4%
log1p-udef50.4%
expm1-udef50.4%
expm1-log1p-u78.8%
associate-*l/77.1%
associate-/l*78.0%
associate-*l*78.0%
Applied egg-rr78.0%
*-un-lft-identity78.0%
unpow278.0%
times-frac78.0%
*-commutative78.0%
associate-*r*77.4%
*-commutative77.4%
*-commutative77.4%
associate-*r*79.0%
*-commutative79.0%
Applied egg-rr79.0%
associate-*l/79.0%
*-lft-identity79.0%
Simplified79.0%
associate-/r/81.4%
associate-*r*79.0%
associate-*r*79.6%
Applied egg-rr79.6%
*-commutative79.6%
associate-*l*79.0%
associate-/r/79.8%
associate-*l*82.3%
Simplified82.3%
Final simplification85.7%
(FPCore (w0 M D h l d) :precision binary64 (+ w0 (* -0.125 (* w0 (/ (* h (pow (/ D (/ d M)) 2.0)) l)))))
double code(double w0, double M, double D, double h, double l, double d) {
return w0 + (-0.125 * (w0 * ((h * pow((D / (d / M)), 2.0)) / l)));
}
real(8) function code(w0, m, d, h, l, d_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_1
code = w0 + ((-0.125d0) * (w0 * ((h * ((d / (d_1 / m)) ** 2.0d0)) / l)))
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
return w0 + (-0.125 * (w0 * ((h * Math.pow((D / (d / M)), 2.0)) / l)));
}
def code(w0, M, D, h, l, d): return w0 + (-0.125 * (w0 * ((h * math.pow((D / (d / M)), 2.0)) / l)))
function code(w0, M, D, h, l, d) return Float64(w0 + Float64(-0.125 * Float64(w0 * Float64(Float64(h * (Float64(D / Float64(d / M)) ^ 2.0)) / l)))) end
function tmp = code(w0, M, D, h, l, d) tmp = w0 + (-0.125 * (w0 * ((h * ((D / (d / M)) ^ 2.0)) / l))); end
code[w0_, M_, D_, h_, l_, d_] := N[(w0 + N[(-0.125 * N[(w0 * N[(N[(h * N[Power[N[(D / N[(d / M), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
w0 + -0.125 \cdot \left(w0 \cdot \frac{h \cdot {\left(\frac{D}{\frac{d}{M}}\right)}^{2}}{\ell}\right)
\end{array}
Initial program 79.6%
Simplified79.2%
Taylor expanded in D around 0 49.4%
expm1-log1p-u44.0%
expm1-udef44.0%
associate-*r*45.1%
pow-prod-down55.4%
*-commutative55.4%
Applied egg-rr55.4%
expm1-def55.4%
expm1-log1p62.5%
associate-*r*66.2%
*-commutative66.2%
times-frac62.4%
associate-/l*63.9%
Simplified63.9%
associate-*r/69.5%
add-sqr-sqrt58.5%
pow258.5%
sqrt-div33.0%
unpow233.0%
sqrt-prod20.6%
add-sqr-sqrt33.5%
sqrt-div33.6%
unpow233.6%
sqrt-prod19.4%
add-sqr-sqrt38.4%
Applied egg-rr38.4%
expm1-log1p-u35.2%
expm1-udef35.2%
associate-*r/32.0%
*-commutative32.0%
associate-/r/32.4%
unpow-prod-down32.3%
*-commutative32.3%
pow232.3%
add-sqr-sqrt67.4%
Applied egg-rr67.4%
expm1-def67.6%
expm1-log1p75.3%
associate-*l/80.1%
*-rgt-identity80.1%
associate-*r/80.1%
associate-*l*80.8%
associate-*r/80.8%
*-rgt-identity80.8%
*-commutative80.8%
*-commutative80.8%
associate-/l*80.2%
Simplified80.2%
Final simplification80.2%
(FPCore (w0 M D h l d) :precision binary64 w0)
double code(double w0, double M, double D, double h, double l, double d) {
return w0;
}
real(8) function code(w0, m, d, h, l, d_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_1
code = w0
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
return w0;
}
def code(w0, M, D, h, l, d): return w0
function code(w0, M, D, h, l, d) return w0 end
function tmp = code(w0, M, D, h, l, d) tmp = w0; end
code[w0_, M_, D_, h_, l_, d_] := w0
\begin{array}{l}
\\
w0
\end{array}
Initial program 79.6%
Simplified79.2%
Taylor expanded in D around 0 67.9%
Final simplification67.9%
herbie shell --seed 2023332
(FPCore (w0 M D h l d)
:name "Henrywood and Agarwal, Equation (9a)"
:precision binary64
(* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))