Average Error: 7.2 → 1.0
Time: 14.7s
Precision: binary64
Cost: 14024
\[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
\[\begin{array}{l} t_1 := \frac{x + \frac{1}{\frac{t - \frac{x}{z}}{y}}}{x + 1}\\ \mathbf{if}\;z \leq -8.2 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.0022:\\ \;\;\;\;\frac{x + \frac{\mathsf{fma}\left(y, z, -x\right)}{\mathsf{fma}\left(z, t, -x\right)}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_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 (/ (+ x (/ 1.0 (/ (- t (/ x z)) y))) (+ x 1.0))))
   (if (<= z -8.2e+15)
     t_1
     (if (<= z 0.0022)
       (/ (+ x (/ (fma y z (- x)) (fma z t (- x)))) (+ x 1.0))
       t_1))))
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 = (x + (1.0 / ((t - (x / z)) / y))) / (x + 1.0);
	double tmp;
	if (z <= -8.2e+15) {
		tmp = t_1;
	} else if (z <= 0.0022) {
		tmp = (x + (fma(y, z, -x) / fma(z, t, -x))) / (x + 1.0);
	} else {
		tmp = t_1;
	}
	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(x + Float64(1.0 / Float64(Float64(t - Float64(x / z)) / y))) / Float64(x + 1.0))
	tmp = 0.0
	if (z <= -8.2e+15)
		tmp = t_1;
	elseif (z <= 0.0022)
		tmp = Float64(Float64(x + Float64(fma(y, z, Float64(-x)) / fma(z, t, Float64(-x)))) / Float64(x + 1.0));
	else
		tmp = t_1;
	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[(x + N[(1.0 / N[(N[(t - N[(x / z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -8.2e+15], t$95$1, If[LessEqual[z, 0.0022], N[(N[(x + N[(N[(y * z + (-x)), $MachinePrecision] / N[(z * t + (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1}
\begin{array}{l}
t_1 := \frac{x + \frac{1}{\frac{t - \frac{x}{z}}{y}}}{x + 1}\\
\mathbf{if}\;z \leq -8.2 \cdot 10^{+15}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 0.0022:\\
\;\;\;\;\frac{x + \frac{\mathsf{fma}\left(y, z, -x\right)}{\mathsf{fma}\left(z, t, -x\right)}}{x + 1}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

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

Derivation

  1. Split input into 2 regimes
  2. if z < -8.2e15 or 0.00220000000000000013 < z

    1. Initial program 15.2

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

      \[\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-rr15.3

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

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

      \[\leadsto \frac{x + {\color{blue}{\left(\frac{z \cdot t - x}{z \cdot y}\right)}}^{-1}}{x + 1} \]
      Proof
      (/.f64 (-.f64 (*.f64 z t) x) (*.f64 z y)): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 t z)) x) (*.f64 z y)): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (*.f64 t z) x) (Rewrite<= *-commutative_binary64 (*.f64 y z))): 0 points increase in error, 0 points decrease in error
    6. Applied egg-rr16.5

      \[\leadsto \frac{x + \color{blue}{\frac{1}{\frac{z \cdot t - x}{z \cdot y}}}}{x + 1} \]
    7. Taylor expanded in z around 0 5.2

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

      \[\leadsto \frac{x + \frac{1}{\color{blue}{\frac{t - \frac{x}{z}}{y}}}}{x + 1} \]
      Proof
      (/.f64 (-.f64 t (/.f64 x z)) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 t)) (/.f64 x z)) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (*.f64 (Rewrite<= *-inverses_binary64 (/.f64 z z)) t) (/.f64 x z)) y): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (Rewrite<= associate-/r/_binary64 (/.f64 z (/.f64 z t))) (/.f64 x z)) y): 28 points increase in error, 5 points decrease in error
      (/.f64 (-.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 z t) z)) (/.f64 x z)) y): 27 points increase in error, 29 points decrease in error
      (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (/.f64 (*.f64 z t) z) y) (/.f64 (/.f64 x z) y))): 2 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-/r*_binary64 (/.f64 (*.f64 z t) (*.f64 z y))) (/.f64 (/.f64 x z) y)): 27 points increase in error, 13 points decrease in error
      (-.f64 (Rewrite=> times-frac_binary64 (*.f64 (/.f64 z z) (/.f64 t y))) (/.f64 (/.f64 x z) y)): 12 points increase in error, 47 points decrease in error
      (-.f64 (*.f64 (Rewrite=> *-inverses_binary64 1) (/.f64 t y)) (/.f64 (/.f64 x z) y)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite=> *-commutative_binary64 (*.f64 (/.f64 t y) 1)) (/.f64 (/.f64 x z) y)): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (/.f64 t y) 1) (Rewrite<= associate-/r*_binary64 (/.f64 x (*.f64 z y)))): 31 points increase in error, 22 points decrease in error
      (-.f64 (*.f64 (/.f64 t y) 1) (Rewrite<= associate-/l/_binary64 (/.f64 (/.f64 x y) z))): 32 points increase in error, 27 points decrease in error
      (-.f64 (Rewrite=> *-rgt-identity_binary64 (/.f64 t y)) (/.f64 (/.f64 x y) z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 t y) (neg.f64 (/.f64 (/.f64 x y) z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 t y) (neg.f64 (Rewrite<= associate-/r*_binary64 (/.f64 x (*.f64 y z))))): 27 points increase in error, 32 points decrease in error
      (+.f64 (/.f64 t y) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 x (*.f64 y z))))): 0 points increase in error, 0 points decrease in error

    if -8.2e15 < z < 0.00220000000000000013

    1. Initial program 0.2

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

      \[\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. Recombined 2 regimes into one program.
  4. Final simplification1.0

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

Alternatives

Alternative 1
Error15.5
Cost1360
\[\begin{array}{l} t_1 := \frac{x - \frac{x}{z \cdot t - x}}{x + 1}\\ \mathbf{if}\;x \leq -1.5 \cdot 10^{-18}:\\ \;\;\;\;\frac{x - \left(z \cdot \frac{y}{x} + -1\right)}{x + 1}\\ \mathbf{elif}\;x \leq 1.85 \cdot 10^{-262}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-250}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-32}:\\ \;\;\;\;\frac{y}{\left(t - \frac{x}{z}\right) \cdot \left(x + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error1.0
Cost1352
\[\begin{array}{l} t_1 := \frac{x + \frac{1}{\frac{t - \frac{x}{z}}{y}}}{x + 1}\\ \mathbf{if}\;z \leq -2.6 \cdot 10^{+16}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.0016:\\ \;\;\;\;\frac{x + \frac{z \cdot y - x}{z \cdot t - x}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error22.6
Cost1240
\[\begin{array}{l} t_1 := \frac{x}{x + 1}\\ t_2 := 1 - y \cdot \frac{z}{x}\\ \mathbf{if}\;t \leq -8.8 \cdot 10^{-69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -3.7 \cdot 10^{-181}:\\ \;\;\;\;1 - \frac{z \cdot y}{x}\\ \mathbf{elif}\;t \leq -3.4 \cdot 10^{-201}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -3.1 \cdot 10^{-278}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.5 \cdot 10^{-191}:\\ \;\;\;\;1 - \frac{y}{x} \cdot \frac{z}{x}\\ \mathbf{elif}\;t \leq 7.5 \cdot 10^{+18}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error6.7
Cost1224
\[\begin{array}{l} t_1 := \frac{x + \frac{1}{\frac{t - \frac{x}{z}}{y}}}{x + 1}\\ \mathbf{if}\;z \leq -2 \cdot 10^{-260}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-159}:\\ \;\;\;\;\frac{x + \frac{z \cdot y - x}{-x}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error12.5
Cost1104
\[\begin{array}{l} t_1 := \frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{if}\;t \leq -2.85 \cdot 10^{-108}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 5.7 \cdot 10^{-106}:\\ \;\;\;\;1 - z \cdot \frac{\frac{y}{x}}{x + 1}\\ \mathbf{elif}\;t \leq 4.3 \cdot 10^{-44}:\\ \;\;\;\;\frac{y}{\left(t - \frac{x}{z}\right) \cdot \left(x + 1\right)}\\ \mathbf{elif}\;t \leq 7.1 \cdot 10^{-28}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error14.8
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -85000:\\ \;\;\;\;1 - \frac{y}{x} \cdot \frac{z}{x}\\ \mathbf{elif}\;x \leq 1.12 \cdot 10^{-27}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Error14.7
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{-15}:\\ \;\;\;\;1 - z \cdot \frac{\frac{y}{x}}{x + 1}\\ \mathbf{elif}\;x \leq 5.4 \cdot 10^{-28}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 8
Error21.5
Cost712
\[\begin{array}{l} t_1 := \frac{x}{x + 1}\\ \mathbf{if}\;z \leq -5 \cdot 10^{-84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{-76}:\\ \;\;\;\;1 - y \cdot \frac{z}{x}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error26.3
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{-18}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 1.25 \cdot 10^{-47}:\\ \;\;\;\;x - x \cdot x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 10
Error22.8
Cost584
\[\begin{array}{l} t_1 := \frac{x}{x + 1}\\ \mathbf{if}\;t \leq -1.85 \cdot 10^{-73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.8 \cdot 10^{+47}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error26.3
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -6.5 \cdot 10^{-19}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 4.9 \cdot 10^{-54}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 12
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)))