
(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)
(+
-1.5
(*
(- -0.375 (* v -0.25))
(/ (* (* r w) (/ -1.0 (+ v -1.0))) (/ (/ 1.0 w) r))))))
double code(double v, double w, double r) {
return ((2.0 / r) / r) + (-1.5 + ((-0.375 - (v * -0.25)) * (((r * w) * (-1.0 / (v + -1.0))) / ((1.0 / w) / r))));
}
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) * ((-1.0d0) / (v + (-1.0d0)))) / ((1.0d0 / w) / r))))
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) * (-1.0 / (v + -1.0))) / ((1.0 / w) / r))));
}
def code(v, w, r): return ((2.0 / r) / r) + (-1.5 + ((-0.375 - (v * -0.25)) * (((r * w) * (-1.0 / (v + -1.0))) / ((1.0 / w) / r))))
function code(v, w, r) return Float64(Float64(Float64(2.0 / r) / r) + Float64(-1.5 + Float64(Float64(-0.375 - Float64(v * -0.25)) * Float64(Float64(Float64(r * w) * Float64(-1.0 / Float64(v + -1.0))) / Float64(Float64(1.0 / w) / r))))) end
function tmp = code(v, w, r) tmp = ((2.0 / r) / r) + (-1.5 + ((-0.375 - (v * -0.25)) * (((r * w) * (-1.0 / (v + -1.0))) / ((1.0 / w) / r)))); end
code[v_, w_, r_] := N[(N[(N[(2.0 / r), $MachinePrecision] / r), $MachinePrecision] + N[(-1.5 + N[(N[(-0.375 - N[(v * -0.25), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(r * w), $MachinePrecision] * N[(-1.0 / N[(v + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 / w), $MachinePrecision] / r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{r}}{r} + \left(-1.5 + \left(-0.375 - v \cdot -0.25\right) \cdot \frac{\left(r \cdot w\right) \cdot \frac{-1}{v + -1}}{\frac{\frac{1}{w}}{r}}\right)
\end{array}
Initial program 84.2%
Simplified95.5%
frac-2neg95.5%
*-commutative95.5%
associate-*r*85.7%
div-inv85.7%
associate-*r*95.5%
*-commutative95.5%
associate-*r*99.8%
pow299.8%
*-commutative99.8%
Applied egg-rr99.8%
associate-*r/99.8%
*-rgt-identity99.8%
neg-sub099.8%
fma-udef99.8%
*-commutative99.8%
+-commutative99.8%
associate--r+99.8%
metadata-eval99.8%
*-commutative99.8%
distribute-neg-frac99.8%
neg-sub099.8%
associate--r-99.8%
metadata-eval99.8%
*-commutative99.8%
Simplified99.8%
div-inv99.8%
div-inv99.8%
pow-flip99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-/r*99.8%
Simplified99.8%
*-un-lft-identity99.8%
add-sqr-sqrt99.7%
times-frac99.7%
sqrt-pow174.0%
metadata-eval74.0%
unpow-174.0%
sqrt-pow199.7%
metadata-eval99.7%
unpow-199.7%
Applied egg-rr99.7%
remove-double-div99.7%
associate-*r/99.8%
Simplified99.8%
inv-pow99.8%
unpow-prod-down99.8%
inv-pow99.8%
Applied egg-rr99.8%
associate-*l/99.8%
*-lft-identity99.8%
unpow-199.8%
Simplified99.8%
Final simplification99.8%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (* (* r w) (* r w))))
(if (or (<= v -3.4e+25) (not (<= v 3200000.0)))
(+ (/ (/ 2.0 r) r) (- -1.5 (* t_0 0.25)))
(+ -1.5 (+ (/ 2.0 (* r r)) (* -0.375 t_0))))))
double code(double v, double w, double r) {
double t_0 = (r * w) * (r * w);
double tmp;
if ((v <= -3.4e+25) || !(v <= 3200000.0)) {
tmp = ((2.0 / r) / r) + (-1.5 - (t_0 * 0.25));
} else {
tmp = -1.5 + ((2.0 / (r * r)) + (-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) :: tmp
t_0 = (r * w) * (r * w)
if ((v <= (-3.4d+25)) .or. (.not. (v <= 3200000.0d0))) then
tmp = ((2.0d0 / r) / r) + ((-1.5d0) - (t_0 * 0.25d0))
else
tmp = (-1.5d0) + ((2.0d0 / (r * r)) + ((-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 tmp;
if ((v <= -3.4e+25) || !(v <= 3200000.0)) {
tmp = ((2.0 / r) / r) + (-1.5 - (t_0 * 0.25));
} else {
tmp = -1.5 + ((2.0 / (r * r)) + (-0.375 * t_0));
}
return tmp;
}
def code(v, w, r): t_0 = (r * w) * (r * w) tmp = 0 if (v <= -3.4e+25) or not (v <= 3200000.0): tmp = ((2.0 / r) / r) + (-1.5 - (t_0 * 0.25)) else: tmp = -1.5 + ((2.0 / (r * r)) + (-0.375 * t_0)) return tmp
function code(v, w, r) t_0 = Float64(Float64(r * w) * Float64(r * w)) tmp = 0.0 if ((v <= -3.4e+25) || !(v <= 3200000.0)) tmp = Float64(Float64(Float64(2.0 / r) / r) + Float64(-1.5 - Float64(t_0 * 0.25))); else tmp = Float64(-1.5 + Float64(Float64(2.0 / Float64(r * r)) + Float64(-0.375 * t_0))); end return tmp end
function tmp_2 = code(v, w, r) t_0 = (r * w) * (r * w); tmp = 0.0; if ((v <= -3.4e+25) || ~((v <= 3200000.0))) tmp = ((2.0 / r) / r) + (-1.5 - (t_0 * 0.25)); else tmp = -1.5 + ((2.0 / (r * r)) + (-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]}, If[Or[LessEqual[v, -3.4e+25], N[Not[LessEqual[v, 3200000.0]], $MachinePrecision]], N[(N[(N[(2.0 / r), $MachinePrecision] / r), $MachinePrecision] + N[(-1.5 - N[(t$95$0 * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.5 + N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + 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)\\
\mathbf{if}\;v \leq -3.4 \cdot 10^{+25} \lor \neg \left(v \leq 3200000\right):\\
\;\;\;\;\frac{\frac{2}{r}}{r} + \left(-1.5 - t_0 \cdot 0.25\right)\\
\mathbf{else}:\\
\;\;\;\;-1.5 + \left(\frac{2}{r \cdot r} + -0.375 \cdot t_0\right)\\
\end{array}
\end{array}
if v < -3.39999999999999984e25 or 3.2e6 < v Initial program 78.2%
Simplified94.8%
frac-2neg94.8%
*-commutative94.8%
associate-*r*81.5%
div-inv81.5%
associate-*r*94.7%
*-commutative94.7%
associate-*r*99.8%
pow299.8%
*-commutative99.8%
Applied egg-rr99.8%
associate-*r/99.9%
*-rgt-identity99.9%
neg-sub099.9%
fma-udef99.9%
*-commutative99.9%
+-commutative99.9%
associate--r+99.9%
metadata-eval99.9%
*-commutative99.9%
distribute-neg-frac99.9%
neg-sub099.9%
associate--r-99.9%
metadata-eval99.9%
*-commutative99.9%
Simplified99.9%
Taylor expanded in v around inf 76.7%
*-commutative76.7%
unpow276.7%
unpow276.7%
swap-sqr99.2%
unpow299.2%
Simplified99.2%
unpow286.9%
Applied egg-rr99.2%
if -3.39999999999999984e25 < v < 3.2e6Initial program 89.3%
Simplified80.2%
Taylor expanded in v around 0 80.2%
*-commutative80.2%
unpow280.2%
unpow280.2%
swap-sqr99.7%
unpow299.7%
*-commutative99.7%
Simplified99.7%
unpow299.7%
Applied egg-rr99.7%
Final simplification99.5%
(FPCore (v w r) :precision binary64 (+ (/ (/ 2.0 r) r) (+ -1.5 (* (- -0.375 (* v -0.25)) (* (* r w) (* (* r w) (/ -1.0 (+ 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) * (-1.0 / (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) * ((-1.0d0) / (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) * (-1.0 / (v + -1.0))))));
}
def code(v, w, r): return ((2.0 / r) / r) + (-1.5 + ((-0.375 - (v * -0.25)) * ((r * w) * ((r * w) * (-1.0 / (v + -1.0))))))
function code(v, w, r) return Float64(Float64(Float64(2.0 / r) / r) + Float64(-1.5 + Float64(Float64(-0.375 - Float64(v * -0.25)) * Float64(Float64(r * w) * Float64(Float64(r * w) * Float64(-1.0 / 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) * (-1.0 / (v + -1.0)))))); end
code[v_, w_, r_] := N[(N[(N[(2.0 / r), $MachinePrecision] / r), $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[(-1.0 / N[(v + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{r}}{r} + \left(-1.5 + \left(-0.375 - v \cdot -0.25\right) \cdot \left(\left(r \cdot w\right) \cdot \left(\left(r \cdot w\right) \cdot \frac{-1}{v + -1}\right)\right)\right)
\end{array}
Initial program 84.2%
Simplified95.5%
frac-2neg95.5%
*-commutative95.5%
associate-*r*85.7%
div-inv85.7%
associate-*r*95.5%
*-commutative95.5%
associate-*r*99.8%
pow299.8%
*-commutative99.8%
Applied egg-rr99.8%
associate-*r/99.8%
*-rgt-identity99.8%
neg-sub099.8%
fma-udef99.8%
*-commutative99.8%
+-commutative99.8%
associate--r+99.8%
metadata-eval99.8%
*-commutative99.8%
distribute-neg-frac99.8%
neg-sub099.8%
associate--r-99.8%
metadata-eval99.8%
*-commutative99.8%
Simplified99.8%
div-inv99.8%
div-inv99.8%
pow-flip99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-/r*99.8%
Simplified99.8%
*-un-lft-identity99.8%
add-sqr-sqrt99.7%
times-frac99.7%
sqrt-pow174.0%
metadata-eval74.0%
unpow-174.0%
sqrt-pow199.7%
metadata-eval99.7%
unpow-199.7%
Applied egg-rr99.7%
remove-double-div99.7%
associate-/r/99.8%
/-rgt-identity99.8%
Simplified99.8%
Final simplification99.8%
(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(Float64(2.0 / 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[(N[(2.0 / r), $MachinePrecision] / r), $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{\frac{2}{r}}{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.2%
Simplified95.5%
frac-2neg95.5%
*-commutative95.5%
associate-*r*85.7%
div-inv85.7%
associate-*r*95.5%
*-commutative95.5%
associate-*r*99.8%
pow299.8%
*-commutative99.8%
Applied egg-rr99.8%
associate-*r/99.8%
*-rgt-identity99.8%
neg-sub099.8%
fma-udef99.8%
*-commutative99.8%
+-commutative99.8%
associate--r+99.8%
metadata-eval99.8%
*-commutative99.8%
distribute-neg-frac99.8%
neg-sub099.8%
associate--r-99.8%
metadata-eval99.8%
*-commutative99.8%
Simplified99.8%
unpow293.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (v w r) :precision binary64 (+ -1.5 (+ (/ 2.0 (* r r)) (* -0.375 (* (* r w) (* r w))))))
double code(double v, double w, double r) {
return -1.5 + ((2.0 / (r * r)) + (-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 = (-1.5d0) + ((2.0d0 / (r * r)) + ((-0.375d0) * ((r * w) * (r * w))))
end function
public static double code(double v, double w, double r) {
return -1.5 + ((2.0 / (r * r)) + (-0.375 * ((r * w) * (r * w))));
}
def code(v, w, r): return -1.5 + ((2.0 / (r * r)) + (-0.375 * ((r * w) * (r * w))))
function code(v, w, r) return Float64(-1.5 + Float64(Float64(2.0 / Float64(r * r)) + Float64(-0.375 * Float64(Float64(r * w) * Float64(r * w))))) end
function tmp = code(v, w, r) tmp = -1.5 + ((2.0 / (r * r)) + (-0.375 * ((r * w) * (r * w)))); end
code[v_, w_, r_] := N[(-1.5 + N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[(N[(r * w), $MachinePrecision] * N[(r * w), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1.5 + \left(\frac{2}{r \cdot r} + -0.375 \cdot \left(\left(r \cdot w\right) \cdot \left(r \cdot w\right)\right)\right)
\end{array}
Initial program 84.2%
Simplified77.3%
Taylor expanded in v around 0 76.3%
*-commutative76.3%
unpow276.3%
unpow276.3%
swap-sqr93.8%
unpow293.8%
*-commutative93.8%
Simplified93.8%
unpow293.8%
Applied egg-rr93.8%
Final simplification93.8%
herbie shell --seed 2024023
(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))