Average Error: 7.4 → 2.3
Time: 11.6s
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^{+105}:\\ \;\;\;\;\frac{y}{\frac{t_1}{\frac{z}{x + 1}}}\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+211}:\\ \;\;\;\;\frac{x + \frac{\mathsf{fma}\left(y, z, -x\right)}{\mathsf{fma}\left(z, t, -x\right)}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x + 1} \cdot \left(x + \frac{y}{t}\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 (- (* z t) x)) (t_2 (/ (+ x (/ (- (* y z) x) t_1)) (+ x 1.0))))
   (if (<= t_2 -1e+105)
     (/ y (/ t_1 (/ z (+ x 1.0))))
     (if (<= t_2 2e+211)
       (/ (+ x (/ (fma y z (- x)) (fma z t (- x)))) (+ x 1.0))
       (* (/ 1.0 (+ x 1.0)) (+ x (/ y t)))))))
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+105) {
		tmp = y / (t_1 / (z / (x + 1.0)));
	} else if (t_2 <= 2e+211) {
		tmp = (x + (fma(y, z, -x) / fma(z, t, -x))) / (x + 1.0);
	} else {
		tmp = (1.0 / (x + 1.0)) * (x + (y / t));
	}
	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+105)
		tmp = Float64(y / Float64(t_1 / Float64(z / Float64(x + 1.0))));
	elseif (t_2 <= 2e+211)
		tmp = Float64(Float64(x + Float64(fma(y, z, Float64(-x)) / fma(z, t, Float64(-x)))) / Float64(x + 1.0));
	else
		tmp = Float64(Float64(1.0 / Float64(x + 1.0)) * Float64(x + Float64(y / t)));
	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+105], N[(y / N[(t$95$1 / N[(z / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2e+211], N[(N[(x + N[(N[(y * z + (-x)), $MachinePrecision] / N[(z * t + (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] * N[(x + N[(y / t), $MachinePrecision]), $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^{+105}:\\
\;\;\;\;\frac{y}{\frac{t_1}{\frac{z}{x + 1}}}\\

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

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


\end{array}

Error

Target

Original7.4
Target0.4
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)) < -9.9999999999999994e104

    1. Initial program 27.0

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Simplified27.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 27.0

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

      \[\leadsto \color{blue}{\frac{y}{\frac{t \cdot z - x}{\frac{z}{x + 1}}}} \]
      Proof
      (/.f64 y (/.f64 (-.f64 (*.f64 t z) x) (/.f64 z (+.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 (-.f64 (Rewrite=> *-commutative_binary64 (*.f64 z t)) x) (/.f64 z (+.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 (Rewrite=> fma-neg_binary64 (fma.f64 z t (neg.f64 x))) (/.f64 z (+.f64 x 1)))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 (fma.f64 z t (neg.f64 x)) (/.f64 z (Rewrite=> +-commutative_binary64 (+.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (fma.f64 z t (neg.f64 x)) (+.f64 1 x)) z))): 7 points increase in error, 11 points decrease in error
      (/.f64 y (/.f64 (*.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 z t) x)) (+.f64 1 x)) z)): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 (*.f64 (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 t z)) x) (+.f64 1 x)) z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y z) (*.f64 (-.f64 (*.f64 t z) x) (+.f64 1 x)))): 56 points increase in error, 24 points decrease in error

    if -9.9999999999999994e104 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1)) < 1.9999999999999999e211

    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)): 1 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)): 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

    if 1.9999999999999999e211 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1))

    1. Initial program 53.6

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Simplified53.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-rr53.6

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

      \[\leadsto \frac{1}{x + 1} \cdot \left(x + \color{blue}{\frac{y}{t}}\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 -1 \cdot 10^{+105}:\\ \;\;\;\;\frac{y}{\frac{z \cdot t - x}{\frac{z}{x + 1}}}\\ \mathbf{elif}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq 2 \cdot 10^{+211}:\\ \;\;\;\;\frac{x + \frac{\mathsf{fma}\left(y, z, -x\right)}{\mathsf{fma}\left(z, t, -x\right)}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x + 1} \cdot \left(x + \frac{y}{t}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error2.3
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^{+105}:\\ \;\;\;\;\frac{y}{\frac{t_1}{\frac{z}{x + 1}}}\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+211}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x + 1} \cdot \left(x + \frac{y}{t}\right)\\ \end{array} \]
Alternative 2
Error24.2
Cost1240
\[\begin{array}{l} t_1 := \frac{x}{x + 1}\\ t_2 := \frac{y}{t \cdot \left(x + 1\right)}\\ \mathbf{if}\;z \leq -9.2 \cdot 10^{+66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3 \cdot 10^{-82}:\\ \;\;\;\;1 - \frac{y}{\frac{x}{z}}\\ \mathbf{elif}\;z \leq 9.2 \cdot 10^{+36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{+100}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+162}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+210}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error22.8
Cost1104
\[\begin{array}{l} t_1 := \frac{x}{x + 1}\\ \mathbf{if}\;t \leq -2.2 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.4 \cdot 10^{-16}:\\ \;\;\;\;1 - \frac{y}{\frac{x}{z}}\\ \mathbf{elif}\;t \leq 5 \cdot 10^{+28}:\\ \;\;\;\;\frac{y}{t \cdot \left(x + 1\right)}\\ \mathbf{elif}\;t \leq 3.4 \cdot 10^{+86}:\\ \;\;\;\;1 - \frac{y}{x} \cdot \frac{z}{x}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error20.7
Cost980
\[\begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{-17}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{-150}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-14}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 7300000000:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Error11.8
Cost968
\[\begin{array}{l} t_1 := \frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{if}\;t \leq -5.8 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 9 \cdot 10^{-53}:\\ \;\;\;\;1 - z \cdot \frac{\frac{y}{x}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error22.7
Cost848
\[\begin{array}{l} t_1 := \frac{x}{x + 1}\\ \mathbf{if}\;t \leq -1.52 \cdot 10^{+29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.12 \cdot 10^{-23}:\\ \;\;\;\;1 - \frac{y}{\frac{x}{z}}\\ \mathbf{elif}\;t \leq 5.5 \cdot 10^{+25}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;t \leq 1.04 \cdot 10^{+96}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error14.2
Cost840
\[\begin{array}{l} t_1 := \frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{if}\;z \leq -4.4 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 10^{-163}:\\ \;\;\;\;1 - \frac{y}{\frac{x}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error20.4
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -4.4 \cdot 10^{-17}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-100}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 9
Error26.9
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2.05 \cdot 10^{-82}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 6.5 \cdot 10^{-59}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 10
Error28.4
Cost64
\[1 \]

Error

Reproduce

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