Average Error: 10.8 → 3.7
Time: 23.0s
Precision: binary64
Cost: 8584
\[\frac{x - y \cdot z}{t - a \cdot z} \]
\[\begin{array}{l} t_1 := t - z \cdot a\\ t_2 := \frac{x}{t_1} - \frac{y}{\frac{t_1}{z}}\\ t_3 := \frac{x - y \cdot z}{t_1}\\ \mathbf{if}\;t_3 \leq -2 \cdot 10^{+265}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_3 \leq 10^{-68}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, z, -x\right)}{z \cdot a - t}\\ \mathbf{elif}\;t_3 \leq \infty:\\ \;\;\;\;t_2\\ \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 (- t (* z a)))
        (t_2 (- (/ x t_1) (/ y (/ t_1 z))))
        (t_3 (/ (- x (* y z)) t_1)))
   (if (<= t_3 -2e+265)
     t_2
     (if (<= t_3 1e-68)
       (/ (fma y z (- x)) (- (* z a) t))
       (if (<= t_3 INFINITY) t_2 (/ 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 = t - (z * a);
	double t_2 = (x / t_1) - (y / (t_1 / z));
	double t_3 = (x - (y * z)) / t_1;
	double tmp;
	if (t_3 <= -2e+265) {
		tmp = t_2;
	} else if (t_3 <= 1e-68) {
		tmp = fma(y, z, -x) / ((z * a) - t);
	} else if (t_3 <= ((double) INFINITY)) {
		tmp = t_2;
	} 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(t - Float64(z * a))
	t_2 = Float64(Float64(x / t_1) - Float64(y / Float64(t_1 / z)))
	t_3 = Float64(Float64(x - Float64(y * z)) / t_1)
	tmp = 0.0
	if (t_3 <= -2e+265)
		tmp = t_2;
	elseif (t_3 <= 1e-68)
		tmp = Float64(fma(y, z, Float64(-x)) / Float64(Float64(z * a) - t));
	elseif (t_3 <= Inf)
		tmp = t_2;
	else
		tmp = Float64(y / a);
	end
	return 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[(t - N[(z * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x / t$95$1), $MachinePrecision] - N[(y / N[(t$95$1 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[t$95$3, -2e+265], t$95$2, If[LessEqual[t$95$3, 1e-68], N[(N[(y * z + (-x)), $MachinePrecision] / N[(N[(z * a), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, Infinity], t$95$2, N[(y / a), $MachinePrecision]]]]]]]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
t_1 := t - z \cdot a\\
t_2 := \frac{x}{t_1} - \frac{y}{\frac{t_1}{z}}\\
t_3 := \frac{x - y \cdot z}{t_1}\\
\mathbf{if}\;t_3 \leq -2 \cdot 10^{+265}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_3 \leq 10^{-68}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, z, -x\right)}{z \cdot a - t}\\

\mathbf{elif}\;t_3 \leq \infty:\\
\;\;\;\;t_2\\

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


\end{array}

Error

Target

Original10.8
Target1.6
Herbie3.7
\[\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 3 regimes
  2. if (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < -2.00000000000000013e265 or 1.00000000000000007e-68 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < +inf.0

    1. Initial program 12.1

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

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

    if -2.00000000000000013e265 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < 1.00000000000000007e-68

    1. Initial program 5.7

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Simplified5.7

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, z, -x\right)}{z \cdot a - t}} \]
      Proof
      (/.f64 (fma.f64 y z (neg.f64 x)) (-.f64 (*.f64 z a) t)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 y z) x)) (-.f64 (*.f64 z a) t)): 1 points increase in error, 1 points decrease in error
      (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 a z)) t)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 a z) t)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= metadata-eval (/.f64 -1 -1)) (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 a z) t))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 -1 (-.f64 (*.f64 y z) x)) (*.f64 -1 (-.f64 (*.f64 a z) t)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (*.f64 y z) x))) (*.f64 -1 (-.f64 (*.f64 a z) t))): 0 points increase in error, 0 points decrease in error
      (/.f64 (neg.f64 (Rewrite=> sub-neg_binary64 (+.f64 (*.f64 y z) (neg.f64 x)))) (*.f64 -1 (-.f64 (*.f64 a z) t))): 0 points increase in error, 0 points decrease in error
      (/.f64 (neg.f64 (Rewrite=> +-commutative_binary64 (+.f64 (neg.f64 x) (*.f64 y z)))) (*.f64 -1 (-.f64 (*.f64 a z) t))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite=> distribute-neg-in_binary64 (+.f64 (neg.f64 (neg.f64 x)) (neg.f64 (*.f64 y z)))) (*.f64 -1 (-.f64 (*.f64 a z) t))): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite=> remove-double-neg_binary64 x) (neg.f64 (*.f64 y z))) (*.f64 -1 (-.f64 (*.f64 a z) t))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= sub-neg_binary64 (-.f64 x (*.f64 y z))) (*.f64 -1 (-.f64 (*.f64 a z) t))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (*.f64 y z)) (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 (*.f64 a z) t)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (*.f64 y z)) (neg.f64 (Rewrite=> sub-neg_binary64 (+.f64 (*.f64 a z) (neg.f64 t))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (*.f64 y z)) (neg.f64 (Rewrite=> +-commutative_binary64 (+.f64 (neg.f64 t) (*.f64 a z))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (*.f64 y z)) (Rewrite=> distribute-neg-in_binary64 (+.f64 (neg.f64 (neg.f64 t)) (neg.f64 (*.f64 a z))))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (*.f64 y z)) (+.f64 (Rewrite=> remove-double-neg_binary64 t) (neg.f64 (*.f64 a z)))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (*.f64 y z)) (Rewrite<= sub-neg_binary64 (-.f64 t (*.f64 a z)))): 0 points increase in error, 0 points decrease in error

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

    1. Initial program 64.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -2 \cdot 10^{+265}:\\ \;\;\;\;\frac{x}{t - z \cdot a} - \frac{y}{\frac{t - z \cdot a}{z}}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq 10^{-68}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, z, -x\right)}{z \cdot a - t}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq \infty:\\ \;\;\;\;\frac{x}{t - z \cdot a} - \frac{y}{\frac{t - z \cdot a}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]

