
(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)))
(t_1 (+ 3.0 t_0))
(t_2 (* 0.125 (+ 3.0 (* -2.0 v))))
(t_3 (* (* r w) (* r w))))
(if (<= v -0.18)
(+ t_0 (- -1.5 (* t_3 0.25)))
(if (<= v 1.85e-19)
(- t_1 (+ (* t_2 t_3) 4.5))
(+ t_1 (- (* t_2 (* (* r w) (/ (* r w) v))) 4.5))))))
double code(double v, double w, double r) {
double t_0 = 2.0 / (r * r);
double t_1 = 3.0 + t_0;
double t_2 = 0.125 * (3.0 + (-2.0 * v));
double t_3 = (r * w) * (r * w);
double tmp;
if (v <= -0.18) {
tmp = t_0 + (-1.5 - (t_3 * 0.25));
} else if (v <= 1.85e-19) {
tmp = t_1 - ((t_2 * t_3) + 4.5);
} else {
tmp = t_1 + ((t_2 * ((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) :: t_1
real(8) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = 2.0d0 / (r * r)
t_1 = 3.0d0 + t_0
t_2 = 0.125d0 * (3.0d0 + ((-2.0d0) * v))
t_3 = (r * w) * (r * w)
if (v <= (-0.18d0)) then
tmp = t_0 + ((-1.5d0) - (t_3 * 0.25d0))
else if (v <= 1.85d-19) then
tmp = t_1 - ((t_2 * t_3) + 4.5d0)
else
tmp = t_1 + ((t_2 * ((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);
double t_1 = 3.0 + t_0;
double t_2 = 0.125 * (3.0 + (-2.0 * v));
double t_3 = (r * w) * (r * w);
double tmp;
if (v <= -0.18) {
tmp = t_0 + (-1.5 - (t_3 * 0.25));
} else if (v <= 1.85e-19) {
tmp = t_1 - ((t_2 * t_3) + 4.5);
} else {
tmp = t_1 + ((t_2 * ((r * w) * ((r * w) / v))) - 4.5);
}
return tmp;
}
def code(v, w, r): t_0 = 2.0 / (r * r) t_1 = 3.0 + t_0 t_2 = 0.125 * (3.0 + (-2.0 * v)) t_3 = (r * w) * (r * w) tmp = 0 if v <= -0.18: tmp = t_0 + (-1.5 - (t_3 * 0.25)) elif v <= 1.85e-19: tmp = t_1 - ((t_2 * t_3) + 4.5) else: tmp = t_1 + ((t_2 * ((r * w) * ((r * w) / v))) - 4.5) return tmp
function code(v, w, r) t_0 = Float64(2.0 / Float64(r * r)) t_1 = Float64(3.0 + t_0) t_2 = Float64(0.125 * Float64(3.0 + Float64(-2.0 * v))) t_3 = Float64(Float64(r * w) * Float64(r * w)) tmp = 0.0 if (v <= -0.18) tmp = Float64(t_0 + Float64(-1.5 - Float64(t_3 * 0.25))); elseif (v <= 1.85e-19) tmp = Float64(t_1 - Float64(Float64(t_2 * t_3) + 4.5)); else tmp = Float64(t_1 + Float64(Float64(t_2 * Float64(Float64(r * w) * Float64(Float64(r * w) / v))) - 4.5)); end return tmp end
function tmp_2 = code(v, w, r) t_0 = 2.0 / (r * r); t_1 = 3.0 + t_0; t_2 = 0.125 * (3.0 + (-2.0 * v)); t_3 = (r * w) * (r * w); tmp = 0.0; if (v <= -0.18) tmp = t_0 + (-1.5 - (t_3 * 0.25)); elseif (v <= 1.85e-19) tmp = t_1 - ((t_2 * t_3) + 4.5); else tmp = t_1 + ((t_2 * ((r * w) * ((r * w) / v))) - 4.5); end tmp_2 = tmp; end
code[v_, w_, r_] := Block[{t$95$0 = N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(3.0 + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(0.125 * N[(3.0 + N[(-2.0 * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(r * w), $MachinePrecision] * N[(r * w), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[v, -0.18], N[(t$95$0 + N[(-1.5 - N[(t$95$3 * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[v, 1.85e-19], N[(t$95$1 - N[(N[(t$95$2 * t$95$3), $MachinePrecision] + 4.5), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(N[(t$95$2 * N[(N[(r * w), $MachinePrecision] * N[(N[(r * w), $MachinePrecision] / v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{r \cdot r}\\
t_1 := 3 + t\_0\\
t_2 := 0.125 \cdot \left(3 + -2 \cdot v\right)\\
t_3 := \left(r \cdot w\right) \cdot \left(r \cdot w\right)\\
\mathbf{if}\;v \leq -0.18:\\
\;\;\;\;t\_0 + \left(-1.5 - t\_3 \cdot 0.25\right)\\
\mathbf{elif}\;v \leq 1.85 \cdot 10^{-19}:\\
\;\;\;\;t\_1 - \left(t\_2 \cdot t\_3 + 4.5\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1 + \left(t\_2 \cdot \left(\left(r \cdot w\right) \cdot \frac{r \cdot w}{v}\right) - 4.5\right)\\
\end{array}
\end{array}
if v < -0.17999999999999999Initial program 78.5%
Simplified85.3%
Taylor expanded in v around inf 81.5%
*-commutative81.5%
*-commutative81.5%
unpow281.5%
unpow281.5%
swap-sqr98.7%
unpow298.7%
*-commutative98.7%
Simplified98.7%
*-commutative98.7%
pow298.7%
Applied egg-rr98.7%
if -0.17999999999999999 < v < 1.85000000000000003e-19Initial program 85.8%
associate--l-85.8%
associate-*l*81.6%
sqr-neg81.6%
associate-*l*85.8%
associate-/l*85.8%
fma-define85.7%
Simplified85.8%
*-commutative85.8%
associate-*r/85.8%
associate-*r*96.4%
associate-*l*99.8%
*-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in v around 0 99.8%
if 1.85000000000000003e-19 < v Initial program 86.6%
associate--l-86.6%
associate-*l*82.2%
sqr-neg82.2%
associate-*l*86.6%
associate-/l*93.0%
fma-define93.0%
Simplified93.0%
*-commutative93.0%
associate-*r/90.7%
associate-*r*96.4%
associate-*l*97.6%
*-commutative97.6%
Applied egg-rr97.6%
Taylor expanded in v around inf 99.9%
associate-*r/99.9%
mul-1-neg99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
Simplified99.9%
Final simplification99.6%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (* (* r w) (* r w))) (t_1 (/ 2.0 (* r r))))
(if (or (<= v -0.34) (not (<= v 4.5e-55)))
(+ t_1 (- -1.5 (* t_0 0.25)))
(- (+ 3.0 t_1) (+ (* (* 0.125 (+ 3.0 (* -2.0 v))) t_0) 4.5)))))
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 <= -0.34) || !(v <= 4.5e-55)) {
tmp = t_1 + (-1.5 - (t_0 * 0.25));
} else {
tmp = (3.0 + t_1) - (((0.125 * (3.0 + (-2.0 * v))) * t_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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (r * w) * (r * w)
t_1 = 2.0d0 / (r * r)
if ((v <= (-0.34d0)) .or. (.not. (v <= 4.5d-55))) then
tmp = t_1 + ((-1.5d0) - (t_0 * 0.25d0))
else
tmp = (3.0d0 + t_1) - (((0.125d0 * (3.0d0 + ((-2.0d0) * v))) * t_0) + 4.5d0)
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 <= -0.34) || !(v <= 4.5e-55)) {
tmp = t_1 + (-1.5 - (t_0 * 0.25));
} else {
tmp = (3.0 + t_1) - (((0.125 * (3.0 + (-2.0 * v))) * t_0) + 4.5);
}
return tmp;
}
def code(v, w, r): t_0 = (r * w) * (r * w) t_1 = 2.0 / (r * r) tmp = 0 if (v <= -0.34) or not (v <= 4.5e-55): tmp = t_1 + (-1.5 - (t_0 * 0.25)) else: tmp = (3.0 + t_1) - (((0.125 * (3.0 + (-2.0 * v))) * t_0) + 4.5) 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 <= -0.34) || !(v <= 4.5e-55)) tmp = Float64(t_1 + Float64(-1.5 - Float64(t_0 * 0.25))); else tmp = Float64(Float64(3.0 + t_1) - Float64(Float64(Float64(0.125 * Float64(3.0 + Float64(-2.0 * v))) * t_0) + 4.5)); 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 <= -0.34) || ~((v <= 4.5e-55))) tmp = t_1 + (-1.5 - (t_0 * 0.25)); else tmp = (3.0 + t_1) - (((0.125 * (3.0 + (-2.0 * v))) * t_0) + 4.5); 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, -0.34], N[Not[LessEqual[v, 4.5e-55]], $MachinePrecision]], N[(t$95$1 + N[(-1.5 - N[(t$95$0 * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(3.0 + t$95$1), $MachinePrecision] - N[(N[(N[(0.125 * N[(3.0 + N[(-2.0 * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + 4.5), $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 -0.34 \lor \neg \left(v \leq 4.5 \cdot 10^{-55}\right):\\
\;\;\;\;t\_1 + \left(-1.5 - t\_0 \cdot 0.25\right)\\
\mathbf{else}:\\
\;\;\;\;\left(3 + t\_1\right) - \left(\left(0.125 \cdot \left(3 + -2 \cdot v\right)\right) \cdot t\_0 + 4.5\right)\\
\end{array}
\end{array}
if v < -0.340000000000000024 or 4.4999999999999997e-55 < v Initial program 84.0%
Simplified88.4%
Taylor expanded in v around inf 85.0%
*-commutative85.0%
*-commutative85.0%
unpow285.0%
unpow285.0%
swap-sqr99.4%
unpow299.4%
*-commutative99.4%
Simplified99.4%
*-commutative99.4%
pow299.4%
Applied egg-rr99.4%
if -0.340000000000000024 < v < 4.4999999999999997e-55Initial program 85.2%
associate--l-85.2%
associate-*l*81.0%
sqr-neg81.0%
associate-*l*85.2%
associate-/l*85.2%
fma-define85.2%
Simplified85.2%
*-commutative85.2%
associate-*r/85.2%
associate-*r*96.3%
associate-*l*99.8%
*-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in v around 0 99.8%
Final simplification99.6%
(FPCore (v w r) :precision binary64 (+ (+ 3.0 (/ 2.0 (* r r))) (- (* (* 0.125 (+ 3.0 (* -2.0 v))) (* (* r w) (* w (/ r (+ v -1.0))))) 4.5)))
double code(double v, double w, double r) {
return (3.0 + (2.0 / (r * r))) + (((0.125 * (3.0 + (-2.0 * v))) * ((r * w) * (w * (r / (v + -1.0))))) - 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))) * ((r * w) * (w * (r / (v + (-1.0d0)))))) - 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))) * ((r * w) * (w * (r / (v + -1.0))))) - 4.5);
}
def code(v, w, r): return (3.0 + (2.0 / (r * r))) + (((0.125 * (3.0 + (-2.0 * v))) * ((r * w) * (w * (r / (v + -1.0))))) - 4.5)
function code(v, w, r) return Float64(Float64(3.0 + Float64(2.0 / Float64(r * r))) + Float64(Float64(Float64(0.125 * Float64(3.0 + Float64(-2.0 * v))) * Float64(Float64(r * w) * Float64(w * Float64(r / Float64(v + -1.0))))) - 4.5)) end
function tmp = code(v, w, r) tmp = (3.0 + (2.0 / (r * r))) + (((0.125 * (3.0 + (-2.0 * v))) * ((r * w) * (w * (r / (v + -1.0))))) - 4.5); end
code[v_, w_, r_] := 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[(r * w), $MachinePrecision] * N[(w * N[(r / N[(v + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(3 + \frac{2}{r \cdot r}\right) + \left(\left(0.125 \cdot \left(3 + -2 \cdot v\right)\right) \cdot \left(\left(r \cdot w\right) \cdot \left(w \cdot \frac{r}{v + -1}\right)\right) - 4.5\right)
\end{array}
Initial program 84.5%
associate--l-84.5%
associate-*l*80.4%
sqr-neg80.4%
associate-*l*84.5%
associate-/l*88.6%
fma-define88.5%
Simplified88.6%
*-commutative88.6%
associate-*r/87.3%
associate-*r*96.0%
associate-*l*98.7%
*-commutative98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (v w r) :precision binary64 (+ (/ 2.0 (* r r)) (- -1.5 (* (* (* r w) (* r w)) 0.25))))
double code(double v, double w, double r) {
return (2.0 / (r * r)) + (-1.5 - (((r * w) * (r * w)) * 0.25));
}
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) - (((r * w) * (r * w)) * 0.25d0))
end function
public static double code(double v, double w, double r) {
return (2.0 / (r * r)) + (-1.5 - (((r * w) * (r * w)) * 0.25));
}
def code(v, w, r): return (2.0 / (r * r)) + (-1.5 - (((r * w) * (r * w)) * 0.25))
function code(v, w, r) return Float64(Float64(2.0 / Float64(r * r)) + Float64(-1.5 - Float64(Float64(Float64(r * w) * Float64(r * w)) * 0.25))) end
function tmp = code(v, w, r) tmp = (2.0 / (r * r)) + (-1.5 - (((r * w) * (r * w)) * 0.25)); end
code[v_, w_, r_] := N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[(-1.5 - N[(N[(N[(r * w), $MachinePrecision] * N[(r * w), $MachinePrecision]), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{r \cdot r} + \left(-1.5 - \left(\left(r \cdot w\right) \cdot \left(r \cdot w\right)\right) \cdot 0.25\right)
\end{array}
Initial program 84.5%
Simplified87.0%
Taylor expanded in v around inf 79.9%
*-commutative79.9%
*-commutative79.9%
unpow279.9%
unpow279.9%
swap-sqr94.3%
unpow294.3%
*-commutative94.3%
Simplified94.3%
*-commutative94.3%
pow294.3%
Applied egg-rr94.3%
Final simplification94.3%
herbie shell --seed 2024044
(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))