Average Error: 10.4 → 4.0
Time: 14.8s
Precision: binary64
Cost: 3792
\[\frac{x - y \cdot z}{t - a \cdot z} \]
\[\begin{array}{l} t_1 := \frac{x - y \cdot z}{t - z \cdot a}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;z \cdot \frac{y}{z \cdot a - t}\\ \mathbf{elif}\;t_1 \leq -1 \cdot 10^{-286}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\frac{y}{a} - \frac{\frac{x}{a}}{z}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+277}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (/ (- x (* y z)) (- t (* a z))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (/ (- x (* y z)) (- t (* z a)))))
   (if (<= t_1 (- INFINITY))
     (* z (/ y (- (* z a) t)))
     (if (<= t_1 -1e-286)
       t_1
       (if (<= t_1 0.0)
         (- (/ y a) (/ (/ x a) z))
         (if (<= t_1 5e+277) t_1 (/ y a)))))))
double code(double x, double y, double z, double t, double a) {
	return (x - (y * z)) / (t - (a * z));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (x - (y * z)) / (t - (z * a));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = z * (y / ((z * a) - t));
	} else if (t_1 <= -1e-286) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		tmp = (y / a) - ((x / a) / z);
	} else if (t_1 <= 5e+277) {
		tmp = t_1;
	} else {
		tmp = y / a;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t, double a) {
	return (x - (y * z)) / (t - (a * z));
}
public static double code(double x, double y, double z, double t, double a) {
	double t_1 = (x - (y * z)) / (t - (z * a));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = z * (y / ((z * a) - t));
	} else if (t_1 <= -1e-286) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		tmp = (y / a) - ((x / a) / z);
	} else if (t_1 <= 5e+277) {
		tmp = t_1;
	} else {
		tmp = y / a;
	}
	return tmp;
}
def code(x, y, z, t, a):
	return (x - (y * z)) / (t - (a * z))
def code(x, y, z, t, a):
	t_1 = (x - (y * z)) / (t - (z * a))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = z * (y / ((z * a) - t))
	elif t_1 <= -1e-286:
		tmp = t_1
	elif t_1 <= 0.0:
		tmp = (y / a) - ((x / a) / z)
	elif t_1 <= 5e+277:
		tmp = t_1
	else:
		tmp = y / a
	return tmp
function code(x, y, z, t, a)
	return Float64(Float64(x - Float64(y * z)) / Float64(t - Float64(a * z)))
end
function code(x, y, z, t, a)
	t_1 = Float64(Float64(x - Float64(y * z)) / Float64(t - Float64(z * a)))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(z * Float64(y / Float64(Float64(z * a) - t)));
	elseif (t_1 <= -1e-286)
		tmp = t_1;
	elseif (t_1 <= 0.0)
		tmp = Float64(Float64(y / a) - Float64(Float64(x / a) / z));
	elseif (t_1 <= 5e+277)
		tmp = t_1;
	else
		tmp = Float64(y / a);
	end
	return tmp
