
(FPCore (x y z t a b) :precision binary64 (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))
double code(double x, double y, double z, double t, double a, double b) {
return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
}
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 + y) * a)) - (y * b)) / ((x + t) + y)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
}
def code(x, y, z, t, a, b): return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(t + y) * a)) - Float64(y * b)) / Float64(Float64(x + t) + y)) end
function tmp = code(x, y, z, t, a, b) tmp = ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(N[(t + y), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / N[(N[(x + t), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a b) :precision binary64 (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))
double code(double x, double y, double z, double t, double a, double b) {
return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
}
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 + y) * a)) - (y * b)) / ((x + t) + y)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
}
def code(x, y, z, t, a, b): return ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y)
function code(x, y, z, t, a, b) return Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(t + y) * a)) - Float64(y * b)) / Float64(Float64(x + t) + y)) end
function tmp = code(x, y, z, t, a, b) tmp = ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y); end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(N[(t + y), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / N[(N[(x + t), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}
\end{array}
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (pow (+ t y) 2.0))
(t_2 (/ z (+ t y)))
(t_3 (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))
(t_4
(-
(-
(fma
(- (- (fma b (/ y t_1) t_2) (/ a (+ t y))) (* y (/ z t_1)))
x
(* y t_2))
(* -1.0 a))
(* b (/ y (+ t y))))))
(if (<= t_3 (- INFINITY)) t_4 (if (<= t_3 5e+300) t_3 t_4))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = pow((t + y), 2.0);
double t_2 = z / (t + y);
double t_3 = ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
double t_4 = (fma(((fma(b, (y / t_1), t_2) - (a / (t + y))) - (y * (z / t_1))), x, (y * t_2)) - (-1.0 * a)) - (b * (y / (t + y)));
double tmp;
if (t_3 <= -((double) INFINITY)) {
tmp = t_4;
} else if (t_3 <= 5e+300) {
tmp = t_3;
} else {
tmp = t_4;
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(t + y) ^ 2.0 t_2 = Float64(z / Float64(t + y)) t_3 = Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(t + y) * a)) - Float64(y * b)) / Float64(Float64(x + t) + y)) t_4 = Float64(Float64(fma(Float64(Float64(fma(b, Float64(y / t_1), t_2) - Float64(a / Float64(t + y))) - Float64(y * Float64(z / t_1))), x, Float64(y * t_2)) - Float64(-1.0 * a)) - Float64(b * Float64(y / Float64(t + y)))) tmp = 0.0 if (t_3 <= Float64(-Inf)) tmp = t_4; elseif (t_3 <= 5e+300) tmp = t_3; else tmp = t_4; end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[Power[N[(t + y), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(z / N[(t + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(N[(t + y), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / N[(N[(x + t), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[(N[(N[(N[(b * N[(y / t$95$1), $MachinePrecision] + t$95$2), $MachinePrecision] - N[(a / N[(t + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y * N[(z / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x + N[(y * t$95$2), $MachinePrecision]), $MachinePrecision] - N[(-1.0 * a), $MachinePrecision]), $MachinePrecision] - N[(b * N[(y / N[(t + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, (-Infinity)], t$95$4, If[LessEqual[t$95$3, 5e+300], t$95$3, t$95$4]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := {\left(t + y\right)}^{2}\\
t_2 := \frac{z}{t + y}\\
t_3 := \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\\
t_4 := \left(\mathsf{fma}\left(\left(\mathsf{fma}\left(b, \frac{y}{t\_1}, t\_2\right) - \frac{a}{t + y}\right) - y \cdot \frac{z}{t\_1}, x, y \cdot t\_2\right) - -1 \cdot a\right) - b \cdot \frac{y}{t + y}\\
\mathbf{if}\;t\_3 \leq -\infty:\\
\;\;\;\;t\_4\\
\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{+300}:\\
\;\;\;\;t\_3\\
\mathbf{else}:\\
\;\;\;\;t\_4\\
\end{array}
\end{array}
if (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < -inf.0 or 5.00000000000000026e300 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 5.2%
Taylor expanded in x around 0
lower--.f64N/A
Applied rewrites78.3%
if -inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 5.00000000000000026e300Initial program 99.1%
Final simplification89.4%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (pow (+ t y) 2.0))
(t_2 (/ z (+ t y)))
(t_3 (+ (+ y x) t))
(t_4 (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y))))
(if (or (<= t_4 (- INFINITY)) (not (<= t_4 5e+300)))
(-
(-
(fma
(- (- (fma b (/ y t_1) t_2) (/ a (+ t y))) (* y (/ z t_1)))
x
(* y t_2))
(* -1.0 a))
(* b (/ y (+ t y))))
(*
(* -1.0 a)
(fma
(/ (/ (fma (+ y x) z (* (* -1.0 b) y)) t_3) a)
-1.0
(/ (* -1.0 (+ t y)) t_3))))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = pow((t + y), 2.0);
double t_2 = z / (t + y);
double t_3 = (y + x) + t;
double t_4 = ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
double tmp;
if ((t_4 <= -((double) INFINITY)) || !(t_4 <= 5e+300)) {
tmp = (fma(((fma(b, (y / t_1), t_2) - (a / (t + y))) - (y * (z / t_1))), x, (y * t_2)) - (-1.0 * a)) - (b * (y / (t + y)));
} else {
tmp = (-1.0 * a) * fma(((fma((y + x), z, ((-1.0 * b) * y)) / t_3) / a), -1.0, ((-1.0 * (t + y)) / t_3));
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(t + y) ^ 2.0 t_2 = Float64(z / Float64(t + y)) t_3 = Float64(Float64(y + x) + t) t_4 = Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(t + y) * a)) - Float64(y * b)) / Float64(Float64(x + t) + y)) tmp = 0.0 if ((t_4 <= Float64(-Inf)) || !(t_4 <= 5e+300)) tmp = Float64(Float64(fma(Float64(Float64(fma(b, Float64(y / t_1), t_2) - Float64(a / Float64(t + y))) - Float64(y * Float64(z / t_1))), x, Float64(y * t_2)) - Float64(-1.0 * a)) - Float64(b * Float64(y / Float64(t + y)))); else tmp = Float64(Float64(-1.0 * a) * fma(Float64(Float64(fma(Float64(y + x), z, Float64(Float64(-1.0 * b) * y)) / t_3) / a), -1.0, Float64(Float64(-1.0 * Float64(t + y)) / t_3))); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[Power[N[(t + y), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(z / N[(t + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(y + x), $MachinePrecision] + t), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(N[(t + y), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / N[(N[(x + t), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$4, (-Infinity)], N[Not[LessEqual[t$95$4, 5e+300]], $MachinePrecision]], N[(N[(N[(N[(N[(N[(b * N[(y / t$95$1), $MachinePrecision] + t$95$2), $MachinePrecision] - N[(a / N[(t + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y * N[(z / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x + N[(y * t$95$2), $MachinePrecision]), $MachinePrecision] - N[(-1.0 * a), $MachinePrecision]), $MachinePrecision] - N[(b * N[(y / N[(t + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * a), $MachinePrecision] * N[(N[(N[(N[(N[(y + x), $MachinePrecision] * z + N[(N[(-1.0 * b), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / t$95$3), $MachinePrecision] / a), $MachinePrecision] * -1.0 + N[(N[(-1.0 * N[(t + y), $MachinePrecision]), $MachinePrecision] / t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := {\left(t + y\right)}^{2}\\
t_2 := \frac{z}{t + y}\\
t_3 := \left(y + x\right) + t\\
t_4 := \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\\
\mathbf{if}\;t\_4 \leq -\infty \lor \neg \left(t\_4 \leq 5 \cdot 10^{+300}\right):\\
\;\;\;\;\left(\mathsf{fma}\left(\left(\mathsf{fma}\left(b, \frac{y}{t\_1}, t\_2\right) - \frac{a}{t + y}\right) - y \cdot \frac{z}{t\_1}, x, y \cdot t\_2\right) - -1 \cdot a\right) - b \cdot \frac{y}{t + y}\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{\frac{\mathsf{fma}\left(y + x, z, \left(-1 \cdot b\right) \cdot y\right)}{t\_3}}{a}, -1, \frac{-1 \cdot \left(t + y\right)}{t\_3}\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < -inf.0 or 5.00000000000000026e300 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 5.2%
Taylor expanded in x around 0
lower--.f64N/A
Applied rewrites78.3%
if -inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 5.00000000000000026e300Initial program 99.1%
Taylor expanded in a around -inf
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites93.9%
Final simplification86.6%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (/ y (pow (+ y x) 2.0)))
(t_2 (+ (+ y x) t))
(t_3 (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))
(t_4 (/ y (+ y x))))
(if (or (<= t_3 (- INFINITY)) (not (<= t_3 5e+300)))
(+
z
(-
(fma
(- (- (fma b t_1 (/ a (+ y x))) (/ z (+ y x))) (* a t_1))
t
(* a t_4))
(* b t_4)))
(*
(* -1.0 a)
(fma
(/ (/ (fma (+ y x) z (* (* -1.0 b) y)) t_2) a)
-1.0
(/ (* -1.0 (+ t y)) t_2))))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = y / pow((y + x), 2.0);
double t_2 = (y + x) + t;
double t_3 = ((((x + y) * z) + ((t + y) * a)) - (y * b)) / ((x + t) + y);
double t_4 = y / (y + x);
double tmp;
if ((t_3 <= -((double) INFINITY)) || !(t_3 <= 5e+300)) {
tmp = z + (fma(((fma(b, t_1, (a / (y + x))) - (z / (y + x))) - (a * t_1)), t, (a * t_4)) - (b * t_4));
} else {
tmp = (-1.0 * a) * fma(((fma((y + x), z, ((-1.0 * b) * y)) / t_2) / a), -1.0, ((-1.0 * (t + y)) / t_2));
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(y / (Float64(y + x) ^ 2.0)) t_2 = Float64(Float64(y + x) + t) t_3 = Float64(Float64(Float64(Float64(Float64(x + y) * z) + Float64(Float64(t + y) * a)) - Float64(y * b)) / Float64(Float64(x + t) + y)) t_4 = Float64(y / Float64(y + x)) tmp = 0.0 if ((t_3 <= Float64(-Inf)) || !(t_3 <= 5e+300)) tmp = Float64(z + Float64(fma(Float64(Float64(fma(b, t_1, Float64(a / Float64(y + x))) - Float64(z / Float64(y + x))) - Float64(a * t_1)), t, Float64(a * t_4)) - Float64(b * t_4))); else tmp = Float64(Float64(-1.0 * a) * fma(Float64(Float64(fma(Float64(y + x), z, Float64(Float64(-1.0 * b) * y)) / t_2) / a), -1.0, Float64(Float64(-1.0 * Float64(t + y)) / t_2))); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y / N[Power[N[(y + x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y + x), $MachinePrecision] + t), $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[(x + y), $MachinePrecision] * z), $MachinePrecision] + N[(N[(t + y), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] - N[(y * b), $MachinePrecision]), $MachinePrecision] / N[(N[(x + t), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(y / N[(y + x), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$3, (-Infinity)], N[Not[LessEqual[t$95$3, 5e+300]], $MachinePrecision]], N[(z + N[(N[(N[(N[(N[(b * t$95$1 + N[(a / N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(z / N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a * t$95$1), $MachinePrecision]), $MachinePrecision] * t + N[(a * t$95$4), $MachinePrecision]), $MachinePrecision] - N[(b * t$95$4), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 * a), $MachinePrecision] * N[(N[(N[(N[(N[(y + x), $MachinePrecision] * z + N[(N[(-1.0 * b), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision] / a), $MachinePrecision] * -1.0 + N[(N[(-1.0 * N[(t + y), $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{y}{{\left(y + x\right)}^{2}}\\
t_2 := \left(y + x\right) + t\\
t_3 := \frac{\left(\left(x + y\right) \cdot z + \left(t + y\right) \cdot a\right) - y \cdot b}{\left(x + t\right) + y}\\
t_4 := \frac{y}{y + x}\\
\mathbf{if}\;t\_3 \leq -\infty \lor \neg \left(t\_3 \leq 5 \cdot 10^{+300}\right):\\
\;\;\;\;z + \left(\mathsf{fma}\left(\left(\mathsf{fma}\left(b, t\_1, \frac{a}{y + x}\right) - \frac{z}{y + x}\right) - a \cdot t\_1, t, a \cdot t\_4\right) - b \cdot t\_4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{\frac{\mathsf{fma}\left(y + x, z, \left(-1 \cdot b\right) \cdot y\right)}{t\_2}}{a}, -1, \frac{-1 \cdot \left(t + y\right)}{t\_2}\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < -inf.0 or 5.00000000000000026e300 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) Initial program 5.2%
Taylor expanded in t around 0
associate--l+N/A
lower-+.f64N/A
lower--.f64N/A
Applied rewrites72.3%
if -inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 (+.f64 x y) z) (*.f64 (+.f64 t y) a)) (*.f64 y b)) (+.f64 (+.f64 x t) y)) < 5.00000000000000026e300Initial program 99.1%
Taylor expanded in a around -inf
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites93.9%
Final simplification83.9%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (+ (+ y x) t)) (t_2 (* -1.0 (/ y t_1))))
(if (or (<= z -1.75e+74) (not (<= z 7.8e-47)))
(*
(-
(+ (- (/ (/ (* (+ t y) a) z) t_1) t_2) (/ x t_1))
(* (* -1.0 (/ b z)) t_2))
z)
(*
(* -1.0 a)
(fma
(/ (/ (fma (+ y x) z (* (* -1.0 b) y)) t_1) a)
-1.0
(/ (* -1.0 (+ t y)) t_1))))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (y + x) + t;
double t_2 = -1.0 * (y / t_1);
double tmp;
if ((z <= -1.75e+74) || !(z <= 7.8e-47)) {
tmp = (((((((t + y) * a) / z) / t_1) - t_2) + (x / t_1)) - ((-1.0 * (b / z)) * t_2)) * z;
} else {
tmp = (-1.0 * a) * fma(((fma((y + x), z, ((-1.0 * b) * y)) / t_1) / a), -1.0, ((-1.0 * (t + y)) / t_1));
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(Float64(y + x) + t) t_2 = Float64(-1.0 * Float64(y / t_1)) tmp = 0.0 if ((z <= -1.75e+74) || !(z <= 7.8e-47)) tmp = Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(t + y) * a) / z) / t_1) - t_2) + Float64(x / t_1)) - Float64(Float64(-1.0 * Float64(b / z)) * t_2)) * z); else tmp = Float64(Float64(-1.0 * a) * fma(Float64(Float64(fma(Float64(y + x), z, Float64(Float64(-1.0 * b) * y)) / t_1) / a), -1.0, Float64(Float64(-1.0 * Float64(t + y)) / t_1))); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(y + x), $MachinePrecision] + t), $MachinePrecision]}, Block[{t$95$2 = N[(-1.0 * N[(y / t$95$1), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[z, -1.75e+74], N[Not[LessEqual[z, 7.8e-47]], $MachinePrecision]], N[(N[(N[(N[(N[(N[(N[(N[(t + y), $MachinePrecision] * a), $MachinePrecision] / z), $MachinePrecision] / t$95$1), $MachinePrecision] - t$95$2), $MachinePrecision] + N[(x / t$95$1), $MachinePrecision]), $MachinePrecision] - N[(N[(-1.0 * N[(b / z), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], N[(N[(-1.0 * a), $MachinePrecision] * N[(N[(N[(N[(N[(y + x), $MachinePrecision] * z + N[(N[(-1.0 * b), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision] / a), $MachinePrecision] * -1.0 + N[(N[(-1.0 * N[(t + y), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(y + x\right) + t\\
t_2 := -1 \cdot \frac{y}{t\_1}\\
\mathbf{if}\;z \leq -1.75 \cdot 10^{+74} \lor \neg \left(z \leq 7.8 \cdot 10^{-47}\right):\\
\;\;\;\;\left(\left(\left(\frac{\frac{\left(t + y\right) \cdot a}{z}}{t\_1} - t\_2\right) + \frac{x}{t\_1}\right) - \left(-1 \cdot \frac{b}{z}\right) \cdot t\_2\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{\frac{\mathsf{fma}\left(y + x, z, \left(-1 \cdot b\right) \cdot y\right)}{t\_1}}{a}, -1, \frac{-1 \cdot \left(t + y\right)}{t\_1}\right)\\
\end{array}
\end{array}
if z < -1.75000000000000007e74 or 7.79999999999999956e-47 < z Initial program 40.4%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites81.8%
if -1.75000000000000007e74 < z < 7.79999999999999956e-47Initial program 67.7%
Taylor expanded in a around -inf
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites84.0%
Final simplification83.0%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (+ (+ y x) t)))
(if (or (<= z -8.5e+87) (not (<= z 7.8e-47)))
(*
(-
(+ (- (/ (/ (* (+ t y) a) z) t_1) (* -1.0 (/ y t_1))) (/ x t_1))
(*
(* -1.0 (/ b z))
(/ (* -1.0 y) (* -1.0 (* x (- (* -1.0 (/ (+ t y) x)) 1.0))))))
z)
(*
(* -1.0 a)
(fma
(/ (/ (fma (+ y x) z (* (* -1.0 b) y)) t_1) a)
-1.0
(/ (* -1.0 (+ t y)) t_1))))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (y + x) + t;
double tmp;
if ((z <= -8.5e+87) || !(z <= 7.8e-47)) {
tmp = (((((((t + y) * a) / z) / t_1) - (-1.0 * (y / t_1))) + (x / t_1)) - ((-1.0 * (b / z)) * ((-1.0 * y) / (-1.0 * (x * ((-1.0 * ((t + y) / x)) - 1.0)))))) * z;
} else {
tmp = (-1.0 * a) * fma(((fma((y + x), z, ((-1.0 * b) * y)) / t_1) / a), -1.0, ((-1.0 * (t + y)) / t_1));
}
return tmp;
}
function code(x, y, z, t, a, b) t_1 = Float64(Float64(y + x) + t) tmp = 0.0 if ((z <= -8.5e+87) || !(z <= 7.8e-47)) tmp = Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(t + y) * a) / z) / t_1) - Float64(-1.0 * Float64(y / t_1))) + Float64(x / t_1)) - Float64(Float64(-1.0 * Float64(b / z)) * Float64(Float64(-1.0 * y) / Float64(-1.0 * Float64(x * Float64(Float64(-1.0 * Float64(Float64(t + y) / x)) - 1.0)))))) * z); else tmp = Float64(Float64(-1.0 * a) * fma(Float64(Float64(fma(Float64(y + x), z, Float64(Float64(-1.0 * b) * y)) / t_1) / a), -1.0, Float64(Float64(-1.0 * Float64(t + y)) / t_1))); end return tmp end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(y + x), $MachinePrecision] + t), $MachinePrecision]}, If[Or[LessEqual[z, -8.5e+87], N[Not[LessEqual[z, 7.8e-47]], $MachinePrecision]], N[(N[(N[(N[(N[(N[(N[(N[(t + y), $MachinePrecision] * a), $MachinePrecision] / z), $MachinePrecision] / t$95$1), $MachinePrecision] - N[(-1.0 * N[(y / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x / t$95$1), $MachinePrecision]), $MachinePrecision] - N[(N[(-1.0 * N[(b / z), $MachinePrecision]), $MachinePrecision] * N[(N[(-1.0 * y), $MachinePrecision] / N[(-1.0 * N[(x * N[(N[(-1.0 * N[(N[(t + y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision], N[(N[(-1.0 * a), $MachinePrecision] * N[(N[(N[(N[(N[(y + x), $MachinePrecision] * z + N[(N[(-1.0 * b), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision] / a), $MachinePrecision] * -1.0 + N[(N[(-1.0 * N[(t + y), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(y + x\right) + t\\
\mathbf{if}\;z \leq -8.5 \cdot 10^{+87} \lor \neg \left(z \leq 7.8 \cdot 10^{-47}\right):\\
\;\;\;\;\left(\left(\left(\frac{\frac{\left(t + y\right) \cdot a}{z}}{t\_1} - -1 \cdot \frac{y}{t\_1}\right) + \frac{x}{t\_1}\right) - \left(-1 \cdot \frac{b}{z}\right) \cdot \frac{-1 \cdot y}{-1 \cdot \left(x \cdot \left(-1 \cdot \frac{t + y}{x} - 1\right)\right)}\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;\left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{\frac{\mathsf{fma}\left(y + x, z, \left(-1 \cdot b\right) \cdot y\right)}{t\_1}}{a}, -1, \frac{-1 \cdot \left(t + y\right)}{t\_1}\right)\\
\end{array}
\end{array}
if z < -8.5000000000000001e87 or 7.79999999999999956e-47 < z Initial program 40.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites81.5%
Taylor expanded in x around -inf
lower-*.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lift-+.f6479.8
Applied rewrites79.8%
if -8.5000000000000001e87 < z < 7.79999999999999956e-47Initial program 67.4%
Taylor expanded in a around -inf
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites83.6%
Final simplification81.9%
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (+ (+ y x) t)))
(*
(* -1.0 a)
(fma
(/ (/ (fma (+ y x) z (* (* -1.0 b) y)) t_1) a)
-1.0
(/ (* -1.0 (+ t y)) t_1)))))
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (y + x) + t;
return (-1.0 * a) * fma(((fma((y + x), z, ((-1.0 * b) * y)) / t_1) / a), -1.0, ((-1.0 * (t + y)) / t_1));
}
function code(x, y, z, t, a, b) t_1 = Float64(Float64(y + x) + t) return Float64(Float64(-1.0 * a) * fma(Float64(Float64(fma(Float64(y + x), z, Float64(Float64(-1.0 * b) * y)) / t_1) / a), -1.0, Float64(Float64(-1.0 * Float64(t + y)) / t_1))) end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(y + x), $MachinePrecision] + t), $MachinePrecision]}, N[(N[(-1.0 * a), $MachinePrecision] * N[(N[(N[(N[(N[(y + x), $MachinePrecision] * z + N[(N[(-1.0 * b), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision] / a), $MachinePrecision] * -1.0 + N[(N[(-1.0 * N[(t + y), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(y + x\right) + t\\
\left(-1 \cdot a\right) \cdot \mathsf{fma}\left(\frac{\frac{\mathsf{fma}\left(y + x, z, \left(-1 \cdot b\right) \cdot y\right)}{t\_1}}{a}, -1, \frac{-1 \cdot \left(t + y\right)}{t\_1}\right)
\end{array}
\end{array}
Initial program 55.4%
Taylor expanded in a around -inf
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites64.2%
herbie shell --seed 2025065
(FPCore (x y z t a b)
:name "AI.Clustering.Hierarchical.Internal:ward from clustering-0.2.1"
:precision binary64
:alt
(! :herbie-platform default (if (< (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)) -3581311708415056400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (+ z a) b) (if (< (/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)) 12285964308315609000000000000000000000000000000000000000000000000000000000000000000) (/ 1 (/ (+ (+ x t) y) (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)))) (- (+ z a) b))))
(/ (- (+ (* (+ x y) z) (* (+ t y) a)) (* y b)) (+ (+ x t) y)))