
(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 3 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}
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
(FPCore (w0 M_m D_m h l d_m)
:precision binary64
(let* ((t_0 (/ (* M_m D_m) (* 2.0 d_m))) (t_1 (* (pow t_0 2.0) (/ h l))))
(if (<= t_1 -4e+297)
(* (sqrt (/ (* h -0.25) l)) (* D_m (/ (* M_m w0) d_m)))
(if (<= t_1 1.0)
(* w0 (sqrt (- 1.0 (* (/ h l) (* (/ (* (* M_m D_m) 0.5) d_m) t_0)))))
w0))))M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
double t_0 = (M_m * D_m) / (2.0 * d_m);
double t_1 = pow(t_0, 2.0) * (h / l);
double tmp;
if (t_1 <= -4e+297) {
tmp = sqrt(((h * -0.25) / l)) * (D_m * ((M_m * w0) / d_m));
} else if (t_1 <= 1.0) {
tmp = w0 * sqrt((1.0 - ((h / l) * ((((M_m * D_m) * 0.5) / d_m) * t_0))));
} else {
tmp = w0;
}
return tmp;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_m_1
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (m_m * d_m) / (2.0d0 * d_m_1)
t_1 = (t_0 ** 2.0d0) * (h / l)
if (t_1 <= (-4d+297)) then
tmp = sqrt(((h * (-0.25d0)) / l)) * (d_m * ((m_m * w0) / d_m_1))
else if (t_1 <= 1.0d0) then
tmp = w0 * sqrt((1.0d0 - ((h / l) * ((((m_m * d_m) * 0.5d0) / d_m_1) * t_0))))
else
tmp = w0
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
double t_0 = (M_m * D_m) / (2.0 * d_m);
double t_1 = Math.pow(t_0, 2.0) * (h / l);
double tmp;
if (t_1 <= -4e+297) {
tmp = Math.sqrt(((h * -0.25) / l)) * (D_m * ((M_m * w0) / d_m));
} else if (t_1 <= 1.0) {
tmp = w0 * Math.sqrt((1.0 - ((h / l) * ((((M_m * D_m) * 0.5) / d_m) * t_0))));
} else {
tmp = w0;
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) d_m = math.fabs(d) def code(w0, M_m, D_m, h, l, d_m): t_0 = (M_m * D_m) / (2.0 * d_m) t_1 = math.pow(t_0, 2.0) * (h / l) tmp = 0 if t_1 <= -4e+297: tmp = math.sqrt(((h * -0.25) / l)) * (D_m * ((M_m * w0) / d_m)) elif t_1 <= 1.0: tmp = w0 * math.sqrt((1.0 - ((h / l) * ((((M_m * D_m) * 0.5) / d_m) * t_0)))) else: tmp = w0 return tmp
M_m = abs(M) D_m = abs(D) d_m = abs(d) function code(w0, M_m, D_m, h, l, d_m) t_0 = Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) t_1 = Float64((t_0 ^ 2.0) * Float64(h / l)) tmp = 0.0 if (t_1 <= -4e+297) tmp = Float64(sqrt(Float64(Float64(h * -0.25) / l)) * Float64(D_m * Float64(Float64(M_m * w0) / d_m))); elseif (t_1 <= 1.0) tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) * Float64(Float64(Float64(Float64(M_m * D_m) * 0.5) / d_m) * t_0))))); else tmp = w0; end return tmp end
M_m = abs(M); D_m = abs(D); d_m = abs(d); function tmp_2 = code(w0, M_m, D_m, h, l, d_m) t_0 = (M_m * D_m) / (2.0 * d_m); t_1 = (t_0 ^ 2.0) * (h / l); tmp = 0.0; if (t_1 <= -4e+297) tmp = sqrt(((h * -0.25) / l)) * (D_m * ((M_m * w0) / d_m)); elseif (t_1 <= 1.0) tmp = w0 * sqrt((1.0 - ((h / l) * ((((M_m * D_m) * 0.5) / d_m) * t_0)))); else tmp = w0; end tmp_2 = tmp; end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[t$95$0, 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -4e+297], N[(N[Sqrt[N[(N[(h * -0.25), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision] * N[(D$95$m * N[(N[(M$95$m * w0), $MachinePrecision] / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1.0], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * 0.5), $MachinePrecision] / d$95$m), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
\begin{array}{l}
t_0 := \frac{M\_m \cdot D\_m}{2 \cdot d\_m}\\
t_1 := {t\_0}^{2} \cdot \frac{h}{\ell}\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+297}:\\
\;\;\;\;\sqrt{\frac{h \cdot -0.25}{\ell}} \cdot \left(D\_m \cdot \frac{M\_m \cdot w0}{d\_m}\right)\\
\mathbf{elif}\;t\_1 \leq 1:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{\left(M\_m \cdot D\_m\right) \cdot 0.5}{d\_m} \cdot t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;w0\\
\end{array}
\end{array}
if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < -4.0000000000000001e297Initial program 57.6%
Simplified57.6%
clear-num57.6%
un-div-inv57.6%
associate-/l*57.6%
Applied egg-rr57.6%
associate-*r/59.1%
associate-*r/59.1%
*-commutative59.1%
Applied egg-rr59.1%
add-cube-cbrt59.1%
pow359.1%
associate-/r/59.1%
Applied egg-rr59.1%
Taylor expanded in h around -inf 0.0%
mul-1-neg0.0%
distribute-rgt-neg-in0.0%
associate-/l*0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt51.1%
mul-1-neg51.1%
rem-cube-cbrt51.1%
Simplified51.1%
if -4.0000000000000001e297 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < 1Initial program 99.9%
Simplified98.2%
associate-*r/99.9%
unpow299.9%
associate-/r*99.9%
frac-times79.9%
associate-/l*79.9%
div-inv79.9%
metadata-eval79.9%
Applied egg-rr79.9%
times-frac99.9%
associate-*r*99.9%
*-commutative99.9%
Applied egg-rr99.9%
if 1 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) Initial program 0.0%
Simplified0.0%
Taylor expanded in M around 0 71.1%
Final simplification84.6%
M_m = (fabs.f64 M) D_m = (fabs.f64 D) d_m = (fabs.f64 d) (FPCore (w0 M_m D_m h l d_m) :precision binary64 (if (<= (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)) -4000.0) (* w0 (* (sqrt (/ (* h -0.25) l)) (* D_m (/ M_m d_m)))) w0))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
double tmp;
if ((pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -4000.0) {
tmp = w0 * (sqrt(((h * -0.25) / l)) * (D_m * (M_m / d_m)));
} else {
tmp = w0;
}
return tmp;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_m_1
real(8) :: tmp
if (((((m_m * d_m) / (2.0d0 * d_m_1)) ** 2.0d0) * (h / l)) <= (-4000.0d0)) then
tmp = w0 * (sqrt(((h * (-0.25d0)) / l)) * (d_m * (m_m / d_m_1)))
else
tmp = w0
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
double tmp;
if ((Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -4000.0) {
tmp = w0 * (Math.sqrt(((h * -0.25) / l)) * (D_m * (M_m / d_m)));
} else {
tmp = w0;
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) d_m = math.fabs(d) def code(w0, M_m, D_m, h, l, d_m): tmp = 0 if (math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -4000.0: tmp = w0 * (math.sqrt(((h * -0.25) / l)) * (D_m * (M_m / d_m))) else: tmp = w0 return tmp
M_m = abs(M) D_m = abs(D) d_m = abs(d) function code(w0, M_m, D_m, h, l, d_m) tmp = 0.0 if (Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)) <= -4000.0) tmp = Float64(w0 * Float64(sqrt(Float64(Float64(h * -0.25) / l)) * Float64(D_m * Float64(M_m / d_m)))); else tmp = w0; end return tmp end
M_m = abs(M); D_m = abs(D); d_m = abs(d); function tmp_2 = code(w0, M_m, D_m, h, l, d_m) tmp = 0.0; if (((((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l)) <= -4000.0) tmp = w0 * (sqrt(((h * -0.25) / l)) * (D_m * (M_m / d_m))); else tmp = w0; end tmp_2 = tmp; end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] d_m = N[Abs[d], $MachinePrecision] code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := If[LessEqual[N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], -4000.0], N[(w0 * N[(N[Sqrt[N[(N[(h * -0.25), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision] * N[(D$95$m * N[(M$95$m / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], w0]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
\begin{array}{l}
\mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -4000:\\
\;\;\;\;w0 \cdot \left(\sqrt{\frac{h \cdot -0.25}{\ell}} \cdot \left(D\_m \cdot \frac{M\_m}{d\_m}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;w0\\
\end{array}
\end{array}
if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < -4e3Initial program 65.8%
Simplified63.5%
clear-num63.5%
un-div-inv63.5%
associate-/l*63.5%
Applied egg-rr63.5%
associate-*r/64.7%
associate-*r/64.7%
*-commutative64.7%
Applied egg-rr64.7%
add-cube-cbrt64.6%
pow364.6%
associate-/r/64.6%
Applied egg-rr64.6%
Taylor expanded in h around -inf 0.0%
mul-1-neg0.0%
distribute-rgt-neg-in0.0%
associate-/l*0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt43.0%
mul-1-neg43.0%
rem-cube-cbrt43.0%
Simplified43.0%
if -4e3 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) Initial program 85.1%
Simplified84.5%
Taylor expanded in M around 0 94.8%
Final simplification78.5%
M_m = (fabs.f64 M) D_m = (fabs.f64 D) d_m = (fabs.f64 d) (FPCore (w0 M_m D_m h l d_m) :precision binary64 w0)
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
return w0;
}
M_m = abs(m)
D_m = abs(d)
d_m = abs(d)
real(8) function code(w0, m_m, d_m, h, l, d_m_1)
real(8), intent (in) :: w0
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: d_m_1
code = w0
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
public static double code(double w0, double M_m, double D_m, double h, double l, double d_m) {
return w0;
}
M_m = math.fabs(M) D_m = math.fabs(D) d_m = math.fabs(d) def code(w0, M_m, D_m, h, l, d_m): return w0
M_m = abs(M) D_m = abs(D) d_m = abs(d) function code(w0, M_m, D_m, h, l, d_m) return w0 end
M_m = abs(M); D_m = abs(D); d_m = abs(d); function tmp = code(w0, M_m, D_m, h, l, d_m) tmp = w0; end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] d_m = N[Abs[d], $MachinePrecision] code[w0_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := w0
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
w0
\end{array}
Initial program 79.0%
Simplified77.9%
Taylor expanded in M around 0 66.5%
herbie shell --seed 2024191
(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))))))