
(FPCore (v w r) :precision binary64 (- (- (+ 3.0 (/ 2.0 (* r r))) (/ (* (* 0.125 (- 3.0 (* 2.0 v))) (* (* (* w w) r) r)) (- 1.0 v))) 4.5))
double code(double v, double w, double r) {
return ((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 4.5;
}
real(8) function code(v, w, r)
real(8), intent (in) :: v
real(8), intent (in) :: w
real(8), intent (in) :: r
code = ((3.0d0 + (2.0d0 / (r * r))) - (((0.125d0 * (3.0d0 - (2.0d0 * v))) * (((w * w) * r) * r)) / (1.0d0 - v))) - 4.5d0
end function
public static double code(double v, double w, double r) {
return ((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 4.5;
}
def code(v, w, r): return ((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 4.5
function code(v, w, r) return Float64(Float64(Float64(3.0 + Float64(2.0 / Float64(r * r))) - Float64(Float64(Float64(0.125 * Float64(3.0 - Float64(2.0 * v))) * Float64(Float64(Float64(w * w) * r) * r)) / Float64(1.0 - v))) - 4.5) end
function tmp = code(v, w, r) tmp = ((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 4.5; end
code[v_, w_, r_] := N[(N[(N[(3.0 + N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(0.125 * N[(3.0 - N[(2.0 * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(w * w), $MachinePrecision] * r), $MachinePrecision] * r), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(3 + \frac{2}{r \cdot r}\right) - \frac{\left(0.125 \cdot \left(3 - 2 \cdot v\right)\right) \cdot \left(\left(\left(w \cdot w\right) \cdot r\right) \cdot r\right)}{1 - v}\right) - 4.5
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (v w r) :precision binary64 (- (- (+ 3.0 (/ 2.0 (* r r))) (/ (* (* 0.125 (- 3.0 (* 2.0 v))) (* (* (* w w) r) r)) (- 1.0 v))) 4.5))
double code(double v, double w, double r) {
return ((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 4.5;
}
real(8) function code(v, w, r)
real(8), intent (in) :: v
real(8), intent (in) :: w
real(8), intent (in) :: r
code = ((3.0d0 + (2.0d0 / (r * r))) - (((0.125d0 * (3.0d0 - (2.0d0 * v))) * (((w * w) * r) * r)) / (1.0d0 - v))) - 4.5d0
end function
public static double code(double v, double w, double r) {
return ((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 4.5;
}
def code(v, w, r): return ((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 4.5
function code(v, w, r) return Float64(Float64(Float64(3.0 + Float64(2.0 / Float64(r * r))) - Float64(Float64(Float64(0.125 * Float64(3.0 - Float64(2.0 * v))) * Float64(Float64(Float64(w * w) * r) * r)) / Float64(1.0 - v))) - 4.5) end
function tmp = code(v, w, r) tmp = ((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (((w * w) * r) * r)) / (1.0 - v))) - 4.5; end
code[v_, w_, r_] := N[(N[(N[(3.0 + N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(0.125 * N[(3.0 - N[(2.0 * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(w * w), $MachinePrecision] * r), $MachinePrecision] * r), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(3 + \frac{2}{r \cdot r}\right) - \frac{\left(0.125 \cdot \left(3 - 2 \cdot v\right)\right) \cdot \left(\left(\left(w \cdot w\right) \cdot r\right) \cdot r\right)}{1 - v}\right) - 4.5
\end{array}
(FPCore (v w r) :precision binary64 (+ (/ (/ 2.0 r) r) (- -1.5 (/ (fma v -0.25 0.375) (* (/ 1.0 (* r w)) (/ (/ (- 1.0 v) r) w))))))
double code(double v, double w, double r) {
return ((2.0 / r) / r) + (-1.5 - (fma(v, -0.25, 0.375) / ((1.0 / (r * w)) * (((1.0 - v) / r) / w))));
}
function code(v, w, r) return Float64(Float64(Float64(2.0 / r) / r) + Float64(-1.5 - Float64(fma(v, -0.25, 0.375) / Float64(Float64(1.0 / Float64(r * w)) * Float64(Float64(Float64(1.0 - v) / r) / w))))) end
code[v_, w_, r_] := N[(N[(N[(2.0 / r), $MachinePrecision] / r), $MachinePrecision] + N[(-1.5 - N[(N[(v * -0.25 + 0.375), $MachinePrecision] / N[(N[(1.0 / N[(r * w), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(1.0 - v), $MachinePrecision] / r), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{r}}{r} + \left(-1.5 - \frac{\mathsf{fma}\left(v, -0.25, 0.375\right)}{\frac{1}{r \cdot w} \cdot \frac{\frac{1 - v}{r}}{w}}\right)
\end{array}
Initial program 82.1%
Simplified97.1%
associate-/r*97.1%
*-un-lft-identity97.1%
*-commutative97.1%
times-frac99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (v w r)
:precision binary64
(if (<= r 5e-5)
(+ -1.5 (+ (* 2.0 (pow r -2.0)) (* -0.25 (* w (* r (* r w))))))
(+
(/ (/ 2.0 r) r)
(- -1.5 (/ (fma v -0.25 0.375) (/ (- 1.0 v) (* r (* w (* r w)))))))))
double code(double v, double w, double r) {
double tmp;
if (r <= 5e-5) {
tmp = -1.5 + ((2.0 * pow(r, -2.0)) + (-0.25 * (w * (r * (r * w)))));
} else {
tmp = ((2.0 / r) / r) + (-1.5 - (fma(v, -0.25, 0.375) / ((1.0 - v) / (r * (w * (r * w))))));
}
return tmp;
}
function code(v, w, r) tmp = 0.0 if (r <= 5e-5) tmp = Float64(-1.5 + Float64(Float64(2.0 * (r ^ -2.0)) + Float64(-0.25 * Float64(w * Float64(r * Float64(r * w)))))); else tmp = Float64(Float64(Float64(2.0 / r) / r) + Float64(-1.5 - Float64(fma(v, -0.25, 0.375) / Float64(Float64(1.0 - v) / Float64(r * Float64(w * Float64(r * w))))))); end return tmp end
code[v_, w_, r_] := If[LessEqual[r, 5e-5], N[(-1.5 + N[(N[(2.0 * N[Power[r, -2.0], $MachinePrecision]), $MachinePrecision] + N[(-0.25 * N[(w * N[(r * N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(2.0 / r), $MachinePrecision] / r), $MachinePrecision] + N[(-1.5 - N[(N[(v * -0.25 + 0.375), $MachinePrecision] / N[(N[(1.0 - v), $MachinePrecision] / N[(r * N[(w * N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;r \leq 5 \cdot 10^{-5}:\\
\;\;\;\;-1.5 + \left(2 \cdot {r}^{-2} + -0.25 \cdot \left(w \cdot \left(r \cdot \left(r \cdot w\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{r}}{r} + \left(-1.5 - \frac{\mathsf{fma}\left(v, -0.25, 0.375\right)}{\frac{1 - v}{r \cdot \left(w \cdot \left(r \cdot w\right)\right)}}\right)\\
\end{array}
\end{array}
if r < 5.00000000000000024e-5Initial program 81.5%
Simplified83.8%
expm1-log1p-u81.0%
expm1-udef81.0%
div-inv81.0%
pow281.0%
pow-flip81.0%
metadata-eval81.0%
Applied egg-rr81.0%
expm1-def81.0%
expm1-log1p83.9%
Simplified83.9%
Taylor expanded in v around inf 81.2%
*-commutative81.1%
Simplified81.2%
Taylor expanded in r around 0 78.5%
*-commutative78.5%
unpow278.5%
unpow278.5%
swap-sqr96.4%
unpow296.4%
Simplified96.4%
unpow296.4%
associate-*r*95.4%
Applied egg-rr95.4%
if 5.00000000000000024e-5 < r Initial program 84.7%
Simplified99.9%
Final simplification96.3%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (* (* r w) (* r w))) (t_1 (/ (/ 2.0 r) r)))
(if (or (<= v -64000000000.0) (not (<= v 2.2e-41)))
(+ t_1 (- -1.5 (* 0.25 t_0)))
(+ t_1 (- -1.5 (* 0.375 t_0))))))
double code(double v, double w, double r) {
double t_0 = (r * w) * (r * w);
double t_1 = (2.0 / r) / r;
double tmp;
if ((v <= -64000000000.0) || !(v <= 2.2e-41)) {
tmp = t_1 + (-1.5 - (0.25 * t_0));
} else {
tmp = t_1 + (-1.5 - (0.375 * t_0));
}
return tmp;
}
real(8) function code(v, w, r)
real(8), intent (in) :: v
real(8), intent (in) :: w
real(8), intent (in) :: r
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (r * w) * (r * w)
t_1 = (2.0d0 / r) / r
if ((v <= (-64000000000.0d0)) .or. (.not. (v <= 2.2d-41))) then
tmp = t_1 + ((-1.5d0) - (0.25d0 * t_0))
else
tmp = t_1 + ((-1.5d0) - (0.375d0 * t_0))
end if
code = tmp
end function
public static double code(double v, double w, double r) {
double t_0 = (r * w) * (r * w);
double t_1 = (2.0 / r) / r;
double tmp;
if ((v <= -64000000000.0) || !(v <= 2.2e-41)) {
tmp = t_1 + (-1.5 - (0.25 * t_0));
} else {
tmp = t_1 + (-1.5 - (0.375 * t_0));
}
return tmp;
}
def code(v, w, r): t_0 = (r * w) * (r * w) t_1 = (2.0 / r) / r tmp = 0 if (v <= -64000000000.0) or not (v <= 2.2e-41): tmp = t_1 + (-1.5 - (0.25 * t_0)) else: tmp = t_1 + (-1.5 - (0.375 * t_0)) return tmp
function code(v, w, r) t_0 = Float64(Float64(r * w) * Float64(r * w)) t_1 = Float64(Float64(2.0 / r) / r) tmp = 0.0 if ((v <= -64000000000.0) || !(v <= 2.2e-41)) tmp = Float64(t_1 + Float64(-1.5 - Float64(0.25 * t_0))); else tmp = Float64(t_1 + Float64(-1.5 - Float64(0.375 * t_0))); end return tmp end
function tmp_2 = code(v, w, r) t_0 = (r * w) * (r * w); t_1 = (2.0 / r) / r; tmp = 0.0; if ((v <= -64000000000.0) || ~((v <= 2.2e-41))) tmp = t_1 + (-1.5 - (0.25 * t_0)); else tmp = t_1 + (-1.5 - (0.375 * t_0)); end tmp_2 = tmp; end
code[v_, w_, r_] := Block[{t$95$0 = N[(N[(r * w), $MachinePrecision] * N[(r * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(2.0 / r), $MachinePrecision] / r), $MachinePrecision]}, If[Or[LessEqual[v, -64000000000.0], N[Not[LessEqual[v, 2.2e-41]], $MachinePrecision]], N[(t$95$1 + N[(-1.5 - N[(0.25 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(-1.5 - N[(0.375 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(r \cdot w\right) \cdot \left(r \cdot w\right)\\
t_1 := \frac{\frac{2}{r}}{r}\\
\mathbf{if}\;v \leq -64000000000 \lor \neg \left(v \leq 2.2 \cdot 10^{-41}\right):\\
\;\;\;\;t_1 + \left(-1.5 - 0.25 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;t_1 + \left(-1.5 - 0.375 \cdot t_0\right)\\
\end{array}
\end{array}
if v < -6.4e10 or 2.2e-41 < v Initial program 79.6%
Simplified97.0%
Taylor expanded in v around inf 81.1%
unpow281.1%
unpow281.1%
swap-sqr99.7%
unpow299.7%
Simplified99.7%
unpow299.7%
Applied egg-rr99.7%
if -6.4e10 < v < 2.2e-41Initial program 85.3%
Simplified97.2%
associate-/r*97.2%
*-un-lft-identity97.2%
*-commutative97.2%
times-frac99.8%
Applied egg-rr99.8%
frac-2neg99.8%
metadata-eval99.8%
frac-times97.2%
neg-mul-197.2%
distribute-neg-frac97.2%
distribute-rgt-neg-in97.2%
Applied egg-rr97.2%
Taylor expanded in v around 0 78.0%
*-commutative78.0%
unpow278.0%
unpow278.0%
swap-sqr99.8%
unpow299.8%
Simplified99.8%
unpow287.2%
Applied egg-rr99.8%
Final simplification99.7%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (* r (* w w))) (t_1 (/ 2.0 (* r r))))
(if (<= v -80000000000.0)
(+ -1.5 (+ t_1 (* (* r -0.25) t_0)))
(+ -1.5 (+ t_1 (* t_0 (* r -0.375)))))))
double code(double v, double w, double r) {
double t_0 = r * (w * w);
double t_1 = 2.0 / (r * r);
double tmp;
if (v <= -80000000000.0) {
tmp = -1.5 + (t_1 + ((r * -0.25) * t_0));
} else {
tmp = -1.5 + (t_1 + (t_0 * (r * -0.375)));
}
return tmp;
}
real(8) function code(v, w, r)
real(8), intent (in) :: v
real(8), intent (in) :: w
real(8), intent (in) :: r
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = r * (w * w)
t_1 = 2.0d0 / (r * r)
if (v <= (-80000000000.0d0)) then
tmp = (-1.5d0) + (t_1 + ((r * (-0.25d0)) * t_0))
else
tmp = (-1.5d0) + (t_1 + (t_0 * (r * (-0.375d0))))
end if
code = tmp
end function
public static double code(double v, double w, double r) {
double t_0 = r * (w * w);
double t_1 = 2.0 / (r * r);
double tmp;
if (v <= -80000000000.0) {
tmp = -1.5 + (t_1 + ((r * -0.25) * t_0));
} else {
tmp = -1.5 + (t_1 + (t_0 * (r * -0.375)));
}
return tmp;
}
def code(v, w, r): t_0 = r * (w * w) t_1 = 2.0 / (r * r) tmp = 0 if v <= -80000000000.0: tmp = -1.5 + (t_1 + ((r * -0.25) * t_0)) else: tmp = -1.5 + (t_1 + (t_0 * (r * -0.375))) return tmp
function code(v, w, r) t_0 = Float64(r * Float64(w * w)) t_1 = Float64(2.0 / Float64(r * r)) tmp = 0.0 if (v <= -80000000000.0) tmp = Float64(-1.5 + Float64(t_1 + Float64(Float64(r * -0.25) * t_0))); else tmp = Float64(-1.5 + Float64(t_1 + Float64(t_0 * Float64(r * -0.375)))); end return tmp end
function tmp_2 = code(v, w, r) t_0 = r * (w * w); t_1 = 2.0 / (r * r); tmp = 0.0; if (v <= -80000000000.0) tmp = -1.5 + (t_1 + ((r * -0.25) * t_0)); else tmp = -1.5 + (t_1 + (t_0 * (r * -0.375))); end tmp_2 = tmp; end
code[v_, w_, r_] := Block[{t$95$0 = N[(r * N[(w * w), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[v, -80000000000.0], N[(-1.5 + N[(t$95$1 + N[(N[(r * -0.25), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.5 + N[(t$95$1 + N[(t$95$0 * N[(r * -0.375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := r \cdot \left(w \cdot w\right)\\
t_1 := \frac{2}{r \cdot r}\\
\mathbf{if}\;v \leq -80000000000:\\
\;\;\;\;-1.5 + \left(t_1 + \left(r \cdot -0.25\right) \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-1.5 + \left(t_1 + t_0 \cdot \left(r \cdot -0.375\right)\right)\\
\end{array}
\end{array}
if v < -8e10Initial program 76.5%
Simplified83.6%
Taylor expanded in v around inf 83.5%
*-commutative83.5%
Simplified83.5%
if -8e10 < v Initial program 84.6%
Simplified86.2%
Taylor expanded in v around 0 84.0%
*-commutative84.0%
Simplified84.0%
Final simplification83.9%
(FPCore (v w r) :precision binary64 (+ -1.5 (+ (/ 2.0 (* r r)) (* (* r (* w w)) (* r -0.375)))))
double code(double v, double w, double r) {
return -1.5 + ((2.0 / (r * r)) + ((r * (w * w)) * (r * -0.375)));
}
real(8) function code(v, w, r)
real(8), intent (in) :: v
real(8), intent (in) :: w
real(8), intent (in) :: r
code = (-1.5d0) + ((2.0d0 / (r * r)) + ((r * (w * w)) * (r * (-0.375d0))))
end function
public static double code(double v, double w, double r) {
return -1.5 + ((2.0 / (r * r)) + ((r * (w * w)) * (r * -0.375)));
}
def code(v, w, r): return -1.5 + ((2.0 / (r * r)) + ((r * (w * w)) * (r * -0.375)))
function code(v, w, r) return Float64(-1.5 + Float64(Float64(2.0 / Float64(r * r)) + Float64(Float64(r * Float64(w * w)) * Float64(r * -0.375)))) end
function tmp = code(v, w, r) tmp = -1.5 + ((2.0 / (r * r)) + ((r * (w * w)) * (r * -0.375))); end
code[v_, w_, r_] := N[(-1.5 + N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[(N[(r * N[(w * w), $MachinePrecision]), $MachinePrecision] * N[(r * -0.375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1.5 + \left(\frac{2}{r \cdot r} + \left(r \cdot \left(w \cdot w\right)\right) \cdot \left(r \cdot -0.375\right)\right)
\end{array}
Initial program 82.1%
Simplified85.4%
Taylor expanded in v around 0 81.1%
*-commutative81.1%
Simplified81.1%
Final simplification81.1%
(FPCore (v w r) :precision binary64 (+ (/ (/ 2.0 r) r) (- -1.5 (* 0.25 (* (* r w) (* r w))))))
double code(double v, double w, double r) {
return ((2.0 / r) / r) + (-1.5 - (0.25 * ((r * w) * (r * w))));
}
real(8) function code(v, w, r)
real(8), intent (in) :: v
real(8), intent (in) :: w
real(8), intent (in) :: r
code = ((2.0d0 / r) / r) + ((-1.5d0) - (0.25d0 * ((r * w) * (r * w))))
end function
public static double code(double v, double w, double r) {
return ((2.0 / r) / r) + (-1.5 - (0.25 * ((r * w) * (r * w))));
}
def code(v, w, r): return ((2.0 / r) / r) + (-1.5 - (0.25 * ((r * w) * (r * w))))
function code(v, w, r) return Float64(Float64(Float64(2.0 / r) / r) + Float64(-1.5 - Float64(0.25 * Float64(Float64(r * w) * Float64(r * w))))) end
function tmp = code(v, w, r) tmp = ((2.0 / r) / r) + (-1.5 - (0.25 * ((r * w) * (r * w)))); end
code[v_, w_, r_] := N[(N[(N[(2.0 / r), $MachinePrecision] / r), $MachinePrecision] + N[(-1.5 - N[(0.25 * N[(N[(r * w), $MachinePrecision] * N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{r}}{r} + \left(-1.5 - 0.25 \cdot \left(\left(r \cdot w\right) \cdot \left(r \cdot w\right)\right)\right)
\end{array}
Initial program 82.1%
Simplified97.1%
Taylor expanded in v around inf 76.4%
unpow276.4%
unpow276.4%
swap-sqr94.2%
unpow294.2%
Simplified94.2%
unpow294.2%
Applied egg-rr94.2%
Final simplification94.2%
herbie shell --seed 2024024
(FPCore (v w r)
:name "Rosa's TurbineBenchmark"
:precision binary64
(- (- (+ 3.0 (/ 2.0 (* r r))) (/ (* (* 0.125 (- 3.0 (* 2.0 v))) (* (* (* w w) r) r)) (- 1.0 v))) 4.5))