
(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 4 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 (/ (+ (* v -0.25) 0.375) (/ (+ v -1.0) (* (* r w) (* r w)))))))
double code(double v, double w, double r) {
return (2.0 / (r * r)) + (-1.5 + (((v * -0.25) + 0.375) / ((v + -1.0) / ((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) + (((v * (-0.25d0)) + 0.375d0) / ((v + (-1.0d0)) / ((r * w) * (r * w)))))
end function
public static double code(double v, double w, double r) {
return (2.0 / (r * r)) + (-1.5 + (((v * -0.25) + 0.375) / ((v + -1.0) / ((r * w) * (r * w)))));
}
def code(v, w, r): return (2.0 / (r * r)) + (-1.5 + (((v * -0.25) + 0.375) / ((v + -1.0) / ((r * w) * (r * w)))))
function code(v, w, r) return Float64(Float64(2.0 / Float64(r * r)) + Float64(-1.5 + Float64(Float64(Float64(v * -0.25) + 0.375) / Float64(Float64(v + -1.0) / Float64(Float64(r * w) * Float64(r * w)))))) end
function tmp = code(v, w, r) tmp = (2.0 / (r * r)) + (-1.5 + (((v * -0.25) + 0.375) / ((v + -1.0) / ((r * w) * (r * w))))); end
code[v_, w_, r_] := N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[(-1.5 + N[(N[(N[(v * -0.25), $MachinePrecision] + 0.375), $MachinePrecision] / N[(N[(v + -1.0), $MachinePrecision] / N[(N[(r * w), $MachinePrecision] * N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{r \cdot r} + \left(-1.5 + \frac{v \cdot -0.25 + 0.375}{\frac{v + -1}{\left(r \cdot w\right) \cdot \left(r \cdot w\right)}}\right)
\end{array}
Initial program 84.8%
Simplified86.2%
fma-undefine86.2%
*-commutative86.2%
+-commutative86.2%
associate-*r/86.6%
*-commutative86.6%
associate-/l*87.4%
clear-num87.4%
un-div-inv87.4%
+-commutative87.4%
distribute-rgt-in87.4%
*-commutative87.4%
associate-*l*87.8%
metadata-eval87.8%
metadata-eval87.8%
associate-*r*82.2%
pow282.2%
pow282.2%
pow-prod-down99.9%
*-commutative99.9%
Applied egg-rr99.9%
unpow299.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (/ 2.0 (* r r))))
(if (or (<= v -170000000.0) (not (<= v 0.19)))
(+ (+ t_0 3.0) (- (* (* v -0.25) (* w (* r (/ (* r w) v)))) 4.5))
(+
t_0
(+
-1.5
(/ (+ (* v -0.25) 0.375) (* (/ 1.0 (* r w)) (/ -1.0 (* r w)))))))))
double code(double v, double w, double r) {
double t_0 = 2.0 / (r * r);
double tmp;
if ((v <= -170000000.0) || !(v <= 0.19)) {
tmp = (t_0 + 3.0) + (((v * -0.25) * (w * (r * ((r * w) / v)))) - 4.5);
} else {
tmp = t_0 + (-1.5 + (((v * -0.25) + 0.375) / ((1.0 / (r * w)) * (-1.0 / (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 <= (-170000000.0d0)) .or. (.not. (v <= 0.19d0))) then
tmp = (t_0 + 3.0d0) + (((v * (-0.25d0)) * (w * (r * ((r * w) / v)))) - 4.5d0)
else
tmp = t_0 + ((-1.5d0) + (((v * (-0.25d0)) + 0.375d0) / ((1.0d0 / (r * w)) * ((-1.0d0) / (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 <= -170000000.0) || !(v <= 0.19)) {
tmp = (t_0 + 3.0) + (((v * -0.25) * (w * (r * ((r * w) / v)))) - 4.5);
} else {
tmp = t_0 + (-1.5 + (((v * -0.25) + 0.375) / ((1.0 / (r * w)) * (-1.0 / (r * w)))));
}
return tmp;
}
def code(v, w, r): t_0 = 2.0 / (r * r) tmp = 0 if (v <= -170000000.0) or not (v <= 0.19): tmp = (t_0 + 3.0) + (((v * -0.25) * (w * (r * ((r * w) / v)))) - 4.5) else: tmp = t_0 + (-1.5 + (((v * -0.25) + 0.375) / ((1.0 / (r * w)) * (-1.0 / (r * w))))) return tmp
function code(v, w, r) t_0 = Float64(2.0 / Float64(r * r)) tmp = 0.0 if ((v <= -170000000.0) || !(v <= 0.19)) tmp = Float64(Float64(t_0 + 3.0) + Float64(Float64(Float64(v * -0.25) * Float64(w * Float64(r * Float64(Float64(r * w) / v)))) - 4.5)); else tmp = Float64(t_0 + Float64(-1.5 + Float64(Float64(Float64(v * -0.25) + 0.375) / Float64(Float64(1.0 / Float64(r * w)) * Float64(-1.0 / 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 <= -170000000.0) || ~((v <= 0.19))) tmp = (t_0 + 3.0) + (((v * -0.25) * (w * (r * ((r * w) / v)))) - 4.5); else tmp = t_0 + (-1.5 + (((v * -0.25) + 0.375) / ((1.0 / (r * w)) * (-1.0 / (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, -170000000.0], N[Not[LessEqual[v, 0.19]], $MachinePrecision]], N[(N[(t$95$0 + 3.0), $MachinePrecision] + N[(N[(N[(v * -0.25), $MachinePrecision] * N[(w * N[(r * N[(N[(r * w), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[(-1.5 + N[(N[(N[(v * -0.25), $MachinePrecision] + 0.375), $MachinePrecision] / N[(N[(1.0 / N[(r * w), $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{r \cdot r}\\
\mathbf{if}\;v \leq -170000000 \lor \neg \left(v \leq 0.19\right):\\
\;\;\;\;\left(t\_0 + 3\right) + \left(\left(v \cdot -0.25\right) \cdot \left(w \cdot \left(r \cdot \frac{r \cdot w}{v}\right)\right) - 4.5\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 + \left(-1.5 + \frac{v \cdot -0.25 + 0.375}{\frac{1}{r \cdot w} \cdot \frac{-1}{r \cdot w}}\right)\\
\end{array}
\end{array}
if v < -1.7e8 or 0.19 < v Initial program 82.0%
associate--l-82.0%
associate-*l*77.5%
sqr-neg77.5%
associate-*l*82.0%
associate-/l*87.6%
fma-define87.6%
Simplified87.6%
associate-/l*86.0%
*-commutative86.0%
associate-*r/85.1%
*-commutative85.1%
associate-*l*93.4%
associate-*l*98.1%
associate-*r/99.0%
Applied egg-rr99.0%
Taylor expanded in v around inf 99.8%
*-commutative99.8%
Simplified99.8%
Taylor expanded in v around inf 99.8%
associate-*r/99.8%
associate-*r*99.8%
neg-mul-199.8%
*-commutative99.8%
Simplified99.8%
if -1.7e8 < v < 0.19Initial program 87.2%
Simplified87.2%
fma-undefine87.2%
*-commutative87.2%
+-commutative87.2%
associate-*r/87.2%
*-commutative87.2%
associate-/l*87.2%
clear-num87.2%
un-div-inv87.2%
+-commutative87.2%
distribute-rgt-in87.2%
*-commutative87.2%
associate-*l*87.2%
metadata-eval87.2%
metadata-eval87.2%
associate-*r*82.8%
pow282.8%
pow282.8%
pow-prod-down99.9%
*-commutative99.9%
Applied egg-rr99.9%
*-un-lft-identity99.9%
unpow299.9%
times-frac99.8%
Applied egg-rr99.8%
Taylor expanded in v around 0 99.4%
Final simplification99.6%
(FPCore (v w r)
:precision binary64
(if (or (<= v -7000000.0) (not (<= v 1.5)))
(+
(+ (/ 2.0 (* r r)) 3.0)
(- (* (* v -0.25) (* w (* r (/ (* r w) v)))) 4.5))
(+
(+ 3.0 (/ (/ 2.0 r) r))
(- (* 0.375 (* (* r w) (/ (* r w) (+ v -1.0)))) 4.5))))
double code(double v, double w, double r) {
double tmp;
if ((v <= -7000000.0) || !(v <= 1.5)) {
tmp = ((2.0 / (r * r)) + 3.0) + (((v * -0.25) * (w * (r * ((r * w) / v)))) - 4.5);
} else {
tmp = (3.0 + ((2.0 / r) / r)) + ((0.375 * ((r * w) * ((r * w) / (v + -1.0)))) - 4.5);
}
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) :: tmp
if ((v <= (-7000000.0d0)) .or. (.not. (v <= 1.5d0))) then
tmp = ((2.0d0 / (r * r)) + 3.0d0) + (((v * (-0.25d0)) * (w * (r * ((r * w) / v)))) - 4.5d0)
else
tmp = (3.0d0 + ((2.0d0 / r) / r)) + ((0.375d0 * ((r * w) * ((r * w) / (v + (-1.0d0))))) - 4.5d0)
end if
code = tmp
end function
public static double code(double v, double w, double r) {
double tmp;
if ((v <= -7000000.0) || !(v <= 1.5)) {
tmp = ((2.0 / (r * r)) + 3.0) + (((v * -0.25) * (w * (r * ((r * w) / v)))) - 4.5);
} else {
tmp = (3.0 + ((2.0 / r) / r)) + ((0.375 * ((r * w) * ((r * w) / (v + -1.0)))) - 4.5);
}
return tmp;
}
def code(v, w, r): tmp = 0 if (v <= -7000000.0) or not (v <= 1.5): tmp = ((2.0 / (r * r)) + 3.0) + (((v * -0.25) * (w * (r * ((r * w) / v)))) - 4.5) else: tmp = (3.0 + ((2.0 / r) / r)) + ((0.375 * ((r * w) * ((r * w) / (v + -1.0)))) - 4.5) return tmp
function code(v, w, r) tmp = 0.0 if ((v <= -7000000.0) || !(v <= 1.5)) tmp = Float64(Float64(Float64(2.0 / Float64(r * r)) + 3.0) + Float64(Float64(Float64(v * -0.25) * Float64(w * Float64(r * Float64(Float64(r * w) / v)))) - 4.5)); else tmp = Float64(Float64(3.0 + Float64(Float64(2.0 / r) / r)) + Float64(Float64(0.375 * Float64(Float64(r * w) * Float64(Float64(r * w) / Float64(v + -1.0)))) - 4.5)); end return tmp end
function tmp_2 = code(v, w, r) tmp = 0.0; if ((v <= -7000000.0) || ~((v <= 1.5))) tmp = ((2.0 / (r * r)) + 3.0) + (((v * -0.25) * (w * (r * ((r * w) / v)))) - 4.5); else tmp = (3.0 + ((2.0 / r) / r)) + ((0.375 * ((r * w) * ((r * w) / (v + -1.0)))) - 4.5); end tmp_2 = tmp; end
code[v_, w_, r_] := If[Or[LessEqual[v, -7000000.0], N[Not[LessEqual[v, 1.5]], $MachinePrecision]], N[(N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + 3.0), $MachinePrecision] + N[(N[(N[(v * -0.25), $MachinePrecision] * N[(w * N[(r * N[(N[(r * w), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]), $MachinePrecision], N[(N[(3.0 + N[(N[(2.0 / r), $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision] + N[(N[(0.375 * N[(N[(r * w), $MachinePrecision] * N[(N[(r * w), $MachinePrecision] / N[(v + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;v \leq -7000000 \lor \neg \left(v \leq 1.5\right):\\
\;\;\;\;\left(\frac{2}{r \cdot r} + 3\right) + \left(\left(v \cdot -0.25\right) \cdot \left(w \cdot \left(r \cdot \frac{r \cdot w}{v}\right)\right) - 4.5\right)\\
\mathbf{else}:\\
\;\;\;\;\left(3 + \frac{\frac{2}{r}}{r}\right) + \left(0.375 \cdot \left(\left(r \cdot w\right) \cdot \frac{r \cdot w}{v + -1}\right) - 4.5\right)\\
\end{array}
\end{array}
if v < -7e6 or 1.5 < v Initial program 81.9%
associate--l-81.9%
associate-*l*77.3%
sqr-neg77.3%
associate-*l*81.9%
associate-/l*87.5%
fma-define87.5%
Simplified87.5%
associate-/l*85.9%
*-commutative85.9%
associate-*r/85.0%
*-commutative85.0%
associate-*l*93.3%
associate-*l*98.1%
associate-*r/99.0%
Applied egg-rr99.0%
Taylor expanded in v around inf 99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in v around inf 99.9%
associate-*r/99.9%
associate-*r*99.9%
neg-mul-199.9%
*-commutative99.9%
Simplified99.9%
if -7e6 < v < 1.5Initial program 87.3%
associate--l-87.3%
associate-*l*82.9%
sqr-neg82.9%
associate-*l*87.3%
associate-/l*87.3%
fma-define87.3%
Simplified87.3%
associate-/r*87.2%
div-inv87.2%
Applied egg-rr87.2%
Taylor expanded in v around 0 86.8%
un-div-inv86.8%
Applied egg-rr86.8%
associate-/l*86.8%
*-commutative86.8%
associate-*r/86.8%
associate-*l*94.5%
associate-*r*99.4%
*-commutative99.4%
associate-*r/99.4%
Applied egg-rr99.4%
Final simplification99.6%
(FPCore (v w r) :precision binary64 (- (+ (/ 2.0 (* r r)) 3.0) (+ 4.5 (* 0.375 (* w (* r (* r w)))))))
double code(double v, double w, double r) {
return ((2.0 / (r * r)) + 3.0) - (4.5 + (0.375 * (w * (r * (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)) + 3.0d0) - (4.5d0 + (0.375d0 * (w * (r * (r * w)))))
end function
public static double code(double v, double w, double r) {
return ((2.0 / (r * r)) + 3.0) - (4.5 + (0.375 * (w * (r * (r * w)))));
}
def code(v, w, r): return ((2.0 / (r * r)) + 3.0) - (4.5 + (0.375 * (w * (r * (r * w)))))
function code(v, w, r) return Float64(Float64(Float64(2.0 / Float64(r * r)) + 3.0) - Float64(4.5 + Float64(0.375 * Float64(w * Float64(r * Float64(r * w)))))) end
function tmp = code(v, w, r) tmp = ((2.0 / (r * r)) + 3.0) - (4.5 + (0.375 * (w * (r * (r * w))))); end
code[v_, w_, r_] := N[(N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + 3.0), $MachinePrecision] - N[(4.5 + N[(0.375 * N[(w * N[(r * N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{2}{r \cdot r} + 3\right) - \left(4.5 + 0.375 \cdot \left(w \cdot \left(r \cdot \left(r \cdot w\right)\right)\right)\right)
\end{array}
Initial program 84.8%
associate--l-84.8%
associate-*l*80.3%
sqr-neg80.3%
associate-*l*84.8%
associate-/l*87.4%
fma-define87.4%
Simplified87.4%
associate-/l*86.6%
*-commutative86.6%
associate-*r/86.2%
*-commutative86.2%
associate-*l*94.2%
associate-*l*98.0%
associate-*r/98.4%
Applied egg-rr98.4%
Taylor expanded in v around 0 82.8%
Taylor expanded in v around 0 92.2%
Final simplification92.2%
herbie shell --seed 2024089
(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))