Average Error: 10.5 → 3.5
Time: 12.2s
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} - y \cdot \frac{z}{t_1}\\ t_3 := \frac{x - y \cdot z}{t_1}\\ \mathbf{if}\;t_3 \leq -5 \cdot 10^{-321}:\\ \;\;\;\;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 (/ z t_1))))
        (t_3 (/ (- x (* y z)) t_1)))
   (if (<= t_3 -5e-321)
     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 * (z / t_1));
	double t_3 = (x - (y * z)) / t_1;
	double tmp;
	if (t_3 <= -5e-321) {
		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 * (z / t_1));
	double t_3 = (x - (y * z)) / t_1;
	double tmp;
	if (t_3 <= -5e-321) {
		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 * (z / t_1))
	t_3 = (x - (y * z)) / t_1
	tmp = 0
	if t_3 <= -5e-321:
		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(z / t_1)))
	t_3 = Float64(Float64(x - Float64(y * z)) / t_1)
	tmp = 0.0
	if (t_3 <= -5e-321)
		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 * (z / t_1));
	t_3 = (x - (y * z)) / t_1;
	tmp = 0.0;
	if (t_3 <= -5e-321)
		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[(z / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[t$95$3, -5e-321], 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} - y \cdot \frac{z}{t_1}\\
t_3 := \frac{x - y \cdot z}{t_1}\\
\mathbf{if}\;t_3 \leq -5 \cdot 10^{-321}:\\
\;\;\;\;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.5
\[\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))) < -4.99994e-321 or -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. Simplified4.6

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
      Proof
      (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 z a))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (Rewrite<= *-commutative_binary64 (*.f64 a z)))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in x around 0 4.6

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

      \[\leadsto \color{blue}{\frac{x}{t - z \cdot a} - \frac{y}{t - z \cdot a} \cdot z} \]
      Proof
      (-.f64 (/.f64 x (-.f64 t (*.f64 z a))) (*.f64 (/.f64 y (-.f64 t (*.f64 z a))) z)): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 x (-.f64 t (*.f64 z a))) (Rewrite<= associate-/r/_binary64 (/.f64 y (/.f64 (-.f64 t (*.f64 z a)) z)))): 10 points increase in error, 34 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 x (-.f64 t (*.f64 z a))) (neg.f64 (/.f64 y (/.f64 (-.f64 t (*.f64 z a)) z))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 x (-.f64 t (Rewrite<= *-commutative_binary64 (*.f64 a z)))) (neg.f64 (/.f64 y (/.f64 (-.f64 t (*.f64 z a)) z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 x (-.f64 t (*.f64 a z))) (neg.f64 (/.f64 y (/.f64 (-.f64 t (Rewrite<= *-commutative_binary64 (*.f64 a z))) z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 x (-.f64 t (*.f64 a z))) (neg.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y z) (-.f64 t (*.f64 a z)))))): 49 points increase in error, 6 points decrease in error
      (+.f64 (/.f64 x (-.f64 t (*.f64 a z))) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 y z) (-.f64 t (*.f64 a z)))))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr4.0

      \[\leadsto \frac{x}{t - z \cdot a} - \color{blue}{\frac{z}{\frac{t - z \cdot a}{y}}} \]
    6. Applied egg-rr1.6

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

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

    1. Initial program 25.1

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

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
      Proof
      (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 z a))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (Rewrite<= *-commutative_binary64 (*.f64 a z)))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around inf 27.4

      \[\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}} \]
    4. Simplified15.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, 3 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))))): 1 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)))): 21 points increase in error, 11 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)))))): 5 points increase in error, 12 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. Simplified64.0

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
      Proof
      (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (*.f64 z a))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 x (*.f64 y z)) (-.f64 t (Rewrite<= *-commutative_binary64 (*.f64 a z)))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in z around inf 0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x - y \cdot z}{t - z \cdot a} \leq -5 \cdot 10^{-321}:\\ \;\;\;\;\frac{x}{t - z \cdot a} - y \cdot \frac{z}{t - z \cdot a}\\ \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} - y \cdot \frac{z}{t - z \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]

Alternatives

Alternative 1
Error5.2
Cost3020
\[\begin{array}{l} t_1 := \frac{x - y \cdot z}{t - z \cdot a}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-321}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\frac{y}{a} - \frac{\frac{x}{z}}{a}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+304}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 2
Error5.0
Cost3020
\[\begin{array}{l} t_1 := \frac{x - y \cdot z}{t - z \cdot a}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-321}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\frac{y}{a} + \frac{\frac{y}{a} \cdot \frac{t}{a} - \frac{x}{a}}{z}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+304}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 3
Error18.1
Cost972
\[\begin{array}{l} \mathbf{if}\;z \leq -2500000000000:\\ \;\;\;\;\frac{y - \frac{x}{z}}{a}\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-216}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{elif}\;z \leq 1820:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a} - \frac{\frac{x}{z}}{a}\\ \end{array} \]
Alternative 4
Error22.8
Cost844
\[\begin{array}{l} \mathbf{if}\;z \leq -1.55 \cdot 10^{+97}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-216}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{elif}\;z \leq 1.15 \cdot 10^{+70}:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 5
Error18.2
Cost844
\[\begin{array}{l} t_1 := \frac{y - \frac{x}{z}}{a}\\ \mathbf{if}\;z \leq -132000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.4 \cdot 10^{-216}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{elif}\;z \leq 1550:\\ \;\;\;\;\frac{x - y \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error22.5
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -9.2 \cdot 10^{+102}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 10^{+47}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 7
Error29.6
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -0.024:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 4.9 \cdot 10^{+40}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
Alternative 8
Error41.7
Cost192
\[\frac{x}{t} \]

Error

Reproduce

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