Average Error: 7.2 → 0.9
Time: 14.6s
Precision: binary64
Cost: 21636
\[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(z, t, -x\right)\\ \mathbf{if}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq \infty:\\ \;\;\;\;\frac{x + \mathsf{fma}\left(y, \frac{z}{t_1}, \frac{-x}{t_1}\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} \]
(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 (fma z t (- x))))
   (if (<= (/ (+ x (/ (- (* y z) x) (- (* z t) x))) (+ x 1.0)) INFINITY)
     (/ (+ x (fma y (/ z t_1) (/ (- x) t_1))) (+ x 1.0))
     (-
      (+ (/ y (* t (+ x 1.0))) (/ 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 = fma(z, t, -x);
	double tmp;
	if (((x + (((y * z) - x) / ((z * t) - x))) / (x + 1.0)) <= ((double) INFINITY)) {
		tmp = (x + fma(y, (z / t_1), (-x / t_1))) / (x + 1.0);
	} else {
		tmp = ((y / (t * (x + 1.0))) + (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 = fma(z, t, Float64(-x))
	tmp = 0.0
	if (Float64(Float64(x + Float64(Float64(Float64(y * z) - x) / Float64(Float64(z * t) - x))) / Float64(x + 1.0)) <= Inf)
		tmp = Float64(Float64(x + fma(y, Float64(z / t_1), Float64(Float64(-x) / t_1))) / Float64(x + 1.0));
	else
		tmp = Float64(Float64(Float64(y / Float64(t * Float64(x + 1.0))) + 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[(z * t + (-x)), $MachinePrecision]}, If[LessEqual[N[(N[(x + N[(N[(N[(y * z), $MachinePrecision] - x), $MachinePrecision] / N[(N[(z * t), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(x + N[(y * N[(z / t$95$1), $MachinePrecision] + N[((-x) / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y / N[(t * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 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 := \mathsf{fma}\left(z, t, -x\right)\\
\mathbf{if}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq \infty:\\
\;\;\;\;\frac{x + \mathsf{fma}\left(y, \frac{z}{t_1}, \frac{-x}{t_1}\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}

Error

Target

Original7.2
Target0.4
Herbie0.9
\[\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 (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1)) < +inf.0

    1. Initial program 4.6

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

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

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

    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 t around inf 0.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 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq \infty:\\ \;\;\;\;\frac{x + \mathsf{fma}\left(y, \frac{z}{\mathsf{fma}\left(z, t, -x\right)}, \frac{-x}{\mathsf{fma}\left(z, t, -x\right)}\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.7
Cost1484
\[\begin{array}{l} t_1 := z \cdot t - x\\ t_2 := \frac{x + \frac{y}{\frac{t_1}{z}}}{x + 1}\\ \mathbf{if}\;z \leq -1.178357846683742 \cdot 10^{+207}:\\ \;\;\;\;\frac{x}{x + 1} + \frac{\frac{y}{x + 1} - \frac{x}{z \cdot \left(x + 1\right)}}{t}\\ \mathbf{elif}\;z \leq -4574405.895937794:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.980609776715349 \cdot 10^{+115}:\\ \;\;\;\;\frac{x + \frac{y \cdot z - x}{t_1}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error12.9
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1224771699823524 \cdot 10^{-69}:\\ \;\;\;\;\frac{x - \frac{x}{z \cdot t - x}}{x + 1}\\ \mathbf{elif}\;x \leq 1.9879648142229198 \cdot 10^{-57}:\\ \;\;\;\;\frac{x + \frac{y - \frac{x}{z}}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + \left(1 - z \cdot \frac{y}{x}\right)}{x + 1}\\ \end{array} \]
Alternative 3
Error15.3
Cost840
\[\begin{array}{l} t_1 := \frac{x + 1}{x + 1}\\ \mathbf{if}\;x \leq -7.250079545500468 \cdot 10^{-14}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.9879648142229198 \cdot 10^{-57}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error20.9
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -8.226271010474927 \cdot 10^{-38}:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{elif}\;x \leq 1.9879648142229198 \cdot 10^{-57}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Error

Reproduce

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