Average Error: 10.5 → 3.9
Time: 16.9s
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}{t_1} - \frac{y}{\frac{t_1}{z}}\\ t_3 := \frac{x - y \cdot z}{t_1}\\ \mathbf{if}\;t_3 \leq -1 \cdot 10^{-305}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_3 \leq 0:\\ \;\;\;\;\frac{y}{a} + \frac{\frac{y}{a} \cdot \frac{t}{a} - \frac{x}{a}}{z}\\ \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 -1e-305)
     t_2
     (if (<= t_3 0.0)
       (+ (/ y a) (/ (- (* (/ y a) (/ t a)) (/ x a)) z))
       (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 <= -1e-305) {
		tmp = t_2;
	} else if (t_3 <= 0.0) {
		tmp = (y / a) + ((((y / a) * (t / a)) - (x / a)) / z);
	} else if (t_3 <= ((double) INFINITY)) {
		tmp = t_2;
	} 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 / t_1) - (y / (t_1 / z));
	double t_3 = (x - (y * z)) / t_1;
	double tmp;
	if (t_3 <= -1e-305) {
		tmp = t_2;
	} else if (t_3 <= 0.0) {
		tmp = (y / a) + ((((y / a) * (t / a)) - (x / a)) / z);
	} else if (t_3 <= Double.POSITIVE_INFINITY) {
		tmp = t_2;
	} 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 / t_1) - (y / (t_1 / z))
	t_3 = (x - (y * z)) / t_1
	tmp = 0
	if t_3 <= -1e-305:
		tmp = t_2
	elif t_3 <= 0.0:
		tmp = (y / a) + ((((y / a) * (t / a)) - (x / a)) / z)
	elif t_3 <= math.inf:
		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 <= -1e-305)
		tmp = t_2;
	elseif (t_3 <= 0.0)
		tmp = Float64(Float64(y / a) + Float64(Float64(Float64(Float64(y / a) * Float64(t / a)) - Float64(x / a)) / z));
	elseif (t_3 <= Inf)
		tmp = t_2;
	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 / t_1) - (y / (t_1 / z));
	t_3 = (x - (y * z)) / t_1;
	tmp = 0.0;
	if (t_3 <= -1e-305)
		tmp = t_2;
	elseif (t_3 <= 0.0)
		tmp = (y / a) + ((((y / a) * (t / a)) - (x / a)) / z);
	elseif (t_3 <= Inf)
		tmp = t_2;
	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 / 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, -1e-305], t$95$2, If[LessEqual[t$95$3, 0.0], N[(N[(y / a), $MachinePrecision] + N[(N[(N[(N[(y / a), $MachinePrecision] * N[(t / a), $MachinePrecision]), $MachinePrecision] - N[(x / a), $MachinePrecision]), $MachinePrecision] / z), $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 -1 \cdot 10^{-305}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;\frac{y}{a} + \frac{\frac{y}{a} \cdot \frac{t}{a} - \frac{x}{a}}{z}\\

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

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.5
Target1.6
Herbie3.9
\[\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))) < -9.99999999999999996e-306 or -0.0 < (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 a z))) < +inf.0

    1. Initial program 4.8

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

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

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

    1. Initial program 24.9

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

      \[\leadsto \color{blue}{\left(-1 \cdot \frac{x}{a \cdot z} + \frac{y}{a}\right) - -1 \cdot \frac{y \cdot t}{{a}^{2} \cdot z}} \]
    3. Simplified16.2

      \[\leadsto \color{blue}{\frac{y}{a} + \frac{\frac{y}{a} \cdot \frac{t}{a} - \frac{x}{a}}{z}} \]
      Proof
      (+.f64 (/.f64 y a) (/.f64 (-.f64 (*.f64 (/.f64 y a) (/.f64 t a)) (/.f64 x a)) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 y a) (/.f64 (-.f64 (Rewrite<= times-frac_binary64 (/.f64 (*.f64 y t) (*.f64 a a))) (/.f64 x a)) z)): 19 points increase in error, 7 points decrease in error
      (+.f64 (/.f64 y a) (/.f64 (-.f64 (/.f64 (*.f64 y t) (Rewrite<= unpow2_binary64 (pow.f64 a 2))) (/.f64 x a)) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 y a) (/.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 (*.f64 y t) (pow.f64 a 2)) (neg.f64 (/.f64 x a)))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 y a) (/.f64 (+.f64 (/.f64 (*.f64 y t) (pow.f64 a 2)) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 x a)))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 y a) (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.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) (/.f64 (+.f64 (*.f64 -1 (/.f64 x a)) (Rewrite<= *-lft-identity_binary64 (*.f64 1 (/.f64 (*.f64 y t) (pow.f64 a 2))))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 y a) (/.f64 (+.f64 (*.f64 -1 (/.f64 x a)) (*.f64 (Rewrite<= metadata-eval (neg.f64 -1)) (/.f64 (*.f64 y t) (pow.f64 a 2)))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 y a) (/.f64 (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (*.f64 -1 (/.f64 x a)) (*.f64 -1 (/.f64 (*.f64 y t) (pow.f64 a 2))))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 y a) (/.f64 (Rewrite=> distribute-lft-out--_binary64 (*.f64 -1 (-.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<= associate-*r/_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
      (+.f64 (/.f64 y a) (*.f64 -1 (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (/.f64 x a) z) (/.f64 (/.f64 (*.f64 y t) (pow.f64 a 2)) z))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 y a) (*.f64 -1 (-.f64 (Rewrite<= associate-/r*_binary64 (/.f64 x (*.f64 a z))) (/.f64 (/.f64 (*.f64 y t) (pow.f64 a 2)) z)))): 22 points increase in error, 12 points decrease in error
      (+.f64 (/.f64 y a) (*.f64 -1 (-.f64 (/.f64 x (*.f64 a z)) (Rewrite<= associate-/r*_binary64 (/.f64 (*.f64 y t) (*.f64 (pow.f64 a 2) z)))))): 6 points increase in error, 9 points decrease in error
      (+.f64 (/.f64 y a) (Rewrite<= distribute-lft-out--_binary64 (-.f64 (*.f64 -1 (/.f64 x (*.f64 a z))) (*.f64 -1 (/.f64 (*.f64 y t) (*.f64 (pow.f64 a 2) z)))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 (/.f64 y a) (*.f64 -1 (/.f64 x (*.f64 a z)))) (*.f64 -1 (/.f64 (*.f64 y t) (*.f64 (pow.f64 a 2) z))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 x (*.f64 a z))) (/.f64 y a))) (*.f64 -1 (/.f64 (*.f64 y t) (*.f64 (pow.f64 a 2) 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. Taylor expanded in t around 0 64.0

      \[\leadsto \frac{x - y \cdot z}{\color{blue}{-1 \cdot \left(a \cdot z\right)}} \]
    3. Simplified64.0

      \[\leadsto \frac{x - y \cdot z}{\color{blue}{a \cdot \left(-z\right)}} \]
      Proof
      (*.f64 a (neg.f64 z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 a z))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 a z))): 0 points increase in error, 0 points decrease in error
    4. Taylor expanded in x around 0 0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -1 \cdot 10^{-305}:\\ \;\;\;\;\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 0:\\ \;\;\;\;\frac{y}{a} + \frac{\frac{y}{a} \cdot \frac{t}{a} - \frac{x}{a}}{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
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 -4 \cdot 10^{-15}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_3 \leq 5 \cdot 10^{-47}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_3 \leq \infty:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 2
Error3.8
Cost2892
\[\begin{array}{l} t_1 := z \cdot \frac{y}{z \cdot a - t}\\ t_2 := \frac{x - y \cdot z}{t - z \cdot a}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+293}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq \infty:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 3
Error35.1
Cost1440
\[\begin{array}{l} \mathbf{if}\;a \leq -3.283550737243939 \cdot 10^{+71}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;a \leq -2.761400692472974 \cdot 10^{+48}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;a \leq -7.485741865276206 \cdot 10^{+26}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;a \leq -4.5 \cdot 10^{-96}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;a \leq -3.9 \cdot 10^{-131}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;a \leq -1.72 \cdot 10^{-141}:\\ \;\;\;\;\frac{-z}{\frac{t}{y}}\\ \mathbf{elif}\;a \leq 3.8 \cdot 10^{-175}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;a \leq 2.5 \cdot 10^{-109}:\\ \;\;\;\;y \cdot \frac{-z}{t}\\ \mathbf{elif}\;a \leq 121509.1836416618:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 4
Error20.7
Cost1240
\[\begin{array}{l} t_1 := \frac{x - y \cdot z}{t}\\ t_2 := \frac{y - \frac{x}{z}}{a}\\ \mathbf{if}\;a \leq -3.283550737243939 \cdot 10^{+71}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.761400692472974 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -7.485741865276206 \cdot 10^{+26}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -163537142336442.75:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{elif}\;a \leq -1.1203436424377849 \cdot 10^{-17}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 121509.1836416618:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error21.3
Cost1240
\[\begin{array}{l} t_1 := \frac{x - y \cdot z}{t}\\ t_2 := \frac{y - \frac{x}{z}}{a}\\ \mathbf{if}\;a \leq -3.283550737243939 \cdot 10^{+71}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.761400692472974 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -7.485741865276206 \cdot 10^{+26}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -4.5 \cdot 10^{-96}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{elif}\;a \leq -3.1 \cdot 10^{-140}:\\ \;\;\;\;z \cdot \frac{y}{z \cdot a - t}\\ \mathbf{elif}\;a \leq 121509.1836416618:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error20.6
Cost976
\[\begin{array}{l} t_1 := \frac{x - y \cdot z}{t}\\ t_2 := \frac{y - \frac{x}{z}}{a}\\ \mathbf{if}\;a \leq -3.283550737243939 \cdot 10^{+71}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.761400692472974 \cdot 10^{+48}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.1203436424377849 \cdot 10^{-17}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 121509.1836416618:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error23.8
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -1.8880112677245298 \cdot 10^{-13}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 3.6201869576045154 \cdot 10^{+87}:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 8
Error30.2
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1.8880112677245298 \cdot 10^{-13}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 3.6201869576045154 \cdot 10^{+87}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 9
Error41.9
Cost192
\[\frac{y}{a} \]

Error

Reproduce

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