end
function tmp = code(x, y, z, t, a)
	tmp = (x - (y * z)) / (t - (a * z));
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = (x - (y * z)) / (t - (z * a));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = z * (y / ((z * a) - t));
	elseif (t_1 <= -1e-286)
		tmp = t_1;
	elseif (t_1 <= 0.0)
		tmp = (y / a) - ((x / a) / z);
	elseif (t_1 <= 5e+277)
		tmp = t_1;
	else
		tmp = y / a;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / N[(t - N[(a * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / N[(t - N[(z * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(z * N[(y / N[(N[(z * a), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -1e-286], t$95$1, If[LessEqual[t$95$1, 0.0], N[(N[(y / a), $MachinePrecision] - N[(N[(x / a), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+277], t$95$1, N[(y / a), $MachinePrecision]]]]]]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
t_1 := \frac{x - y \cdot z}{t - z \cdot a}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;z \cdot \frac{y}{z \cdot a - t}\\

\mathbf{elif}\;t_1 \leq -1 \cdot 10^{-286}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\frac{y}{a} - \frac{\frac{x}{a}}{z}\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+277}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\frac{y}{a}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.4
Target1.6
Herbie4.0
\[\begin{array}{l} \mathbf{if}\;z < -32113435955957344:\\ \;\;\;\;\frac{x}{t - a \cdot z} - \frac{y}{\frac{t}{z} - a}\\ \mathbf{elif}\;z < 3.5139522372978296 \cdot 10^{-86}:\\ \;\;\;\;\left(x - y \cdot z\right) \cdot \frac{1}{t - a \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t - a \cdot z} - \frac{y}{\frac{t}{z} - a}\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -inf.0

    1. Initial program 64.0

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Applied egg-rr0.2

      \[\leadsto \color{blue}{\frac{x}{t - z \cdot a} - \frac{y}{\frac{t - z \cdot a}{z}}} \]
    3. Applied egg-rr51.0

      \[\leadsto \color{blue}{\frac{\left(-x\right) \cdot \frac{t - z \cdot a}{z} - \left(-\left(t - z \cdot a\right)\right) \cdot y}{\left(-\left(t - z \cdot a\right)\right) \cdot \frac{t - z \cdot a}{z}}} \]
    4. Taylor expanded in y around inf 64.0

      \[\leadsto \color{blue}{\frac{y \cdot z}{a \cdot z - t}} \]
    5. Simplified0.3

      \[\leadsto \color{blue}{\frac{y}{z \cdot a - t} \cdot z} \]
      Proof
      (*.f64 (/.f64 y (-.f64 (*.f64 z a) t)) z): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 y (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 a z)) t)) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/r/_binary64 (/.f64 y (/.f64 (-.f64 (*.f64 a z) t) z))): 26 points increase in error, 51 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y z) (-.f64 (*.f64 a z) t))): 56 points increase in error, 36 points decrease in error

    if -inf.0 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -1.00000000000000005e-286 or -0.0 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < 4.99999999999999982e277

    1. Initial program 0.2

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

    if -1.00000000000000005e-286 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -0.0

    1. Initial program 22.8

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Taylor expanded in x around 0 22.8

      \[\leadsto \color{blue}{\frac{x}{t - a \cdot z} + -1 \cdot \frac{y \cdot z}{t - a \cdot z}} \]
    3. Taylor expanded in z around -inf 20.3

      \[\leadsto \color{blue}{-1 \cdot \frac{\frac{x}{a} - \frac{y \cdot t}{{a}^{2}}}{z} + \frac{y}{a}} \]
    4. Simplified18.9

      \[\leadsto \color{blue}{\frac{y}{a} - \frac{\frac{x}{a} - \frac{t}{a \cdot a} \cdot y}{z}} \]
      Proof
      (-.f64 (/.f64 y a) (/.f64 (-.f64 (/.f64 x a) (*.f64 (/.f64 t (*.f64 a a)) y)) z)): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 y a) (/.f64 (-.f64 (/.f64 x a) (*.f64 (/.f64 t (Rewrite<= unpow2_binary64 (pow.f64 a 2))) y)) z)): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 y a) (/.f64 (-.f64 (/.f64 x a) (Rewrite<= associate-/r/_binary64 (/.f64 t (/.f64 (pow.f64 a 2) y)))) z)): 0 points increase in error, 10 points decrease in error
      (-.f64 (/.f64 y a) (/.f64 (-.f64 (/.f64 x a) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 t y) (pow.f64 a 2)))) z)): 15 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 y a) (/.f64 (-.f64 (/.f64 x a) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 y t)) (pow.f64 a 2))) z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 y a) (neg.f64 (/.f64 (-.f64 (/.f64 x a) (/.f64 (*.f64 y t) (pow.f64 a 2))) z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 y a) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (-.f64 (/.f64 x a) (/.f64 (*.f64 y t) (pow.f64 a 2))) z)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (-.f64 (/.f64 x a) (/.f64 (*.f64 y t) (pow.f64 a 2))) z)) (/.f64 y a))): 0 points increase in error, 0 points decrease in error
    5. Taylor expanded in x around inf 27.9

      \[\leadsto \frac{y}{a} - \color{blue}{\frac{x}{a \cdot z}} \]
    6. Simplified18.3

      \[\leadsto \frac{y}{a} - \color{blue}{\frac{\frac{x}{a}}{z}} \]
      Proof
      (/.f64 (/.f64 x a) z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/r*_binary64 (/.f64 x (*.f64 a z))): 43 points increase in error, 45 points decrease in error

    if 4.99999999999999982e277 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z)))

    1. Initial program 56.3

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Applied egg-rr34.5

      \[\leadsto \color{blue}{\frac{x}{t - z \cdot a} - \frac{y}{\frac{t - z \cdot a}{z}}} \]
    3. Taylor expanded in z around inf 13.5

      \[\leadsto \color{blue}{\frac{y}{a}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification4.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -\infty:\\ \;\;\;\;z \cdot \frac{y}{z \cdot a - t}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -1 \cdot 10^{-286}:\\ \;\;\;\;\frac{x - y \cdot z}{t - z \cdot a}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq 0:\\ \;\;\;\;\frac{y}{a} - \frac{\frac{x}{a}}{z}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq 5 \cdot 10^{+277}:\\ \;\;\;\;\frac{x - y \cdot z}{t - z \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]

Alternatives

Alternative 1
Error4.7
Cost3020
\[\begin{array}{l} t_1 := t - z \cdot a\\ t_2 := \frac{x - y \cdot z}{t_1}\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{-286}:\\ \;\;\;\;\frac{x}{t_1} - \frac{y}{\frac{t_1}{z}}\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\frac{y}{a} - \frac{\frac{x}{a}}{z}\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+277}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 2
Error19.1
Cost1104
\[\begin{array}{l} t_1 := \frac{y}{a} - \frac{\frac{x}{a}}{z}\\ \mathbf{if}\;a \leq -3.807058238593454 \cdot 10^{+47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.236255697608965 \cdot 10^{-19}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{elif}\;a \leq -2.4598406166785418 \cdot 10^{-39}:\\ \;\;\;\;z \cdot \frac{y}{z \cdot a - t}\\ \mathbf{elif}\;a \leq 7.838130072657034 \cdot 10^{-33}:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error19.1
Cost1104
\[\begin{array}{l} t_1 := \frac{y}{a} - \frac{\frac{x}{a}}{z}\\ \mathbf{if}\;a \leq -3.807058238593454 \cdot 10^{+47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.236255697608965 \cdot 10^{-19}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{elif}\;a \leq -2.4598406166785418 \cdot 10^{-39}:\\ \;\;\;\;z \cdot \frac{y}{z \cdot a - t}\\ \mathbf{elif}\;a \leq 7.838130072657034 \cdot 10^{-33}:\\ \;\;\;\;\frac{x}{t} - \frac{y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error30.3
Cost1044
\[\begin{array}{l} \mathbf{if}\;z \leq -3.3043010206685736 \cdot 10^{+35}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 1.485172758092062 \cdot 10^{-70}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;z \leq 9.452559685024887 \cdot 10^{-23}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 1764789110297539000:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;z \leq 1.877279497121892 \cdot 10^{+79}:\\ \;\;\;\;\frac{-\frac{x}{z}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 5
Error21.0
Cost976
\[\begin{array}{l} t_1 := \frac{y - \frac{x}{z}}{a}\\ t_2 := \frac{x - y \cdot z}{t}\\ \mathbf{if}\;t \leq -1.1158412050880445 \cdot 10^{+120}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -7.633557933342039 \cdot 10^{+83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -0.011652457230334095:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{elif}\;t \leq 6.945481174584904 \cdot 10^{-39}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error20.4
Cost976
\[\begin{array}{l} t_1 := \frac{y - \frac{x}{z}}{a}\\ \mathbf{if}\;a \leq -3.807058238593454 \cdot 10^{+47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.236255697608965 \cdot 10^{-19}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{elif}\;a \leq -2.4598406166785418 \cdot 10^{-39}:\\ \;\;\;\;z \cdot \frac{y}{z \cdot a - t}\\ \mathbf{elif}\;a \leq 5.63537267832634 \cdot 10^{-41}:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error23.9
Cost712
\[\begin{array}{l} t_1 := \frac{y - \frac{x}{z}}{a}\\ \mathbf{if}\;z \leq -6.972263115183724 \cdot 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.73388352056891 \cdot 10^{-98}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error18.9
Cost712
\[\begin{array}{l} t_1 := \frac{y - \frac{x}{z}}{a}\\ \mathbf{if}\;z \leq -3.3043010206685736 \cdot 10^{+35}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.485172758092062 \cdot 10^{-70}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error30.2
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -3.3043010206685736 \cdot 10^{+35}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 1.485172758092062 \cdot 10^{-70}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 10
Error42.2
Cost192
\[\frac{y}{a} \]

Error

Reproduce

herbie shell --seed 2022316 
(FPCore (x y z t a)
  :name "Diagrams.Solve.Tridiagonal:solveTriDiagonal from diagrams-solve-0.1, A"
  :precision binary64

  :herbie-target
  (if (< z -32113435955957344.0) (- (/ x (- t (* a z))) (/ y (- (/ t z) a))) (if (< z 3.5139522372978296e-86) (* (- x (* y z)) (/ 1.0 (- t (* a z)))) (- (/ x (- t (* a z))) (/ y (- (/ t z) a)))))

  (/ (- x (* y z)) (- t (* a z))))