
(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;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(v, w, r)
use fmin_fmax_functions
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}
Herbie found 10 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;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(v, w, r)
use fmin_fmax_functions
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)) 1.5))
(t_1 (* (* w r) 0.125))
(t_2 (fma (* -2.0 (* r w)) t_1 t_0)))
(if (<= v -3.25e+41)
t_2
(if (<= v 3e-19) (fma (* -3.0 (* r w)) t_1 t_0) t_2))))
double code(double v, double w, double r) {
double t_0 = (2.0 / (r * r)) - 1.5;
double t_1 = (w * r) * 0.125;
double t_2 = fma((-2.0 * (r * w)), t_1, t_0);
double tmp;
if (v <= -3.25e+41) {
tmp = t_2;
} else if (v <= 3e-19) {
tmp = fma((-3.0 * (r * w)), t_1, t_0);
} else {
tmp = t_2;
}
return tmp;
}
function code(v, w, r) t_0 = Float64(Float64(2.0 / Float64(r * r)) - 1.5) t_1 = Float64(Float64(w * r) * 0.125) t_2 = fma(Float64(-2.0 * Float64(r * w)), t_1, t_0) tmp = 0.0 if (v <= -3.25e+41) tmp = t_2; elseif (v <= 3e-19) tmp = fma(Float64(-3.0 * Float64(r * w)), t_1, t_0); else tmp = t_2; end return tmp end
code[v_, w_, r_] := Block[{t$95$0 = N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] - 1.5), $MachinePrecision]}, Block[{t$95$1 = N[(N[(w * r), $MachinePrecision] * 0.125), $MachinePrecision]}, Block[{t$95$2 = N[(N[(-2.0 * N[(r * w), $MachinePrecision]), $MachinePrecision] * t$95$1 + t$95$0), $MachinePrecision]}, If[LessEqual[v, -3.25e+41], t$95$2, If[LessEqual[v, 3e-19], N[(N[(-3.0 * N[(r * w), $MachinePrecision]), $MachinePrecision] * t$95$1 + t$95$0), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{r \cdot r} - 1.5\\
t_1 := \left(w \cdot r\right) \cdot 0.125\\
t_2 := \mathsf{fma}\left(-2 \cdot \left(r \cdot w\right), t\_1, t\_0\right)\\
\mathbf{if}\;v \leq -3.25 \cdot 10^{+41}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;v \leq 3 \cdot 10^{-19}:\\
\;\;\;\;\mathsf{fma}\left(-3 \cdot \left(r \cdot w\right), t\_1, t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if v < -3.24999999999999988e41 or 2.99999999999999993e-19 < v Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites99.3%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites94.8%
Taylor expanded in v around inf
lower-*.f64N/A
lower-*.f6493.3
Applied rewrites93.3%
if -3.24999999999999988e41 < v < 2.99999999999999993e-19Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites99.3%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites94.8%
Taylor expanded in v around 0
lower-*.f64N/A
lower-*.f6493.3
Applied rewrites93.3%
(FPCore (v w r) :precision binary64 (- (fma (* (fma v 2.0 -3.0) (* (* (/ r (- 1.0 v)) w) (* w r))) 0.125 (- (/ 2.0 (* r r)) -3.0)) 4.5))
double code(double v, double w, double r) {
return fma((fma(v, 2.0, -3.0) * (((r / (1.0 - v)) * w) * (w * r))), 0.125, ((2.0 / (r * r)) - -3.0)) - 4.5;
}
function code(v, w, r) return Float64(fma(Float64(fma(v, 2.0, -3.0) * Float64(Float64(Float64(r / Float64(1.0 - v)) * w) * Float64(w * r))), 0.125, Float64(Float64(2.0 / Float64(r * r)) - -3.0)) - 4.5) end
code[v_, w_, r_] := N[(N[(N[(N[(v * 2.0 + -3.0), $MachinePrecision] * N[(N[(N[(r / N[(1.0 - v), $MachinePrecision]), $MachinePrecision] * w), $MachinePrecision] * N[(w * r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.125 + N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] - -3.0), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(v, 2, -3\right) \cdot \left(\left(\frac{r}{1 - v} \cdot w\right) \cdot \left(w \cdot r\right)\right), 0.125, \frac{2}{r \cdot r} - -3\right) - 4.5
\end{array}
Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites99.3%
(FPCore (v w r) :precision binary64 (- (fma (* (fma v 2.0 -3.0) 0.125) (* (* (/ r (- 1.0 v)) w) (* w r)) (- (/ 2.0 (* r r)) -3.0)) 4.5))
double code(double v, double w, double r) {
return fma((fma(v, 2.0, -3.0) * 0.125), (((r / (1.0 - v)) * w) * (w * r)), ((2.0 / (r * r)) - -3.0)) - 4.5;
}
function code(v, w, r) return Float64(fma(Float64(fma(v, 2.0, -3.0) * 0.125), Float64(Float64(Float64(r / Float64(1.0 - v)) * w) * Float64(w * r)), Float64(Float64(2.0 / Float64(r * r)) - -3.0)) - 4.5) end
code[v_, w_, r_] := N[(N[(N[(N[(v * 2.0 + -3.0), $MachinePrecision] * 0.125), $MachinePrecision] * N[(N[(N[(r / N[(1.0 - v), $MachinePrecision]), $MachinePrecision] * w), $MachinePrecision] * N[(w * r), $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] - -3.0), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(v, 2, -3\right) \cdot 0.125, \left(\frac{r}{1 - v} \cdot w\right) \cdot \left(w \cdot r\right), \frac{2}{r \cdot r} - -3\right) - 4.5
\end{array}
Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites99.4%
(FPCore (v w r)
:precision binary64
(if (<= r 5500000.0)
(fma (* -3.0 (* r w)) (* (* w r) 0.125) (- (/ 2.0 (* r r)) 1.5))
(-
(fma (* (fma v 2.0 -3.0) (* (* (/ r (- 1.0 v)) w) (* w r))) 0.125 3.0)
4.5)))
double code(double v, double w, double r) {
double tmp;
if (r <= 5500000.0) {
tmp = fma((-3.0 * (r * w)), ((w * r) * 0.125), ((2.0 / (r * r)) - 1.5));
} else {
tmp = fma((fma(v, 2.0, -3.0) * (((r / (1.0 - v)) * w) * (w * r))), 0.125, 3.0) - 4.5;
}
return tmp;
}
function code(v, w, r) tmp = 0.0 if (r <= 5500000.0) tmp = fma(Float64(-3.0 * Float64(r * w)), Float64(Float64(w * r) * 0.125), Float64(Float64(2.0 / Float64(r * r)) - 1.5)); else tmp = Float64(fma(Float64(fma(v, 2.0, -3.0) * Float64(Float64(Float64(r / Float64(1.0 - v)) * w) * Float64(w * r))), 0.125, 3.0) - 4.5); end return tmp end
code[v_, w_, r_] := If[LessEqual[r, 5500000.0], N[(N[(-3.0 * N[(r * w), $MachinePrecision]), $MachinePrecision] * N[(N[(w * r), $MachinePrecision] * 0.125), $MachinePrecision] + N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] - 1.5), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(v * 2.0 + -3.0), $MachinePrecision] * N[(N[(N[(r / N[(1.0 - v), $MachinePrecision]), $MachinePrecision] * w), $MachinePrecision] * N[(w * r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.125 + 3.0), $MachinePrecision] - 4.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;r \leq 5500000:\\
\;\;\;\;\mathsf{fma}\left(-3 \cdot \left(r \cdot w\right), \left(w \cdot r\right) \cdot 0.125, \frac{2}{r \cdot r} - 1.5\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(v, 2, -3\right) \cdot \left(\left(\frac{r}{1 - v} \cdot w\right) \cdot \left(w \cdot r\right)\right), 0.125, 3\right) - 4.5\\
\end{array}
\end{array}
if r < 5.5e6Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites99.3%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites94.8%
Taylor expanded in v around 0
lower-*.f64N/A
lower-*.f6493.3
Applied rewrites93.3%
if 5.5e6 < r Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites99.3%
Taylor expanded in r around inf
Applied rewrites55.8%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (* (* w r) 0.125)))
(if (<= r 1.6e+15)
(fma (* -2.0 (* r w)) t_0 (- (/ 2.0 (* r r)) 1.5))
(fma (* (* (fma 2.0 v -3.0) w) (/ r (- 1.0 v))) t_0 -1.5))))
double code(double v, double w, double r) {
double t_0 = (w * r) * 0.125;
double tmp;
if (r <= 1.6e+15) {
tmp = fma((-2.0 * (r * w)), t_0, ((2.0 / (r * r)) - 1.5));
} else {
tmp = fma(((fma(2.0, v, -3.0) * w) * (r / (1.0 - v))), t_0, -1.5);
}
return tmp;
}
function code(v, w, r) t_0 = Float64(Float64(w * r) * 0.125) tmp = 0.0 if (r <= 1.6e+15) tmp = fma(Float64(-2.0 * Float64(r * w)), t_0, Float64(Float64(2.0 / Float64(r * r)) - 1.5)); else tmp = fma(Float64(Float64(fma(2.0, v, -3.0) * w) * Float64(r / Float64(1.0 - v))), t_0, -1.5); end return tmp end
code[v_, w_, r_] := Block[{t$95$0 = N[(N[(w * r), $MachinePrecision] * 0.125), $MachinePrecision]}, If[LessEqual[r, 1.6e+15], N[(N[(-2.0 * N[(r * w), $MachinePrecision]), $MachinePrecision] * t$95$0 + N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] - 1.5), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(2.0 * v + -3.0), $MachinePrecision] * w), $MachinePrecision] * N[(r / N[(1.0 - v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0 + -1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(w \cdot r\right) \cdot 0.125\\
\mathbf{if}\;r \leq 1.6 \cdot 10^{+15}:\\
\;\;\;\;\mathsf{fma}\left(-2 \cdot \left(r \cdot w\right), t\_0, \frac{2}{r \cdot r} - 1.5\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\mathsf{fma}\left(2, v, -3\right) \cdot w\right) \cdot \frac{r}{1 - v}, t\_0, -1.5\right)\\
\end{array}
\end{array}
if r < 1.6e15Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites99.3%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites94.8%
Taylor expanded in v around inf
lower-*.f64N/A
lower-*.f6493.3
Applied rewrites93.3%
if 1.6e15 < r Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites99.3%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites94.8%
Taylor expanded in r around inf
Applied rewrites55.1%
(FPCore (v w r) :precision binary64 (fma (* -3.0 (* r w)) (* (* w r) 0.125) (- (/ 2.0 (* r r)) 1.5)))
double code(double v, double w, double r) {
return fma((-3.0 * (r * w)), ((w * r) * 0.125), ((2.0 / (r * r)) - 1.5));
}
function code(v, w, r) return fma(Float64(-3.0 * Float64(r * w)), Float64(Float64(w * r) * 0.125), Float64(Float64(2.0 / Float64(r * r)) - 1.5)) end
code[v_, w_, r_] := N[(N[(-3.0 * N[(r * w), $MachinePrecision]), $MachinePrecision] * N[(N[(w * r), $MachinePrecision] * 0.125), $MachinePrecision] + N[(N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision] - 1.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-3 \cdot \left(r \cdot w\right), \left(w \cdot r\right) \cdot 0.125, \frac{2}{r \cdot r} - 1.5\right)
\end{array}
Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites99.3%
lift--.f64N/A
lift-fma.f64N/A
associate--l+N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-fma.f64N/A
Applied rewrites94.8%
Taylor expanded in v around 0
lower-*.f64N/A
lower-*.f6493.3
Applied rewrites93.3%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (* (* w w) r)))
(if (<=
(-
(-
(+ 3.0 (/ 2.0 (* r r)))
(/ (* (* 0.125 (- 3.0 (* 2.0 v))) (* t_0 r)) (- 1.0 v)))
4.5)
-1.505)
(- (fma (* (fma v 2.0 -3.0) (* t_0 0.125)) r 3.0) 4.5)
(- (* 2.0 (/ 1.0 (pow r 2.0))) 1.5))))
double code(double v, double w, double r) {
double t_0 = (w * w) * r;
double tmp;
if ((((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (t_0 * r)) / (1.0 - v))) - 4.5) <= -1.505) {
tmp = fma((fma(v, 2.0, -3.0) * (t_0 * 0.125)), r, 3.0) - 4.5;
} else {
tmp = (2.0 * (1.0 / pow(r, 2.0))) - 1.5;
}
return tmp;
}
function code(v, w, r) t_0 = Float64(Float64(w * w) * r) tmp = 0.0 if (Float64(Float64(Float64(3.0 + Float64(2.0 / Float64(r * r))) - Float64(Float64(Float64(0.125 * Float64(3.0 - Float64(2.0 * v))) * Float64(t_0 * r)) / Float64(1.0 - v))) - 4.5) <= -1.505) tmp = Float64(fma(Float64(fma(v, 2.0, -3.0) * Float64(t_0 * 0.125)), r, 3.0) - 4.5); else tmp = Float64(Float64(2.0 * Float64(1.0 / (r ^ 2.0))) - 1.5); end return tmp end
code[v_, w_, r_] := Block[{t$95$0 = N[(N[(w * w), $MachinePrecision] * r), $MachinePrecision]}, If[LessEqual[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[(t$95$0 * r), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision], -1.505], N[(N[(N[(N[(v * 2.0 + -3.0), $MachinePrecision] * N[(t$95$0 * 0.125), $MachinePrecision]), $MachinePrecision] * r + 3.0), $MachinePrecision] - 4.5), $MachinePrecision], N[(N[(2.0 * N[(1.0 / N[Power[r, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(w \cdot w\right) \cdot r\\
\mathbf{if}\;\left(\left(3 + \frac{2}{r \cdot r}\right) - \frac{\left(0.125 \cdot \left(3 - 2 \cdot v\right)\right) \cdot \left(t\_0 \cdot r\right)}{1 - v}\right) - 4.5 \leq -1.505:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(v, 2, -3\right) \cdot \left(t\_0 \cdot 0.125\right), r, 3\right) - 4.5\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{1}{{r}^{2}} - 1.5\\
\end{array}
\end{array}
if (-.f64 (-.f64 (+.f64 #s(literal 3 binary64) (/.f64 #s(literal 2 binary64) (*.f64 r r))) (/.f64 (*.f64 (*.f64 #s(literal 1/8 binary64) (-.f64 #s(literal 3 binary64) (*.f64 #s(literal 2 binary64) v))) (*.f64 (*.f64 (*.f64 w w) r) r)) (-.f64 #s(literal 1 binary64) v))) #s(literal 9/2 binary64)) < -1.5049999999999999Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites85.9%
Taylor expanded in r around inf
Applied rewrites50.5%
Taylor expanded in v around 0
Applied rewrites39.8%
if -1.5049999999999999 < (-.f64 (-.f64 (+.f64 #s(literal 3 binary64) (/.f64 #s(literal 2 binary64) (*.f64 r r))) (/.f64 (*.f64 (*.f64 #s(literal 1/8 binary64) (-.f64 #s(literal 3 binary64) (*.f64 #s(literal 2 binary64) v))) (*.f64 (*.f64 (*.f64 w w) r) r)) (-.f64 #s(literal 1 binary64) v))) #s(literal 9/2 binary64)) Initial program 85.3%
Taylor expanded in w around 0
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-pow.f6457.2
Applied rewrites57.2%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (* (* w w) r)))
(if (<=
(-
(-
(+ 3.0 (/ 2.0 (* r r)))
(/ (* (* 0.125 (- 3.0 (* 2.0 v))) (* t_0 r)) (- 1.0 v)))
4.5)
-1.0)
(- (fma (* (fma v 2.0 -3.0) (* t_0 0.125)) r 3.0) 4.5)
(/ (/ 2.0 r) r))))
double code(double v, double w, double r) {
double t_0 = (w * w) * r;
double tmp;
if ((((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * (t_0 * r)) / (1.0 - v))) - 4.5) <= -1.0) {
tmp = fma((fma(v, 2.0, -3.0) * (t_0 * 0.125)), r, 3.0) - 4.5;
} else {
tmp = (2.0 / r) / r;
}
return tmp;
}
function code(v, w, r) t_0 = Float64(Float64(w * w) * r) tmp = 0.0 if (Float64(Float64(Float64(3.0 + Float64(2.0 / Float64(r * r))) - Float64(Float64(Float64(0.125 * Float64(3.0 - Float64(2.0 * v))) * Float64(t_0 * r)) / Float64(1.0 - v))) - 4.5) <= -1.0) tmp = Float64(fma(Float64(fma(v, 2.0, -3.0) * Float64(t_0 * 0.125)), r, 3.0) - 4.5); else tmp = Float64(Float64(2.0 / r) / r); end return tmp end
code[v_, w_, r_] := Block[{t$95$0 = N[(N[(w * w), $MachinePrecision] * r), $MachinePrecision]}, If[LessEqual[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[(t$95$0 * r), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision], -1.0], N[(N[(N[(N[(v * 2.0 + -3.0), $MachinePrecision] * N[(t$95$0 * 0.125), $MachinePrecision]), $MachinePrecision] * r + 3.0), $MachinePrecision] - 4.5), $MachinePrecision], N[(N[(2.0 / r), $MachinePrecision] / r), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(w \cdot w\right) \cdot r\\
\mathbf{if}\;\left(\left(3 + \frac{2}{r \cdot r}\right) - \frac{\left(0.125 \cdot \left(3 - 2 \cdot v\right)\right) \cdot \left(t\_0 \cdot r\right)}{1 - v}\right) - 4.5 \leq -1:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(v, 2, -3\right) \cdot \left(t\_0 \cdot 0.125\right), r, 3\right) - 4.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{r}}{r}\\
\end{array}
\end{array}
if (-.f64 (-.f64 (+.f64 #s(literal 3 binary64) (/.f64 #s(literal 2 binary64) (*.f64 r r))) (/.f64 (*.f64 (*.f64 #s(literal 1/8 binary64) (-.f64 #s(literal 3 binary64) (*.f64 #s(literal 2 binary64) v))) (*.f64 (*.f64 (*.f64 w w) r) r)) (-.f64 #s(literal 1 binary64) v))) #s(literal 9/2 binary64)) < -1Initial program 85.3%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
Applied rewrites85.9%
Taylor expanded in r around inf
Applied rewrites50.5%
Taylor expanded in v around 0
Applied rewrites39.8%
if -1 < (-.f64 (-.f64 (+.f64 #s(literal 3 binary64) (/.f64 #s(literal 2 binary64) (*.f64 r r))) (/.f64 (*.f64 (*.f64 #s(literal 1/8 binary64) (-.f64 #s(literal 3 binary64) (*.f64 #s(literal 2 binary64) v))) (*.f64 (*.f64 (*.f64 w w) r) r)) (-.f64 #s(literal 1 binary64) v))) #s(literal 9/2 binary64)) Initial program 85.3%
Taylor expanded in r around 0
lower-/.f64N/A
lower-pow.f6444.1
Applied rewrites44.1%
lift-pow.f64N/A
pow2N/A
lift-*.f6444.1
Applied rewrites44.1%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6444.1
Applied rewrites44.1%
(FPCore (v w r) :precision binary64 (/ (/ 2.0 r) r))
double code(double v, double w, double r) {
return (2.0 / r) / r;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(v, w, r)
use fmin_fmax_functions
real(8), intent (in) :: v
real(8), intent (in) :: w
real(8), intent (in) :: r
code = (2.0d0 / r) / r
end function
public static double code(double v, double w, double r) {
return (2.0 / r) / r;
}
def code(v, w, r): return (2.0 / r) / r
function code(v, w, r) return Float64(Float64(2.0 / r) / r) end
function tmp = code(v, w, r) tmp = (2.0 / r) / r; end
code[v_, w_, r_] := N[(N[(2.0 / r), $MachinePrecision] / r), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{2}{r}}{r}
\end{array}
Initial program 85.3%
Taylor expanded in r around 0
lower-/.f64N/A
lower-pow.f6444.1
Applied rewrites44.1%
lift-pow.f64N/A
pow2N/A
lift-*.f6444.1
Applied rewrites44.1%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6444.1
Applied rewrites44.1%
(FPCore (v w r) :precision binary64 (/ 2.0 (* r r)))
double code(double v, double w, double r) {
return 2.0 / (r * r);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(v, w, r)
use fmin_fmax_functions
real(8), intent (in) :: v
real(8), intent (in) :: w
real(8), intent (in) :: r
code = 2.0d0 / (r * r)
end function
public static double code(double v, double w, double r) {
return 2.0 / (r * r);
}
def code(v, w, r): return 2.0 / (r * r)
function code(v, w, r) return Float64(2.0 / Float64(r * r)) end
function tmp = code(v, w, r) tmp = 2.0 / (r * r); end
code[v_, w_, r_] := N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{r \cdot r}
\end{array}
Initial program 85.3%
Taylor expanded in r around 0
lower-/.f64N/A
lower-pow.f6444.1
Applied rewrites44.1%
lift-pow.f64N/A
pow2N/A
lift-*.f6444.1
Applied rewrites44.1%
herbie shell --seed 2025161
(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))