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

\mathbf{elif}\;t_2 \leq 10^{+223}:\\
\;\;\;\;t_2\\

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


\end{array}

Error

Target

Original7.1
Target0.3
Herbie1.9
\[\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. Applied egg-rr4.0

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

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

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

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

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

    1. Initial program 0.7

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

    if 1.00000000000000005e223 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1))

    1. Initial program 56.0

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Taylor expanded in z around inf 12.2

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

Alternatives

Alternative 1
Error2.4
Cost3400
\[\begin{array}{l} t_1 := \frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+15}:\\ \;\;\;\;\frac{-y}{1} \cdot \frac{z}{\left(x - t \cdot z\right) \cdot \left(1 + x\right)}\\ \mathbf{elif}\;t_1 \leq 10^{+223}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{t} + x}{1 + x}\\ \end{array} \]
Alternative 2
Error11.7
Cost1688
\[\begin{array}{l} t_1 := \frac{x + \frac{y + \left(-\frac{x}{z}\right)}{t}}{x + 1}\\ t_2 := \frac{x - \frac{x}{t \cdot z - x}}{1 + x}\\ \mathbf{if}\;x \leq -2.5 \cdot 10^{-21}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -3.4 \cdot 10^{-38}:\\ \;\;\;\;\frac{-y}{1 + x} \cdot \frac{z}{x - t \cdot z}\\ \mathbf{elif}\;x \leq -6 \cdot 10^{-50}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-110}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-102}:\\ \;\;\;\;1 + \frac{\left(t - y\right) \cdot z}{x}\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-52}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error20.8
Cost1236
\[\begin{array}{l} t_1 := \frac{x}{1 + x}\\ t_2 := 1 + \frac{t - y}{x} \cdot z\\ \mathbf{if}\;x \leq -1.08 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{-43}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -6 \cdot 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-205}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-51}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 4
Error20.2
Cost1236
\[\begin{array}{l} t_1 := \frac{x}{1 + x}\\ t_2 := 1 + \frac{\left(t - y\right) \cdot z}{x}\\ \mathbf{if}\;x \leq -2.1 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -9.6 \cdot 10^{-43}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-205}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-5}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Error11.3
Cost1096
\[\begin{array}{l} t_1 := \frac{\frac{y}{t} + x}{1 + x}\\ \mathbf{if}\;t \leq -5.5 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.8 \cdot 10^{-88}:\\ \;\;\;\;1 + \frac{t - y}{\left(1 + x\right) \cdot x} \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error10.4
Cost1096
\[\begin{array}{l} t_1 := \frac{\frac{y}{t} + x}{1 + x}\\ \mathbf{if}\;t \leq -1.6 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.2 \cdot 10^{-88}:\\ \;\;\;\;1 + \frac{t - y}{1 + x} \cdot \frac{z}{x}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error12.3
Cost1096
\[\begin{array}{l} t_1 := \frac{\frac{y}{t} + x}{1 + x}\\ \mathbf{if}\;z \leq -5.4 \cdot 10^{+25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.00028:\\ \;\;\;\;\frac{x - \frac{x}{t \cdot z - x}}{1 + x}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error13.2
Cost840
\[\begin{array}{l} t_1 := \frac{\frac{y}{t} + x}{1 + x}\\ \mathbf{if}\;t \leq -7.5 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.3 \cdot 10^{-88}:\\ \;\;\;\;1 + \frac{\left(t - y\right) \cdot z}{x}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error20.2
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3.75 \cdot 10^{-50}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-52}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 10
Error20.1
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.4 \cdot 10^{-54}:\\ \;\;\;\;\frac{x}{1 + x}\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-51}:\\ \;\;\;\;\frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 11
Error28.4
Cost64
\[1 \]

Error

Reproduce

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