
(FPCore (x y z t a b) :precision binary64 (/ (+ x (/ (* y z) t)) (+ (+ a 1.0) (/ (* y b) t))))
double code(double x, double y, double z, double t, double a, double b) {
return (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / 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, b)
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), intent (in) :: b
code = (x + ((y * z) / t)) / ((a + 1.0d0) + ((y * b) / t))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / t));
}
def code(x, y, z, t, a, b): return (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / t))
function code(x, y, z, t, a, b) return Float64(Float64(x + Float64(Float64(y * z) / t)) / Float64(Float64(a + 1.0) + Float64(Float64(y * b) / t))) end
function tmp = code(x, y, z, t, a, b) tmp = (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / t)); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / N[(N[(a + 1.0), $MachinePrecision] + N[(N[(y * b), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (/ (+ x (/ (* y z) t)) (+ (+ a 1.0) (/ (* y b) t))))
double code(double x, double y, double z, double t, double a, double b) {
return (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / 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, b)
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), intent (in) :: b
code = (x + ((y * z) / t)) / ((a + 1.0d0) + ((y * b) / t))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / t));
}
def code(x, y, z, t, a, b): return (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / t))
function code(x, y, z, t, a, b) return Float64(Float64(x + Float64(Float64(y * z) / t)) / Float64(Float64(a + 1.0) + Float64(Float64(y * b) / t))) end
function tmp = code(x, y, z, t, a, b) tmp = (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / t)); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / N[(N[(a + 1.0), $MachinePrecision] + N[(N[(y * b), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}}
\end{array}
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (/ (+ x (/ (* y z) t)) (+ (+ a 1.0) (/ (* y b) t))))
(t_2 (fma b (/ y t) (+ 1.0 a))))
(if (<= t_1 (- INFINITY))
(* (+ (/ (/ y t) t_2) (/ (/ x z) t_2)) z)
(if (<= t_1 1e+301) t_1 (/ z b)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / t));
double t_2 = fma(b, (y / t), (1.0 + a));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = (((y / t) / t_2) + ((x / z) / t_2)) * z;
} else if (t_1 <= 1e+301) {
tmp = t_1;
} else {
tmp = z / b;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(Float64(x + Float64(Float64(y * z) / t)) / Float64(Float64(a + 1.0) + Float64(Float64(y * b) / t))) t_2 = fma(b, Float64(y / t), Float64(1.0 + a)) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(Float64(Float64(Float64(y / t) / t_2) + Float64(Float64(x / z) / t_2)) * z); elseif (t_1 <= 1e+301) tmp = t_1; else tmp = Float64(z / b); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / N[(N[(a + 1.0), $MachinePrecision] + N[(N[(y * b), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(b * N[(y / t), $MachinePrecision] + N[(1.0 + a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(N[(y / t), $MachinePrecision] / t$95$2), $MachinePrecision] + N[(N[(x / z), $MachinePrecision] / t$95$2), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[t$95$1, 1e+301], t$95$1, N[(z / b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}}\\
t_2 := \mathsf{fma}\left(b, \frac{y}{t}, 1 + a\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;\left(\frac{\frac{y}{t}}{t\_2} + \frac{\frac{x}{z}}{t\_2}\right) \cdot z\\
\mathbf{elif}\;t\_1 \leq 10^{+301}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a #s(literal 1 binary64)) (/.f64 (*.f64 y b) t))) < -inf.0Initial program 38.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites85.4%
if -inf.0 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a #s(literal 1 binary64)) (/.f64 (*.f64 y b) t))) < 1.00000000000000005e301Initial program 91.9%
if 1.00000000000000005e301 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a #s(literal 1 binary64)) (/.f64 (*.f64 y b) t))) Initial program 12.1%
Taylor expanded in y around inf
lower-/.f6486.6
Applied rewrites86.6%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (/ (+ x (/ (* y z) t)) (+ (+ a 1.0) (/ (* y b) t))))
(t_2 (fma b (/ y t) (+ 1.0 a))))
(if (<= t_1 2e+28)
(* (+ (/ (/ y t) t_2) (/ (/ x z) t_2)) z)
(if (<= t_1 INFINITY)
(fma
(/ (+ (* y (/ z (- -1.0 a))) (/ (* (* y x) b) (pow (+ 1.0 a) 2.0))) t)
-1.0
(/ x (+ 1.0 a)))
(/ z b)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / t));
double t_2 = fma(b, (y / t), (1.0 + a));
double tmp;
if (t_1 <= 2e+28) {
tmp = (((y / t) / t_2) + ((x / z) / t_2)) * z;
} else if (t_1 <= ((double) INFINITY)) {
tmp = fma((((y * (z / (-1.0 - a))) + (((y * x) * b) / pow((1.0 + a), 2.0))) / t), -1.0, (x / (1.0 + a)));
} else {
tmp = z / b;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(Float64(x + Float64(Float64(y * z) / t)) / Float64(Float64(a + 1.0) + Float64(Float64(y * b) / t))) t_2 = fma(b, Float64(y / t), Float64(1.0 + a)) tmp = 0.0 if (t_1 <= 2e+28) tmp = Float64(Float64(Float64(Float64(y / t) / t_2) + Float64(Float64(x / z) / t_2)) * z); elseif (t_1 <= Inf) tmp = fma(Float64(Float64(Float64(y * Float64(z / Float64(-1.0 - a))) + Float64(Float64(Float64(y * x) * b) / (Float64(1.0 + a) ^ 2.0))) / t), -1.0, Float64(x / Float64(1.0 + a))); else tmp = Float64(z / b); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / N[(N[(a + 1.0), $MachinePrecision] + N[(N[(y * b), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(b * N[(y / t), $MachinePrecision] + N[(1.0 + a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 2e+28], N[(N[(N[(N[(y / t), $MachinePrecision] / t$95$2), $MachinePrecision] + N[(N[(x / z), $MachinePrecision] / t$95$2), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[t$95$1, Infinity], N[(N[(N[(N[(y * N[(z / N[(-1.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(y * x), $MachinePrecision] * b), $MachinePrecision] / N[Power[N[(1.0 + a), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision] * -1.0 + N[(x / N[(1.0 + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z / b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}}\\
t_2 := \mathsf{fma}\left(b, \frac{y}{t}, 1 + a\right)\\
\mathbf{if}\;t\_1 \leq 2 \cdot 10^{+28}:\\
\;\;\;\;\left(\frac{\frac{y}{t}}{t\_2} + \frac{\frac{x}{z}}{t\_2}\right) \cdot z\\
\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{y \cdot \frac{z}{-1 - a} + \frac{\left(y \cdot x\right) \cdot b}{{\left(1 + a\right)}^{2}}}{t}, -1, \frac{x}{1 + a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a #s(literal 1 binary64)) (/.f64 (*.f64 y b) t))) < 1.99999999999999992e28Initial program 85.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites76.2%
if 1.99999999999999992e28 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a #s(literal 1 binary64)) (/.f64 (*.f64 y b) t))) < +inf.0Initial program 87.3%
Taylor expanded in t around -inf
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites72.1%
if +inf.0 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a #s(literal 1 binary64)) (/.f64 (*.f64 y b) t))) Initial program 0.0%
Taylor expanded in y around inf
lower-/.f64100.0
Applied rewrites100.0%
Final simplification77.8%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (/ (+ x (/ (* y z) t)) (+ (+ a 1.0) (/ (* y b) t))))
(t_2 (fma b (/ y t) (+ 1.0 a))))
(if (<= t_1 2e+28)
(* (+ (/ (/ y t) t_2) (/ (/ x z) t_2)) z)
(if (<= t_1 1e+301)
(fma
-1.0
(/ (+ (/ (* y z) (- -1.0 a)) (/ (* b (* x y)) (pow (+ 1.0 a) 2.0))) t)
(/ x (+ 1.0 a)))
(/ z b)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / t));
double t_2 = fma(b, (y / t), (1.0 + a));
double tmp;
if (t_1 <= 2e+28) {
tmp = (((y / t) / t_2) + ((x / z) / t_2)) * z;
} else if (t_1 <= 1e+301) {
tmp = fma(-1.0, ((((y * z) / (-1.0 - a)) + ((b * (x * y)) / pow((1.0 + a), 2.0))) / t), (x / (1.0 + a)));
} else {
tmp = z / b;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(Float64(x + Float64(Float64(y * z) / t)) / Float64(Float64(a + 1.0) + Float64(Float64(y * b) / t))) t_2 = fma(b, Float64(y / t), Float64(1.0 + a)) tmp = 0.0 if (t_1 <= 2e+28) tmp = Float64(Float64(Float64(Float64(y / t) / t_2) + Float64(Float64(x / z) / t_2)) * z); elseif (t_1 <= 1e+301) tmp = fma(-1.0, Float64(Float64(Float64(Float64(y * z) / Float64(-1.0 - a)) + Float64(Float64(b * Float64(x * y)) / (Float64(1.0 + a) ^ 2.0))) / t), Float64(x / Float64(1.0 + a))); else tmp = Float64(z / b); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / N[(N[(a + 1.0), $MachinePrecision] + N[(N[(y * b), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(b * N[(y / t), $MachinePrecision] + N[(1.0 + a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 2e+28], N[(N[(N[(N[(y / t), $MachinePrecision] / t$95$2), $MachinePrecision] + N[(N[(x / z), $MachinePrecision] / t$95$2), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], If[LessEqual[t$95$1, 1e+301], N[(-1.0 * N[(N[(N[(N[(y * z), $MachinePrecision] / N[(-1.0 - a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * N[(x * y), $MachinePrecision]), $MachinePrecision] / N[Power[N[(1.0 + a), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision] + N[(x / N[(1.0 + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z / b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}}\\
t_2 := \mathsf{fma}\left(b, \frac{y}{t}, 1 + a\right)\\
\mathbf{if}\;t\_1 \leq 2 \cdot 10^{+28}:\\
\;\;\;\;\left(\frac{\frac{y}{t}}{t\_2} + \frac{\frac{x}{z}}{t\_2}\right) \cdot z\\
\mathbf{elif}\;t\_1 \leq 10^{+301}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{\frac{y \cdot z}{-1 - a} + \frac{b \cdot \left(x \cdot y\right)}{{\left(1 + a\right)}^{2}}}{t}, \frac{x}{1 + a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{b}\\
\end{array}
\end{array}
if (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a #s(literal 1 binary64)) (/.f64 (*.f64 y b) t))) < 1.99999999999999992e28Initial program 85.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites76.2%
if 1.99999999999999992e28 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a #s(literal 1 binary64)) (/.f64 (*.f64 y b) t))) < 1.00000000000000005e301Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites58.2%
Taylor expanded in t around -inf
lower-fma.f64N/A
Applied rewrites76.2%
if 1.00000000000000005e301 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a #s(literal 1 binary64)) (/.f64 (*.f64 y b) t))) Initial program 12.1%
Taylor expanded in y around inf
lower-/.f6486.6
Applied rewrites86.6%
Final simplification77.7%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma b (/ y t) (+ 1.0 a))))
(if (<= y -1.85e+82)
(/ (+ z (/ (* t x) y)) b)
(if (<= y 5.2e+158) (* (+ (/ (/ y t) t_1) (/ (/ x z) t_1)) z) (/ z b)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(b, (y / t), (1.0 + a));
double tmp;
if (y <= -1.85e+82) {
tmp = (z + ((t * x) / y)) / b;
} else if (y <= 5.2e+158) {
tmp = (((y / t) / t_1) + ((x / z) / t_1)) * z;
} else {
tmp = z / b;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(b, Float64(y / t), Float64(1.0 + a)) tmp = 0.0 if (y <= -1.85e+82) tmp = Float64(Float64(z + Float64(Float64(t * x) / y)) / b); elseif (y <= 5.2e+158) tmp = Float64(Float64(Float64(Float64(y / t) / t_1) + Float64(Float64(x / z) / t_1)) * z); else tmp = Float64(z / b); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * N[(y / t), $MachinePrecision] + N[(1.0 + a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.85e+82], N[(N[(z + N[(N[(t * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], If[LessEqual[y, 5.2e+158], N[(N[(N[(N[(y / t), $MachinePrecision] / t$95$1), $MachinePrecision] + N[(N[(x / z), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], N[(z / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, \frac{y}{t}, 1 + a\right)\\
\mathbf{if}\;y \leq -1.85 \cdot 10^{+82}:\\
\;\;\;\;\frac{z + \frac{t \cdot x}{y}}{b}\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+158}:\\
\;\;\;\;\left(\frac{\frac{y}{t}}{t\_1} + \frac{\frac{x}{z}}{t\_1}\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{b}\\
\end{array}
\end{array}
if y < -1.8500000000000001e82Initial program 50.8%
Taylor expanded in y around -inf
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites58.0%
Taylor expanded in b around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lift-*.f6475.7
Applied rewrites75.7%
if -1.8500000000000001e82 < y < 5.2e158Initial program 92.1%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites79.8%
if 5.2e158 < y Initial program 43.6%
Taylor expanded in y around inf
lower-/.f6468.5
Applied rewrites68.5%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (fma b (/ y t) (+ 1.0 a))))
(if (or (<= y -1.85e+82) (not (<= y 4.3e+158)))
(/ (+ z (/ (* t x) y)) b)
(* (+ (/ (/ y t) t_1) (/ (/ x z) t_1)) z))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = fma(b, (y / t), (1.0 + a));
double tmp;
if ((y <= -1.85e+82) || !(y <= 4.3e+158)) {
tmp = (z + ((t * x) / y)) / b;
} else {
tmp = (((y / t) / t_1) + ((x / z) / t_1)) * z;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = fma(b, Float64(y / t), Float64(1.0 + a)) tmp = 0.0 if ((y <= -1.85e+82) || !(y <= 4.3e+158)) tmp = Float64(Float64(z + Float64(Float64(t * x) / y)) / b); else tmp = Float64(Float64(Float64(Float64(y / t) / t_1) + Float64(Float64(x / z) / t_1)) * z); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * N[(y / t), $MachinePrecision] + N[(1.0 + a), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[y, -1.85e+82], N[Not[LessEqual[y, 4.3e+158]], $MachinePrecision]], N[(N[(z + N[(N[(t * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision], N[(N[(N[(N[(y / t), $MachinePrecision] / t$95$1), $MachinePrecision] + N[(N[(x / z), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, \frac{y}{t}, 1 + a\right)\\
\mathbf{if}\;y \leq -1.85 \cdot 10^{+82} \lor \neg \left(y \leq 4.3 \cdot 10^{+158}\right):\\
\;\;\;\;\frac{z + \frac{t \cdot x}{y}}{b}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{\frac{y}{t}}{t\_1} + \frac{\frac{x}{z}}{t\_1}\right) \cdot z\\
\end{array}
\end{array}
if y < -1.8500000000000001e82 or 4.3e158 < y Initial program 47.1%
Taylor expanded in y around -inf
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites51.1%
Taylor expanded in b around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lift-*.f6470.6
Applied rewrites70.6%
if -1.8500000000000001e82 < y < 4.3e158Initial program 92.1%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites79.8%
Final simplification76.8%
(FPCore (x y z t a b) :precision binary64 (/ (+ z (/ (* t x) y)) b))
double code(double x, double y, double z, double t, double a, double b) {
return (z + ((t * x) / y)) / b;
}
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, b)
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), intent (in) :: b
code = (z + ((t * x) / y)) / b
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (z + ((t * x) / y)) / b;
}
def code(x, y, z, t, a, b): return (z + ((t * x) / y)) / b
function code(x, y, z, t, a, b) return Float64(Float64(z + Float64(Float64(t * x) / y)) / b) end
function tmp = code(x, y, z, t, a, b) tmp = (z + ((t * x) / y)) / b; end
code[x_, y_, z_, t_, a_, b_] := N[(N[(z + N[(N[(t * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{z + \frac{t \cdot x}{y}}{b}
\end{array}
Initial program 77.5%
Taylor expanded in y around -inf
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites32.0%
Taylor expanded in b around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lift-*.f6442.1
Applied rewrites42.1%
(FPCore (x y z t a b) :precision binary64 (/ (* z (+ 1.0 (/ (* t x) (* y z)))) b))
double code(double x, double y, double z, double t, double a, double b) {
return (z * (1.0 + ((t * x) / (y * z)))) / b;
}
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, b)
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), intent (in) :: b
code = (z * (1.0d0 + ((t * x) / (y * z)))) / b
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (z * (1.0 + ((t * x) / (y * z)))) / b;
}
def code(x, y, z, t, a, b): return (z * (1.0 + ((t * x) / (y * z)))) / b
function code(x, y, z, t, a, b) return Float64(Float64(z * Float64(1.0 + Float64(Float64(t * x) / Float64(y * z)))) / b) end
function tmp = code(x, y, z, t, a, b) tmp = (z * (1.0 + ((t * x) / (y * z)))) / b; end
code[x_, y_, z_, t_, a_, b_] := N[(N[(z * N[(1.0 + N[(N[(t * x), $MachinePrecision] / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{z \cdot \left(1 + \frac{t \cdot x}{y \cdot z}\right)}{b}
\end{array}
Initial program 77.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites66.2%
Taylor expanded in b around inf
lower-/.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lower-*.f6438.9
Applied rewrites38.9%
herbie shell --seed 2025057
(FPCore (x y z t a b)
:name "Diagrams.Solve.Tridiagonal:solveCyclicTriDiagonal from diagrams-solve-0.1, B"
:precision binary64
:alt
(! :herbie-platform default (if (< t -1707385670788761/12500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (* 1 (* (+ x (* (/ y t) z)) (/ 1 (+ (+ a 1) (* (/ y t) b))))) (if (< t 1518483551868623/5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ z b) (* 1 (* (+ x (* (/ y t) z)) (/ 1 (+ (+ a 1) (* (/ y t) b))))))))
(/ (+ x (/ (* y z) t)) (+ (+ a 1.0) (/ (* y b) t))))