Average Error: 10.3 → 4.6
Time: 14.8s
Precision: binary64
Cost: 3404
\[\frac{x - y \cdot z}{t - a \cdot z} \]
\[\begin{array}{l} t_1 := t - z \cdot a\\ t_2 := \frac{x - y \cdot z}{t_1}\\ \mathbf{if}\;t_2 \leq -5 \cdot 10^{-320}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\frac{y \cdot z - x}{a} \cdot \frac{1}{z}\\ \mathbf{elif}\;t_2 \leq \infty:\\ \;\;\;\;\frac{x}{t_1} - \frac{y}{\frac{t_1}{z}}\\ \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 (* y z)) t_1)))
   (if (<= t_2 -5e-320)
     t_2
     (if (<= t_2 0.0)
       (* (/ (- (* y z) x) a) (/ 1.0 z))
       (if (<= t_2 INFINITY) (- (/ x t_1) (/ y (/ t_1 z))) (/ 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 - (y * z)) / t_1;
	double tmp;
	if (t_2 <= -5e-320) {
		tmp = t_2;
	} else if (t_2 <= 0.0) {
		tmp = (((y * z) - x) / a) * (1.0 / z);
	} else if (t_2 <= ((double) INFINITY)) {
		tmp = (x / t_1) - (y / (t_1 / z));
	} 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 = t - (z * a);
	double t_2 = (x - (y * z)) / t_1;
	double tmp;
	if (t_2 <= -5e-320) {
		tmp = t_2;
	} else if (t_2 <= 0.0) {
		tmp = (((y * z) - x) / a) * (1.0 / z);
	} else if (t_2 <= Double.POSITIVE_INFINITY) {
		tmp = (x / t_1) - (y / (t_1 / z));
	} 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 = t - (z * a)
	t_2 = (x - (y * z)) / t_1
	tmp = 0
	if t_2 <= -5e-320:
		tmp = t_2
	elif t_2 <= 0.0:
		tmp = (((y * z) - x) / a) * (1.0 / z)
	elif t_2 <= math.inf:
		tmp = (x / t_1) - (y / (t_1 / z))
	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 - Float64(y * z)) / t_1)
	tmp = 0.0
	if (t_2 <= -5e-320)
		tmp = t_2;
	elseif (t_2 <= 0.0)
		tmp = Float64(Float64(Float64(Float64(y * z) - x) / a) * Float64(1.0 / z));
	elseif (t_2 <= Inf)
		tmp = Float64(Float64(x / t_1) - Float64(y / Float64(t_1 / z)));
	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 = t - (z * a);
	t_2 = (x - (y * z)) / t_1;
	tmp = 0.0;
	if (t_2 <= -5e-320)
		tmp = t_2;
	elseif (t_2 <= 0.0)
		tmp = (((y * z) - x) / a) * (1.0 / z);
	elseif (t_2 <= Inf)
		tmp = (x / t_1) - (y / (t_1 / z));
	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[(t - N[(z * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, -5e-320], t$95$2, If[LessEqual[t$95$2, 0.0], N[(N[(N[(N[(y * z), $MachinePrecision] - x), $MachinePrecision] / a), $MachinePrecision] * N[(1.0 / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, Infinity], N[(N[(x / t$95$1), $MachinePrecision] - N[(y / N[(t$95$1 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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 - y \cdot z}{t_1}\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{-320}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\frac{y \cdot z - x}{a} \cdot \frac{1}{z}\\

\mathbf{elif}\;t_2 \leq \infty:\\
\;\;\;\;\frac{x}{t_1} - \frac{y}{\frac{t_1}{z}}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.3
Target1.7
Herbie4.6
\[\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))) < -4.99994e-320

    1. Initial program 4.7

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

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

    1. Initial program 25.0

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Simplified25.0

      \[\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)): 2 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
    3. Taylor expanded in a around inf 42.0

      \[\leadsto \color{blue}{\frac{y \cdot z - x}{a \cdot z}} \]
    4. Simplified42.0

      \[\leadsto \color{blue}{\frac{z \cdot y - x}{a \cdot z}} \]
      Proof
      (/.f64 (-.f64 (*.f64 z y) x) (*.f64 a z)): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 y z)) x) (*.f64 a z)): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr13.6

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

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

    1. Initial program 4.6

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

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

    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. Taylor expanded in z around inf 0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -5 \cdot 10^{-320}:\\ \;\;\;\;\frac{x - y \cdot z}{t - z \cdot a}\\ \mathbf{elif}\;\frac{x - y \cdot z}{t - z \cdot a} \leq 0:\\ \;\;\;\;\frac{y \cdot z - x}{a} \cdot \frac{1}{z}\\ \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
Error4.7
Cost3020
\[\begin{array}{l} t_1 := \frac{x - y \cdot z}{t - z \cdot a}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-320}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\frac{y \cdot z - x}{a} \cdot \frac{1}{z}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+299}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 2
Error23.9
Cost1504
\[\begin{array}{l} t_1 := \frac{x}{t} - \frac{z}{\frac{t}{y}}\\ t_2 := \frac{y - \frac{x}{z}}{a}\\ t_3 := \frac{x}{t - z \cdot a}\\ \mathbf{if}\;x \leq -1.4062868645931722 \cdot 10^{+57}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -7.679981221681303 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.681482577389186 \cdot 10^{-16}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 6.605848701771728 \cdot 10^{-198}:\\ \;\;\;\;\frac{y \cdot z}{z \cdot a - t}\\ \mathbf{elif}\;x \leq 1.51541516108575 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 0.11639560934764356:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.4049389644938383 \cdot 10^{+59}:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{elif}\;x \leq 1.4610883055076494 \cdot 10^{+85}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error24.2
Cost1308
\[\begin{array}{l} t_1 := \frac{x - y \cdot z}{t}\\ t_2 := \frac{x}{t - z \cdot a}\\ \mathbf{if}\;z \leq -3.559080371040271 \cdot 10^{+72}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq -5.640807687612407 \cdot 10^{-56}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -6.427657505448759 \cdot 10^{-180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.7254519731171887 \cdot 10^{-165}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 225817545.48949364:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.1761143164276521 \cdot 10^{+69}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 1.231890320201226 \cdot 10^{+161}:\\ \;\;\;\;y \cdot \frac{-z}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 4
Error20.1
Cost1236
\[\begin{array}{l} t_1 := \frac{y - \frac{x}{z}}{a}\\ \mathbf{if}\;z \leq -133.93565839905298:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 225817545.48949364:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{elif}\;z \leq 1.1761143164276521 \cdot 10^{+69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.3793407466741162 \cdot 10^{+86}:\\ \;\;\;\;y \cdot \frac{-z}{t}\\ \mathbf{elif}\;z \leq 1.231890320201226 \cdot 10^{+161}:\\ \;\;\;\;\frac{x}{t} - \frac{z}{\frac{t}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error31.1
Cost1176
\[\begin{array}{l} t_1 := y \cdot \frac{-z}{t}\\ \mathbf{if}\;z \leq -3.559080371040271 \cdot 10^{+72}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq -809365410661.7437:\\ \;\;\;\;\frac{-x}{z \cdot a}\\ \mathbf{elif}\;z \leq -5.266479664905529 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 225817545.48949364:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;z \leq 1.1761143164276521 \cdot 10^{+69}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 1.231890320201226 \cdot 10^{+161}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 6
Error31.2
Cost1176
\[\begin{array}{l} t_1 := y \cdot \frac{-z}{t}\\ \mathbf{if}\;z \leq -3.496539732784631 \cdot 10^{+98}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq -809365410661.7437:\\ \;\;\;\;\frac{\frac{-x}{z}}{a}\\ \mathbf{elif}\;z \leq -5.266479664905529 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 225817545.48949364:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;z \leq 1.1761143164276521 \cdot 10^{+69}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 1.231890320201226 \cdot 10^{+161}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 7
Error30.8
Cost912
\[\begin{array}{l} \mathbf{if}\;z \leq -133.93565839905298:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 225817545.48949364:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;z \leq 1.1761143164276521 \cdot 10^{+69}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 1.231890320201226 \cdot 10^{+161}:\\ \;\;\;\;y \cdot \frac{-z}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 8
Error23.9
Cost780
\[\begin{array}{l} \mathbf{if}\;z \leq -3.559080371040271 \cdot 10^{+72}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 1.1761143164276521 \cdot 10^{+69}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{elif}\;z \leq 1.231890320201226 \cdot 10^{+161}:\\ \;\;\;\;y \cdot \frac{-z}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 9
Error18.2
Cost712
\[\begin{array}{l} t_1 := \frac{y - \frac{x}{z}}{a}\\ \mathbf{if}\;z \leq -133.93565839905298:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 225817545.48949364:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error29.5
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -133.93565839905298:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 225817545.48949364:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 11
Error42.2
Cost192
\[\frac{x}{t} \]

Error

Reproduce

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