Average Error: 7.2 → 2.1
Time: 12.0s
Precision: binary64
Cost: 16072
\[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
\[\begin{array}{l} t_1 := z \cdot t - x\\ t_2 := \frac{x + \frac{y \cdot z - x}{t_1}}{x + 1}\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+68}:\\ \;\;\;\;\frac{\frac{y}{\frac{t_1}{z}}}{x + 1}\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+286}:\\ \;\;\;\;\frac{x + \frac{\mathsf{fma}\left(y, z, -x\right)}{\mathsf{fma}\left(z, t, -x\right)}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (/ (+ x (/ (- (* y z) x) (- (* t z) x))) (+ x 1.0)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (- (* z t) x)) (t_2 (/ (+ x (/ (- (* y z) x) t_1)) (+ x 1.0))))
   (if (<= t_2 -1e+68)
     (/ (/ y (/ t_1 z)) (+ x 1.0))
     (if (<= t_2 5e+286)
       (/ (+ x (/ (fma y z (- x)) (fma z t (- x)))) (+ x 1.0))
       (/ (+ x (/ y t)) (+ x 1.0))))))
double code(double x, double y, double z, double t) {
	return (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0);
}
double code(double x, double y, double z, double t) {
	double t_1 = (z * t) - x;
	double t_2 = (x + (((y * z) - x) / t_1)) / (x + 1.0);
	double tmp;
	if (t_2 <= -1e+68) {
		tmp = (y / (t_1 / z)) / (x + 1.0);
	} else if (t_2 <= 5e+286) {
		tmp = (x + (fma(y, z, -x) / fma(z, t, -x))) / (x + 1.0);
	} else {
		tmp = (x + (y / t)) / (x + 1.0);
	}
	return tmp;
}
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 code(x, y, z, t)
	t_1 = Float64(Float64(z * t) - x)
	t_2 = Float64(Float64(x + Float64(Float64(Float64(y * z) - x) / t_1)) / Float64(x + 1.0))
	tmp = 0.0
	if (t_2 <= -1e+68)
		tmp = Float64(Float64(y / Float64(t_1 / z)) / Float64(x + 1.0));
	elseif (t_2 <= 5e+286)
		tmp = Float64(Float64(x + Float64(fma(y, z, Float64(-x)) / fma(z, t, Float64(-x)))) / Float64(x + 1.0));
	else
		tmp = Float64(Float64(x + Float64(y / t)) / Float64(x + 1.0));
	end
	return tmp
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]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z * t), $MachinePrecision] - x), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + N[(N[(N[(y * z), $MachinePrecision] - x), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e+68], N[(N[(y / N[(t$95$1 / z), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 5e+286], N[(N[(x + N[(N[(y * z + (-x)), $MachinePrecision] / N[(z * t + (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x + N[(y / t), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1}
\begin{array}{l}
t_1 := z \cdot t - x\\
t_2 := \frac{x + \frac{y \cdot z - x}{t_1}}{x + 1}\\
\mathbf{if}\;t_2 \leq -1 \cdot 10^{+68}:\\
\;\;\;\;\frac{\frac{y}{\frac{t_1}{z}}}{x + 1}\\

\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+286}:\\
\;\;\;\;\frac{x + \frac{\mathsf{fma}\left(y, z, -x\right)}{\mathsf{fma}\left(z, t, -x\right)}}{x + 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\


\end{array}

Error

Target

Original7.2
Target0.3
Herbie2.1
\[\frac{x + \left(\frac{y}{t - \frac{x}{z}} - \frac{x}{t \cdot z - x}\right)}{x + 1} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1)) < -9.99999999999999953e67

    1. Initial program 22.9

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Simplified22.9

      \[\leadsto \color{blue}{\frac{x + \frac{\mathsf{fma}\left(y, z, -x\right)}{\mathsf{fma}\left(z, t, -x\right)}}{x + 1}} \]
      Proof
      (/.f64 (+.f64 x (/.f64 (fma.f64 y z (neg.f64 x)) (fma.f64 z t (neg.f64 x)))) (+.f64 x 1)): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 x (/.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 y z) x)) (fma.f64 z t (neg.f64 x)))) (+.f64 x 1)): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 z t) x)))) (+.f64 x 1)): 1 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 t z)) x))) (+.f64 x 1)): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in y around inf 22.8

      \[\leadsto \color{blue}{\frac{y \cdot z}{\left(t \cdot z - x\right) \cdot \left(1 + x\right)}} \]
    4. Simplified6.4

      \[\leadsto \color{blue}{\frac{y}{x + 1} \cdot \frac{z}{t \cdot z - x}} \]
      Proof
      (*.f64 (/.f64 y (+.f64 x 1)) (/.f64 z (-.f64 (*.f64 t z) x))): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y (Rewrite=> +-commutative_binary64 (+.f64 1 x))) (/.f64 z (-.f64 (*.f64 t z) x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 y z) (*.f64 (+.f64 1 x) (-.f64 (*.f64 t z) x)))): 53 points increase in error, 32 points decrease in error
      (/.f64 (*.f64 y z) (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 (*.f64 t z) x) (+.f64 1 x)))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr7.9

      \[\leadsto \color{blue}{\frac{\frac{y}{\frac{z \cdot t - x}{z}}}{x + 1}} \]

    if -9.99999999999999953e67 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1)) < 5.0000000000000004e286

    1. Initial program 0.7

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Simplified0.7

      \[\leadsto \color{blue}{\frac{x + \frac{\mathsf{fma}\left(y, z, -x\right)}{\mathsf{fma}\left(z, t, -x\right)}}{x + 1}} \]
      Proof
      (/.f64 (+.f64 x (/.f64 (fma.f64 y z (neg.f64 x)) (fma.f64 z t (neg.f64 x)))) (+.f64 x 1)): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 x (/.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 y z) x)) (fma.f64 z t (neg.f64 x)))) (+.f64 x 1)): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 z t) x)))) (+.f64 x 1)): 1 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 t z)) x))) (+.f64 x 1)): 0 points increase in error, 0 points decrease in error

    if 5.0000000000000004e286 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1))

    1. Initial program 61.0

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Simplified61.0

      \[\leadsto \color{blue}{\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}} \]
      Proof
      (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 z t) x))) (+.f64 x 1)): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 t z)) x))) (+.f64 x 1)): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around inf 11.0

      \[\leadsto \color{blue}{\frac{\frac{y}{t} + x}{1 + x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq -1 \cdot 10^{+68}:\\ \;\;\;\;\frac{\frac{y}{\frac{z \cdot t - x}{z}}}{x + 1}\\ \mathbf{elif}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq 5 \cdot 10^{+286}:\\ \;\;\;\;\frac{x + \frac{\mathsf{fma}\left(y, z, -x\right)}{\mathsf{fma}\left(z, t, -x\right)}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \end{array} \]

Alternatives

Alternative 1
Error2.1
Cost3400
\[\begin{array}{l} t_1 := z \cdot t - x\\ t_2 := \frac{x + \frac{y \cdot z - x}{t_1}}{x + 1}\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+68}:\\ \;\;\;\;\frac{\frac{y}{\frac{t_1}{z}}}{x + 1}\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+286}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \end{array} \]
Alternative 2
Error11.0
Cost1232
\[\begin{array}{l} t_1 := \frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{if}\;t \leq -3.2 \cdot 10^{+64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -5.6 \cdot 10^{+15}:\\ \;\;\;\;\frac{x - \frac{x}{z \cdot t - x}}{x + 1}\\ \mathbf{elif}\;t \leq -2.95 \cdot 10^{-108}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 7.8 \cdot 10^{-8}:\\ \;\;\;\;1 - \frac{y}{x + 1} \cdot \frac{z}{x}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error10.5
Cost968
\[\begin{array}{l} t_1 := \frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{if}\;t \leq -2.95 \cdot 10^{-108}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 8.6 \cdot 10^{-22}:\\ \;\;\;\;1 - \frac{y}{x + 1} \cdot \frac{z}{x}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error19.1
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -2.4 \cdot 10^{-9}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3.25 \cdot 10^{-31}:\\ \;\;\;\;y \cdot \frac{z}{z \cdot t - x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Error14.7
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1650000:\\ \;\;\;\;1 + \frac{-1}{x}\\ \mathbf{elif}\;x \leq 4.9 \cdot 10^{-30}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 6
Error14.7
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -8.2 \cdot 10^{-14}:\\ \;\;\;\;1 - \frac{y}{x} \cdot \frac{z}{x + 1}\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-28}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Error20.9
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3.6 \cdot 10^{-17}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-28}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 8
Error20.9
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -2.75 \cdot 10^{-24}:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{-31}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 9
Error26.3
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{-18}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{-52}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 10
Error28.1
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2022325 
(FPCore (x y z t)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, A"
  :precision binary64

  :herbie-target
  (/ (+ x (- (/ y (- t (/ x z))) (/ x (- (* t z) x)))) (+ x 1.0))

  (/ (+ x (/ (- (* y z) x) (- (* t z) x))) (+ x 1.0)))