Alternatives

Alternative 1
Error3.7
Cost3404
\[\begin{array}{l} t_1 := t - z \cdot a\\ t_2 := \frac{x}{t_1} - \frac{y}{\frac{t_1}{z}}\\ t_3 := \frac{x - y \cdot z}{t_1}\\ \mathbf{if}\;t_3 \leq -2 \cdot 10^{+265}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_3 \leq 10^{-68}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_3 \leq \infty:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 2
Error4.3
Cost2892
\[\begin{array}{l} t_1 := \frac{y}{\frac{z \cdot a - t}{z}}\\ t_2 := \frac{x - y \cdot z}{t - z \cdot a}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+261}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq \infty:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 3
Error38.3
Cost1968
\[\begin{array}{l} t_1 := -\frac{\frac{x}{z}}{a}\\ t_2 := \frac{z}{-\frac{t}{y}}\\ \mathbf{if}\;t \leq -1.896340931688344 \cdot 10^{+247}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;t \leq -1.1141616333139348 \cdot 10^{+198}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.9654768578886874 \cdot 10^{+158}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq -1.903345400743932 \cdot 10^{+91}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -2.5 \cdot 10^{-245}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq 1.65 \cdot 10^{-303}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.25 \cdot 10^{-215}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq 3.40251902098155 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.4976109426020955 \cdot 10^{+33}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq 2.379797760615919 \cdot 10^{+94}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;t \leq 2.1835287189728712 \cdot 10^{+150}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq 2.0417231658934437 \cdot 10^{+250}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;-y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 4
Error37.2
Cost1440
\[\begin{array}{l} t_1 := \frac{z}{-\frac{t}{y}}\\ \mathbf{if}\;t \leq -1.896340931688344 \cdot 10^{+247}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;t \leq -1.1141616333139348 \cdot 10^{+198}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.9654768578886874 \cdot 10^{+158}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq -7.107036857477499 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.4976109426020955 \cdot 10^{+33}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq 2.379797760615919 \cdot 10^{+94}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;t \leq 2.1835287189728712 \cdot 10^{+150}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq 2.0417231658934437 \cdot 10^{+250}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error37.3
Cost1440
\[\begin{array}{l} t_1 := \frac{z}{-\frac{t}{y}}\\ \mathbf{if}\;t \leq -1.896340931688344 \cdot 10^{+247}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;t \leq -1.1141616333139348 \cdot 10^{+198}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.9654768578886874 \cdot 10^{+158}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq -7.107036857477499 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.4976109426020955 \cdot 10^{+33}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq 2.379797760615919 \cdot 10^{+94}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;t \leq 2.1835287189728712 \cdot 10^{+150}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;t \leq 2.0417231658934437 \cdot 10^{+250}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;-y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 6
Error22.6
Cost976
\[\begin{array}{l} t_1 := \frac{x}{t - z \cdot a}\\ \mathbf{if}\;z \leq -2.228773682710379 \cdot 10^{+119}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq -1.6161253880169016 \cdot 10^{-166}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.4506407420712875 \cdot 10^{-266}:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{elif}\;z \leq 1.7928795437049846 \cdot 10^{+79}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 7
Error18.4
Cost976
\[\begin{array}{l} t_1 := \frac{x}{t - z \cdot a}\\ t_2 := \frac{y - \frac{x}{z}}{a}\\ \mathbf{if}\;z \leq -1.195835436433266 \cdot 10^{+27}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.6161253880169016 \cdot 10^{-166}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.4506407420712875 \cdot 10^{-266}:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{elif}\;z \leq 2066946390131.2346:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Error22.6
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -2.228773682710379 \cdot 10^{+119}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 1.7928795437049846 \cdot 10^{+79}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 9
Error30.2
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1.195835436433266 \cdot 10^{+27}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 1.2354788662344159 \cdot 10^{-36}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 10
Error42.4
Cost192
\[\frac{y}{a} \]

Error

Reproduce

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