Average Error: 7.5 → 1.7
Time: 17.9s
Precision: binary64
Cost: 9736
\[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
\[\begin{array}{l} t_1 := y \cdot z - x\\ t_2 := z \cdot t - x\\ t_3 := \frac{x + \frac{t_1}{t_2}}{x + 1}\\ \mathbf{if}\;t_3 \leq -\infty:\\ \;\;\;\;\frac{x + z \cdot \frac{y}{t_2}}{x + 1}\\ \mathbf{elif}\;t_3 \leq 2 \cdot 10^{+290}:\\ \;\;\;\;\frac{x + \frac{t_1}{\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 (- (* y z) x))
        (t_2 (- (* z t) x))
        (t_3 (/ (+ x (/ t_1 t_2)) (+ x 1.0))))
   (if (<= t_3 (- INFINITY))
     (/ (+ x (* z (/ y t_2))) (+ x 1.0))
     (if (<= t_3 2e+290)
       (/ (+ x (/ t_1 (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 = (y * z) - x;
	double t_2 = (z * t) - x;
	double t_3 = (x + (t_1 / t_2)) / (x + 1.0);
	double tmp;
	if (t_3 <= -((double) INFINITY)) {
		tmp = (x + (z * (y / t_2))) / (x + 1.0);
	} else if (t_3 <= 2e+290) {
		tmp = (x + (t_1 / 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(y * z) - x)
	t_2 = Float64(Float64(z * t) - x)
	t_3 = Float64(Float64(x + Float64(t_1 / t_2)) / Float64(x + 1.0))
	tmp = 0.0
	if (t_3 <= Float64(-Inf))
		tmp = Float64(Float64(x + Float64(z * Float64(y / t_2))) / Float64(x + 1.0));
	elseif (t_3 <= 2e+290)
		tmp = Float64(Float64(x + Float64(t_1 / 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[(y * z), $MachinePrecision] - x), $MachinePrecision]}, Block[{t$95$2 = N[(N[(z * t), $MachinePrecision] - x), $MachinePrecision]}, Block[{t$95$3 = N[(N[(x + N[(t$95$1 / t$95$2), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, (-Infinity)], N[(N[(x + N[(z * N[(y / t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2e+290], N[(N[(x + N[(t$95$1 / 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 := y \cdot z - x\\
t_2 := z \cdot t - x\\
t_3 := \frac{x + \frac{t_1}{t_2}}{x + 1}\\
\mathbf{if}\;t_3 \leq -\infty:\\
\;\;\;\;\frac{x + z \cdot \frac{y}{t_2}}{x + 1}\\

\mathbf{elif}\;t_3 \leq 2 \cdot 10^{+290}:\\
\;\;\;\;\frac{x + \frac{t_1}{\mathsf{fma}\left(z, t, -x\right)}}{x + 1}\\

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


\end{array}

Error

Target

Original7.5
Target0.4
Herbie1.7
\[\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)) < -inf.0

    1. Initial program 64.0

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Simplified64.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 y around inf 64.0

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

      \[\leadsto \frac{x + \color{blue}{\frac{y}{t \cdot z - x} \cdot z}}{x + 1} \]
      Proof
      (*.f64 (/.f64 y (-.f64 (*.f64 t z) x)) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/r/_binary64 (/.f64 y (/.f64 (-.f64 (*.f64 t z) x) z))): 35 points increase in error, 43 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y z) (-.f64 (*.f64 t z) x))): 60 points increase in error, 33 points decrease in error

    if -inf.0 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1)) < 2.00000000000000012e290

    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{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. Applied egg-rr0.7

      \[\leadsto \frac{x + \frac{y \cdot z - x}{\color{blue}{\mathsf{fma}\left(z, t, -x\right)}}}{x + 1} \]

    if 2.00000000000000012e290 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1))

    1. Initial program 62.4

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

      \[\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. Applied egg-rr62.4

      \[\leadsto \frac{x + \frac{y \cdot z - x}{\color{blue}{\mathsf{fma}\left(z, t, -x\right)}}}{x + 1} \]
    4. Taylor expanded in z around inf 10.6

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

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

Alternatives

Alternative 1
Error1.7
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 -\infty:\\ \;\;\;\;\frac{x + z \cdot \frac{y}{t_1}}{x + 1}\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+290}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \end{array} \]
Alternative 2
Error9.7
Cost1356
\[\begin{array}{l} t_1 := z \cdot t - x\\ t_2 := \frac{x + z \cdot \frac{y}{t_1}}{x + 1}\\ \mathbf{if}\;z \leq -1.7546408002886645 \cdot 10^{-222}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.0699495680227123 \cdot 10^{-180}:\\ \;\;\;\;\frac{x + \left(1 - \frac{y}{\frac{x}{z}}\right)}{x + 1}\\ \mathbf{elif}\;z \leq 1.2884948453134633 \cdot 10^{-80}:\\ \;\;\;\;\frac{x - \frac{x}{t_1}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error12.9
Cost1096
\[\begin{array}{l} t_1 := \frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{if}\;z \leq -1.1036846103518641 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.797881859622258 \cdot 10^{+64}:\\ \;\;\;\;\frac{x - \frac{x}{z \cdot t - x}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error10.8
Cost1096
\[\begin{array}{l} t_1 := \frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{if}\;t \leq -110802274373.59137:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.5771504780352954 \cdot 10^{-23}:\\ \;\;\;\;\frac{x + \left(1 - \frac{y}{\frac{x}{z}}\right)}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error21.0
Cost972
\[\begin{array}{l} t_1 := \frac{x}{x + 1}\\ \mathbf{if}\;x \leq -5.266131275320295 \cdot 10^{-199}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.7034625165738414 \cdot 10^{-98}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 1.214354000889913 \cdot 10^{-30}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{y}{x \cdot \frac{x}{z}}\\ \end{array} \]
Alternative 6
Error14.7
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0159193001986624 \cdot 10^{+56}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 8.364420658329062 \cdot 10^{+46}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{y}{x \cdot \frac{x}{z}}\\ \end{array} \]
Alternative 7
Error21.1
Cost584
\[\begin{array}{l} t_1 := \frac{x}{x + 1}\\ \mathbf{if}\;x \leq -5.266131275320295 \cdot 10^{-199}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.7034625165738414 \cdot 10^{-98}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error20.4
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -4.369574944456255 \cdot 10^{-42}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3.8613453011735436 \cdot 10^{-103}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 9
Error28.1
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2022316 
(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)))