
(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 5 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)) (+ (/ (* 0.125 (fma v -2.0 3.0)) (/ (+ v -1.0) (pow (* r w) 2.0))) -1.5)))
double code(double v, double w, double r) {
return (2.0 / (r * r)) + (((0.125 * fma(v, -2.0, 3.0)) / ((v + -1.0) / pow((r * w), 2.0))) + -1.5);
}
function code(v, w, r) return Float64(Float64(2.0 / Float64(r * r)) + Float64(Float64(Float64(0.125 * fma(v, -2.0, 3.0)) / Float64(Float64(v + -1.0) / (Float64(r * w) ^ 2.0))) + -1.5)) end
code[v_, w_, r_] := N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(0.125 * N[(v * -2.0 + 3.0), $MachinePrecision]), $MachinePrecision] / N[(N[(v + -1.0), $MachinePrecision] / N[Power[N[(r * w), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{r \cdot r} + \left(\frac{0.125 \cdot \mathsf{fma}\left(v, -2, 3\right)}{\frac{v + -1}{{\left(r \cdot w\right)}^{2}}} + -1.5\right)
\end{array}
Initial program 84.6%
Simplified88.9%
clear-num89.0%
un-div-inv88.9%
associate-*r*81.5%
pow281.5%
pow281.5%
pow-prod-down99.8%
Applied egg-rr99.8%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (/ 2.0 (* r r))))
(if (or (<= v -10000000.0) (not (<= v 4e-32)))
(+ t_0 (+ -1.5 (* -0.25 (/ (* r w) (/ (/ 1.0 r) w)))))
(+ t_0 (- -1.5 (* 0.375 (* (* r w) (* r w))))))))
double code(double v, double w, double r) {
double t_0 = 2.0 / (r * r);
double tmp;
if ((v <= -10000000.0) || !(v <= 4e-32)) {
tmp = t_0 + (-1.5 + (-0.25 * ((r * w) / ((1.0 / r) / w))));
} else {
tmp = t_0 + (-1.5 - (0.375 * ((r * w) * (r * w))));
}
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) :: tmp
t_0 = 2.0d0 / (r * r)
if ((v <= (-10000000.0d0)) .or. (.not. (v <= 4d-32))) then
tmp = t_0 + ((-1.5d0) + ((-0.25d0) * ((r * w) / ((1.0d0 / r) / w))))
else
tmp = t_0 + ((-1.5d0) - (0.375d0 * ((r * w) * (r * w))))
end if
code = tmp
end function
public static double code(double v, double w, double r) {
double t_0 = 2.0 / (r * r);
double tmp;
if ((v <= -10000000.0) || !(v <= 4e-32)) {
tmp = t_0 + (-1.5 + (-0.25 * ((r * w) / ((1.0 / r) / w))));
} else {
tmp = t_0 + (-1.5 - (0.375 * ((r * w) * (r * w))));
}
return tmp;
}
def code(v, w, r): t_0 = 2.0 / (r * r) tmp = 0 if (v <= -10000000.0) or not (v <= 4e-32): tmp = t_0 + (-1.5 + (-0.25 * ((r * w) / ((1.0 / r) / w)))) else: tmp = t_0 + (-1.5 - (0.375 * ((r * w) * (r * w)))) return tmp
function code(v, w, r) t_0 = Float64(2.0 / Float64(r * r)) tmp = 0.0 if ((v <= -10000000.0) || !(v <= 4e-32)) tmp = Float64(t_0 + Float64(-1.5 + Float64(-0.25 * Float64(Float64(r * w) / Float64(Float64(1.0 / r) / w))))); else tmp = Float64(t_0 + Float64(-1.5 - Float64(0.375 * Float64(Float64(r * w) * Float64(r * w))))); end return tmp end
function tmp_2 = code(v, w, r) t_0 = 2.0 / (r * r); tmp = 0.0; if ((v <= -10000000.0) || ~((v <= 4e-32))) tmp = t_0 + (-1.5 + (-0.25 * ((r * w) / ((1.0 / r) / w)))); else tmp = t_0 + (-1.5 - (0.375 * ((r * w) * (r * w)))); end tmp_2 = tmp; end
code[v_, w_, r_] := Block[{t$95$0 = N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[v, -10000000.0], N[Not[LessEqual[v, 4e-32]], $MachinePrecision]], N[(t$95$0 + N[(-1.5 + N[(-0.25 * N[(N[(r * w), $MachinePrecision] / N[(N[(1.0 / r), $MachinePrecision] / w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[(-1.5 - N[(0.375 * N[(N[(r * w), $MachinePrecision] * N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{r \cdot r}\\
\mathbf{if}\;v \leq -10000000 \lor \neg \left(v \leq 4 \cdot 10^{-32}\right):\\
\;\;\;\;t\_0 + \left(-1.5 + -0.25 \cdot \frac{r \cdot w}{\frac{\frac{1}{r}}{w}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 + \left(-1.5 - 0.375 \cdot \left(\left(r \cdot w\right) \cdot \left(r \cdot w\right)\right)\right)\\
\end{array}
\end{array}
if v < -1e7 or 4.00000000000000022e-32 < v Initial program 82.5%
Simplified90.6%
Taylor expanded in v around inf 84.7%
*-commutative84.7%
unpow284.7%
unpow284.7%
swap-sqr99.6%
unpow299.6%
Simplified99.6%
unpow299.6%
Applied egg-rr99.6%
/-rgt-identity99.6%
clear-num99.6%
div-inv99.6%
associate-/r*99.6%
Applied egg-rr99.6%
if -1e7 < v < 4.00000000000000022e-32Initial program 87.1%
Simplified87.1%
add-sqr-sqrt87.0%
associate-/l*87.0%
sqrt-prod39.4%
sqrt-prod39.5%
sqrt-prod20.1%
add-sqr-sqrt31.9%
associate-*l*31.9%
add-sqr-sqrt70.4%
sqrt-prod31.9%
sqrt-prod31.9%
sqrt-prod22.6%
add-sqr-sqrt42.0%
associate-*l*42.0%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
Taylor expanded in v around 0 99.8%
Taylor expanded in v around 0 99.8%
associate-*r*99.8%
neg-mul-199.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (* (* r w) (* r w))) (t_1 (/ 2.0 (* r r))))
(if (or (<= v -3100.0) (not (<= v 4.8e-32)))
(+ 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 <= -3100.0) || !(v <= 4.8e-32)) {
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 <= (-3100.0d0)) .or. (.not. (v <= 4.8d-32))) 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 <= -3100.0) || !(v <= 4.8e-32)) {
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 <= -3100.0) or not (v <= 4.8e-32): 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(2.0 / Float64(r * r)) tmp = 0.0 if ((v <= -3100.0) || !(v <= 4.8e-32)) 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 <= -3100.0) || ~((v <= 4.8e-32))) 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[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[v, -3100.0], N[Not[LessEqual[v, 4.8e-32]], $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{2}{r \cdot r}\\
\mathbf{if}\;v \leq -3100 \lor \neg \left(v \leq 4.8 \cdot 10^{-32}\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 < -3100 or 4.8000000000000003e-32 < v Initial program 82.5%
Simplified90.6%
Taylor expanded in v around inf 84.7%
*-commutative84.7%
unpow284.7%
unpow284.7%
swap-sqr99.6%
unpow299.6%
Simplified99.6%
unpow299.6%
Applied egg-rr99.6%
if -3100 < v < 4.8000000000000003e-32Initial program 87.1%
Simplified87.1%
add-sqr-sqrt87.0%
associate-/l*87.0%
sqrt-prod39.4%
sqrt-prod39.5%
sqrt-prod20.1%
add-sqr-sqrt31.9%
associate-*l*31.9%
add-sqr-sqrt70.4%
sqrt-prod31.9%
sqrt-prod31.9%
sqrt-prod22.6%
add-sqr-sqrt42.0%
associate-*l*42.0%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
Taylor expanded in v around 0 99.8%
Taylor expanded in v around 0 99.8%
associate-*r*99.8%
neg-mul-199.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (v w r) :precision binary64 (+ (/ 2.0 (* r r)) (+ -1.5 (* (+ 0.375 (* v -0.25)) (* (* r w) (/ (* r w) (+ v -1.0)))))))
double code(double v, double w, double r) {
return (2.0 / (r * r)) + (-1.5 + ((0.375 + (v * -0.25)) * ((r * w) * ((r * w) / (v + -1.0)))));
}
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.375d0 + (v * (-0.25d0))) * ((r * w) * ((r * w) / (v + (-1.0d0))))))
end function
public static double code(double v, double w, double r) {
return (2.0 / (r * r)) + (-1.5 + ((0.375 + (v * -0.25)) * ((r * w) * ((r * w) / (v + -1.0)))));
}
def code(v, w, r): return (2.0 / (r * r)) + (-1.5 + ((0.375 + (v * -0.25)) * ((r * w) * ((r * w) / (v + -1.0)))))
function code(v, w, r) return Float64(Float64(2.0 / Float64(r * r)) + Float64(-1.5 + Float64(Float64(0.375 + Float64(v * -0.25)) * Float64(Float64(r * w) * Float64(Float64(r * w) / Float64(v + -1.0)))))) end
function tmp = code(v, w, r) tmp = (2.0 / (r * r)) + (-1.5 + ((0.375 + (v * -0.25)) * ((r * w) * ((r * w) / (v + -1.0))))); end
code[v_, w_, r_] := N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[(-1.5 + N[(N[(0.375 + N[(v * -0.25), $MachinePrecision]), $MachinePrecision] * N[(N[(r * w), $MachinePrecision] * N[(N[(r * w), $MachinePrecision] / N[(v + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{r \cdot r} + \left(-1.5 + \left(0.375 + v \cdot -0.25\right) \cdot \left(\left(r \cdot w\right) \cdot \frac{r \cdot w}{v + -1}\right)\right)
\end{array}
Initial program 84.6%
Simplified88.9%
add-sqr-sqrt88.9%
associate-/l*88.9%
sqrt-prod42.9%
sqrt-prod42.9%
sqrt-prod23.0%
add-sqr-sqrt36.0%
associate-*l*36.0%
add-sqr-sqrt72.7%
sqrt-prod36.0%
sqrt-prod36.0%
sqrt-prod25.3%
add-sqr-sqrt46.4%
associate-*l*46.4%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
Taylor expanded in v around 0 99.8%
Final simplification99.8%
(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(2.0 / Float64(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[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[(-1.5 + N[(-0.25 * N[(N[(r * w), $MachinePrecision] * N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{r \cdot 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 84.6%
Simplified88.9%
Taylor expanded in v around inf 77.3%
*-commutative77.3%
unpow277.3%
unpow277.3%
swap-sqr92.5%
unpow292.5%
Simplified92.5%
unpow292.5%
Applied egg-rr92.5%
Final simplification92.5%
herbie shell --seed 2024170
(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))