Average Error: 16.7 → 6.8
Time: 31.1s
Precision: binary64
Cost: 11856
\[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
\[\begin{array}{l} t_1 := \left(a + 1\right) + \frac{y \cdot b}{t}\\ t_2 := x + \frac{y \cdot z}{t}\\ t_3 := \frac{t_2}{t_1}\\ \mathbf{if}\;t_3 \leq -2 \cdot 10^{-115}:\\ \;\;\;\;\frac{x + \frac{y}{t} \cdot z}{t_1}\\ \mathbf{elif}\;t_3 \leq 5 \cdot 10^{-173}:\\ \;\;\;\;\frac{x + \frac{z}{t} \cdot y}{\left(a + 1\right) + \frac{y}{t} \cdot b}\\ \mathbf{elif}\;t_3 \leq 2 \cdot 10^{+295}:\\ \;\;\;\;\frac{t_2}{\left(a + 1\right) + \frac{1}{t} \cdot \left(y \cdot b\right)}\\ \mathbf{elif}\;t_3 \leq \infty:\\ \;\;\;\;\frac{z}{\mathsf{fma}\left(b, \frac{y}{t}, 1 + a\right)} \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{b}\\ \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (/ (+ x (/ (* y z) t)) (+ (+ a 1.0) (/ (* y b) t))))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (+ (+ a 1.0) (/ (* y b) t)))
        (t_2 (+ x (/ (* y z) t)))
        (t_3 (/ t_2 t_1)))
   (if (<= t_3 -2e-115)
     (/ (+ x (* (/ y t) z)) t_1)
     (if (<= t_3 5e-173)
       (/ (+ x (* (/ z t) y)) (+ (+ a 1.0) (* (/ y t) b)))
       (if (<= t_3 2e+295)
         (/ t_2 (+ (+ a 1.0) (* (/ 1.0 t) (* y b))))
         (if (<= t_3 INFINITY)
           (* (/ z (fma b (/ y t) (+ 1.0 a))) (/ y t))
           (/ z b)))))))
