
(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}
Sampling outcomes in binary64 precision:
Herbie found 8 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 (- (fma (pow r -2.0) 2.0 3.0) (fma (* (fma -2.0 v 3.0) 0.125) (/ (pow (* r w) 2.0) (- 1.0 v)) 4.5)))
double code(double v, double w, double r) {
return fma(pow(r, -2.0), 2.0, 3.0) - fma((fma(-2.0, v, 3.0) * 0.125), (pow((r * w), 2.0) / (1.0 - v)), 4.5);
}
function code(v, w, r) return Float64(fma((r ^ -2.0), 2.0, 3.0) - fma(Float64(fma(-2.0, v, 3.0) * 0.125), Float64((Float64(r * w) ^ 2.0) / Float64(1.0 - v)), 4.5)) end
code[v_, w_, r_] := N[(N[(N[Power[r, -2.0], $MachinePrecision] * 2.0 + 3.0), $MachinePrecision] - N[(N[(N[(-2.0 * v + 3.0), $MachinePrecision] * 0.125), $MachinePrecision] * N[(N[Power[N[(r * w), $MachinePrecision], 2.0], $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision] + 4.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left({r}^{-2}, 2, 3\right) - \mathsf{fma}\left(\mathsf{fma}\left(-2, v, 3\right) \cdot 0.125, \frac{{\left(r \cdot w\right)}^{2}}{1 - v}, 4.5\right)
\end{array}
Initial program 82.0%
Applied rewrites99.8%
lift-pow.f64N/A
lift-*.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
metadata-evalN/A
lower-pow.f6499.9
lift-*.f64N/A
pow2N/A
lift-*.f64N/A
lift-pow.f64N/A
unpow1N/A
lower-pow.f64N/A
lift-*.f6499.9
Applied rewrites99.9%
(FPCore (v w r)
:precision binary64
(if (<= r 5e+148)
(-
(fma (pow r -2.0) 2.0 3.0)
(fma (* (fma -2.0 v 3.0) 0.125) (/ (* w (* (* w r) r)) (- 1.0 v)) 4.5))
(+
(-
(+ 3.0 (/ 2.0 (* r r)))
(/ (* (* 0.125 (- 3.0 (* 2.0 v))) (* (* w (* w r)) r)) (- 1.0 v)))
(* -1.0 4.5))))
double code(double v, double w, double r) {
double tmp;
if (r <= 5e+148) {
tmp = fma(pow(r, -2.0), 2.0, 3.0) - fma((fma(-2.0, v, 3.0) * 0.125), ((w * ((w * r) * r)) / (1.0 - v)), 4.5);
} else {
tmp = ((3.0 + (2.0 / (r * r))) - (((0.125 * (3.0 - (2.0 * v))) * ((w * (w * r)) * r)) / (1.0 - v))) + (-1.0 * 4.5);
}
return tmp;
}
function code(v, w, r) tmp = 0.0 if (r <= 5e+148) tmp = Float64(fma((r ^ -2.0), 2.0, 3.0) - fma(Float64(fma(-2.0, v, 3.0) * 0.125), Float64(Float64(w * Float64(Float64(w * r) * r)) / Float64(1.0 - v)), 4.5)); else tmp = 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(w * Float64(w * r)) * r)) / Float64(1.0 - v))) + Float64(-1.0 * 4.5)); end return tmp end
code[v_, w_, r_] := If[LessEqual[r, 5e+148], N[(N[(N[Power[r, -2.0], $MachinePrecision] * 2.0 + 3.0), $MachinePrecision] - N[(N[(N[(-2.0 * v + 3.0), $MachinePrecision] * 0.125), $MachinePrecision] * N[(N[(w * N[(N[(w * r), $MachinePrecision] * r), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision] + 4.5), $MachinePrecision]), $MachinePrecision], 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[(w * N[(w * r), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * 4.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;r \leq 5 \cdot 10^{+148}:\\
\;\;\;\;\mathsf{fma}\left({r}^{-2}, 2, 3\right) - \mathsf{fma}\left(\mathsf{fma}\left(-2, v, 3\right) \cdot 0.125, \frac{w \cdot \left(\left(w \cdot r\right) \cdot r\right)}{1 - v}, 4.5\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(3 + \frac{2}{r \cdot r}\right) - \frac{\left(0.125 \cdot \left(3 - 2 \cdot v\right)\right) \cdot \left(\left(w \cdot \left(w \cdot r\right)\right) \cdot r\right)}{1 - v}\right) + -1 \cdot 4.5\\
\end{array}
\end{array}
if r < 5.00000000000000024e148Initial program 80.3%
Applied rewrites99.8%
lift-pow.f64N/A
lift-*.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
metadata-evalN/A
lower-pow.f6499.9
lift-*.f64N/A
pow2N/A
lift-*.f64N/A
lift-pow.f64N/A
unpow1N/A
lower-pow.f64N/A
lift-*.f6499.9
Applied rewrites99.9%
lift-*.f64N/A
lift-pow.f64N/A
unpow-prod-downN/A
*-commutativeN/A
pow2N/A
associate-*l*N/A
pow2N/A
associate-*r*N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lift-*.f6498.2
Applied rewrites98.2%
if 5.00000000000000024e148 < r Initial program 93.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6497.1
Applied rewrites97.1%
Final simplification98.0%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (+ 3.0 (/ 2.0 (* r r))))
(t_1 (* 0.125 (- 3.0 (* 2.0 v))))
(t_2
(+ (- t_0 (/ (* t_1 (* (* (* w w) r) r)) (- 1.0 v))) (* -1.0 4.5)))
(t_3 (- (* 2.0 (pow r -2.0)) (+ 1.5 (* 0.25 (pow (* r w) 2.0))))))
(if (<= t_2 (- INFINITY))
t_3
(if (<= t_2 -1.0)
(+ (- t_0 (/ (* t_1 (* (* w (* w r)) r)) (- 1.0 v))) (* -1.0 4.5))
t_3))))
double code(double v, double w, double r) {
double t_0 = 3.0 + (2.0 / (r * r));
double t_1 = 0.125 * (3.0 - (2.0 * v));
double t_2 = (t_0 - ((t_1 * (((w * w) * r) * r)) / (1.0 - v))) + (-1.0 * 4.5);
double t_3 = (2.0 * pow(r, -2.0)) - (1.5 + (0.25 * pow((r * w), 2.0)));
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = t_3;
} else if (t_2 <= -1.0) {
tmp = (t_0 - ((t_1 * ((w * (w * r)) * r)) / (1.0 - v))) + (-1.0 * 4.5);
} else {
tmp = t_3;
}
return tmp;
}
public static double code(double v, double w, double r) {
double t_0 = 3.0 + (2.0 / (r * r));
double t_1 = 0.125 * (3.0 - (2.0 * v));
double t_2 = (t_0 - ((t_1 * (((w * w) * r) * r)) / (1.0 - v))) + (-1.0 * 4.5);
double t_3 = (2.0 * Math.pow(r, -2.0)) - (1.5 + (0.25 * Math.pow((r * w), 2.0)));
double tmp;
if (t_2 <= -Double.POSITIVE_INFINITY) {
tmp = t_3;
} else if (t_2 <= -1.0) {
tmp = (t_0 - ((t_1 * ((w * (w * r)) * r)) / (1.0 - v))) + (-1.0 * 4.5);
} else {
tmp = t_3;
}
return tmp;
}
def code(v, w, r): t_0 = 3.0 + (2.0 / (r * r)) t_1 = 0.125 * (3.0 - (2.0 * v)) t_2 = (t_0 - ((t_1 * (((w * w) * r) * r)) / (1.0 - v))) + (-1.0 * 4.5) t_3 = (2.0 * math.pow(r, -2.0)) - (1.5 + (0.25 * math.pow((r * w), 2.0))) tmp = 0 if t_2 <= -math.inf: tmp = t_3 elif t_2 <= -1.0: tmp = (t_0 - ((t_1 * ((w * (w * r)) * r)) / (1.0 - v))) + (-1.0 * 4.5) else: tmp = t_3 return tmp
function code(v, w, r) t_0 = Float64(3.0 + Float64(2.0 / Float64(r * r))) t_1 = Float64(0.125 * Float64(3.0 - Float64(2.0 * v))) t_2 = Float64(Float64(t_0 - Float64(Float64(t_1 * Float64(Float64(Float64(w * w) * r) * r)) / Float64(1.0 - v))) + Float64(-1.0 * 4.5)) t_3 = Float64(Float64(2.0 * (r ^ -2.0)) - Float64(1.5 + Float64(0.25 * (Float64(r * w) ^ 2.0)))) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = t_3; elseif (t_2 <= -1.0) tmp = Float64(Float64(t_0 - Float64(Float64(t_1 * Float64(Float64(w * Float64(w * r)) * r)) / Float64(1.0 - v))) + Float64(-1.0 * 4.5)); else tmp = t_3; end return tmp end
function tmp_2 = code(v, w, r) t_0 = 3.0 + (2.0 / (r * r)); t_1 = 0.125 * (3.0 - (2.0 * v)); t_2 = (t_0 - ((t_1 * (((w * w) * r) * r)) / (1.0 - v))) + (-1.0 * 4.5); t_3 = (2.0 * (r ^ -2.0)) - (1.5 + (0.25 * ((r * w) ^ 2.0))); tmp = 0.0; if (t_2 <= -Inf) tmp = t_3; elseif (t_2 <= -1.0) tmp = (t_0 - ((t_1 * ((w * (w * r)) * r)) / (1.0 - v))) + (-1.0 * 4.5); else tmp = t_3; end tmp_2 = tmp; end
code[v_, w_, r_] := Block[{t$95$0 = N[(3.0 + N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.125 * N[(3.0 - N[(2.0 * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$0 - N[(N[(t$95$1 * N[(N[(N[(w * w), $MachinePrecision] * r), $MachinePrecision] * r), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * 4.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(2.0 * N[Power[r, -2.0], $MachinePrecision]), $MachinePrecision] - N[(1.5 + N[(0.25 * N[Power[N[(r * w), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$3, If[LessEqual[t$95$2, -1.0], N[(N[(t$95$0 - N[(N[(t$95$1 * N[(N[(w * N[(w * r), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * 4.5), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 3 + \frac{2}{r \cdot r}\\
t_1 := 0.125 \cdot \left(3 - 2 \cdot v\right)\\
t_2 := \left(t\_0 - \frac{t\_1 \cdot \left(\left(\left(w \cdot w\right) \cdot r\right) \cdot r\right)}{1 - v}\right) + -1 \cdot 4.5\\
t_3 := 2 \cdot {r}^{-2} - \left(1.5 + 0.25 \cdot {\left(r \cdot w\right)}^{2}\right)\\
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_2 \leq -1:\\
\;\;\;\;\left(t\_0 - \frac{t\_1 \cdot \left(\left(w \cdot \left(w \cdot r\right)\right) \cdot r\right)}{1 - v}\right) + -1 \cdot 4.5\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\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)) < -inf.0 or -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 79.6%
Taylor expanded in w around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites73.2%
Taylor expanded in v around inf
lower--.f64N/A
inv-powN/A
pow2N/A
lift-*.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
metadata-evalN/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
pow-prod-downN/A
lower-pow.f64N/A
lift-*.f6499.1
Applied rewrites99.1%
if -inf.0 < (-.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 89.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.3%
(FPCore (v w r)
:precision binary64
(let* ((t_0 (* 0.125 (- 3.0 (* 2.0 v))))
(t_1 (+ 3.0 (/ 2.0 (* r r))))
(t_2
(+ (- t_1 (/ (* t_0 (* (* (* w w) r) r)) (- 1.0 v))) (* -1.0 4.5))))
(if (or (<= t_2 (- INFINITY)) (not (<= t_2 -1.0)))
(- (* 2.0 (pow r -2.0)) (+ 1.5 (* 0.25 (pow (* r w) 2.0))))
(-
(- t_1 (/ (* t_0 (* (* w (* w r)) r)) (* v (- (pow v -1.0) 1.0))))
4.5))))
double code(double v, double w, double r) {
double t_0 = 0.125 * (3.0 - (2.0 * v));
double t_1 = 3.0 + (2.0 / (r * r));
double t_2 = (t_1 - ((t_0 * (((w * w) * r) * r)) / (1.0 - v))) + (-1.0 * 4.5);
double tmp;
if ((t_2 <= -((double) INFINITY)) || !(t_2 <= -1.0)) {
tmp = (2.0 * pow(r, -2.0)) - (1.5 + (0.25 * pow((r * w), 2.0)));
} else {
tmp = (t_1 - ((t_0 * ((w * (w * r)) * r)) / (v * (pow(v, -1.0) - 1.0)))) - 4.5;
}
return tmp;
}
public static double code(double v, double w, double r) {
double t_0 = 0.125 * (3.0 - (2.0 * v));
double t_1 = 3.0 + (2.0 / (r * r));
double t_2 = (t_1 - ((t_0 * (((w * w) * r) * r)) / (1.0 - v))) + (-1.0 * 4.5);
double tmp;
if ((t_2 <= -Double.POSITIVE_INFINITY) || !(t_2 <= -1.0)) {
tmp = (2.0 * Math.pow(r, -2.0)) - (1.5 + (0.25 * Math.pow((r * w), 2.0)));
} else {
tmp = (t_1 - ((t_0 * ((w * (w * r)) * r)) / (v * (Math.pow(v, -1.0) - 1.0)))) - 4.5;
}
return tmp;
}
def code(v, w, r): t_0 = 0.125 * (3.0 - (2.0 * v)) t_1 = 3.0 + (2.0 / (r * r)) t_2 = (t_1 - ((t_0 * (((w * w) * r) * r)) / (1.0 - v))) + (-1.0 * 4.5) tmp = 0 if (t_2 <= -math.inf) or not (t_2 <= -1.0): tmp = (2.0 * math.pow(r, -2.0)) - (1.5 + (0.25 * math.pow((r * w), 2.0))) else: tmp = (t_1 - ((t_0 * ((w * (w * r)) * r)) / (v * (math.pow(v, -1.0) - 1.0)))) - 4.5 return tmp
function code(v, w, r) t_0 = Float64(0.125 * Float64(3.0 - Float64(2.0 * v))) t_1 = Float64(3.0 + Float64(2.0 / Float64(r * r))) t_2 = Float64(Float64(t_1 - Float64(Float64(t_0 * Float64(Float64(Float64(w * w) * r) * r)) / Float64(1.0 - v))) + Float64(-1.0 * 4.5)) tmp = 0.0 if ((t_2 <= Float64(-Inf)) || !(t_2 <= -1.0)) tmp = Float64(Float64(2.0 * (r ^ -2.0)) - Float64(1.5 + Float64(0.25 * (Float64(r * w) ^ 2.0)))); else tmp = Float64(Float64(t_1 - Float64(Float64(t_0 * Float64(Float64(w * Float64(w * r)) * r)) / Float64(v * Float64((v ^ -1.0) - 1.0)))) - 4.5); end return tmp end
function tmp_2 = code(v, w, r) t_0 = 0.125 * (3.0 - (2.0 * v)); t_1 = 3.0 + (2.0 / (r * r)); t_2 = (t_1 - ((t_0 * (((w * w) * r) * r)) / (1.0 - v))) + (-1.0 * 4.5); tmp = 0.0; if ((t_2 <= -Inf) || ~((t_2 <= -1.0))) tmp = (2.0 * (r ^ -2.0)) - (1.5 + (0.25 * ((r * w) ^ 2.0))); else tmp = (t_1 - ((t_0 * ((w * (w * r)) * r)) / (v * ((v ^ -1.0) - 1.0)))) - 4.5; end tmp_2 = tmp; end
code[v_, w_, r_] := Block[{t$95$0 = N[(0.125 * N[(3.0 - N[(2.0 * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(3.0 + N[(2.0 / N[(r * r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 - N[(N[(t$95$0 * N[(N[(N[(w * w), $MachinePrecision] * r), $MachinePrecision] * r), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * 4.5), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$2, (-Infinity)], N[Not[LessEqual[t$95$2, -1.0]], $MachinePrecision]], N[(N[(2.0 * N[Power[r, -2.0], $MachinePrecision]), $MachinePrecision] - N[(1.5 + N[(0.25 * N[Power[N[(r * w), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 - N[(N[(t$95$0 * N[(N[(w * N[(w * r), $MachinePrecision]), $MachinePrecision] * r), $MachinePrecision]), $MachinePrecision] / N[(v * N[(N[Power[v, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 4.5), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.125 \cdot \left(3 - 2 \cdot v\right)\\
t_1 := 3 + \frac{2}{r \cdot r}\\
t_2 := \left(t\_1 - \frac{t\_0 \cdot \left(\left(\left(w \cdot w\right) \cdot r\right) \cdot r\right)}{1 - v}\right) + -1 \cdot 4.5\\
\mathbf{if}\;t\_2 \leq -\infty \lor \neg \left(t\_2 \leq -1\right):\\
\;\;\;\;2 \cdot {r}^{-2} - \left(1.5 + 0.25 \cdot {\left(r \cdot w\right)}^{2}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t\_1 - \frac{t\_0 \cdot \left(\left(w \cdot \left(w \cdot r\right)\right) \cdot r\right)}{v \cdot \left({v}^{-1} - 1\right)}\right) - 4.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)) < -inf.0 or -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 79.6%
Taylor expanded in w around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites73.2%
Taylor expanded in v around inf
lower--.f64N/A
inv-powN/A
pow2N/A
lift-*.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
metadata-evalN/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
pow-prod-downN/A
lower-pow.f64N/A
lift-*.f6499.1
Applied rewrites99.1%
if -inf.0 < (-.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 89.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in v around inf
lower-*.f64N/A
lower--.f64N/A
inv-powN/A
lower-pow.f6499.7
Applied rewrites99.7%
Final simplification99.3%
(FPCore (v w r) :precision binary64 (- (* 2.0 (pow r -2.0)) (+ 1.5 (* 0.25 (pow (* r w) 2.0)))))
double code(double v, double w, double r) {
return (2.0 * pow(r, -2.0)) - (1.5 + (0.25 * pow((r * w), 2.0)));
}
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 ** (-2.0d0))) - (1.5d0 + (0.25d0 * ((r * w) ** 2.0d0)))
end function
public static double code(double v, double w, double r) {
return (2.0 * Math.pow(r, -2.0)) - (1.5 + (0.25 * Math.pow((r * w), 2.0)));
}
def code(v, w, r): return (2.0 * math.pow(r, -2.0)) - (1.5 + (0.25 * math.pow((r * w), 2.0)))
function code(v, w, r) return Float64(Float64(2.0 * (r ^ -2.0)) - Float64(1.5 + Float64(0.25 * (Float64(r * w) ^ 2.0)))) end
function tmp = code(v, w, r) tmp = (2.0 * (r ^ -2.0)) - (1.5 + (0.25 * ((r * w) ^ 2.0))); end
code[v_, w_, r_] := N[(N[(2.0 * N[Power[r, -2.0], $MachinePrecision]), $MachinePrecision] - N[(1.5 + N[(0.25 * N[Power[N[(r * w), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot {r}^{-2} - \left(1.5 + 0.25 \cdot {\left(r \cdot w\right)}^{2}\right)
\end{array}
Initial program 82.0%
Taylor expanded in w around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites62.1%
Taylor expanded in v around inf
lower--.f64N/A
inv-powN/A
pow2N/A
lift-*.f64N/A
lift-pow.f64N/A
lower-*.f64N/A
lift-pow.f64N/A
lift-*.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
metadata-evalN/A
lower-pow.f64N/A
lower-+.f64N/A
lower-*.f64N/A
pow-prod-downN/A
lower-pow.f64N/A
lift-*.f6494.0
Applied rewrites94.0%
(FPCore (v w r)
:precision binary64
(if (<= r 1.5e-75)
(*
(-
(* 2.0 (pow (pow (* r w) 2.0) -1.0))
(fma 0.375 (* r r) (* 1.5 (pow (* w w) -1.0))))
(* w w))
(*
(-
(/ 2.0 (pow (* r r) 2.0))
(fma
(/ (* (* w w) (fma -2.0 v 3.0)) (- 1.0 v))
0.125
(* 1.5 (pow (* r r) -1.0))))
(* r r))))
double code(double v, double w, double r) {
double tmp;
if (r <= 1.5e-75) {
tmp = ((2.0 * pow(pow((r * w), 2.0), -1.0)) - fma(0.375, (r * r), (1.5 * pow((w * w), -1.0)))) * (w * w);
} else {
tmp = ((2.0 / pow((r * r), 2.0)) - fma((((w * w) * fma(-2.0, v, 3.0)) / (1.0 - v)), 0.125, (1.5 * pow((r * r), -1.0)))) * (r * r);
}
return tmp;
}
function code(v, w, r) tmp = 0.0 if (r <= 1.5e-75) tmp = Float64(Float64(Float64(2.0 * ((Float64(r * w) ^ 2.0) ^ -1.0)) - fma(0.375, Float64(r * r), Float64(1.5 * (Float64(w * w) ^ -1.0)))) * Float64(w * w)); else tmp = Float64(Float64(Float64(2.0 / (Float64(r * r) ^ 2.0)) - fma(Float64(Float64(Float64(w * w) * fma(-2.0, v, 3.0)) / Float64(1.0 - v)), 0.125, Float64(1.5 * (Float64(r * r) ^ -1.0)))) * Float64(r * r)); end return tmp end
code[v_, w_, r_] := If[LessEqual[r, 1.5e-75], N[(N[(N[(2.0 * N[Power[N[Power[N[(r * w), $MachinePrecision], 2.0], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision] - N[(0.375 * N[(r * r), $MachinePrecision] + N[(1.5 * N[Power[N[(w * w), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(w * w), $MachinePrecision]), $MachinePrecision], N[(N[(N[(2.0 / N[Power[N[(r * r), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(N[(w * w), $MachinePrecision] * N[(-2.0 * v + 3.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision] * 0.125 + N[(1.5 * N[Power[N[(r * r), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(r * r), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;r \leq 1.5 \cdot 10^{-75}:\\
\;\;\;\;\left(2 \cdot {\left({\left(r \cdot w\right)}^{2}\right)}^{-1} - \mathsf{fma}\left(0.375, r \cdot r, 1.5 \cdot {\left(w \cdot w\right)}^{-1}\right)\right) \cdot \left(w \cdot w\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{2}{{\left(r \cdot r\right)}^{2}} - \mathsf{fma}\left(\frac{\left(w \cdot w\right) \cdot \mathsf{fma}\left(-2, v, 3\right)}{1 - v}, 0.125, 1.5 \cdot {\left(r \cdot r\right)}^{-1}\right)\right) \cdot \left(r \cdot r\right)\\
\end{array}
\end{array}
if r < 1.4999999999999999e-75Initial program 77.6%
Taylor expanded in w around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites59.9%
Taylor expanded in v around 0
lower--.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
pow-prod-downN/A
lower-pow.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
pow2N/A
lift-*.f64N/A
lower-*.f64N/A
inv-powN/A
pow2N/A
lift-*.f64N/A
lift-pow.f6458.9
Applied rewrites58.9%
if 1.4999999999999999e-75 < r Initial program 93.1%
Taylor expanded in r around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.5%
(FPCore (v w r)
:precision binary64
(*
(-
(* (/ (pow (* r r) -1.0) w) (/ 2.0 w))
(fma
(/ (* (* r r) (fma -2.0 v 3.0)) (- 1.0 v))
0.125
(* (pow (* w w) -1.0) 1.5)))
(* w w)))
double code(double v, double w, double r) {
return (((pow((r * r), -1.0) / w) * (2.0 / w)) - fma((((r * r) * fma(-2.0, v, 3.0)) / (1.0 - v)), 0.125, (pow((w * w), -1.0) * 1.5))) * (w * w);
}
function code(v, w, r) return Float64(Float64(Float64(Float64((Float64(r * r) ^ -1.0) / w) * Float64(2.0 / w)) - fma(Float64(Float64(Float64(r * r) * fma(-2.0, v, 3.0)) / Float64(1.0 - v)), 0.125, Float64((Float64(w * w) ^ -1.0) * 1.5))) * Float64(w * w)) end
code[v_, w_, r_] := N[(N[(N[(N[(N[Power[N[(r * r), $MachinePrecision], -1.0], $MachinePrecision] / w), $MachinePrecision] * N[(2.0 / w), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(N[(r * r), $MachinePrecision] * N[(-2.0 * v + 3.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 - v), $MachinePrecision]), $MachinePrecision] * 0.125 + N[(N[Power[N[(w * w), $MachinePrecision], -1.0], $MachinePrecision] * 1.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(w * w), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{{\left(r \cdot r\right)}^{-1}}{w} \cdot \frac{2}{w} - \mathsf{fma}\left(\frac{\left(r \cdot r\right) \cdot \mathsf{fma}\left(-2, v, 3\right)}{1 - v}, 0.125, {\left(w \cdot w\right)}^{-1} \cdot 1.5\right)\right) \cdot \left(w \cdot w\right)
\end{array}
Initial program 82.0%
Taylor expanded in w around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites62.1%
(FPCore (v w r) :precision binary64 (* (- (* 2.0 (pow (pow (* r w) 2.0) -1.0)) (fma 0.375 (* r r) (* 1.5 (pow (* w w) -1.0)))) (* w w)))
double code(double v, double w, double r) {
return ((2.0 * pow(pow((r * w), 2.0), -1.0)) - fma(0.375, (r * r), (1.5 * pow((w * w), -1.0)))) * (w * w);
}
function code(v, w, r) return Float64(Float64(Float64(2.0 * ((Float64(r * w) ^ 2.0) ^ -1.0)) - fma(0.375, Float64(r * r), Float64(1.5 * (Float64(w * w) ^ -1.0)))) * Float64(w * w)) end
code[v_, w_, r_] := N[(N[(N[(2.0 * N[Power[N[Power[N[(r * w), $MachinePrecision], 2.0], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision] - N[(0.375 * N[(r * r), $MachinePrecision] + N[(1.5 * N[Power[N[(w * w), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(w * w), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(2 \cdot {\left({\left(r \cdot w\right)}^{2}\right)}^{-1} - \mathsf{fma}\left(0.375, r \cdot r, 1.5 \cdot {\left(w \cdot w\right)}^{-1}\right)\right) \cdot \left(w \cdot w\right)
\end{array}
Initial program 82.0%
Taylor expanded in w around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites62.1%
Taylor expanded in v around 0
lower--.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
pow-prod-downN/A
lower-pow.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
pow2N/A
lift-*.f64N/A
lower-*.f64N/A
inv-powN/A
pow2N/A
lift-*.f64N/A
lift-pow.f6461.1
Applied rewrites61.1%
herbie shell --seed 2025065
(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))