
(FPCore (x y z t a) :precision binary64 (+ x (/ (* (- y x) (- z t)) (- a t))))
double code(double x, double y, double z, double t, double a) {
return x + (((y - x) * (z - t)) / (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 - x) * (z - t)) / (a - t))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (((y - x) * (z - t)) / (a - t));
}
def code(x, y, z, t, a): return x + (((y - x) * (z - t)) / (a - t))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(Float64(y - x) * Float64(z - t)) / Float64(a - t))) end
function tmp = code(x, y, z, t, a) tmp = x + (((y - x) * (z - t)) / (a - t)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (/ (* (- y x) (- z t)) (- a t))))
double code(double x, double y, double z, double t, double a) {
return x + (((y - x) * (z - t)) / (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 - x) * (z - t)) / (a - t))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (((y - x) * (z - t)) / (a - t));
}
def code(x, y, z, t, a): return x + (((y - x) * (z - t)) / (a - t))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(Float64(y - x) * Float64(z - t)) / Float64(a - t))) end
function tmp = code(x, y, z, t, a) tmp = x + (((y - x) * (z - t)) / (a - t)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\end{array}
(FPCore (x y z t a) :precision binary64 (if (or (<= a -8.8e-126) (not (<= a 4.4e-225))) (fma (/ (- z t) (- a t)) (- y x) x) (fma (/ (fma -1.0 y x) t) (- z a) y)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((a <= -8.8e-126) || !(a <= 4.4e-225)) {
tmp = fma(((z - t) / (a - t)), (y - x), x);
} else {
tmp = fma((fma(-1.0, y, x) / t), (z - a), y);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((a <= -8.8e-126) || !(a <= 4.4e-225)) tmp = fma(Float64(Float64(z - t) / Float64(a - t)), Float64(y - x), x); else tmp = fma(Float64(fma(-1.0, y, x) / t), Float64(z - a), y); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[a, -8.8e-126], N[Not[LessEqual[a, 4.4e-225]], $MachinePrecision]], N[(N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(-1.0 * y + x), $MachinePrecision] / t), $MachinePrecision] * N[(z - a), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -8.8 \cdot 10^{-126} \lor \neg \left(a \leq 4.4 \cdot 10^{-225}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z - t}{a - t}, y - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(-1, y, x\right)}{t}, z - a, y\right)\\
\end{array}
\end{array}
if a < -8.80000000000000058e-126 or 4.4e-225 < a Initial program 74.8%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.0
Applied rewrites91.0%
if -8.80000000000000058e-126 < a < 4.4e-225Initial program 57.4%
Taylor expanded in t around inf
Applied rewrites91.0%
Final simplification91.0%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (fma (/ (- z t) (- a t)) y x)))
(if (<= y -1.45e-47)
t_1
(if (<= y -2.6e-144)
(fma (/ x t) (- z a) y)
(if (<= y 2.1e-26) (fma x (/ (- t z) (- a t)) x) t_1)))))
double code(double x, double y, double z, double t, double a) {
double t_1 = fma(((z - t) / (a - t)), y, x);
double tmp;
if (y <= -1.45e-47) {
tmp = t_1;
} else if (y <= -2.6e-144) {
tmp = fma((x / t), (z - a), y);
} else if (y <= 2.1e-26) {
tmp = fma(x, ((t - z) / (a - t)), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = fma(Float64(Float64(z - t) / Float64(a - t)), y, x) tmp = 0.0 if (y <= -1.45e-47) tmp = t_1; elseif (y <= -2.6e-144) tmp = fma(Float64(x / t), Float64(z - a), y); elseif (y <= 2.1e-26) tmp = fma(x, Float64(Float64(t - z) / Float64(a - t)), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]}, If[LessEqual[y, -1.45e-47], t$95$1, If[LessEqual[y, -2.6e-144], N[(N[(x / t), $MachinePrecision] * N[(z - a), $MachinePrecision] + y), $MachinePrecision], If[LessEqual[y, 2.1e-26], N[(x * N[(N[(t - z), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{z - t}{a - t}, y, x\right)\\
\mathbf{if}\;y \leq -1.45 \cdot 10^{-47}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq -2.6 \cdot 10^{-144}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{t}, z - a, y\right)\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-26}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{t - z}{a - t}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.45e-47 or 2.10000000000000008e-26 < y Initial program 66.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.7
Applied rewrites90.7%
Taylor expanded in x around 0
Applied rewrites80.1%
if -1.45e-47 < y < -2.6000000000000001e-144Initial program 78.1%
Taylor expanded in t around inf
Applied rewrites84.7%
Taylor expanded in x around inf
Applied rewrites72.4%
if -2.6000000000000001e-144 < y < 2.10000000000000008e-26Initial program 78.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6481.2
Applied rewrites81.2%
Taylor expanded in y around -inf
Applied rewrites56.7%
Taylor expanded in y around 0
Applied rewrites75.0%
Final simplification77.9%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (fma (/ x t) (- z a) y)))
(if (<= t -2.8e+91)
t_1
(if (<= t -2.1e-96)
(* (- y x) (/ z (- a t)))
(if (<= t 1.15e+55) (fma (/ z a) (- y x) x) t_1)))))
double code(double x, double y, double z, double t, double a) {
double t_1 = fma((x / t), (z - a), y);
double tmp;
if (t <= -2.8e+91) {
tmp = t_1;
} else if (t <= -2.1e-96) {
tmp = (y - x) * (z / (a - t));
} else if (t <= 1.15e+55) {
tmp = fma((z / a), (y - x), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = fma(Float64(x / t), Float64(z - a), y) tmp = 0.0 if (t <= -2.8e+91) tmp = t_1; elseif (t <= -2.1e-96) tmp = Float64(Float64(y - x) * Float64(z / Float64(a - t))); elseif (t <= 1.15e+55) tmp = fma(Float64(z / a), Float64(y - x), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(x / t), $MachinePrecision] * N[(z - a), $MachinePrecision] + y), $MachinePrecision]}, If[LessEqual[t, -2.8e+91], t$95$1, If[LessEqual[t, -2.1e-96], N[(N[(y - x), $MachinePrecision] * N[(z / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 1.15e+55], N[(N[(z / a), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{x}{t}, z - a, y\right)\\
\mathbf{if}\;t \leq -2.8 \cdot 10^{+91}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq -2.1 \cdot 10^{-96}:\\
\;\;\;\;\left(y - x\right) \cdot \frac{z}{a - t}\\
\mathbf{elif}\;t \leq 1.15 \cdot 10^{+55}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a}, y - x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -2.7999999999999999e91 or 1.14999999999999994e55 < t Initial program 42.2%
Taylor expanded in t around inf
Applied rewrites78.1%
Taylor expanded in x around inf
Applied rewrites73.3%
if -2.7999999999999999e91 < t < -2.10000000000000001e-96Initial program 77.4%
Taylor expanded in z around inf
Applied rewrites67.5%
if -2.10000000000000001e-96 < t < 1.14999999999999994e55Initial program 89.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.4
Applied rewrites94.4%
Taylor expanded in t around 0
Applied rewrites79.5%
Final simplification75.6%
(FPCore (x y z t a)
:precision binary64
(if (<= a -5.5e-33)
(+ x (* (/ (- z t) a) (- y x)))
(if (<= a 9.8e-222)
(fma (/ (fma -1.0 y x) t) (- z a) y)
(fma (/ (- z t) (- a t)) y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -5.5e-33) {
tmp = x + (((z - t) / a) * (y - x));
} else if (a <= 9.8e-222) {
tmp = fma((fma(-1.0, y, x) / t), (z - a), y);
} else {
tmp = fma(((z - t) / (a - t)), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (a <= -5.5e-33) tmp = Float64(x + Float64(Float64(Float64(z - t) / a) * Float64(y - x))); elseif (a <= 9.8e-222) tmp = fma(Float64(fma(-1.0, y, x) / t), Float64(z - a), y); else tmp = fma(Float64(Float64(z - t) / Float64(a - t)), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -5.5e-33], N[(x + N[(N[(N[(z - t), $MachinePrecision] / a), $MachinePrecision] * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 9.8e-222], N[(N[(N[(-1.0 * y + x), $MachinePrecision] / t), $MachinePrecision] * N[(z - a), $MachinePrecision] + y), $MachinePrecision], N[(N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5.5 \cdot 10^{-33}:\\
\;\;\;\;x + \frac{z - t}{a} \cdot \left(y - x\right)\\
\mathbf{elif}\;a \leq 9.8 \cdot 10^{-222}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(-1, y, x\right)}{t}, z - a, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - t}{a - t}, y, x\right)\\
\end{array}
\end{array}
if a < -5.5e-33Initial program 71.4%
Taylor expanded in a around inf
Applied rewrites75.3%
if -5.5e-33 < a < 9.7999999999999999e-222Initial program 63.9%
Taylor expanded in t around inf
Applied rewrites84.2%
if 9.7999999999999999e-222 < a Initial program 76.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.1
Applied rewrites92.1%
Taylor expanded in x around 0
Applied rewrites79.3%
Final simplification79.4%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -1.6e+63) (not (<= t 1.15e+55))) (fma (/ x t) (- z a) y) (fma (/ z a) (- y x) x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -1.6e+63) || !(t <= 1.15e+55)) {
tmp = fma((x / t), (z - a), y);
} else {
tmp = fma((z / a), (y - x), x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -1.6e+63) || !(t <= 1.15e+55)) tmp = fma(Float64(x / t), Float64(z - a), y); else tmp = fma(Float64(z / a), Float64(y - x), x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -1.6e+63], N[Not[LessEqual[t, 1.15e+55]], $MachinePrecision]], N[(N[(x / t), $MachinePrecision] * N[(z - a), $MachinePrecision] + y), $MachinePrecision], N[(N[(z / a), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.6 \cdot 10^{+63} \lor \neg \left(t \leq 1.15 \cdot 10^{+55}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{t}, z - a, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a}, y - x, x\right)\\
\end{array}
\end{array}
if t < -1.60000000000000006e63 or 1.14999999999999994e55 < t Initial program 42.2%
Taylor expanded in t around inf
Applied rewrites78.9%
Taylor expanded in x around inf
Applied rewrites71.5%
if -1.60000000000000006e63 < t < 1.14999999999999994e55Initial program 88.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.2
Applied rewrites94.2%
Taylor expanded in t around 0
Applied rewrites74.2%
Final simplification73.2%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -1.6e+63) (not (<= t 1.15e+55))) (fma (/ x t) (- z a) y) (fma (/ (- y x) a) z x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -1.6e+63) || !(t <= 1.15e+55)) {
tmp = fma((x / t), (z - a), y);
} else {
tmp = fma(((y - x) / a), z, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -1.6e+63) || !(t <= 1.15e+55)) tmp = fma(Float64(x / t), Float64(z - a), y); else tmp = fma(Float64(Float64(y - x) / a), z, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -1.6e+63], N[Not[LessEqual[t, 1.15e+55]], $MachinePrecision]], N[(N[(x / t), $MachinePrecision] * N[(z - a), $MachinePrecision] + y), $MachinePrecision], N[(N[(N[(y - x), $MachinePrecision] / a), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.6 \cdot 10^{+63} \lor \neg \left(t \leq 1.15 \cdot 10^{+55}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{t}, z - a, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y - x}{a}, z, x\right)\\
\end{array}
\end{array}
if t < -1.60000000000000006e63 or 1.14999999999999994e55 < t Initial program 42.2%
Taylor expanded in t around inf
Applied rewrites78.9%
Taylor expanded in x around inf
Applied rewrites71.5%
if -1.60000000000000006e63 < t < 1.14999999999999994e55Initial program 88.7%
Taylor expanded in t around 0
Applied rewrites72.5%
Final simplification72.1%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -4.1e-53) (not (<= t 1.1e+55))) (fma (/ x t) (- z a) y) (fma (/ z a) y x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -4.1e-53) || !(t <= 1.1e+55)) {
tmp = fma((x / t), (z - a), y);
} else {
tmp = fma((z / a), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -4.1e-53) || !(t <= 1.1e+55)) tmp = fma(Float64(x / t), Float64(z - a), y); else tmp = fma(Float64(z / a), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -4.1e-53], N[Not[LessEqual[t, 1.1e+55]], $MachinePrecision]], N[(N[(x / t), $MachinePrecision] * N[(z - a), $MachinePrecision] + y), $MachinePrecision], N[(N[(z / a), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.1 \cdot 10^{-53} \lor \neg \left(t \leq 1.1 \cdot 10^{+55}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{t}, z - a, y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a}, y, x\right)\\
\end{array}
\end{array}
if t < -4.1000000000000001e-53 or 1.10000000000000005e55 < t Initial program 49.6%
Taylor expanded in t around inf
Applied rewrites73.4%
Taylor expanded in x around inf
Applied rewrites65.7%
if -4.1000000000000001e-53 < t < 1.10000000000000005e55Initial program 89.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.1
Applied rewrites94.1%
Taylor expanded in x around inf
Applied rewrites62.2%
Taylor expanded in t around 0
Applied rewrites57.1%
Taylor expanded in x around 0
Applied rewrites66.5%
Final simplification66.1%
(FPCore (x y z t a) :precision binary64 (if (<= t -1.5e+92) y (if (<= t 2.3e+70) (fma (/ z a) y x) y)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -1.5e+92) {
tmp = y;
} else if (t <= 2.3e+70) {
tmp = fma((z / a), y, x);
} else {
tmp = y;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (t <= -1.5e+92) tmp = y; elseif (t <= 2.3e+70) tmp = fma(Float64(z / a), y, x); else tmp = y; end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -1.5e+92], y, If[LessEqual[t, 2.3e+70], N[(N[(z / a), $MachinePrecision] * y + x), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.5 \cdot 10^{+92}:\\
\;\;\;\;y\\
\mathbf{elif}\;t \leq 2.3 \cdot 10^{+70}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if t < -1.50000000000000007e92 or 2.29999999999999994e70 < t Initial program 42.9%
Taylor expanded in t around inf
Applied rewrites50.0%
if -1.50000000000000007e92 < t < 2.29999999999999994e70Initial program 85.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.3
Applied rewrites92.3%
Taylor expanded in x around inf
Applied rewrites58.5%
Taylor expanded in t around 0
Applied rewrites50.5%
Taylor expanded in x around 0
Applied rewrites59.1%
Final simplification56.1%
(FPCore (x y z t a) :precision binary64 (if (<= t -4.8e+32) y (if (<= t 3.8e+51) (fma t (/ x a) x) y)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -4.8e+32) {
tmp = y;
} else if (t <= 3.8e+51) {
tmp = fma(t, (x / a), x);
} else {
tmp = y;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (t <= -4.8e+32) tmp = y; elseif (t <= 3.8e+51) tmp = fma(t, Float64(x / a), x); else tmp = y; end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -4.8e+32], y, If[LessEqual[t, 3.8e+51], N[(t * N[(x / a), $MachinePrecision] + x), $MachinePrecision], y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -4.8 \cdot 10^{+32}:\\
\;\;\;\;y\\
\mathbf{elif}\;t \leq 3.8 \cdot 10^{+51}:\\
\;\;\;\;\mathsf{fma}\left(t, \frac{x}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if t < -4.79999999999999983e32 or 3.7999999999999997e51 < t Initial program 47.0%
Taylor expanded in t around inf
Applied rewrites42.5%
if -4.79999999999999983e32 < t < 3.7999999999999997e51Initial program 88.1%
Taylor expanded in x around inf
Applied rewrites63.3%
Taylor expanded in z around 0
Applied rewrites41.3%
Taylor expanded in t around 0
Applied rewrites41.3%
Final simplification41.8%
(FPCore (x y z t a) :precision binary64 (if (<= a -1.45e+147) x (if (<= a 4.2e-61) y x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -1.45e+147) {
tmp = x;
} else if (a <= 4.2e-61) {
tmp = y;
} else {
tmp = x;
}
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 (a <= (-1.45d+147)) then
tmp = x
else if (a <= 4.2d-61) then
tmp = y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -1.45e+147) {
tmp = x;
} else if (a <= 4.2e-61) {
tmp = y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if a <= -1.45e+147: tmp = x elif a <= 4.2e-61: tmp = y else: tmp = x return tmp
function code(x, y, z, t, a) tmp = 0.0 if (a <= -1.45e+147) tmp = x; elseif (a <= 4.2e-61) tmp = y; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (a <= -1.45e+147) tmp = x; elseif (a <= 4.2e-61) tmp = y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -1.45e+147], x, If[LessEqual[a, 4.2e-61], y, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.45 \cdot 10^{+147}:\\
\;\;\;\;x\\
\mathbf{elif}\;a \leq 4.2 \cdot 10^{-61}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if a < -1.4499999999999999e147 or 4.1999999999999998e-61 < a Initial program 76.8%
Taylor expanded in a around inf
Applied rewrites52.9%
if -1.4499999999999999e147 < a < 4.1999999999999998e-61Initial program 66.8%
Taylor expanded in t around inf
Applied rewrites30.1%
Final simplification40.0%
(FPCore (x y z t a) :precision binary64 x)
double code(double x, double y, double z, double t, double a) {
return x;
}
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
end function
public static double code(double x, double y, double z, double t, double a) {
return x;
}
def code(x, y, z, t, a): return x
function code(x, y, z, t, a) return x end
function tmp = code(x, y, z, t, a) tmp = x; end
code[x_, y_, z_, t_, a_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 71.1%
Taylor expanded in a around inf
Applied rewrites28.0%
Final simplification28.0%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (+ x (* (/ (- y x) 1.0) (/ (- z t) (- a t))))))
(if (< a -1.6153062845442575e-142)
t_1
(if (< a 3.774403170083174e-182) (- y (* (/ z t) (- y x))) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = x + (((y - x) / 1.0) * ((z - t) / (a - t)));
double tmp;
if (a < -1.6153062845442575e-142) {
tmp = t_1;
} else if (a < 3.774403170083174e-182) {
tmp = y - ((z / t) * (y - 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 = x + (((y - x) / 1.0d0) * ((z - t) / (a - t)))
if (a < (-1.6153062845442575d-142)) then
tmp = t_1
else if (a < 3.774403170083174d-182) then
tmp = y - ((z / t) * (y - 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 = x + (((y - x) / 1.0) * ((z - t) / (a - t)));
double tmp;
if (a < -1.6153062845442575e-142) {
tmp = t_1;
} else if (a < 3.774403170083174e-182) {
tmp = y - ((z / t) * (y - x));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = x + (((y - x) / 1.0) * ((z - t) / (a - t))) tmp = 0 if a < -1.6153062845442575e-142: tmp = t_1 elif a < 3.774403170083174e-182: tmp = y - ((z / t) * (y - x)) else: tmp = t_1 return tmp
function code(x, y, z, t, a) t_1 = Float64(x + Float64(Float64(Float64(y - x) / 1.0) * Float64(Float64(z - t) / Float64(a - t)))) tmp = 0.0 if (a < -1.6153062845442575e-142) tmp = t_1; elseif (a < 3.774403170083174e-182) tmp = Float64(y - Float64(Float64(z / t) * Float64(y - x))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = x + (((y - x) / 1.0) * ((z - t) / (a - t))); tmp = 0.0; if (a < -1.6153062845442575e-142) tmp = t_1; elseif (a < 3.774403170083174e-182) tmp = y - ((z / t) * (y - x)); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(x + N[(N[(N[(y - x), $MachinePrecision] / 1.0), $MachinePrecision] * N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[a, -1.6153062845442575e-142], t$95$1, If[Less[a, 3.774403170083174e-182], N[(y - N[(N[(z / t), $MachinePrecision] * N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x + \frac{y - x}{1} \cdot \frac{z - t}{a - t}\\
\mathbf{if}\;a < -1.6153062845442575 \cdot 10^{-142}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;a < 3.774403170083174 \cdot 10^{-182}:\\
\;\;\;\;y - \frac{z}{t} \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
herbie shell --seed 2025026
(FPCore (x y z t a)
:name "Graphics.Rendering.Chart.Axis.Types:linMap from Chart-1.5.3"
:precision binary64
:alt
(! :herbie-platform default (if (< a -646122513817703/4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (+ x (* (/ (- y x) 1) (/ (- z t) (- a t)))) (if (< a 1887201585041587/50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- y (* (/ z t) (- y x))) (+ x (* (/ (- y x) 1) (/ (- z t) (- a t)))))))
(+ x (/ (* (- y x) (- z t)) (- a t))))