
(FPCore (u v t1) :precision binary64 (/ (* (- t1) v) (* (+ t1 u) (+ t1 u))))
double code(double u, double v, double t1) {
return (-t1 * v) / ((t1 + u) * (t1 + u));
}
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(u, v, t1)
use fmin_fmax_functions
real(8), intent (in) :: u
real(8), intent (in) :: v
real(8), intent (in) :: t1
code = (-t1 * v) / ((t1 + u) * (t1 + u))
end function
public static double code(double u, double v, double t1) {
return (-t1 * v) / ((t1 + u) * (t1 + u));
}
def code(u, v, t1): return (-t1 * v) / ((t1 + u) * (t1 + u))
function code(u, v, t1) return Float64(Float64(Float64(-t1) * v) / Float64(Float64(t1 + u) * Float64(t1 + u))) end
function tmp = code(u, v, t1) tmp = (-t1 * v) / ((t1 + u) * (t1 + u)); end
code[u_, v_, t1_] := N[(N[((-t1) * v), $MachinePrecision] / N[(N[(t1 + u), $MachinePrecision] * N[(t1 + u), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-t1\right) \cdot v}{\left(t1 + u\right) \cdot \left(t1 + u\right)}
\end{array}
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (u v t1) :precision binary64 (/ (* (- t1) v) (* (+ t1 u) (+ t1 u))))
double code(double u, double v, double t1) {
return (-t1 * v) / ((t1 + u) * (t1 + u));
}
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(u, v, t1)
use fmin_fmax_functions
real(8), intent (in) :: u
real(8), intent (in) :: v
real(8), intent (in) :: t1
code = (-t1 * v) / ((t1 + u) * (t1 + u))
end function
public static double code(double u, double v, double t1) {
return (-t1 * v) / ((t1 + u) * (t1 + u));
}
def code(u, v, t1): return (-t1 * v) / ((t1 + u) * (t1 + u))
function code(u, v, t1) return Float64(Float64(Float64(-t1) * v) / Float64(Float64(t1 + u) * Float64(t1 + u))) end
function tmp = code(u, v, t1) tmp = (-t1 * v) / ((t1 + u) * (t1 + u)); end
code[u_, v_, t1_] := N[(N[((-t1) * v), $MachinePrecision] / N[(N[(t1 + u), $MachinePrecision] * N[(t1 + u), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-t1\right) \cdot v}{\left(t1 + u\right) \cdot \left(t1 + u\right)}
\end{array}
(FPCore (u v t1) :precision binary64 (* (/ (* -1.0 t1) (+ u t1)) (/ v (+ u t1))))
double code(double u, double v, double t1) {
return ((-1.0 * t1) / (u + t1)) * (v / (u + t1));
}
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(u, v, t1)
use fmin_fmax_functions
real(8), intent (in) :: u
real(8), intent (in) :: v
real(8), intent (in) :: t1
code = (((-1.0d0) * t1) / (u + t1)) * (v / (u + t1))
end function
public static double code(double u, double v, double t1) {
return ((-1.0 * t1) / (u + t1)) * (v / (u + t1));
}
def code(u, v, t1): return ((-1.0 * t1) / (u + t1)) * (v / (u + t1))
function code(u, v, t1) return Float64(Float64(Float64(-1.0 * t1) / Float64(u + t1)) * Float64(v / Float64(u + t1))) end
function tmp = code(u, v, t1) tmp = ((-1.0 * t1) / (u + t1)) * (v / (u + t1)); end
code[u_, v_, t1_] := N[(N[(N[(-1.0 * t1), $MachinePrecision] / N[(u + t1), $MachinePrecision]), $MachinePrecision] * N[(v / N[(u + t1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1 \cdot t1}{u + t1} \cdot \frac{v}{u + t1}
\end{array}
Initial program 72.4%
lift-/.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6498.0
Applied rewrites98.0%
(FPCore (u v t1) :precision binary64 (* (/ -1.0 (+ u t1)) (* t1 (/ v (+ u t1)))))
double code(double u, double v, double t1) {
return (-1.0 / (u + t1)) * (t1 * (v / (u + t1)));
}
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(u, v, t1)
use fmin_fmax_functions
real(8), intent (in) :: u
real(8), intent (in) :: v
real(8), intent (in) :: t1
code = ((-1.0d0) / (u + t1)) * (t1 * (v / (u + t1)))
end function
public static double code(double u, double v, double t1) {
return (-1.0 / (u + t1)) * (t1 * (v / (u + t1)));
}
def code(u, v, t1): return (-1.0 / (u + t1)) * (t1 * (v / (u + t1)))
function code(u, v, t1) return Float64(Float64(-1.0 / Float64(u + t1)) * Float64(t1 * Float64(v / Float64(u + t1)))) end
function tmp = code(u, v, t1) tmp = (-1.0 / (u + t1)) * (t1 * (v / (u + t1))); end
code[u_, v_, t1_] := N[(N[(-1.0 / N[(u + t1), $MachinePrecision]), $MachinePrecision] * N[(t1 * N[(v / N[(u + t1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{u + t1} \cdot \left(t1 \cdot \frac{v}{u + t1}\right)
\end{array}
Initial program 72.4%
lift-/.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f6498.0
Applied rewrites98.0%
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-/.f64N/A
lift-+.f64N/A
lift-/.f64N/A
frac-timesN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
frac-timesN/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
lift-+.f64N/A
*-commutativeN/A
+-commutativeN/A
associate-/l*N/A
+-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
lift-+.f6498.0
Applied rewrites98.0%
(FPCore (u v t1)
:precision binary64
(let* ((t_1 (/ (fma (* u (/ v t1)) 2.0 (* -1.0 v)) t1)))
(if (<= t1 -5.8e+138)
t_1
(if (<= t1 6e+132) (* (* -1.0 t1) (/ v (pow (+ u t1) 2.0))) t_1))))
double code(double u, double v, double t1) {
double t_1 = fma((u * (v / t1)), 2.0, (-1.0 * v)) / t1;
double tmp;
if (t1 <= -5.8e+138) {
tmp = t_1;
} else if (t1 <= 6e+132) {
tmp = (-1.0 * t1) * (v / pow((u + t1), 2.0));
} else {
tmp = t_1;
}
return tmp;
}
function code(u, v, t1) t_1 = Float64(fma(Float64(u * Float64(v / t1)), 2.0, Float64(-1.0 * v)) / t1) tmp = 0.0 if (t1 <= -5.8e+138) tmp = t_1; elseif (t1 <= 6e+132) tmp = Float64(Float64(-1.0 * t1) * Float64(v / (Float64(u + t1) ^ 2.0))); else tmp = t_1; end return tmp end
code[u_, v_, t1_] := Block[{t$95$1 = N[(N[(N[(u * N[(v / t1), $MachinePrecision]), $MachinePrecision] * 2.0 + N[(-1.0 * v), $MachinePrecision]), $MachinePrecision] / t1), $MachinePrecision]}, If[LessEqual[t1, -5.8e+138], t$95$1, If[LessEqual[t1, 6e+132], N[(N[(-1.0 * t1), $MachinePrecision] * N[(v / N[Power[N[(u + t1), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{\mathsf{fma}\left(u \cdot \frac{v}{t1}, 2, -1 \cdot v\right)}{t1}\\
\mathbf{if}\;t1 \leq -5.8 \cdot 10^{+138}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t1 \leq 6 \cdot 10^{+132}:\\
\;\;\;\;\left(-1 \cdot t1\right) \cdot \frac{v}{{\left(u + t1\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t1 < -5.80000000000000019e138 or 5.9999999999999996e132 < t1 Initial program 43.0%
Taylor expanded in t1 around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6489.4
Applied rewrites89.4%
if -5.80000000000000019e138 < t1 < 5.9999999999999996e132Initial program 83.9%
lift-/.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f6484.1
Applied rewrites84.1%
(FPCore (u v t1)
:precision binary64
(let* ((t_1 (/ (fma (* u (/ v t1)) 2.0 (* -1.0 v)) t1)))
(if (<= t1 -5.8e+138)
t_1
(if (<= t1 6e+132)
(* (* -1.0 t1) (/ v (/ 1.0 (pow (+ u t1) -2.0))))
t_1))))
double code(double u, double v, double t1) {
double t_1 = fma((u * (v / t1)), 2.0, (-1.0 * v)) / t1;
double tmp;
if (t1 <= -5.8e+138) {
tmp = t_1;
} else if (t1 <= 6e+132) {
tmp = (-1.0 * t1) * (v / (1.0 / pow((u + t1), -2.0)));
} else {
tmp = t_1;
}
return tmp;
}
function code(u, v, t1) t_1 = Float64(fma(Float64(u * Float64(v / t1)), 2.0, Float64(-1.0 * v)) / t1) tmp = 0.0 if (t1 <= -5.8e+138) tmp = t_1; elseif (t1 <= 6e+132) tmp = Float64(Float64(-1.0 * t1) * Float64(v / Float64(1.0 / (Float64(u + t1) ^ -2.0)))); else tmp = t_1; end return tmp end
code[u_, v_, t1_] := Block[{t$95$1 = N[(N[(N[(u * N[(v / t1), $MachinePrecision]), $MachinePrecision] * 2.0 + N[(-1.0 * v), $MachinePrecision]), $MachinePrecision] / t1), $MachinePrecision]}, If[LessEqual[t1, -5.8e+138], t$95$1, If[LessEqual[t1, 6e+132], N[(N[(-1.0 * t1), $MachinePrecision] * N[(v / N[(1.0 / N[Power[N[(u + t1), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{\mathsf{fma}\left(u \cdot \frac{v}{t1}, 2, -1 \cdot v\right)}{t1}\\
\mathbf{if}\;t1 \leq -5.8 \cdot 10^{+138}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t1 \leq 6 \cdot 10^{+132}:\\
\;\;\;\;\left(-1 \cdot t1\right) \cdot \frac{v}{\frac{1}{{\left(u + t1\right)}^{-2}}}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t1 < -5.80000000000000019e138 or 5.9999999999999996e132 < t1 Initial program 43.0%
Taylor expanded in t1 around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6489.4
Applied rewrites89.4%
if -5.80000000000000019e138 < t1 < 5.9999999999999996e132Initial program 83.9%
lift-/.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-+.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
mul-1-negN/A
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f6484.1
Applied rewrites84.1%
lift-+.f64N/A
lift-pow.f64N/A
metadata-evalN/A
pow-negN/A
lower-/.f64N/A
lower-pow.f64N/A
lift-+.f6483.8
Applied rewrites83.8%
(FPCore (u v t1) :precision binary64 (/ (fma (* u (/ v t1)) 2.0 (* -1.0 v)) t1))
double code(double u, double v, double t1) {
return fma((u * (v / t1)), 2.0, (-1.0 * v)) / t1;
}
function code(u, v, t1) return Float64(fma(Float64(u * Float64(v / t1)), 2.0, Float64(-1.0 * v)) / t1) end
code[u_, v_, t1_] := N[(N[(N[(u * N[(v / t1), $MachinePrecision]), $MachinePrecision] * 2.0 + N[(-1.0 * v), $MachinePrecision]), $MachinePrecision] / t1), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(u \cdot \frac{v}{t1}, 2, -1 \cdot v\right)}{t1}
\end{array}
Initial program 72.4%
Taylor expanded in t1 around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6451.8
Applied rewrites51.8%
herbie shell --seed 2025093
(FPCore (u v t1)
:name "Rosa's DopplerBench"
:precision binary64
(/ (* (- t1) v) (* (+ t1 u) (+ t1 u))))