
(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 (* (pow (/ (* D M) (* d 2.0)) 2.0) (/ h l)))) (if (<= t_0 2e-13) (* w0 (sqrt (- 1.0 t_0))) w0)))
double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = pow(((D * M) / (d * 2.0)), 2.0) * (h / l);
double tmp;
if (t_0 <= 2e-13) {
tmp = w0 * sqrt((1.0 - t_0));
} else {
tmp = w0;
}
return tmp;
}
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
real(8) :: tmp
t_0 = (((d * m) / (d_1 * 2.0d0)) ** 2.0d0) * (h / l)
if (t_0 <= 2d-13) then
tmp = w0 * sqrt((1.0d0 - t_0))
else
tmp = w0
end if
code = tmp
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
double t_0 = Math.pow(((D * M) / (d * 2.0)), 2.0) * (h / l);
double tmp;
if (t_0 <= 2e-13) {
tmp = w0 * Math.sqrt((1.0 - t_0));
} else {
tmp = w0;
}
return tmp;
}
def code(w0, M, D, h, l, d): t_0 = math.pow(((D * M) / (d * 2.0)), 2.0) * (h / l) tmp = 0 if t_0 <= 2e-13: tmp = w0 * math.sqrt((1.0 - t_0)) else: tmp = w0 return tmp
function code(w0, M, D, h, l, d) t_0 = Float64((Float64(Float64(D * M) / Float64(d * 2.0)) ^ 2.0) * Float64(h / l)) tmp = 0.0 if (t_0 <= 2e-13) tmp = Float64(w0 * sqrt(Float64(1.0 - t_0))); else tmp = w0; end return tmp end
function tmp_2 = code(w0, M, D, h, l, d) t_0 = (((D * M) / (d * 2.0)) ^ 2.0) * (h / l); tmp = 0.0; if (t_0 <= 2e-13) tmp = w0 * sqrt((1.0 - t_0)); else tmp = w0; end tmp_2 = tmp; end
code[w0_, M_, D_, h_, l_, d_] := Block[{t$95$0 = N[(N[Power[N[(N[(D * M), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-13], N[(w0 * N[Sqrt[N[(1.0 - t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(\frac{D \cdot M}{d \cdot 2}\right)}^{2} \cdot \frac{h}{\ell}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-13}:\\
\;\;\;\;w0 \cdot \sqrt{1 - t_0}\\
\mathbf{else}:\\
\;\;\;\;w0\\
\end{array}
\end{array}
if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) < 2.0000000000000001e-13Initial program 90.7%
if 2.0000000000000001e-13 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2) (/.f64 h l)) Initial program 0.0%
Simplified0.0%
Taylor expanded in D around 0 81.8%
Final simplification90.0%
(FPCore (w0 M D h l d) :precision binary64 (if (<= (/ h l) -2.95e-272) (* w0 (sqrt (- 1.0 (* (/ h l) (pow (* (/ D 2.0) (/ M d)) 2.0))))) w0))
double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if ((h / l) <= -2.95e-272) {
tmp = w0 * sqrt((1.0 - ((h / l) * pow(((D / 2.0) * (M / d)), 2.0))));
} else {
tmp = w0;
}
return tmp;
}
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) :: tmp
if ((h / l) <= (-2.95d-272)) then
tmp = w0 * sqrt((1.0d0 - ((h / l) * (((d / 2.0d0) * (m / d_1)) ** 2.0d0))))
else
tmp = w0
end if
code = tmp
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
double tmp;
if ((h / l) <= -2.95e-272) {
tmp = w0 * Math.sqrt((1.0 - ((h / l) * Math.pow(((D / 2.0) * (M / d)), 2.0))));
} else {
tmp = w0;
}
return tmp;
}
def code(w0, M, D, h, l, d): tmp = 0 if (h / l) <= -2.95e-272: tmp = w0 * math.sqrt((1.0 - ((h / l) * math.pow(((D / 2.0) * (M / d)), 2.0)))) else: tmp = w0 return tmp
function code(w0, M, D, h, l, d) tmp = 0.0 if (Float64(h / l) <= -2.95e-272) tmp = Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h / l) * (Float64(Float64(D / 2.0) * Float64(M / d)) ^ 2.0))))); else tmp = w0; end return tmp end
function tmp_2 = code(w0, M, D, h, l, d) tmp = 0.0; if ((h / l) <= -2.95e-272) tmp = w0 * sqrt((1.0 - ((h / l) * (((D / 2.0) * (M / d)) ^ 2.0)))); else tmp = w0; end tmp_2 = tmp; end
code[w0_, M_, D_, h_, l_, d_] := If[LessEqual[N[(h / l), $MachinePrecision], -2.95e-272], N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D / 2.0), $MachinePrecision] * N[(M / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], w0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{h}{\ell} \leq -2.95 \cdot 10^{-272}:\\
\;\;\;\;w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot {\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;w0\\
\end{array}
\end{array}
if (/.f64 h l) < -2.95e-272Initial program 78.1%
Simplified76.7%
if -2.95e-272 < (/.f64 h l) Initial program 90.4%
Simplified90.4%
Taylor expanded in D around 0 98.3%
Final simplification86.4%
(FPCore (w0 M D h l d) :precision binary64 (* w0 (sqrt (- 1.0 (/ (* h (pow (* (* D M) (/ 0.5 d)) 2.0)) l)))))
double code(double w0, double M, double D, double h, double l, double d) {
return w0 * sqrt((1.0 - ((h * pow(((D * M) * (0.5 / d)), 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 * sqrt((1.0d0 - ((h * (((d * m) * (0.5d0 / d_1)) ** 2.0d0)) / 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 - ((h * Math.pow(((D * M) * (0.5 / d)), 2.0)) / l)));
}
def code(w0, M, D, h, l, d): return w0 * math.sqrt((1.0 - ((h * math.pow(((D * M) * (0.5 / d)), 2.0)) / l)))
function code(w0, M, D, h, l, d) return Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(h * (Float64(Float64(D * M) * Float64(0.5 / d)) ^ 2.0)) / l)))) end
function tmp = code(w0, M, D, h, l, d) tmp = w0 * sqrt((1.0 - ((h * (((D * M) * (0.5 / d)) ^ 2.0)) / l))); end
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[(h * N[Power[N[(N[(D * M), $MachinePrecision] * N[(0.5 / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
w0 \cdot \sqrt{1 - \frac{h \cdot {\left(\left(D \cdot M\right) \cdot \frac{0.5}{d}\right)}^{2}}{\ell}}
\end{array}
Initial program 83.6%
Simplified82.9%
*-commutative82.9%
frac-times83.6%
*-commutative83.6%
associate-*l/89.3%
*-commutative89.3%
frac-times89.0%
frac-times89.3%
*-commutative89.3%
div-inv89.3%
*-commutative89.3%
associate-/r*89.3%
metadata-eval89.3%
Applied egg-rr89.3%
Final simplification89.3%
(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 83.6%
Simplified82.9%
Taylor expanded in D around 0 73.7%
Final simplification73.7%
herbie shell --seed 2023307
(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))))))