double code(double x, double y, double z, double t, double a, double b) {
	return (x + ((y * z) / t)) / ((a + 1.0) + ((y * b) / t));
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a + 1.0) + ((y * b) / t);
	double t_2 = x + ((y * z) / t);
	double t_3 = t_2 / t_1;
	double tmp;
	if (t_3 <= -2e-115) {
		tmp = (x + ((y / t) * z)) / t_1;
	} else if (t_3 <= 5e-173) {
		tmp = (x + ((z / t) * y)) / ((a + 1.0) + ((y / t) * b));
	} else if (t_3 <= 2e+295) {
		tmp = t_2 / ((a + 1.0) + ((1.0 / t) * (y * b)));
	} else if (t_3 <= ((double) INFINITY)) {
		tmp = (z / fma(b, (y / t), (1.0 + a))) * (y / t);
	} else {
		tmp = z / b;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	return Float64(Float64(x + Float64(Float64(y * z) / t)) / Float64(Float64(a + 1.0) + Float64(Float64(y * b) / t)))
end
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a + 1.0) + Float64(Float64(y * b) / t))
	t_2 = Float64(x + Float64(Float64(y * z) / t))
	t_3 = Float64(t_2 / t_1)
	tmp = 0.0
	if (t_3 <= -2e-115)
		tmp = Float64(Float64(x + Float64(Float64(y / t) * z)) / t_1);
	elseif (t_3 <= 5e-173)
		tmp = Float64(Float64(x + Float64(Float64(z / t) * y)) / Float64(Float64(a + 1.0) + Float64(Float64(y / t) * b)));
	elseif (t_3 <= 2e+295)
		tmp = Float64(t_2 / Float64(Float64(a + 1.0) + Float64(Float64(1.0 / t) * Float64(y * b))));
	elseif (t_3 <= Inf)
		tmp = Float64(Float64(z / fma(b, Float64(y / t), Float64(1.0 + a))) * Float64(y / t));
	else
		tmp = Float64(z / b);
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] / N[(N[(a + 1.0), $MachinePrecision] + N[(N[(y * b), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a + 1.0), $MachinePrecision] + N[(N[(y * b), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 / t$95$1), $MachinePrecision]}, If[LessEqual[t$95$3, -2e-115], N[(N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[t$95$3, 5e-173], N[(N[(x + N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / N[(N[(a + 1.0), $MachinePrecision] + N[(N[(y / t), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2e+295], N[(t$95$2 / N[(N[(a + 1.0), $MachinePrecision] + N[(N[(1.0 / t), $MachinePrecision] * N[(y * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, Infinity], N[(N[(z / N[(b * N[(y / t), $MachinePrecision] + N[(1.0 + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision], N[(z / b), $MachinePrecision]]]]]]]]
\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}}
\begin{array}{l}
t_1 := \left(a + 1\right) + \frac{y \cdot b}{t}\\
t_2 := x + \frac{y \cdot z}{t}\\
t_3 := \frac{t_2}{t_1}\\
\mathbf{if}\;t_3 \leq -2 \cdot 10^{-115}:\\
\;\;\;\;\frac{x + \frac{y}{t} \cdot z}{t_1}\\

\mathbf{elif}\;t_3 \leq 5 \cdot 10^{-173}:\\
\;\;\;\;\frac{x + \frac{z}{t} \cdot y}{\left(a + 1\right) + \frac{y}{t} \cdot b}\\

\mathbf{elif}\;t_3 \leq 2 \cdot 10^{+295}:\\
\;\;\;\;\frac{t_2}{\left(a + 1\right) + \frac{1}{t} \cdot \left(y \cdot b\right)}\\

\mathbf{elif}\;t_3 \leq \infty:\\
\;\;\;\;\frac{z}{\mathsf{fma}\left(b, \frac{y}{t}, 1 + a\right)} \cdot \frac{y}{t}\\

\mathbf{else}:\\
\;\;\;\;\frac{z}{b}\\


\end{array}

Error

Target

Original16.7
Target13.3
Herbie6.8
\[\begin{array}{l} \mathbf{if}\;t < -1.3659085366310088 \cdot 10^{-271}:\\ \;\;\;\;1 \cdot \left(\left(x + \frac{y}{t} \cdot z\right) \cdot \frac{1}{\left(a + 1\right) + \frac{y}{t} \cdot b}\right)\\ \mathbf{elif}\;t < 3.036967103737246 \cdot 10^{-130}:\\ \;\;\;\;\frac{z}{b}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\left(x + \frac{y}{t} \cdot z\right) \cdot \frac{1}{\left(a + 1\right) + \frac{y}{t} \cdot b}\right)\\ \end{array} \]

Derivation

  1. Split input into 5 regimes
  2. if (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < -2.0000000000000001e-115

    1. Initial program 9.5

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Applied egg-rr8.0

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

    if -2.0000000000000001e-115 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < 5.0000000000000002e-173

    1. Initial program 15.5

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Applied egg-rr10.8

      \[\leadsto \frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \color{blue}{\frac{y}{t} \cdot b}} \]
    3. Applied egg-rr11.1

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

    if 5.0000000000000002e-173 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < 2e295

    1. Initial program 0.2

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Applied egg-rr0.3

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

    if 2e295 < (/.f64 (+.f64 x (/.f64 (*.f64 y z) t)) (+.f64 (+.f64 a 1) (/.f64 (*.f64 y b) t))) < +inf.0

    1. Initial program 59.8

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Simplified39.2

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(z, \frac{y}{t}, x\right)}{\mathsf{fma}\left(y, \frac{b}{t}, a + 1\right)}} \]
      Proof
    3. Taylor expanded in z around inf 36.8

      \[\leadsto \color{blue}{\frac{y \cdot z}{t \cdot \left(1 + \left(\frac{y \cdot b}{t} + a\right)\right)}} \]
    4. Simplified36.8

      \[\leadsto \color{blue}{\frac{y \cdot z}{t \cdot \left(\left(1 + a\right) + \frac{y \cdot b}{t}\right)}} \]
      Proof
    5. Applied egg-rr19.6

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

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

    1. Initial program 64.0

      \[\frac{x + \frac{y \cdot z}{t}}{\left(a + 1\right) + \frac{y \cdot b}{t}} \]
    2. Taylor expanded in y around inf 2.6

      \[\leadsto \color{blue}{\frac{z}{b}} \]
  3. Recombined 5 regimes into one program.

Alternatives

Alternative 1
Error7.4
Cost4684
\[\begin{array}{l} t_1 := \left(a + 1\right) + \frac{y \cdot b}{t}\\ t_2 := x + \frac{y \cdot z}{t}\\ t_3 := \frac{t_2}{t_1}\\ \mathbf{if}\;t_3 \leq -2 \cdot 10^{-115}:\\ \;\;\;\;\frac{x + \frac{y}{t} \cdot z}{t_1}\\ \mathbf{elif}\;t_3 \leq 5 \cdot 10^{-173}:\\ \;\;\;\;\frac{x + \frac{z}{t} \cdot y}{\left(a + 1\right) + \frac{y}{t} \cdot b}\\ \mathbf{elif}\;t_3 \leq 2 \cdot 10^{+295}:\\ \;\;\;\;\frac{t_2}{\left(a + 1\right) + \frac{1}{t} \cdot \left(y \cdot b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{b}\\ \end{array} \]
Alternative 2
Error7.4
Cost4556
\[\begin{array}{l} t_1 := \left(a + 1\right) + \frac{y \cdot b}{t}\\ t_2 := \frac{x + \frac{y \cdot z}{t}}{t_1}\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{-115}:\\ \;\;\;\;\frac{x + \frac{y}{t} \cdot z}{t_1}\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{-173}:\\ \;\;\;\;\frac{x + \frac{z}{t} \cdot y}{\left(a + 1\right) + \frac{y}{t} \cdot b}\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+295}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{b}\\ \end{array} \]
Alternative 3
Error13.2
Cost1616
\[\begin{array}{l} t_1 := x + \frac{y}{t} \cdot z\\ t_2 := \frac{t_1}{\left(a + 1\right) + \frac{b}{t} \cdot y}\\ \mathbf{if}\;t \leq -3.05 \cdot 10^{-84}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 6.5 \cdot 10^{-281}:\\ \;\;\;\;\frac{\frac{t \cdot x}{y} + z}{b}\\ \mathbf{elif}\;t \leq 4.3 \cdot 10^{-195}:\\ \;\;\;\;\frac{t_1}{\left(a + 1\right) + \frac{y \cdot b}{t}}\\ \mathbf{elif}\;t \leq 3.1 \cdot 10^{-120}:\\ \;\;\;\;\frac{y \cdot z}{y \cdot b + t \cdot \left(1 + a\right)}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error13.2
Cost1616
\[\begin{array}{l} t_1 := x + \frac{y}{t} \cdot z\\ \mathbf{if}\;t \leq -1.6 \cdot 10^{-83}:\\ \;\;\;\;\frac{x + \frac{z}{t} \cdot y}{\left(a + 1\right) + \frac{y}{t} \cdot b}\\ \mathbf{elif}\;t \leq 6.5 \cdot 10^{-281}:\\ \;\;\;\;\frac{\frac{t \cdot x}{y} + z}{b}\\ \mathbf{elif}\;t \leq 10^{-196}:\\ \;\;\;\;\frac{t_1}{\left(a + 1\right) + \frac{y \cdot b}{t}}\\ \mathbf{elif}\;t \leq 1.6 \cdot 10^{-119}:\\ \;\;\;\;\frac{y \cdot z}{y \cdot b + t \cdot \left(1 + a\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{\left(a + 1\right) + \frac{b}{t} \cdot y}\\ \end{array} \]
Alternative 5
Error11.8
Cost1352
\[\begin{array}{l} t_1 := \frac{x + \frac{y}{t} \cdot z}{\left(a + 1\right) + \frac{b}{t} \cdot y}\\ \mathbf{if}\;t \leq -9 \cdot 10^{-83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.5 \cdot 10^{-118}:\\ \;\;\;\;\frac{\frac{t \cdot x}{y} + z}{b}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error21.7
Cost968
\[\begin{array}{l} t_1 := \frac{x}{\left(a + 1\right) + \frac{b}{t} \cdot y}\\ \mathbf{if}\;t \leq -13500000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3 \cdot 10^{-65}:\\ \;\;\;\;\frac{\frac{t \cdot x}{y} + z}{b}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error21.0
Cost968
\[\begin{array}{l} t_1 := \frac{\frac{y \cdot z}{t} + x}{1 + a}\\ \mathbf{if}\;t \leq -1650000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 6.2 \cdot 10^{-65}:\\ \;\;\;\;\frac{\frac{t \cdot x}{y} + z}{b}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error37.4
Cost852
\[\begin{array}{l} \mathbf{if}\;t \leq -1.14 \cdot 10^{+114}:\\ \;\;\;\;\frac{x}{a}\\ \mathbf{elif}\;t \leq -3.5 \cdot 10^{+46}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 1.35 \cdot 10^{-21}:\\ \;\;\;\;\frac{z}{b}\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{+268}:\\ \;\;\;\;\frac{x}{a}\\ \mathbf{elif}\;t \leq 2.8 \cdot 10^{+298}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{a}\\ \end{array} \]
Alternative 9
Error37.4
Cost852
\[\begin{array}{l} \mathbf{if}\;t \leq -2.6 \cdot 10^{+114}:\\ \;\;\;\;\frac{x}{a}\\ \mathbf{elif}\;t \leq -5.4 \cdot 10^{+41}:\\ \;\;\;\;x \cdot \left(1 - a\right)\\ \mathbf{elif}\;t \leq 1.35 \cdot 10^{-21}:\\ \;\;\;\;\frac{z}{b}\\ \mathbf{elif}\;t \leq 2.4 \cdot 10^{+269}:\\ \;\;\;\;\frac{x}{a}\\ \mathbf{elif}\;t \leq 4.2 \cdot 10^{+303}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{a}\\ \end{array} \]
Alternative 10
Error24.9
Cost840
\[\begin{array}{l} t_1 := \frac{x}{1 + a}\\ \mathbf{if}\;t \leq -5600000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{-20}:\\ \;\;\;\;\frac{\frac{t \cdot x}{y} + z}{b}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error28.0
Cost584
\[\begin{array}{l} t_1 := \frac{x}{1 + a}\\ \mathbf{if}\;t \leq -7300000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.4 \cdot 10^{-21}:\\ \;\;\;\;\frac{z}{b}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error36.5
Cost456
\[\begin{array}{l} \mathbf{if}\;a \leq -2.1 \cdot 10^{-5}:\\ \;\;\;\;\frac{x}{a}\\ \mathbf{elif}\;a \leq 1.55 \cdot 10^{-5}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{a}\\ \end{array} \]
Alternative 13
Error50.5
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2023010 
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Tridiagonal:solveCyclicTriDiagonal from diagrams-solve-0.1, B"
  :precision binary64

  :herbie-target
  (if (< t -1.3659085366310088e-271) (* 1.0 (* (+ x (* (/ y t) z)) (/ 1.0 (+ (+ a 1.0) (* (/ y t) b))))) (if (< t 3.036967103737246e-130) (/ z b) (* 1.0 (* (+ x (* (/ y t) z)) (/ 1.0 (+ (+ a 1.0) (* (/ y t) b)))))))

  (/ (+ x (/ (* y z) t)) (+ (+ a 1.0) (/ (* y b) t))))