
(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
(let* ((t_0 (+ (/ 2.0 (* r r)) 3.0)))
(if (or (<= v -5e+22) (not (<= v 3.1e-7)))
(+ t_0 (- (* (* v -0.25) (* (* r w) (/ (* r w) v))) 4.5))
(- t_0 (+ 4.5 (* 0.375 (* (* r w) (* r w))))))))
double code(double v, double w, double r) {
double t_0 = (2.0 / (r * r)) + 3.0;
double tmp;
if ((v <= -5e+22) || !(v <= 3.1e-7)) {
tmp = t_0 + (((v * -0.25) * ((r * w) * ((r * w) / v))) - 4.5);
} else {
tmp = t_0 - (4.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)) + 3.0d0
if ((v <= (-5d+22)) .or. (.not. (v <= 3.1d-7))) then
tmp = t_0 + (((v * (-0.25d0)) * ((r * w) * ((r * w) / v))) - 4.5d0)
else
tmp = t_0 - (4.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)) + 3.0;
double tmp;
if ((v <= -5e+22) || !(v <= 3.1e-7)) {
tmp = t_0 + (((v * -0.25) * ((r * w) * ((r * w) / v))) - 4.5);
} else {
tmp = t_0 - (4.5 + (0.375 * ((r * w) * (r * w))));
}
return tmp;
}
def code(v, w, r): t_0 = (2.0 / (r * r)) + 3.0 tmp = 0 if (v <= -5e+22) or not (v <= 3.1e-7): tmp = t_0 + (((v * -0.25) * ((r * w) * ((r * w) / v))) - 4.5) else: tmp = t_0 - (4.5 + (0.375 * ((r * w) * (r * w)))) return tmp
function code(v, w, r) t_0 = Float64(Float64(2.0 / Float64(r * r)) + 3.0) tmp = 0.0 if ((v <= -5e+22) || !(v <= 3.1e-7)) tmp = Float64(t_0 + Float64(Float64(Float64(v * -0.25) * Float64(Float64(r * w) * Float64(Float64(r * w) / v))) - 4.5)); else tmp = Float64(t_0 - Float64(4.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)) + 3.0; tmp = 0.0; if ((v <= -5e+22) || ~((v <= 3.1e-7))) tmp = t_0 + (((v * -0.25) * ((r * w) * ((r * w) / v))) - 4.5); else tmp = t_0 - (4.5 + (0.375 * ((r * w) * (r * w)))); end tmp_2 = tmp; end
code[v_, w_, r_] := Block[{t$95$0 = N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + 3.0), $MachinePrecision]}, If[Or[LessEqual[v, -5e+22], N[Not[LessEqual[v, 3.1e-7]], $MachinePrecision]], N[(t$95$0 + N[(N[(N[(v * -0.25), $MachinePrecision] * N[(N[(r * w), $MachinePrecision] * N[(N[(r * w), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - N[(4.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} + 3\\
\mathbf{if}\;v \leq -5 \cdot 10^{+22} \lor \neg \left(v \leq 3.1 \cdot 10^{-7}\right):\\
\;\;\;\;t\_0 + \left(\left(v \cdot -0.25\right) \cdot \left(\left(r \cdot w\right) \cdot \frac{r \cdot w}{v}\right) - 4.5\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 - \left(4.5 + 0.375 \cdot \left(\left(r \cdot w\right) \cdot \left(r \cdot w\right)\right)\right)\\
\end{array}
\end{array}
if v < -4.9999999999999996e22 or 3.1e-7 < v Initial program 83.2%
associate--l-83.2%
associate-*l*80.3%
sqr-neg80.3%
associate-*l*83.2%
associate-/l*90.4%
fma-define90.4%
Simplified90.4%
associate-/l*90.3%
*-commutative90.3%
associate-*r/89.6%
associate-*l*97.8%
associate-*r*98.4%
*-commutative98.4%
Applied egg-rr98.4%
Taylor expanded in v around inf 97.7%
*-commutative97.7%
Simplified97.7%
Taylor expanded in v around inf 99.8%
associate-*r/99.8%
mul-1-neg99.8%
Simplified99.8%
if -4.9999999999999996e22 < v < 3.1e-7Initial program 87.3%
associate--l-87.3%
associate-*l*82.2%
sqr-neg82.2%
associate-*l*87.3%
associate-/l*87.3%
fma-define87.3%
Simplified87.3%
associate-/l*87.3%
*-commutative87.3%
associate-*r/87.3%
associate-*l*98.1%
associate-*r*99.8%
*-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in v around 0 99.5%
Taylor expanded in v around 0 99.5%
Final simplification99.6%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (+ (/ 2.0 (* r r)) 3.0)))
(if (<= v 2e-7)
(- t_0 (+ 4.5 (* 0.375 (* (* r w) (* r w)))))
(+ t_0 (- (* (* v -0.25) (* (* r w) (* r (/ w v)))) 4.5)))))
double code(double v, double w, double r) {
double t_0 = (2.0 / (r * r)) + 3.0;
double tmp;
if (v <= 2e-7) {
tmp = t_0 - (4.5 + (0.375 * ((r * w) * (r * w))));
} else {
tmp = t_0 + (((v * -0.25) * ((r * w) * (r * (w / v)))) - 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) :: t_0
real(8) :: tmp
t_0 = (2.0d0 / (r * r)) + 3.0d0
if (v <= 2d-7) then
tmp = t_0 - (4.5d0 + (0.375d0 * ((r * w) * (r * w))))
else
tmp = t_0 + (((v * (-0.25d0)) * ((r * w) * (r * (w / v)))) - 4.5d0)
end if
code = tmp
end function
public static double code(double v, double w, double r) {
double t_0 = (2.0 / (r * r)) + 3.0;
double tmp;
if (v <= 2e-7) {
tmp = t_0 - (4.5 + (0.375 * ((r * w) * (r * w))));
} else {
tmp = t_0 + (((v * -0.25) * ((r * w) * (r * (w / v)))) - 4.5);
}
return tmp;
}
def code(v, w, r): t_0 = (2.0 / (r * r)) + 3.0 tmp = 0 if v <= 2e-7: tmp = t_0 - (4.5 + (0.375 * ((r * w) * (r * w)))) else: tmp = t_0 + (((v * -0.25) * ((r * w) * (r * (w / v)))) - 4.5) return tmp
function code(v, w, r) t_0 = Float64(Float64(2.0 / Float64(r * r)) + 3.0) tmp = 0.0 if (v <= 2e-7) tmp = Float64(t_0 - Float64(4.5 + Float64(0.375 * Float64(Float64(r * w) * Float64(r * w))))); else tmp = Float64(t_0 + Float64(Float64(Float64(v * -0.25) * Float64(Float64(r * w) * Float64(r * Float64(w / v)))) - 4.5)); end return tmp end
function tmp_2 = code(v, w, r) t_0 = (2.0 / (r * r)) + 3.0; tmp = 0.0; if (v <= 2e-7) tmp = t_0 - (4.5 + (0.375 * ((r * w) * (r * w)))); else tmp = t_0 + (((v * -0.25) * ((r * w) * (r * (w / v)))) - 4.5); end tmp_2 = tmp; end
code[v_, w_, r_] := Block[{t$95$0 = N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + 3.0), $MachinePrecision]}, If[LessEqual[v, 2e-7], N[(t$95$0 - N[(4.5 + N[(0.375 * N[(N[(r * w), $MachinePrecision] * N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[(N[(N[(v * -0.25), $MachinePrecision] * N[(N[(r * w), $MachinePrecision] * N[(r * N[(w / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{r \cdot r} + 3\\
\mathbf{if}\;v \leq 2 \cdot 10^{-7}:\\
\;\;\;\;t\_0 - \left(4.5 + 0.375 \cdot \left(\left(r \cdot w\right) \cdot \left(r \cdot w\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 + \left(\left(v \cdot -0.25\right) \cdot \left(\left(r \cdot w\right) \cdot \left(r \cdot \frac{w}{v}\right)\right) - 4.5\right)\\
\end{array}
\end{array}
if v < 1.9999999999999999e-7Initial program 85.4%
associate--l-85.4%
associate-*l*81.5%
sqr-neg81.5%
associate-*l*85.4%
associate-/l*88.0%
fma-define88.0%
Simplified88.0%
associate-/l*88.0%
*-commutative88.0%
associate-*r/88.0%
associate-*l*97.6%
associate-*r*99.2%
*-commutative99.2%
Applied egg-rr99.2%
Taylor expanded in v around 0 90.5%
Taylor expanded in v around 0 95.5%
if 1.9999999999999999e-7 < v Initial program 84.2%
associate--l-84.2%
associate-*l*80.4%
sqr-neg80.4%
associate-*l*84.2%
associate-/l*91.2%
fma-define91.2%
Simplified91.2%
associate-/l*91.3%
*-commutative91.3%
associate-*r/90.0%
associate-*l*98.5%
associate-*r*98.6%
*-commutative98.6%
Applied egg-rr98.6%
Taylor expanded in v around inf 96.1%
*-commutative96.1%
Simplified96.1%
Taylor expanded in v around inf 99.8%
mul-1-neg99.8%
associate-/l*98.7%
distribute-rgt-neg-in98.7%
Simplified98.7%
Final simplification96.5%
(FPCore (v w r) :precision binary64 (+ (/ 2.0 (* r r)) (- -1.5 (/ (+ 0.375 (* v -0.25)) (/ (- 1.0 v) (* (* r w) (* r w)))))))
double code(double v, double w, double r) {
return (2.0 / (r * r)) + (-1.5 - ((0.375 + (v * -0.25)) / ((1.0 - v) / ((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.375d0 + (v * (-0.25d0))) / ((1.0d0 - v) / ((r * w) * (r * w)))))
end function
public static double code(double v, double w, double r) {
return (2.0 / (r * r)) + (-1.5 - ((0.375 + (v * -0.25)) / ((1.0 - v) / ((r * w) * (r * w)))));
}
def code(v, w, r): return (2.0 / (r * r)) + (-1.5 - ((0.375 + (v * -0.25)) / ((1.0 - v) / ((r * w) * (r * w)))))
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(1.0 - v) / Float64(Float64(r * w) * Float64(r * w)))))) end
function tmp = code(v, w, r) tmp = (2.0 / (r * r)) + (-1.5 - ((0.375 + (v * -0.25)) / ((1.0 - v) / ((r * w) * (r * w))))); 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[(1.0 - v), $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{0.375 + v \cdot -0.25}{\frac{1 - v}{\left(r \cdot w\right) \cdot \left(r \cdot w\right)}}\right)
\end{array}
Initial program 85.0%
Simplified88.6%
fma-undefine88.6%
*-commutative88.6%
+-commutative88.6%
metadata-eval88.6%
cancel-sign-sub-inv88.6%
associate-*r/89.0%
*-commutative89.0%
associate-/l*89.1%
clear-num89.1%
un-div-inv89.0%
cancel-sign-sub-inv89.0%
metadata-eval89.0%
distribute-rgt-in89.0%
metadata-eval89.0%
*-commutative89.0%
associate-*l*89.4%
metadata-eval89.4%
Applied egg-rr99.5%
unpow299.5%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (v w r) :precision binary64 (- (+ (/ 2.0 (* r r)) 3.0) (+ 4.5 (* 0.375 (* (* r w) (* r w))))))
double code(double v, double w, double r) {
return ((2.0 / (r * r)) + 3.0) - (4.5 + (0.375 * ((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)) + 3.0d0) - (4.5d0 + (0.375d0 * ((r * w) * (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 * ((r * w) * (r * w))));
}
def code(v, w, r): return ((2.0 / (r * r)) + 3.0) - (4.5 + (0.375 * ((r * w) * (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(Float64(r * w) * Float64(r * w))))) end
function tmp = code(v, w, r) tmp = ((2.0 / (r * r)) + 3.0) - (4.5 + (0.375 * ((r * w) * (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[(N[(r * w), $MachinePrecision] * N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{2}{r \cdot r} + 3\right) - \left(4.5 + 0.375 \cdot \left(\left(r \cdot w\right) \cdot \left(r \cdot w\right)\right)\right)
\end{array}
Initial program 85.0%
associate--l-85.0%
associate-*l*81.2%
sqr-neg81.2%
associate-*l*85.0%
associate-/l*89.0%
fma-define89.0%
Simplified89.0%
associate-/l*89.0%
*-commutative89.0%
associate-*r/88.6%
associate-*l*97.9%
associate-*r*99.0%
*-commutative99.0%
Applied egg-rr99.0%
Taylor expanded in v around 0 81.4%
Taylor expanded in v around 0 93.5%
Final simplification93.5%
herbie shell --seed 2024076
(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))