
(FPCore (x y z t) :precision binary64 (/ (+ x (/ (- (* y z) x) (- (* t z) x))) (+ x 1.0)))
double code(double x, double y, double z, double t) {
return (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0d0)
end function
public static double code(double x, double y, double z, double t) {
return (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0);
}
def code(x, y, z, t): return (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0)
function code(x, y, z, t) return Float64(Float64(x + Float64(Float64(Float64(y * z) - x) / Float64(Float64(t * z) - x))) / Float64(x + 1.0)) end
function tmp = code(x, y, z, t) tmp = (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0); end
code[x_, y_, z_, t_] := N[(N[(x + N[(N[(N[(y * z), $MachinePrecision] - x), $MachinePrecision] / N[(N[(t * z), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (/ (+ x (/ (- (* y z) x) (- (* t z) x))) (+ x 1.0)))
double code(double x, double y, double z, double t) {
return (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0d0)
end function
public static double code(double x, double y, double z, double t) {
return (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0);
}
def code(x, y, z, t): return (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0)
function code(x, y, z, t) return Float64(Float64(x + Float64(Float64(Float64(y * z) - x) / Float64(Float64(t * z) - x))) / Float64(x + 1.0)) end
function tmp = code(x, y, z, t) tmp = (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0); end
code[x_, y_, z_, t_] := N[(N[(x + N[(N[(N[(y * z), $MachinePrecision] - x), $MachinePrecision] / N[(N[(t * z), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1}
\end{array}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ (+ x (/ (- x (* y z)) (- x (* z t)))) (+ x 1.0)))
(t_2 (fma z t (- x)))
(t_3 (* (/ z t_2) (/ y (+ x 1.0)))))
(if (<= t_1 -5e+21)
t_3
(if (<= t_1 5e-7)
(/ (- x (/ (- (/ x z) y) t)) (+ x 1.0))
(if (<= t_1 2.0)
(/ (+ x (/ (- x) t_2)) (+ x 1.0))
(if (<= t_1 INFINITY) t_3 (/ (+ x (/ y t)) (+ x 1.0))))))))
double code(double x, double y, double z, double t) {
double t_1 = (x + ((x - (y * z)) / (x - (z * t)))) / (x + 1.0);
double t_2 = fma(z, t, -x);
double t_3 = (z / t_2) * (y / (x + 1.0));
double tmp;
if (t_1 <= -5e+21) {
tmp = t_3;
} else if (t_1 <= 5e-7) {
tmp = (x - (((x / z) - y) / t)) / (x + 1.0);
} else if (t_1 <= 2.0) {
tmp = (x + (-x / t_2)) / (x + 1.0);
} else if (t_1 <= ((double) INFINITY)) {
tmp = t_3;
} else {
tmp = (x + (y / t)) / (x + 1.0);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(x + Float64(Float64(x - Float64(y * z)) / Float64(x - Float64(z * t)))) / Float64(x + 1.0)) t_2 = fma(z, t, Float64(-x)) t_3 = Float64(Float64(z / t_2) * Float64(y / Float64(x + 1.0))) tmp = 0.0 if (t_1 <= -5e+21) tmp = t_3; elseif (t_1 <= 5e-7) tmp = Float64(Float64(x - Float64(Float64(Float64(x / z) - y) / t)) / Float64(x + 1.0)); elseif (t_1 <= 2.0) tmp = Float64(Float64(x + Float64(Float64(-x) / t_2)) / Float64(x + 1.0)); elseif (t_1 <= Inf) tmp = t_3; else tmp = Float64(Float64(x + Float64(y / t)) / Float64(x + 1.0)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x + N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / N[(x - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(z * t + (-x)), $MachinePrecision]}, Block[{t$95$3 = N[(N[(z / t$95$2), $MachinePrecision] * N[(y / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+21], t$95$3, If[LessEqual[t$95$1, 5e-7], N[(N[(x - N[(N[(N[(x / z), $MachinePrecision] - y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[(N[(x + N[((-x) / t$95$2), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, Infinity], t$95$3, N[(N[(x + N[(y / t), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x + \frac{x - y \cdot z}{x - z \cdot t}}{x + 1}\\
t_2 := \mathsf{fma}\left(z, t, -x\right)\\
t_3 := \frac{z}{t\_2} \cdot \frac{y}{x + 1}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+21}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{x - \frac{\frac{x}{z} - y}{t}}{x + 1}\\
\mathbf{elif}\;t\_1 \leq 2:\\
\;\;\;\;\frac{x + \frac{-x}{t\_2}}{x + 1}\\
\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;t\_3\\
\mathbf{else}:\\
\;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\
\end{array}
\end{array}
if (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x #s(literal 1 binary64))) < -5e21 or 2 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x #s(literal 1 binary64))) < +inf.0Initial program 84.9%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6484.4
Applied rewrites84.4%
Applied rewrites99.3%
if -5e21 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x #s(literal 1 binary64))) < 4.99999999999999977e-7Initial program 95.6%
Taylor expanded in t around -inf
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
sub-negN/A
mul-1-negN/A
remove-double-negN/A
lower-/.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6499.3
Applied rewrites99.3%
if 4.99999999999999977e-7 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 100.0%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6499.5
Applied rewrites99.5%
if +inf.0 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x #s(literal 1 binary64))) Initial program 0.0%
Taylor expanded in z around inf
lower-/.f64100.0
Applied rewrites100.0%
Final simplification99.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ (+ x (/ (- x (* y z)) (- x (* z t)))) (+ x 1.0)))
(t_2 (fma z t (- x)))
(t_3 (* (/ z t_2) (/ y (+ x 1.0)))))
(if (<= t_1 -5e+21)
t_3
(if (<= t_1 5e-7)
(/ (+ x (/ (- (* y z) x) (* z t))) (+ x 1.0))
(if (<= t_1 2.0)
(/ (+ x (/ (- x) t_2)) (+ x 1.0))
(if (<= t_1 INFINITY) t_3 (/ (+ x (/ y t)) (+ x 1.0))))))))
double code(double x, double y, double z, double t) {
double t_1 = (x + ((x - (y * z)) / (x - (z * t)))) / (x + 1.0);
double t_2 = fma(z, t, -x);
double t_3 = (z / t_2) * (y / (x + 1.0));
double tmp;
if (t_1 <= -5e+21) {
tmp = t_3;
} else if (t_1 <= 5e-7) {
tmp = (x + (((y * z) - x) / (z * t))) / (x + 1.0);
} else if (t_1 <= 2.0) {
tmp = (x + (-x / t_2)) / (x + 1.0);
} else if (t_1 <= ((double) INFINITY)) {
tmp = t_3;
} else {
tmp = (x + (y / t)) / (x + 1.0);
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(x + Float64(Float64(x - Float64(y * z)) / Float64(x - Float64(z * t)))) / Float64(x + 1.0)) t_2 = fma(z, t, Float64(-x)) t_3 = Float64(Float64(z / t_2) * Float64(y / Float64(x + 1.0))) tmp = 0.0 if (t_1 <= -5e+21) tmp = t_3; elseif (t_1 <= 5e-7) tmp = Float64(Float64(x + Float64(Float64(Float64(y * z) - x) / Float64(z * t))) / Float64(x + 1.0)); elseif (t_1 <= 2.0) tmp = Float64(Float64(x + Float64(Float64(-x) / t_2)) / Float64(x + 1.0)); elseif (t_1 <= Inf) tmp = t_3; else tmp = Float64(Float64(x + Float64(y / t)) / Float64(x + 1.0)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x + N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / N[(x - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(z * t + (-x)), $MachinePrecision]}, Block[{t$95$3 = N[(N[(z / t$95$2), $MachinePrecision] * N[(y / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+21], t$95$3, If[LessEqual[t$95$1, 5e-7], N[(N[(x + N[(N[(N[(y * z), $MachinePrecision] - x), $MachinePrecision] / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[(N[(x + N[((-x) / t$95$2), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, Infinity], t$95$3, N[(N[(x + N[(y / t), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{x + \frac{x - y \cdot z}{x - z \cdot t}}{x + 1}\\
t_2 := \mathsf{fma}\left(z, t, -x\right)\\
t_3 := \frac{z}{t\_2} \cdot \frac{y}{x + 1}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+21}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-7}:\\
\;\;\;\;\frac{x + \frac{y \cdot z - x}{z \cdot t}}{x + 1}\\
\mathbf{elif}\;t\_1 \leq 2:\\
\;\;\;\;\frac{x + \frac{-x}{t\_2}}{x + 1}\\
\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;t\_3\\
\mathbf{else}:\\
\;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\
\end{array}
\end{array}
if (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x #s(literal 1 binary64))) < -5e21 or 2 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x #s(literal 1 binary64))) < +inf.0Initial program 77.5%
Taylor expanded in y around inf
lower-/.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6476.8
Applied rewrites76.8%
Applied rewrites92.9%
if -5e21 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x #s(literal 1 binary64))) < 4.99999999999999977e-7Initial program 95.9%
Taylor expanded in t around inf
lower-*.f6493.4
Applied rewrites93.4%
if 4.99999999999999977e-7 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x #s(literal 1 binary64))) < 2Initial program 100.0%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6499.2
Applied rewrites99.2%
if +inf.0 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x #s(literal 1 binary64))) Initial program 0.0%
Taylor expanded in z around inf
lower-/.f6499.9
Applied rewrites99.9%
Final simplification96.4%
(FPCore (x y z t) :precision binary64 (/ (+ x (- (/ y (- t (/ x z))) (/ x (- (* t z) x)))) (+ x 1.0)))
double code(double x, double y, double z, double t) {
return (x + ((y / (t - (x / z))) - (x / ((t * z) - x)))) / (x + 1.0);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x + ((y / (t - (x / z))) - (x / ((t * z) - x)))) / (x + 1.0d0)
end function
public static double code(double x, double y, double z, double t) {
return (x + ((y / (t - (x / z))) - (x / ((t * z) - x)))) / (x + 1.0);
}
def code(x, y, z, t): return (x + ((y / (t - (x / z))) - (x / ((t * z) - x)))) / (x + 1.0)
function code(x, y, z, t) return Float64(Float64(x + Float64(Float64(y / Float64(t - Float64(x / z))) - Float64(x / Float64(Float64(t * z) - x)))) / Float64(x + 1.0)) end
function tmp = code(x, y, z, t) tmp = (x + ((y / (t - (x / z))) - (x / ((t * z) - x)))) / (x + 1.0); end
code[x_, y_, z_, t_] := N[(N[(x + N[(N[(y / N[(t - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x / N[(N[(t * z), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + \left(\frac{y}{t - \frac{x}{z}} - \frac{x}{t \cdot z - x}\right)}{x + 1}
\end{array}
herbie shell --seed 2024223
(FPCore (x y z t)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, A"
:precision binary64
:alt
(! :herbie-platform default (/ (+ x (- (/ y (- t (/ x z))) (/ x (- (* t z) x)))) (+ x 1)))
(/ (+ x (/ (- (* y z) x) (- (* t z) x))) (+ x 1.0)))