
(FPCore (x y z t a) :precision binary64 (- (+ x y) (/ (* (- z t) y) (- a t))))
double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
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(x, y, z, t, a)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = (x + y) - (((z - t) * y) / (a - t))
end function
public static double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
def code(x, y, z, t, a): return (x + y) - (((z - t) * y) / (a - t))
function code(x, y, z, t, a) return Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t))) end
function tmp = code(x, y, z, t, a) tmp = (x + y) - (((z - t) * y) / (a - t)); end
code[x_, y_, z_, t_, a_] := N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (- (+ x y) (/ (* (- z t) y) (- a t))))
double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
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(x, y, z, t, a)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = (x + y) - (((z - t) * y) / (a - t))
end function
public static double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
def code(x, y, z, t, a): return (x + y) - (((z - t) * y) / (a - t))
function code(x, y, z, t, a) return Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t))) end
function tmp = code(x, y, z, t, a) tmp = (x + y) - (((z - t) * y) / (a - t)); end
code[x_, y_, z_, t_, a_] := N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\end{array}
(FPCore (x y z t a) :precision binary64 (fma y (/ (- z a) (- t a)) x))
double code(double x, double y, double z, double t, double a) {
return fma(y, ((z - a) / (t - a)), x);
}
function code(x, y, z, t, a) return fma(y, Float64(Float64(z - a) / Float64(t - a)), x) end
code[x_, y_, z_, t_, a_] := N[(y * N[(N[(z - a), $MachinePrecision] / N[(t - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \frac{z - a}{t - a}, x\right)
\end{array}
Initial program 76.7%
Applied rewrites89.2%
Taylor expanded in z around 0
Applied rewrites98.1%
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (- (+ x y) (* (/ y a) z)))) (if (<= a -1.45e+34) t_1 (if (<= a 2.2e+101) (fma y (/ z (- t a)) x) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (x + y) - ((y / a) * z);
double tmp;
if (a <= -1.45e+34) {
tmp = t_1;
} else if (a <= 2.2e+101) {
tmp = fma(y, (z / (t - a)), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(x + y) - Float64(Float64(y / a) * z)) tmp = 0.0 if (a <= -1.45e+34) tmp = t_1; elseif (a <= 2.2e+101) tmp = fma(y, Float64(z / Float64(t - a)), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(x + y), $MachinePrecision] - N[(N[(y / a), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -1.45e+34], t$95$1, If[LessEqual[a, 2.2e+101], N[(y * N[(z / N[(t - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x + y\right) - \frac{y}{a} \cdot z\\
\mathbf{if}\;a \leq -1.45 \cdot 10^{+34}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a \leq 2.2 \cdot 10^{+101}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{t - a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if a < -1.4500000000000001e34 or 2.2000000000000001e101 < a Initial program 76.7%
Taylor expanded in t around 0
Applied rewrites64.5%
Applied rewrites66.1%
if -1.4500000000000001e34 < a < 2.2000000000000001e101Initial program 76.7%
Applied rewrites89.2%
Taylor expanded in z around inf
Applied rewrites76.5%
(FPCore (x y z t a) :precision binary64 (if (<= a -2.1e+134) (fma y 1.0 x) (if (<= a 3.8e+106) (fma y (/ z (- t a)) x) (fma y 1.0 x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -2.1e+134) {
tmp = fma(y, 1.0, x);
} else if (a <= 3.8e+106) {
tmp = fma(y, (z / (t - a)), x);
} else {
tmp = fma(y, 1.0, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (a <= -2.1e+134) tmp = fma(y, 1.0, x); elseif (a <= 3.8e+106) tmp = fma(y, Float64(z / Float64(t - a)), x); else tmp = fma(y, 1.0, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -2.1e+134], N[(y * 1.0 + x), $MachinePrecision], If[LessEqual[a, 3.8e+106], N[(y * N[(z / N[(t - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(y * 1.0 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.1 \cdot 10^{+134}:\\
\;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\
\mathbf{elif}\;a \leq 3.8 \cdot 10^{+106}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{t - a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\
\end{array}
\end{array}
if a < -2.1000000000000001e134 or 3.7999999999999998e106 < a Initial program 76.7%
Applied rewrites89.2%
Taylor expanded in a around inf
Applied rewrites60.1%
if -2.1000000000000001e134 < a < 3.7999999999999998e106Initial program 76.7%
Applied rewrites89.2%
Taylor expanded in z around inf
Applied rewrites76.5%
(FPCore (x y z t a) :precision binary64 (if (<= a -5.2e+107) (fma y 1.0 x) (if (<= a 8.2e+102) (fma (/ y t) (- z a) x) (fma y 1.0 x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -5.2e+107) {
tmp = fma(y, 1.0, x);
} else if (a <= 8.2e+102) {
tmp = fma((y / t), (z - a), x);
} else {
tmp = fma(y, 1.0, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (a <= -5.2e+107) tmp = fma(y, 1.0, x); elseif (a <= 8.2e+102) tmp = fma(Float64(y / t), Float64(z - a), x); else tmp = fma(y, 1.0, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -5.2e+107], N[(y * 1.0 + x), $MachinePrecision], If[LessEqual[a, 8.2e+102], N[(N[(y / t), $MachinePrecision] * N[(z - a), $MachinePrecision] + x), $MachinePrecision], N[(y * 1.0 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5.2 \cdot 10^{+107}:\\
\;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\
\mathbf{elif}\;a \leq 8.2 \cdot 10^{+102}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - a, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\
\end{array}
\end{array}
if a < -5.2000000000000002e107 or 8.1999999999999999e102 < a Initial program 76.7%
Applied rewrites89.2%
Taylor expanded in a around inf
Applied rewrites60.1%
if -5.2000000000000002e107 < a < 8.1999999999999999e102Initial program 76.7%
Taylor expanded in t around -inf
Applied rewrites57.6%
Applied rewrites61.4%
(FPCore (x y z t a) :precision binary64 (if (<= a -2.5e+107) (fma y 1.0 x) (if (<= a 8e+102) (fma y (/ z t) x) (fma y 1.0 x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -2.5e+107) {
tmp = fma(y, 1.0, x);
} else if (a <= 8e+102) {
tmp = fma(y, (z / t), x);
} else {
tmp = fma(y, 1.0, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (a <= -2.5e+107) tmp = fma(y, 1.0, x); elseif (a <= 8e+102) tmp = fma(y, Float64(z / t), x); else tmp = fma(y, 1.0, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -2.5e+107], N[(y * 1.0 + x), $MachinePrecision], If[LessEqual[a, 8e+102], N[(y * N[(z / t), $MachinePrecision] + x), $MachinePrecision], N[(y * 1.0 + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.5 \cdot 10^{+107}:\\
\;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\
\mathbf{elif}\;a \leq 8 \cdot 10^{+102}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{z}{t}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\
\end{array}
\end{array}
if a < -2.5000000000000001e107 or 7.99999999999999982e102 < a Initial program 76.7%
Applied rewrites89.2%
Taylor expanded in a around inf
Applied rewrites60.1%
if -2.5000000000000001e107 < a < 7.99999999999999982e102Initial program 76.7%
Applied rewrites89.2%
Taylor expanded in z around inf
Applied rewrites76.5%
Taylor expanded in t around inf
Applied rewrites62.1%
(FPCore (x y z t a) :precision binary64 (if (<= (- (+ x y) (/ (* (- z t) y) (- a t))) (- INFINITY)) (* (/ y t) z) (fma y 1.0 x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (((x + y) - (((z - t) * y) / (a - t))) <= -((double) INFINITY)) {
tmp = (y / t) * z;
} else {
tmp = fma(y, 1.0, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t))) <= Float64(-Inf)) tmp = Float64(Float64(y / t) * z); else tmp = fma(y, 1.0, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-Infinity)], N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision], N[(y * 1.0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \leq -\infty:\\
\;\;\;\;\frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, 1, x\right)\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -inf.0Initial program 76.7%
Taylor expanded in t around -inf
Applied rewrites57.6%
Taylor expanded in z around inf
Applied rewrites18.6%
Applied rewrites20.3%
if -inf.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) Initial program 76.7%
Applied rewrites89.2%
Taylor expanded in a around inf
Applied rewrites60.1%
(FPCore (x y z t a) :precision binary64 (fma y 1.0 x))
double code(double x, double y, double z, double t, double a) {
return fma(y, 1.0, x);
}
function code(x, y, z, t, a) return fma(y, 1.0, x) end
code[x_, y_, z_, t_, a_] := N[(y * 1.0 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, 1, x\right)
\end{array}
Initial program 76.7%
Applied rewrites89.2%
Taylor expanded in a around inf
Applied rewrites60.1%
herbie shell --seed 2025153
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTick from plot-0.2.3.4, B"
:precision binary64
(- (+ x y) (/ (* (- z t) y) (- a t))))