
(FPCore (x y z t a) :precision binary64 (+ x (/ (* (- y z) (- t x)) (- a z))))
double code(double x, double y, double z, double t, double a) {
return x + (((y - z) * (t - x)) / (a - z));
}
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 - x)) / (a - z))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (((y - z) * (t - x)) / (a - z));
}
def code(x, y, z, t, a): return x + (((y - z) * (t - x)) / (a - z))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(Float64(y - z) * Float64(t - x)) / Float64(a - z))) end
function tmp = code(x, y, z, t, a) tmp = x + (((y - z) * (t - x)) / (a - z)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (/ (* (- y z) (- t x)) (- a z))))
double code(double x, double y, double z, double t, double a) {
return x + (((y - z) * (t - x)) / (a - z));
}
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 - x)) / (a - z))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (((y - z) * (t - x)) / (a - z));
}
def code(x, y, z, t, a): return x + (((y - z) * (t - x)) / (a - z))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(Float64(y - z) * Float64(t - x)) / Float64(a - z))) end
function tmp = code(x, y, z, t, a) tmp = x + (((y - z) * (t - x)) / (a - z)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}
\end{array}
(FPCore (x y z t a) :precision binary64 (if (or (<= z -1.6e+99) (not (<= z 1.06e+98))) (fma (- (- t x)) (/ (- y a) z) t) (+ x (/ (* (- y z) (- t x)) (- a z)))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -1.6e+99) || !(z <= 1.06e+98)) {
tmp = fma(-(t - x), ((y - a) / z), t);
} else {
tmp = x + (((y - z) * (t - x)) / (a - z));
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -1.6e+99) || !(z <= 1.06e+98)) tmp = fma(Float64(-Float64(t - x)), Float64(Float64(y - a) / z), t); else tmp = Float64(x + Float64(Float64(Float64(y - z) * Float64(t - x)) / Float64(a - z))); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -1.6e+99], N[Not[LessEqual[z, 1.06e+98]], $MachinePrecision]], N[((-N[(t - x), $MachinePrecision]) * N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision] + t), $MachinePrecision], N[(x + N[(N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{+99} \lor \neg \left(z \leq 1.06 \cdot 10^{+98}\right):\\
\;\;\;\;\mathsf{fma}\left(-\left(t - x\right), \frac{y - a}{z}, t\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}\\
\end{array}
\end{array}
if z < -1.6e99 or 1.0600000000000001e98 < z Initial program 28.1%
Taylor expanded in z around inf
Applied rewrites90.2%
if -1.6e99 < z < 1.0600000000000001e98Initial program 86.7%
Final simplification87.9%
(FPCore (x y z t a) :precision binary64 (if (or (<= a -0.0073) (not (<= a 3000000.0))) (fma (- t x) (/ (- y z) a) x) (fma (- (- t x)) (/ (- y a) z) t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((a <= -0.0073) || !(a <= 3000000.0)) {
tmp = fma((t - x), ((y - z) / a), x);
} else {
tmp = fma(-(t - x), ((y - a) / z), t);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((a <= -0.0073) || !(a <= 3000000.0)) tmp = fma(Float64(t - x), Float64(Float64(y - z) / a), x); else tmp = fma(Float64(-Float64(t - x)), Float64(Float64(y - a) / z), t); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[a, -0.0073], N[Not[LessEqual[a, 3000000.0]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * N[(N[(y - z), $MachinePrecision] / a), $MachinePrecision] + x), $MachinePrecision], N[((-N[(t - x), $MachinePrecision]) * N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision] + t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.0073 \lor \neg \left(a \leq 3000000\right):\\
\;\;\;\;\mathsf{fma}\left(t - x, \frac{y - z}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-\left(t - x\right), \frac{y - a}{z}, t\right)\\
\end{array}
\end{array}
if a < -0.00730000000000000007 or 3e6 < a Initial program 72.5%
Taylor expanded in x around inf
Applied rewrites79.3%
Taylor expanded in a around inf
Applied rewrites78.8%
if -0.00730000000000000007 < a < 3e6Initial program 61.6%
Taylor expanded in z around inf
Applied rewrites83.9%
Final simplification81.5%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (/ (- y z) a)))
(if (<= a -0.0073)
(fma (- t x) t_1 x)
(if (<= a 3000000.0)
(fma (- (- t x)) (/ (- y a) z) t)
(+ x (* t_1 (- t x)))))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y - z) / a;
double tmp;
if (a <= -0.0073) {
tmp = fma((t - x), t_1, x);
} else if (a <= 3000000.0) {
tmp = fma(-(t - x), ((y - a) / z), t);
} else {
tmp = x + (t_1 * (t - x));
}
return tmp;
}
function code(x, y, z, t, a) t_1 = Float64(Float64(y - z) / a) tmp = 0.0 if (a <= -0.0073) tmp = fma(Float64(t - x), t_1, x); elseif (a <= 3000000.0) tmp = fma(Float64(-Float64(t - x)), Float64(Float64(y - a) / z), t); else tmp = Float64(x + Float64(t_1 * Float64(t - x))); end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y - z), $MachinePrecision] / a), $MachinePrecision]}, If[LessEqual[a, -0.0073], N[(N[(t - x), $MachinePrecision] * t$95$1 + x), $MachinePrecision], If[LessEqual[a, 3000000.0], N[((-N[(t - x), $MachinePrecision]) * N[(N[(y - a), $MachinePrecision] / z), $MachinePrecision] + t), $MachinePrecision], N[(x + N[(t$95$1 * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y - z}{a}\\
\mathbf{if}\;a \leq -0.0073:\\
\;\;\;\;\mathsf{fma}\left(t - x, t\_1, x\right)\\
\mathbf{elif}\;a \leq 3000000:\\
\;\;\;\;\mathsf{fma}\left(-\left(t - x\right), \frac{y - a}{z}, t\right)\\
\mathbf{else}:\\
\;\;\;\;x + t\_1 \cdot \left(t - x\right)\\
\end{array}
\end{array}
if a < -0.00730000000000000007Initial program 73.0%
Taylor expanded in x around inf
Applied rewrites81.8%
Taylor expanded in a around inf
Applied rewrites79.3%
if -0.00730000000000000007 < a < 3e6Initial program 61.6%
Taylor expanded in z around inf
Applied rewrites83.9%
if 3e6 < a Initial program 71.9%
Taylor expanded in a around inf
Applied rewrites78.3%
(FPCore (x y z t a) :precision binary64 (if (or (<= a -0.0065) (not (<= a 1.65e-6))) (fma (- t x) (/ (- y z) a) x) (fma (/ (- x t) z) y t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((a <= -0.0065) || !(a <= 1.65e-6)) {
tmp = fma((t - x), ((y - z) / a), x);
} else {
tmp = fma(((x - t) / z), y, t);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((a <= -0.0065) || !(a <= 1.65e-6)) tmp = fma(Float64(t - x), Float64(Float64(y - z) / a), x); else tmp = fma(Float64(Float64(x - t) / z), y, t); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[a, -0.0065], N[Not[LessEqual[a, 1.65e-6]], $MachinePrecision]], N[(N[(t - x), $MachinePrecision] * N[(N[(y - z), $MachinePrecision] / a), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(x - t), $MachinePrecision] / z), $MachinePrecision] * y + t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.0065 \lor \neg \left(a \leq 1.65 \cdot 10^{-6}\right):\\
\;\;\;\;\mathsf{fma}\left(t - x, \frac{y - z}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x - t}{z}, y, t\right)\\
\end{array}
\end{array}
if a < -0.0064999999999999997 or 1.65000000000000008e-6 < a Initial program 72.1%
Taylor expanded in x around inf
Applied rewrites78.8%
Taylor expanded in a around inf
Applied rewrites78.4%
if -0.0064999999999999997 < a < 1.65000000000000008e-6Initial program 61.8%
Taylor expanded in z around inf
Applied rewrites84.4%
Taylor expanded in a around 0
Applied rewrites81.4%
Final simplification79.9%
(FPCore (x y z t a) :precision binary64 (if (<= a -0.01) (fma (- y z) (/ t a) x) (if (<= a 1.65e-6) (fma (/ (- x t) z) y t) (+ x (* (- t x) (/ y a))))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -0.01) {
tmp = fma((y - z), (t / a), x);
} else if (a <= 1.65e-6) {
tmp = fma(((x - t) / z), y, t);
} else {
tmp = x + ((t - x) * (y / a));
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (a <= -0.01) tmp = fma(Float64(y - z), Float64(t / a), x); elseif (a <= 1.65e-6) tmp = fma(Float64(Float64(x - t) / z), y, t); else tmp = Float64(x + Float64(Float64(t - x) * Float64(y / a))); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -0.01], N[(N[(y - z), $MachinePrecision] * N[(t / a), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[a, 1.65e-6], N[(N[(N[(x - t), $MachinePrecision] / z), $MachinePrecision] * y + t), $MachinePrecision], N[(x + N[(N[(t - x), $MachinePrecision] * N[(y / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(y - z, \frac{t}{a}, x\right)\\
\mathbf{elif}\;a \leq 1.65 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x - t}{z}, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(t - x\right) \cdot \frac{y}{a}\\
\end{array}
\end{array}
if a < -0.0100000000000000002Initial program 73.0%
Taylor expanded in a around inf
Applied rewrites78.8%
Taylor expanded in x around 0
Applied rewrites77.2%
if -0.0100000000000000002 < a < 1.65000000000000008e-6Initial program 61.8%
Taylor expanded in z around inf
Applied rewrites84.4%
Taylor expanded in a around 0
Applied rewrites81.4%
if 1.65000000000000008e-6 < a Initial program 71.2%
Taylor expanded in z around 0
Applied rewrites57.2%
Applied rewrites68.0%
(FPCore (x y z t a) :precision binary64 (if (or (<= a -0.01) (not (<= a 2.8e-6))) (fma (- y z) (/ t a) x) (fma (/ (- x t) z) y t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((a <= -0.01) || !(a <= 2.8e-6)) {
tmp = fma((y - z), (t / a), x);
} else {
tmp = fma(((x - t) / z), y, t);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((a <= -0.01) || !(a <= 2.8e-6)) tmp = fma(Float64(y - z), Float64(t / a), x); else tmp = fma(Float64(Float64(x - t) / z), y, t); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[a, -0.01], N[Not[LessEqual[a, 2.8e-6]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * N[(t / a), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(x - t), $MachinePrecision] / z), $MachinePrecision] * y + t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.01 \lor \neg \left(a \leq 2.8 \cdot 10^{-6}\right):\\
\;\;\;\;\mathsf{fma}\left(y - z, \frac{t}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x - t}{z}, y, t\right)\\
\end{array}
\end{array}
if a < -0.0100000000000000002 or 2.79999999999999987e-6 < a Initial program 72.1%
Taylor expanded in a around inf
Applied rewrites76.8%
Taylor expanded in x around 0
Applied rewrites70.9%
if -0.0100000000000000002 < a < 2.79999999999999987e-6Initial program 61.8%
Taylor expanded in z around inf
Applied rewrites84.4%
Taylor expanded in a around 0
Applied rewrites81.4%
Final simplification76.3%
(FPCore (x y z t a) :precision binary64 (if (or (<= a -0.01) (not (<= a 2.8e-6))) (fma y (/ t a) x) (fma (/ (- x t) z) y t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((a <= -0.01) || !(a <= 2.8e-6)) {
tmp = fma(y, (t / a), x);
} else {
tmp = fma(((x - t) / z), y, t);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((a <= -0.01) || !(a <= 2.8e-6)) tmp = fma(y, Float64(t / a), x); else tmp = fma(Float64(Float64(x - t) / z), y, t); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[a, -0.01], N[Not[LessEqual[a, 2.8e-6]], $MachinePrecision]], N[(y * N[(t / a), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(x - t), $MachinePrecision] / z), $MachinePrecision] * y + t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.01 \lor \neg \left(a \leq 2.8 \cdot 10^{-6}\right):\\
\;\;\;\;\mathsf{fma}\left(y, \frac{t}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x - t}{z}, y, t\right)\\
\end{array}
\end{array}
if a < -0.0100000000000000002 or 2.79999999999999987e-6 < a Initial program 72.1%
Taylor expanded in a around inf
Applied rewrites76.8%
Taylor expanded in x around 0
Applied rewrites70.9%
Taylor expanded in y around inf
Applied rewrites63.3%
if -0.0100000000000000002 < a < 2.79999999999999987e-6Initial program 61.8%
Taylor expanded in z around inf
Applied rewrites84.4%
Taylor expanded in a around 0
Applied rewrites81.4%
Final simplification72.7%
(FPCore (x y z t a) :precision binary64 (if (<= a -0.01) (fma (- y z) (/ t a) x) (if (<= a 1.65e-6) (fma (/ (- x t) z) y t) (fma (/ (- t x) a) y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -0.01) {
tmp = fma((y - z), (t / a), x);
} else if (a <= 1.65e-6) {
tmp = fma(((x - t) / z), y, t);
} else {
tmp = fma(((t - x) / a), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (a <= -0.01) tmp = fma(Float64(y - z), Float64(t / a), x); elseif (a <= 1.65e-6) tmp = fma(Float64(Float64(x - t) / z), y, t); else tmp = fma(Float64(Float64(t - x) / a), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -0.01], N[(N[(y - z), $MachinePrecision] * N[(t / a), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[a, 1.65e-6], N[(N[(N[(x - t), $MachinePrecision] / z), $MachinePrecision] * y + t), $MachinePrecision], N[(N[(N[(t - x), $MachinePrecision] / a), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(y - z, \frac{t}{a}, x\right)\\
\mathbf{elif}\;a \leq 1.65 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x - t}{z}, y, t\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t - x}{a}, y, x\right)\\
\end{array}
\end{array}
if a < -0.0100000000000000002Initial program 73.0%
Taylor expanded in a around inf
Applied rewrites78.8%
Taylor expanded in x around 0
Applied rewrites77.2%
if -0.0100000000000000002 < a < 1.65000000000000008e-6Initial program 61.8%
Taylor expanded in z around inf
Applied rewrites84.4%
Taylor expanded in a around 0
Applied rewrites81.4%
if 1.65000000000000008e-6 < a Initial program 71.2%
Taylor expanded in z around 0
Applied rewrites66.9%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -1.2e+23) (not (<= z 5.2e+77))) t (fma y (/ t a) x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -1.2e+23) || !(z <= 5.2e+77)) {
tmp = t;
} else {
tmp = fma(y, (t / a), x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -1.2e+23) || !(z <= 5.2e+77)) tmp = t; else tmp = fma(y, Float64(t / a), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -1.2e+23], N[Not[LessEqual[z, 5.2e+77]], $MachinePrecision]], t, N[(y * N[(t / a), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{+23} \lor \neg \left(z \leq 5.2 \cdot 10^{+77}\right):\\
\;\;\;\;t\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{t}{a}, x\right)\\
\end{array}
\end{array}
if z < -1.2e23 or 5.2000000000000004e77 < z Initial program 38.7%
Taylor expanded in z around inf
Applied rewrites54.1%
if -1.2e23 < z < 5.2000000000000004e77Initial program 86.6%
Taylor expanded in a around inf
Applied rewrites67.9%
Taylor expanded in x around 0
Applied rewrites60.4%
Taylor expanded in y around inf
Applied rewrites57.3%
Final simplification56.0%
(FPCore (x y z t a) :precision binary64 (if (<= z -1.15e+23) t (if (<= z 5e+77) x t)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -1.15e+23) {
tmp = t;
} else if (z <= 5e+77) {
tmp = x;
} else {
tmp = t;
}
return tmp;
}
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
real(8) :: tmp
if (z <= (-1.15d+23)) then
tmp = t
else if (z <= 5d+77) then
tmp = x
else
tmp = t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -1.15e+23) {
tmp = t;
} else if (z <= 5e+77) {
tmp = x;
} else {
tmp = t;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if z <= -1.15e+23: tmp = t elif z <= 5e+77: tmp = x else: tmp = t return tmp
function code(x, y, z, t, a) tmp = 0.0 if (z <= -1.15e+23) tmp = t; elseif (z <= 5e+77) tmp = x; else tmp = t; end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (z <= -1.15e+23) tmp = t; elseif (z <= 5e+77) tmp = x; else tmp = t; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -1.15e+23], t, If[LessEqual[z, 5e+77], x, t]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+23}:\\
\;\;\;\;t\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+77}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\\
\end{array}
\end{array}
if z < -1.15e23 or 5.00000000000000004e77 < z Initial program 38.7%
Taylor expanded in z around inf
Applied rewrites54.1%
if -1.15e23 < z < 5.00000000000000004e77Initial program 86.6%
Taylor expanded in a around inf
Applied rewrites37.7%
(FPCore (x y z t a) :precision binary64 t)
double code(double x, double y, double z, double t, double a) {
return 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 = t
end function
public static double code(double x, double y, double z, double t, double a) {
return t;
}
def code(x, y, z, t, a): return t
function code(x, y, z, t, a) return t end
function tmp = code(x, y, z, t, a) tmp = t; end
code[x_, y_, z_, t_, a_] := t
\begin{array}{l}
\\
t
\end{array}
Initial program 66.8%
Taylor expanded in z around inf
Applied rewrites27.5%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (- t (* (/ y z) (- t x)))))
(if (< z -1.2536131056095036e+188)
t_1
(if (< z 4.446702369113811e+64)
(+ x (/ (- y z) (/ (- a z) (- t x))))
t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = t - ((y / z) * (t - x));
double tmp;
if (z < -1.2536131056095036e+188) {
tmp = t_1;
} else if (z < 4.446702369113811e+64) {
tmp = x + ((y - z) / ((a - z) / (t - x)));
} else {
tmp = t_1;
}
return tmp;
}
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
real(8) :: t_1
real(8) :: tmp
t_1 = t - ((y / z) * (t - x))
if (z < (-1.2536131056095036d+188)) then
tmp = t_1
else if (z < 4.446702369113811d+64) then
tmp = x + ((y - z) / ((a - z) / (t - x)))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = t - ((y / z) * (t - x));
double tmp;
if (z < -1.2536131056095036e+188) {
tmp = t_1;
} else if (z < 4.446702369113811e+64) {
tmp = x + ((y - z) / ((a - z) / (t - x)));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = t - ((y / z) * (t - x)) tmp = 0 if z < -1.2536131056095036e+188: tmp = t_1 elif z < 4.446702369113811e+64: tmp = x + ((y - z) / ((a - z) / (t - x))) else: tmp = t_1 return tmp
function code(x, y, z, t, a) t_1 = Float64(t - Float64(Float64(y / z) * Float64(t - x))) tmp = 0.0 if (z < -1.2536131056095036e+188) tmp = t_1; elseif (z < 4.446702369113811e+64) tmp = Float64(x + Float64(Float64(y - z) / Float64(Float64(a - z) / Float64(t - x)))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = t - ((y / z) * (t - x)); tmp = 0.0; if (z < -1.2536131056095036e+188) tmp = t_1; elseif (z < 4.446702369113811e+64) tmp = x + ((y - z) / ((a - z) / (t - x))); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(t - N[(N[(y / z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[z, -1.2536131056095036e+188], t$95$1, If[Less[z, 4.446702369113811e+64], N[(x + N[(N[(y - z), $MachinePrecision] / N[(N[(a - z), $MachinePrecision] / N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := t - \frac{y}{z} \cdot \left(t - x\right)\\
\mathbf{if}\;z < -1.2536131056095036 \cdot 10^{+188}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z < 4.446702369113811 \cdot 10^{+64}:\\
\;\;\;\;x + \frac{y - z}{\frac{a - z}{t - x}}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
herbie shell --seed 2025021
(FPCore (x y z t a)
:name "Graphics.Rendering.Chart.Axis.Types:invLinMap from Chart-1.5.3"
:precision binary64
:alt
(! :herbie-platform default (if (< z -125361310560950360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- t (* (/ y z) (- t x))) (if (< z 44467023691138110000000000000000000000000000000000000000000000000) (+ x (/ (- y z) (/ (- a z) (- t x)))) (- t (* (/ y z) (- t x))))))
(+ x (/ (* (- y z) (- t x)) (- a z))))