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

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

\mathbf{else}:\\
\;\;\;\;\left(t_1 + \frac{x}{x + 1}\right) - \frac{x}{\left(z \cdot t\right) \cdot \left(x + 1\right)}\\


\end{array}

Error

Target

Original7.2
Target0.3
Herbie2.3
\[\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 z around inf 21.1

      \[\leadsto \frac{\color{blue}{\frac{y}{t} + x}}{x + 1} \]
    4. Taylor expanded in y around inf 27.5

      \[\leadsto \color{blue}{\frac{y}{\left(1 + x\right) \cdot t}} \]

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

    1. Initial program 0.6

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

      \[\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.6

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

    if 3.9999999999999997e249 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1))

    1. Initial program 57.1

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

      \[\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 t around inf 11.0

      \[\leadsto \color{blue}{\left(\frac{x}{1 + x} + \frac{y}{\left(1 + x\right) \cdot t}\right) - \frac{x}{\left(1 + x\right) \cdot \left(t \cdot z\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.3

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

Alternatives

Alternative 1
Error2.3
Cost3784
\[\begin{array}{l} t_1 := \frac{y}{t \cdot \left(x + 1\right)}\\ t_2 := \frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+249}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\left(t_1 + \frac{x}{x + 1}\right) - \frac{x}{\left(z \cdot t\right) \cdot \left(x + 1\right)}\\ \end{array} \]
Alternative 2
Error2.3
Cost3400
\[\begin{array}{l} t_1 := \frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{y}{t \cdot \left(x + 1\right)}\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+249}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \end{array} \]
Alternative 3
Error12.5
Cost1688
\[\begin{array}{l} t_1 := z \cdot t - x\\ t_2 := \frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{if}\;t \leq -2.5 \cdot 10^{+51}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -2.9 \cdot 10^{-8}:\\ \;\;\;\;\frac{x - \frac{x}{t_1}}{x + 1}\\ \mathbf{elif}\;t \leq -2.7 \cdot 10^{-46}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.05 \cdot 10^{-122}:\\ \;\;\;\;\frac{\left(x + 1\right) - \frac{y}{\frac{x}{z}}}{x + 1}\\ \mathbf{elif}\;t \leq 2.25 \cdot 10^{-69}:\\ \;\;\;\;\frac{y}{t_1} \cdot \frac{z}{x + 1}\\ \mathbf{elif}\;t \leq 7 \cdot 10^{-18}:\\ \;\;\;\;\frac{x + \frac{y \cdot z - x}{-x}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error12.4
Cost1624
\[\begin{array}{l} t_1 := z \cdot t - x\\ t_2 := \frac{x + \frac{y}{t}}{x + 1}\\ t_3 := \frac{\left(x + 1\right) - \frac{y}{\frac{x}{z}}}{x + 1}\\ \mathbf{if}\;t \leq -1.35 \cdot 10^{+51}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.62 \cdot 10^{-6}:\\ \;\;\;\;\frac{x - \frac{x}{t_1}}{x + 1}\\ \mathbf{elif}\;t \leq -1.45 \cdot 10^{-47}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{-122}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 2.65 \cdot 10^{-71}:\\ \;\;\;\;\frac{y}{t_1} \cdot \frac{z}{x + 1}\\ \mathbf{elif}\;t \leq 10^{-15}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error13.5
Cost1360
\[\begin{array}{l} t_1 := z \cdot t - x\\ t_2 := \frac{x - \frac{x}{t_1}}{x + 1}\\ t_3 := \frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{if}\;z \leq -1.4 \cdot 10^{+93}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{-75}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-103}:\\ \;\;\;\;\frac{y \cdot z}{t_1 \cdot \left(x + 1\right)}\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{-55}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 6
Error17.0
Cost1106
\[\begin{array}{l} \mathbf{if}\;z \leq -7.2 \cdot 10^{+92} \lor \neg \left(z \leq -9.5 \cdot 10^{+30} \lor \neg \left(z \leq -1.06 \cdot 10^{-221}\right) \land z \leq 2.2 \cdot 10^{-57}\right):\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Error12.1
Cost1097
\[\begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{-147} \lor \neg \left(x \leq 4.8 \cdot 10^{-69}\right):\\ \;\;\;\;\frac{x - \frac{x}{z \cdot t - x}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \frac{y - \frac{x}{z}}{t}}{x + 1}\\ \end{array} \]
Alternative 8
Error21.0
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{-9}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -3.8 \cdot 10^{-53}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.9 \cdot 10^{-147}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 2.25 \cdot 10^{-122}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-102}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-69}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 9
Error21.0
Cost984
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1 \cdot 10^{-8}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -5.4 \cdot 10^{-52}:\\ \;\;\;\;x \cdot \left(1 - x\right)\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-147}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.02 \cdot 10^{-122}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-102}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-69}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 10
Error21.1
Cost980
\[\begin{array}{l} t_1 := \frac{x}{x + 1}\\ \mathbf{if}\;x \leq -2.8 \cdot 10^{-59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -4.9 \cdot 10^{-147}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-120}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 1.22 \cdot 10^{-102}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-58}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error16.0
Cost972
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-60}:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-134}:\\ \;\;\;\;\frac{1 - y \cdot \frac{z}{x}}{x + 1}\\ \mathbf{elif}\;x \leq 500:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1 - y \cdot \frac{z}{x \cdot x}\\ \end{array} \]
Alternative 12
Error27.2
Cost592
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-10}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-49}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.35 \cdot 10^{-135}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{-101}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 13
Error28.9
Cost64
\[1 \]

Error

Reproduce

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