Diagrams.Solve.Tridiagonal:solveTriDiagonal from diagrams-solve-0.1, A

Percentage Accurate: 85.4% → 91.8%
Time: 10.8s
Alternatives: 6
Speedup: 0.5×

Specification

?
\[\begin{array}{l} \\ \frac{x - y \cdot z}{t - a \cdot z} \end{array} \]
(FPCore (x y z t a) :precision binary64 (/ (- x (* y z)) (- t (* a z))))
double code(double x, double y, double z, double t, double a) {
	return (x - (y * z)) / (t - (a * z));
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = (x - (y * z)) / (t - (a * z))
end function
public static double code(double x, double y, double z, double t, double a) {
	return (x - (y * z)) / (t - (a * z));
}
def code(x, y, z, t, a):
	return (x - (y * z)) / (t - (a * z))
function code(x, y, z, t, a)
	return Float64(Float64(x - Float64(y * z)) / Float64(t - Float64(a * z)))
end
function tmp = code(x, y, z, t, a)
	tmp = (x - (y * z)) / (t - (a * z));
end
code[x_, y_, z_, t_, a_] := N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / N[(t - N[(a * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x - y \cdot z}{t - a \cdot z}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 85.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x - y \cdot z}{t - a \cdot z} \end{array} \]
(FPCore (x y z t a) :precision binary64 (/ (- x (* y z)) (- t (* a z))))
double code(double x, double y, double z, double t, double a) {
	return (x - (y * z)) / (t - (a * z));
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = (x - (y * z)) / (t - (a * z))
end function
public static double code(double x, double y, double z, double t, double a) {
	return (x - (y * z)) / (t - (a * z));
}
def code(x, y, z, t, a):
	return (x - (y * z)) / (t - (a * z))
function code(x, y, z, t, a)
	return Float64(Float64(x - Float64(y * z)) / Float64(t - Float64(a * z)))
end
function tmp = code(x, y, z, t, a)
	tmp = (x - (y * z)) / (t - (a * z));
end
code[x_, y_, z_, t_, a_] := N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] / N[(t - N[(a * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x - y \cdot z}{t - a \cdot z}
\end{array}

Alternative 1: 91.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4.6 \cdot 10^{+119} \lor \neg \left(z \leq 8 \cdot 10^{+136}\right):\\ \;\;\;\;\frac{y}{a - \frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - z \cdot y}{t - z \cdot a}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (if (or (<= z -4.6e+119) (not (<= z 8e+136)))
   (/ y (- a (/ t z)))
   (/ (- x (* z y)) (- t (* z a)))))
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((z <= -4.6e+119) || !(z <= 8e+136)) {
		tmp = y / (a - (t / z));
	} else {
		tmp = (x - (z * y)) / (t - (z * a));
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8) :: tmp
    if ((z <= (-4.6d+119)) .or. (.not. (z <= 8d+136))) then
        tmp = y / (a - (t / z))
    else
        tmp = (x - (z * y)) / (t - (z * a))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((z <= -4.6e+119) || !(z <= 8e+136)) {
		tmp = y / (a - (t / z));
	} else {
		tmp = (x - (z * y)) / (t - (z * a));
	}
	return tmp;
}
def code(x, y, z, t, a):
	tmp = 0
	if (z <= -4.6e+119) or not (z <= 8e+136):
		tmp = y / (a - (t / z))
	else:
		tmp = (x - (z * y)) / (t - (z * a))
	return tmp
function code(x, y, z, t, a)
	tmp = 0.0
	if ((z <= -4.6e+119) || !(z <= 8e+136))
		tmp = Float64(y / Float64(a - Float64(t / z)));
	else
		tmp = Float64(Float64(x - Float64(z * y)) / Float64(t - Float64(z * a)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	tmp = 0.0;
	if ((z <= -4.6e+119) || ~((z <= 8e+136)))
		tmp = y / (a - (t / z));
	else
		tmp = (x - (z * y)) / (t - (z * a));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -4.6e+119], N[Not[LessEqual[z, 8e+136]], $MachinePrecision]], N[(y / N[(a - N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision] / N[(t - N[(z * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+119} \lor \neg \left(z \leq 8 \cdot 10^{+136}\right):\\
\;\;\;\;\frac{y}{a - \frac{t}{z}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x - z \cdot y}{t - z \cdot a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -4.6000000000000001e119 or 8.00000000000000047e136 < z

    1. Initial program 51.3%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Step-by-step derivation
      1. *-commutative51.3%

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

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 44.2%

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot z}{t - a \cdot z}} \]
    6. Step-by-step derivation
      1. mul-1-neg44.2%

        \[\leadsto \color{blue}{-\frac{y \cdot z}{t - a \cdot z}} \]
      2. associate-/l*64.1%

        \[\leadsto -\color{blue}{y \cdot \frac{z}{t - a \cdot z}} \]
      3. distribute-rgt-neg-in64.1%

        \[\leadsto \color{blue}{y \cdot \left(-\frac{z}{t - a \cdot z}\right)} \]
      4. distribute-neg-frac264.1%

        \[\leadsto y \cdot \color{blue}{\frac{z}{-\left(t - a \cdot z\right)}} \]
      5. sub-neg64.1%

        \[\leadsto y \cdot \frac{z}{-\color{blue}{\left(t + \left(-a \cdot z\right)\right)}} \]
      6. mul-1-neg64.1%

        \[\leadsto y \cdot \frac{z}{-\left(t + \color{blue}{-1 \cdot \left(a \cdot z\right)}\right)} \]
      7. +-commutative64.1%

        \[\leadsto y \cdot \frac{z}{-\color{blue}{\left(-1 \cdot \left(a \cdot z\right) + t\right)}} \]
      8. mul-1-neg64.1%

        \[\leadsto y \cdot \frac{z}{-\left(\color{blue}{\left(-a \cdot z\right)} + t\right)} \]
      9. distribute-rgt-neg-in64.1%

        \[\leadsto y \cdot \frac{z}{-\left(\color{blue}{a \cdot \left(-z\right)} + t\right)} \]
      10. fma-undefine64.1%

        \[\leadsto y \cdot \frac{z}{-\color{blue}{\mathsf{fma}\left(a, -z, t\right)}} \]
      11. neg-sub064.1%

        \[\leadsto y \cdot \frac{z}{\color{blue}{0 - \mathsf{fma}\left(a, -z, t\right)}} \]
      12. fma-undefine64.1%

        \[\leadsto y \cdot \frac{z}{0 - \color{blue}{\left(a \cdot \left(-z\right) + t\right)}} \]
      13. distribute-rgt-neg-in64.1%

        \[\leadsto y \cdot \frac{z}{0 - \left(\color{blue}{\left(-a \cdot z\right)} + t\right)} \]
      14. mul-1-neg64.1%

        \[\leadsto y \cdot \frac{z}{0 - \left(\color{blue}{-1 \cdot \left(a \cdot z\right)} + t\right)} \]
      15. associate-*r*64.1%

        \[\leadsto y \cdot \frac{z}{0 - \left(\color{blue}{\left(-1 \cdot a\right) \cdot z} + t\right)} \]
      16. neg-mul-164.1%

        \[\leadsto y \cdot \frac{z}{0 - \left(\color{blue}{\left(-a\right)} \cdot z + t\right)} \]
      17. *-commutative64.1%

        \[\leadsto y \cdot \frac{z}{0 - \left(\color{blue}{z \cdot \left(-a\right)} + t\right)} \]
      18. associate--r+64.1%

        \[\leadsto y \cdot \frac{z}{\color{blue}{\left(0 - z \cdot \left(-a\right)\right) - t}} \]
      19. neg-sub064.1%

        \[\leadsto y \cdot \frac{z}{\color{blue}{\left(-z \cdot \left(-a\right)\right)} - t} \]
      20. distribute-rgt-neg-out64.1%

        \[\leadsto y \cdot \frac{z}{\left(-\color{blue}{\left(-z \cdot a\right)}\right) - t} \]
      21. remove-double-neg64.1%

        \[\leadsto y \cdot \frac{z}{\color{blue}{z \cdot a} - t} \]
    7. Simplified64.1%

      \[\leadsto \color{blue}{y \cdot \frac{z}{z \cdot a - t}} \]
    8. Step-by-step derivation
      1. clear-num64.1%

        \[\leadsto y \cdot \color{blue}{\frac{1}{\frac{z \cdot a - t}{z}}} \]
      2. un-div-inv64.3%

        \[\leadsto \color{blue}{\frac{y}{\frac{z \cdot a - t}{z}}} \]
      3. *-commutative64.3%

        \[\leadsto \frac{y}{\frac{\color{blue}{a \cdot z} - t}{z}} \]
    9. Applied egg-rr64.3%

      \[\leadsto \color{blue}{\frac{y}{\frac{a \cdot z - t}{z}}} \]
    10. Taylor expanded in a around 0 90.4%

      \[\leadsto \frac{y}{\color{blue}{a + -1 \cdot \frac{t}{z}}} \]
    11. Step-by-step derivation
      1. neg-mul-190.4%

        \[\leadsto \frac{y}{a + \color{blue}{\left(-\frac{t}{z}\right)}} \]
      2. unsub-neg90.4%

        \[\leadsto \frac{y}{\color{blue}{a - \frac{t}{z}}} \]
    12. Simplified90.4%

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

    if -4.6000000000000001e119 < z < 8.00000000000000047e136

    1. Initial program 94.9%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification93.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.6 \cdot 10^{+119} \lor \neg \left(z \leq 8 \cdot 10^{+136}\right):\\ \;\;\;\;\frac{y}{a - \frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x - z \cdot y}{t - z \cdot a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 53.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{-25}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 3 \cdot 10^{-149}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;z \leq 3300:\\ \;\;\;\;\frac{\frac{x}{a}}{-z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (if (<= z -4.5e-25)
   (/ y a)
   (if (<= z 3e-149) (/ x t) (if (<= z 3300.0) (/ (/ x a) (- z)) (/ y a)))))
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if (z <= -4.5e-25) {
		tmp = y / a;
	} else if (z <= 3e-149) {
		tmp = x / t;
	} else if (z <= 3300.0) {
		tmp = (x / a) / -z;
	} else {
		tmp = y / a;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8) :: tmp
    if (z <= (-4.5d-25)) then
        tmp = y / a
    else if (z <= 3d-149) then
        tmp = x / t
    else if (z <= 3300.0d0) then
        tmp = (x / a) / -z
    else
        tmp = y / a
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	double tmp;
	if (z <= -4.5e-25) {
		tmp = y / a;
	} else if (z <= 3e-149) {
		tmp = x / t;
	} else if (z <= 3300.0) {
		tmp = (x / a) / -z;
	} else {
		tmp = y / a;
	}
	return tmp;
}
def code(x, y, z, t, a):
	tmp = 0
	if z <= -4.5e-25:
		tmp = y / a
	elif z <= 3e-149:
		tmp = x / t
	elif z <= 3300.0:
		tmp = (x / a) / -z
	else:
		tmp = y / a
	return tmp
function code(x, y, z, t, a)
	tmp = 0.0
	if (z <= -4.5e-25)
		tmp = Float64(y / a);
	elseif (z <= 3e-149)
		tmp = Float64(x / t);
	elseif (z <= 3300.0)
		tmp = Float64(Float64(x / a) / Float64(-z));
	else
		tmp = Float64(y / a);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	tmp = 0.0;
	if (z <= -4.5e-25)
		tmp = y / a;
	elseif (z <= 3e-149)
		tmp = x / t;
	elseif (z <= 3300.0)
		tmp = (x / a) / -z;
	else
		tmp = y / a;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -4.5e-25], N[(y / a), $MachinePrecision], If[LessEqual[z, 3e-149], N[(x / t), $MachinePrecision], If[LessEqual[z, 3300.0], N[(N[(x / a), $MachinePrecision] / (-z)), $MachinePrecision], N[(y / a), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-25}:\\
\;\;\;\;\frac{y}{a}\\

\mathbf{elif}\;z \leq 3 \cdot 10^{-149}:\\
\;\;\;\;\frac{x}{t}\\

\mathbf{elif}\;z \leq 3300:\\
\;\;\;\;\frac{\frac{x}{a}}{-z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -4.5000000000000001e-25 or 3300 < z

    1. Initial program 64.8%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Step-by-step derivation
      1. *-commutative64.8%

        \[\leadsto \frac{x - y \cdot z}{t - \color{blue}{z \cdot a}} \]
    3. Simplified64.8%

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
    4. Add Preprocessing
    5. Taylor expanded in z around inf 64.0%

      \[\leadsto \color{blue}{\frac{y}{a}} \]

    if -4.5000000000000001e-25 < z < 3.0000000000000002e-149

    1. Initial program 99.8%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Step-by-step derivation
      1. *-commutative99.8%

        \[\leadsto \frac{x - y \cdot z}{t - \color{blue}{z \cdot a}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
    4. Add Preprocessing
    5. Taylor expanded in z around 0 59.1%

      \[\leadsto \color{blue}{\frac{x}{t}} \]

    if 3.0000000000000002e-149 < z < 3300

    1. Initial program 99.8%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Step-by-step derivation
      1. *-commutative99.8%

        \[\leadsto \frac{x - y \cdot z}{t - \color{blue}{z \cdot a}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
    4. Add Preprocessing
    5. Taylor expanded in t around 0 55.1%

      \[\leadsto \color{blue}{-1 \cdot \frac{x - y \cdot z}{a \cdot z}} \]
    6. Step-by-step derivation
      1. mul-1-neg55.1%

        \[\leadsto \color{blue}{-\frac{x - y \cdot z}{a \cdot z}} \]
      2. associate-/r*55.2%

        \[\leadsto -\color{blue}{\frac{\frac{x - y \cdot z}{a}}{z}} \]
      3. sub-neg55.2%

        \[\leadsto -\frac{\frac{\color{blue}{x + \left(-y \cdot z\right)}}{a}}{z} \]
      4. distribute-rgt-neg-out55.2%

        \[\leadsto -\frac{\frac{x + \color{blue}{y \cdot \left(-z\right)}}{a}}{z} \]
      5. +-commutative55.2%

        \[\leadsto -\frac{\frac{\color{blue}{y \cdot \left(-z\right) + x}}{a}}{z} \]
      6. fma-define55.2%

        \[\leadsto -\frac{\frac{\color{blue}{\mathsf{fma}\left(y, -z, x\right)}}{a}}{z} \]
    7. Simplified55.2%

      \[\leadsto \color{blue}{-\frac{\frac{\mathsf{fma}\left(y, -z, x\right)}{a}}{z}} \]
    8. Taylor expanded in y around 0 43.0%

      \[\leadsto -\frac{\color{blue}{\frac{x}{a}}}{z} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification59.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{-25}:\\ \;\;\;\;\frac{y}{a}\\ \mathbf{elif}\;z \leq 3 \cdot 10^{-149}:\\ \;\;\;\;\frac{x}{t}\\ \mathbf{elif}\;z \leq 3300:\\ \;\;\;\;\frac{\frac{x}{a}}{-z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 73.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -7.5 \cdot 10^{-28} \lor \neg \left(z \leq 950\right):\\ \;\;\;\;\frac{y}{a - \frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (if (or (<= z -7.5e-28) (not (<= z 950.0)))
   (/ y (- a (/ t z)))
   (/ x (- t (* z a)))))
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((z <= -7.5e-28) || !(z <= 950.0)) {
		tmp = y / (a - (t / z));
	} else {
		tmp = x / (t - (z * a));
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8) :: tmp
    if ((z <= (-7.5d-28)) .or. (.not. (z <= 950.0d0))) then
        tmp = y / (a - (t / z))
    else
        tmp = x / (t - (z * a))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((z <= -7.5e-28) || !(z <= 950.0)) {
		tmp = y / (a - (t / z));
	} else {
		tmp = x / (t - (z * a));
	}
	return tmp;
}
def code(x, y, z, t, a):
	tmp = 0
	if (z <= -7.5e-28) or not (z <= 950.0):
		tmp = y / (a - (t / z))
	else:
		tmp = x / (t - (z * a))
	return tmp
function code(x, y, z, t, a)
	tmp = 0.0
	if ((z <= -7.5e-28) || !(z <= 950.0))
		tmp = Float64(y / Float64(a - Float64(t / z)));
	else
		tmp = Float64(x / Float64(t - Float64(z * a)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	tmp = 0.0;
	if ((z <= -7.5e-28) || ~((z <= 950.0)))
		tmp = y / (a - (t / z));
	else
		tmp = x / (t - (z * a));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -7.5e-28], N[Not[LessEqual[z, 950.0]], $MachinePrecision]], N[(y / N[(a - N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(t - N[(z * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{-28} \lor \neg \left(z \leq 950\right):\\
\;\;\;\;\frac{y}{a - \frac{t}{z}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{t - z \cdot a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -7.5000000000000003e-28 or 950 < z

    1. Initial program 65.0%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Step-by-step derivation
      1. *-commutative65.0%

        \[\leadsto \frac{x - y \cdot z}{t - \color{blue}{z \cdot a}} \]
    3. Simplified65.0%

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 51.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot z}{t - a \cdot z}} \]
    6. Step-by-step derivation
      1. mul-1-neg51.9%

        \[\leadsto \color{blue}{-\frac{y \cdot z}{t - a \cdot z}} \]
      2. associate-/l*66.3%

        \[\leadsto -\color{blue}{y \cdot \frac{z}{t - a \cdot z}} \]
      3. distribute-rgt-neg-in66.3%

        \[\leadsto \color{blue}{y \cdot \left(-\frac{z}{t - a \cdot z}\right)} \]
      4. distribute-neg-frac266.3%

        \[\leadsto y \cdot \color{blue}{\frac{z}{-\left(t - a \cdot z\right)}} \]
      5. sub-neg66.3%

        \[\leadsto y \cdot \frac{z}{-\color{blue}{\left(t + \left(-a \cdot z\right)\right)}} \]
      6. mul-1-neg66.3%

        \[\leadsto y \cdot \frac{z}{-\left(t + \color{blue}{-1 \cdot \left(a \cdot z\right)}\right)} \]
      7. +-commutative66.3%

        \[\leadsto y \cdot \frac{z}{-\color{blue}{\left(-1 \cdot \left(a \cdot z\right) + t\right)}} \]
      8. mul-1-neg66.3%

        \[\leadsto y \cdot \frac{z}{-\left(\color{blue}{\left(-a \cdot z\right)} + t\right)} \]
      9. distribute-rgt-neg-in66.3%

        \[\leadsto y \cdot \frac{z}{-\left(\color{blue}{a \cdot \left(-z\right)} + t\right)} \]
      10. fma-undefine66.3%

        \[\leadsto y \cdot \frac{z}{-\color{blue}{\mathsf{fma}\left(a, -z, t\right)}} \]
      11. neg-sub066.3%

        \[\leadsto y \cdot \frac{z}{\color{blue}{0 - \mathsf{fma}\left(a, -z, t\right)}} \]
      12. fma-undefine66.3%

        \[\leadsto y \cdot \frac{z}{0 - \color{blue}{\left(a \cdot \left(-z\right) + t\right)}} \]
      13. distribute-rgt-neg-in66.3%

        \[\leadsto y \cdot \frac{z}{0 - \left(\color{blue}{\left(-a \cdot z\right)} + t\right)} \]
      14. mul-1-neg66.3%

        \[\leadsto y \cdot \frac{z}{0 - \left(\color{blue}{-1 \cdot \left(a \cdot z\right)} + t\right)} \]
      15. associate-*r*66.3%

        \[\leadsto y \cdot \frac{z}{0 - \left(\color{blue}{\left(-1 \cdot a\right) \cdot z} + t\right)} \]
      16. neg-mul-166.3%

        \[\leadsto y \cdot \frac{z}{0 - \left(\color{blue}{\left(-a\right)} \cdot z + t\right)} \]
      17. *-commutative66.3%

        \[\leadsto y \cdot \frac{z}{0 - \left(\color{blue}{z \cdot \left(-a\right)} + t\right)} \]
      18. associate--r+66.3%

        \[\leadsto y \cdot \frac{z}{\color{blue}{\left(0 - z \cdot \left(-a\right)\right) - t}} \]
      19. neg-sub066.3%

        \[\leadsto y \cdot \frac{z}{\color{blue}{\left(-z \cdot \left(-a\right)\right)} - t} \]
      20. distribute-rgt-neg-out66.3%

        \[\leadsto y \cdot \frac{z}{\left(-\color{blue}{\left(-z \cdot a\right)}\right) - t} \]
      21. remove-double-neg66.3%

        \[\leadsto y \cdot \frac{z}{\color{blue}{z \cdot a} - t} \]
    7. Simplified66.3%

      \[\leadsto \color{blue}{y \cdot \frac{z}{z \cdot a - t}} \]
    8. Step-by-step derivation
      1. clear-num66.2%

        \[\leadsto y \cdot \color{blue}{\frac{1}{\frac{z \cdot a - t}{z}}} \]
      2. un-div-inv66.4%

        \[\leadsto \color{blue}{\frac{y}{\frac{z \cdot a - t}{z}}} \]
      3. *-commutative66.4%

        \[\leadsto \frac{y}{\frac{\color{blue}{a \cdot z} - t}{z}} \]
    9. Applied egg-rr66.4%

      \[\leadsto \color{blue}{\frac{y}{\frac{a \cdot z - t}{z}}} \]
    10. Taylor expanded in a around 0 83.0%

      \[\leadsto \frac{y}{\color{blue}{a + -1 \cdot \frac{t}{z}}} \]
    11. Step-by-step derivation
      1. neg-mul-183.0%

        \[\leadsto \frac{y}{a + \color{blue}{\left(-\frac{t}{z}\right)}} \]
      2. unsub-neg83.0%

        \[\leadsto \frac{y}{\color{blue}{a - \frac{t}{z}}} \]
    12. Simplified83.0%

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

    if -7.5000000000000003e-28 < z < 950

    1. Initial program 99.8%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Step-by-step derivation
      1. *-commutative99.8%

        \[\leadsto \frac{x - y \cdot z}{t - \color{blue}{z \cdot a}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 75.4%

      \[\leadsto \color{blue}{\frac{x}{t - a \cdot z}} \]
    6. Step-by-step derivation
      1. *-commutative75.4%

        \[\leadsto \frac{x}{t - \color{blue}{z \cdot a}} \]
    7. Simplified75.4%

      \[\leadsto \color{blue}{\frac{x}{t - z \cdot a}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -7.5 \cdot 10^{-28} \lor \neg \left(z \leq 950\right):\\ \;\;\;\;\frac{y}{a - \frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 63.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2.9 \cdot 10^{-12} \lor \neg \left(z \leq 1050\right):\\ \;\;\;\;\frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (if (or (<= z -2.9e-12) (not (<= z 1050.0))) (/ y a) (/ x (- t (* z a)))))
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((z <= -2.9e-12) || !(z <= 1050.0)) {
		tmp = y / a;
	} else {
		tmp = x / (t - (z * a));
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8) :: tmp
    if ((z <= (-2.9d-12)) .or. (.not. (z <= 1050.0d0))) then
        tmp = y / a
    else
        tmp = x / (t - (z * a))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((z <= -2.9e-12) || !(z <= 1050.0)) {
		tmp = y / a;
	} else {
		tmp = x / (t - (z * a));
	}
	return tmp;
}
def code(x, y, z, t, a):
	tmp = 0
	if (z <= -2.9e-12) or not (z <= 1050.0):
		tmp = y / a
	else:
		tmp = x / (t - (z * a))
	return tmp
function code(x, y, z, t, a)
	tmp = 0.0
	if ((z <= -2.9e-12) || !(z <= 1050.0))
		tmp = Float64(y / a);
	else
		tmp = Float64(x / Float64(t - Float64(z * a)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	tmp = 0.0;
	if ((z <= -2.9e-12) || ~((z <= 1050.0)))
		tmp = y / a;
	else
		tmp = x / (t - (z * a));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -2.9e-12], N[Not[LessEqual[z, 1050.0]], $MachinePrecision]], N[(y / a), $MachinePrecision], N[(x / N[(t - N[(z * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{-12} \lor \neg \left(z \leq 1050\right):\\
\;\;\;\;\frac{y}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{t - z \cdot a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.9000000000000002e-12 or 1050 < z

    1. Initial program 64.2%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Step-by-step derivation
      1. *-commutative64.2%

        \[\leadsto \frac{x - y \cdot z}{t - \color{blue}{z \cdot a}} \]
    3. Simplified64.2%

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
    4. Add Preprocessing
    5. Taylor expanded in z around inf 64.9%

      \[\leadsto \color{blue}{\frac{y}{a}} \]

    if -2.9000000000000002e-12 < z < 1050

    1. Initial program 99.8%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Step-by-step derivation
      1. *-commutative99.8%

        \[\leadsto \frac{x - y \cdot z}{t - \color{blue}{z \cdot a}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 74.4%

      \[\leadsto \color{blue}{\frac{x}{t - a \cdot z}} \]
    6. Step-by-step derivation
      1. *-commutative74.4%

        \[\leadsto \frac{x}{t - \color{blue}{z \cdot a}} \]
    7. Simplified74.4%

      \[\leadsto \color{blue}{\frac{x}{t - z \cdot a}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification69.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.9 \cdot 10^{-12} \lor \neg \left(z \leq 1050\right):\\ \;\;\;\;\frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t - z \cdot a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 54.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.05 \cdot 10^{-24} \lor \neg \left(z \leq 1900\right):\\ \;\;\;\;\frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (if (or (<= z -1.05e-24) (not (<= z 1900.0))) (/ y a) (/ x t)))
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((z <= -1.05e-24) || !(z <= 1900.0)) {
		tmp = y / a;
	} else {
		tmp = x / t;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8) :: tmp
    if ((z <= (-1.05d-24)) .or. (.not. (z <= 1900.0d0))) then
        tmp = y / a
    else
        tmp = x / t
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((z <= -1.05e-24) || !(z <= 1900.0)) {
		tmp = y / a;
	} else {
		tmp = x / t;
	}
	return tmp;
}
def code(x, y, z, t, a):
	tmp = 0
	if (z <= -1.05e-24) or not (z <= 1900.0):
		tmp = y / a
	else:
		tmp = x / t
	return tmp
function code(x, y, z, t, a)
	tmp = 0.0
	if ((z <= -1.05e-24) || !(z <= 1900.0))
		tmp = Float64(y / a);
	else
		tmp = Float64(x / t);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	tmp = 0.0;
	if ((z <= -1.05e-24) || ~((z <= 1900.0)))
		tmp = y / a;
	else
		tmp = x / t;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -1.05e-24], N[Not[LessEqual[z, 1900.0]], $MachinePrecision]], N[(y / a), $MachinePrecision], N[(x / t), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{-24} \lor \neg \left(z \leq 1900\right):\\
\;\;\;\;\frac{y}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{t}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.05e-24 or 1900 < z

    1. Initial program 64.8%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Step-by-step derivation
      1. *-commutative64.8%

        \[\leadsto \frac{x - y \cdot z}{t - \color{blue}{z \cdot a}} \]
    3. Simplified64.8%

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
    4. Add Preprocessing
    5. Taylor expanded in z around inf 64.0%

      \[\leadsto \color{blue}{\frac{y}{a}} \]

    if -1.05e-24 < z < 1900

    1. Initial program 99.8%

      \[\frac{x - y \cdot z}{t - a \cdot z} \]
    2. Step-by-step derivation
      1. *-commutative99.8%

        \[\leadsto \frac{x - y \cdot z}{t - \color{blue}{z \cdot a}} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
    4. Add Preprocessing
    5. Taylor expanded in z around 0 51.6%

      \[\leadsto \color{blue}{\frac{x}{t}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.05 \cdot 10^{-24} \lor \neg \left(z \leq 1900\right):\\ \;\;\;\;\frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 36.3% accurate, 3.7× speedup?

\[\begin{array}{l} \\ \frac{x}{t} \end{array} \]
(FPCore (x y z t a) :precision binary64 (/ x t))
double code(double x, double y, double z, double t, double a) {
	return x / t;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = x / t
end function
public static double code(double x, double y, double z, double t, double a) {
	return x / t;
}
def code(x, y, z, t, a):
	return x / t
function code(x, y, z, t, a)
	return Float64(x / t)
end
function tmp = code(x, y, z, t, a)
	tmp = x / t;
end
code[x_, y_, z_, t_, a_] := N[(x / t), $MachinePrecision]
\begin{array}{l}

\\
\frac{x}{t}
\end{array}
Derivation
  1. Initial program 81.8%

    \[\frac{x - y \cdot z}{t - a \cdot z} \]
  2. Step-by-step derivation
    1. *-commutative81.8%

      \[\leadsto \frac{x - y \cdot z}{t - \color{blue}{z \cdot a}} \]
  3. Simplified81.8%

    \[\leadsto \color{blue}{\frac{x - y \cdot z}{t - z \cdot a}} \]
  4. Add Preprocessing
  5. Taylor expanded in z around 0 31.5%

    \[\leadsto \color{blue}{\frac{x}{t}} \]
  6. Add Preprocessing

Developer Target 1: 97.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := t - a \cdot z\\ t_2 := \frac{x}{t\_1} - \frac{y}{\frac{t}{z} - a}\\ \mathbf{if}\;z < -32113435955957344:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;z < 3.5139522372978296 \cdot 10^{-86}:\\ \;\;\;\;\left(x - y \cdot z\right) \cdot \frac{1}{t\_1}\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (- t (* a z))) (t_2 (- (/ x t_1) (/ y (- (/ t z) a)))))
   (if (< z -32113435955957344.0)
     t_2
     (if (< z 3.5139522372978296e-86) (* (- x (* y z)) (/ 1.0 t_1)) t_2))))
double code(double x, double y, double z, double t, double a) {
	double t_1 = t - (a * z);
	double t_2 = (x / t_1) - (y / ((t / z) - a));
	double tmp;
	if (z < -32113435955957344.0) {
		tmp = t_2;
	} else if (z < 3.5139522372978296e-86) {
		tmp = (x - (y * z)) * (1.0 / t_1);
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = t - (a * z)
    t_2 = (x / t_1) - (y / ((t / z) - a))
    if (z < (-32113435955957344.0d0)) then
        tmp = t_2
    else if (z < 3.5139522372978296d-86) then
        tmp = (x - (y * z)) * (1.0d0 / t_1)
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	double t_1 = t - (a * z);
	double t_2 = (x / t_1) - (y / ((t / z) - a));
	double tmp;
	if (z < -32113435955957344.0) {
		tmp = t_2;
	} else if (z < 3.5139522372978296e-86) {
		tmp = (x - (y * z)) * (1.0 / t_1);
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t, a):
	t_1 = t - (a * z)
	t_2 = (x / t_1) - (y / ((t / z) - a))
	tmp = 0
	if z < -32113435955957344.0:
		tmp = t_2
	elif z < 3.5139522372978296e-86:
		tmp = (x - (y * z)) * (1.0 / t_1)
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t, a)
	t_1 = Float64(t - Float64(a * z))
	t_2 = Float64(Float64(x / t_1) - Float64(y / Float64(Float64(t / z) - a)))
	tmp = 0.0
	if (z < -32113435955957344.0)
		tmp = t_2;
	elseif (z < 3.5139522372978296e-86)
		tmp = Float64(Float64(x - Float64(y * z)) * Float64(1.0 / t_1));
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = t - (a * z);
	t_2 = (x / t_1) - (y / ((t / z) - a));
	tmp = 0.0;
	if (z < -32113435955957344.0)
		tmp = t_2;
	elseif (z < 3.5139522372978296e-86)
		tmp = (x - (y * z)) * (1.0 / t_1);
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(t - N[(a * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x / t$95$1), $MachinePrecision] - N[(y / N[(N[(t / z), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[z, -32113435955957344.0], t$95$2, If[Less[z, 3.5139522372978296e-86], N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := t - a \cdot z\\
t_2 := \frac{x}{t\_1} - \frac{y}{\frac{t}{z} - a}\\
\mathbf{if}\;z < -32113435955957344:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;z < 3.5139522372978296 \cdot 10^{-86}:\\
\;\;\;\;\left(x - y \cdot z\right) \cdot \frac{1}{t\_1}\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}

Reproduce

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

  :alt
  (! :herbie-platform default (if (< z -32113435955957344) (- (/ x (- t (* a z))) (/ y (- (/ t z) a))) (if (< z 4392440296622287/125000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (* (- x (* y z)) (/ 1 (- t (* a z)))) (- (/ x (- t (* a z))) (/ y (- (/ t z) a))))))

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