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

Percentage Accurate: 95.6% → 97.7%
Time: 9.2s
Alternatives: 6
Speedup: 0.5×

Specification

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

\\
\frac{x}{y - z \cdot t}
\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: 95.6% accurate, 1.0× speedup?

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

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

Alternative 1: 97.7% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y, z, t] = \mathsf{sort}([x, y, z, t])\\ \\ \begin{array}{l} \mathbf{if}\;z \cdot t \leq 10^{+244}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{-z}\\ \end{array} \end{array} \]
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (if (<= (* z t) 1e+244) (/ x (- y (* z t))) (/ (/ x t) (- z))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z * t) <= 1e+244) {
		tmp = x / (y - (z * t));
	} else {
		tmp = (x / t) / -z;
	}
	return tmp;
}
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((z * t) <= 1d+244) then
        tmp = x / (y - (z * t))
    else
        tmp = (x / t) / -z
    end if
    code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((z * t) <= 1e+244) {
		tmp = x / (y - (z * t));
	} else {
		tmp = (x / t) / -z;
	}
	return tmp;
}
[x, y, z, t] = sort([x, y, z, t])
def code(x, y, z, t):
	tmp = 0
	if (z * t) <= 1e+244:
		tmp = x / (y - (z * t))
	else:
		tmp = (x / t) / -z
	return tmp
x, y, z, t = sort([x, y, z, t])
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(z * t) <= 1e+244)
		tmp = Float64(x / Float64(y - Float64(z * t)));
	else
		tmp = Float64(Float64(x / t) / Float64(-z));
	end
	return tmp
end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((z * t) <= 1e+244)
		tmp = x / (y - (z * t));
	else
		tmp = (x / t) / -z;
	end
	tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := If[LessEqual[N[(z * t), $MachinePrecision], 1e+244], N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / t), $MachinePrecision] / (-z)), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq 10^{+244}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < 1.00000000000000007e244

    1. Initial program 98.3%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing

    if 1.00000000000000007e244 < (*.f64 z t)

    1. Initial program 64.6%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 81.3%

      \[\leadsto \color{blue}{\frac{-1 \cdot \frac{x}{t} + -1 \cdot \frac{x \cdot y}{{t}^{2} \cdot z}}{z}} \]
    4. Step-by-step derivation
      1. distribute-lft-out81.3%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\frac{x}{t} + \frac{x \cdot y}{{t}^{2} \cdot z}\right)}}{z} \]
      2. associate-*r/81.3%

        \[\leadsto \color{blue}{-1 \cdot \frac{\frac{x}{t} + \frac{x \cdot y}{{t}^{2} \cdot z}}{z}} \]
      3. mul-1-neg81.3%

        \[\leadsto \color{blue}{-\frac{\frac{x}{t} + \frac{x \cdot y}{{t}^{2} \cdot z}}{z}} \]
      4. *-commutative81.3%

        \[\leadsto -\frac{\frac{x}{t} + \frac{x \cdot y}{\color{blue}{z \cdot {t}^{2}}}}{z} \]
    5. Simplified81.3%

      \[\leadsto \color{blue}{-\frac{\frac{x}{t} + \frac{x \cdot y}{z \cdot {t}^{2}}}{z}} \]
    6. Taylor expanded in t around inf 99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot t \leq 10^{+244}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{-z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 73.6% accurate, 0.3× speedup?

\[\begin{array}{l} [x, y, z, t] = \mathsf{sort}([x, y, z, t])\\ \\ \begin{array}{l} \mathbf{if}\;t \leq -0.00125 \lor \neg \left(t \leq 2.45 \cdot 10^{+36}\right) \land \left(t \leq 6.8 \cdot 10^{+78} \lor \neg \left(t \leq 2.4 \cdot 10^{+96}\right)\right):\\ \;\;\;\;\frac{\frac{x}{t}}{-z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \end{array} \]
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (if (or (<= t -0.00125)
         (and (not (<= t 2.45e+36)) (or (<= t 6.8e+78) (not (<= t 2.4e+96)))))
   (/ (/ x t) (- z))
   (/ x y)))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
	double tmp;
	if ((t <= -0.00125) || (!(t <= 2.45e+36) && ((t <= 6.8e+78) || !(t <= 2.4e+96)))) {
		tmp = (x / t) / -z;
	} else {
		tmp = x / y;
	}
	return tmp;
}
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((t <= (-0.00125d0)) .or. (.not. (t <= 2.45d+36)) .and. (t <= 6.8d+78) .or. (.not. (t <= 2.4d+96))) then
        tmp = (x / t) / -z
    else
        tmp = x / y
    end if
    code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((t <= -0.00125) || (!(t <= 2.45e+36) && ((t <= 6.8e+78) || !(t <= 2.4e+96)))) {
		tmp = (x / t) / -z;
	} else {
		tmp = x / y;
	}
	return tmp;
}
[x, y, z, t] = sort([x, y, z, t])
def code(x, y, z, t):
	tmp = 0
	if (t <= -0.00125) or (not (t <= 2.45e+36) and ((t <= 6.8e+78) or not (t <= 2.4e+96))):
		tmp = (x / t) / -z
	else:
		tmp = x / y
	return tmp
x, y, z, t = sort([x, y, z, t])
function code(x, y, z, t)
	tmp = 0.0
	if ((t <= -0.00125) || (!(t <= 2.45e+36) && ((t <= 6.8e+78) || !(t <= 2.4e+96))))
		tmp = Float64(Float64(x / t) / Float64(-z));
	else
		tmp = Float64(x / y);
	end
	return tmp
end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((t <= -0.00125) || (~((t <= 2.45e+36)) && ((t <= 6.8e+78) || ~((t <= 2.4e+96)))))
		tmp = (x / t) / -z;
	else
		tmp = x / y;
	end
	tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -0.00125], And[N[Not[LessEqual[t, 2.45e+36]], $MachinePrecision], Or[LessEqual[t, 6.8e+78], N[Not[LessEqual[t, 2.4e+96]], $MachinePrecision]]]], N[(N[(x / t), $MachinePrecision] / (-z)), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq -0.00125 \lor \neg \left(t \leq 2.45 \cdot 10^{+36}\right) \land \left(t \leq 6.8 \cdot 10^{+78} \lor \neg \left(t \leq 2.4 \cdot 10^{+96}\right)\right):\\
\;\;\;\;\frac{\frac{x}{t}}{-z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < -0.00125000000000000003 or 2.4499999999999999e36 < t < 6.80000000000000014e78 or 2.39999999999999993e96 < t

    1. Initial program 92.0%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing
    3. Taylor expanded in z around inf 61.4%

      \[\leadsto \color{blue}{\frac{-1 \cdot \frac{x}{t} + -1 \cdot \frac{x \cdot y}{{t}^{2} \cdot z}}{z}} \]
    4. Step-by-step derivation
      1. distribute-lft-out61.4%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(\frac{x}{t} + \frac{x \cdot y}{{t}^{2} \cdot z}\right)}}{z} \]
      2. associate-*r/61.4%

        \[\leadsto \color{blue}{-1 \cdot \frac{\frac{x}{t} + \frac{x \cdot y}{{t}^{2} \cdot z}}{z}} \]
      3. mul-1-neg61.4%

        \[\leadsto \color{blue}{-\frac{\frac{x}{t} + \frac{x \cdot y}{{t}^{2} \cdot z}}{z}} \]
      4. *-commutative61.4%

        \[\leadsto -\frac{\frac{x}{t} + \frac{x \cdot y}{\color{blue}{z \cdot {t}^{2}}}}{z} \]
    5. Simplified61.4%

      \[\leadsto \color{blue}{-\frac{\frac{x}{t} + \frac{x \cdot y}{z \cdot {t}^{2}}}{z}} \]
    6. Taylor expanded in t around inf 68.6%

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

    if -0.00125000000000000003 < t < 2.4499999999999999e36 or 6.80000000000000014e78 < t < 2.39999999999999993e96

    1. Initial program 99.3%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 73.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -0.00125 \lor \neg \left(t \leq 2.45 \cdot 10^{+36}\right) \land \left(t \leq 6.8 \cdot 10^{+78} \lor \neg \left(t \leq 2.4 \cdot 10^{+96}\right)\right):\\ \;\;\;\;\frac{\frac{x}{t}}{-z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 71.5% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y, z, t] = \mathsf{sort}([x, y, z, t])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{-49} \lor \neg \left(y \leq 1.1 \cdot 10^{-91}\right):\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z \cdot \left(-t\right)}\\ \end{array} \end{array} \]
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (if (or (<= y -1.05e-49) (not (<= y 1.1e-91))) (/ x y) (/ x (* z (- t)))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -1.05e-49) || !(y <= 1.1e-91)) {
		tmp = x / y;
	} else {
		tmp = x / (z * -t);
	}
	return tmp;
}
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((y <= (-1.05d-49)) .or. (.not. (y <= 1.1d-91))) then
        tmp = x / y
    else
        tmp = x / (z * -t)
    end if
    code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -1.05e-49) || !(y <= 1.1e-91)) {
		tmp = x / y;
	} else {
		tmp = x / (z * -t);
	}
	return tmp;
}
[x, y, z, t] = sort([x, y, z, t])
def code(x, y, z, t):
	tmp = 0
	if (y <= -1.05e-49) or not (y <= 1.1e-91):
		tmp = x / y
	else:
		tmp = x / (z * -t)
	return tmp
x, y, z, t = sort([x, y, z, t])
function code(x, y, z, t)
	tmp = 0.0
	if ((y <= -1.05e-49) || !(y <= 1.1e-91))
		tmp = Float64(x / y);
	else
		tmp = Float64(x / Float64(z * Float64(-t)));
	end
	return tmp
end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((y <= -1.05e-49) || ~((y <= 1.1e-91)))
		tmp = x / y;
	else
		tmp = x / (z * -t);
	end
	tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -1.05e-49], N[Not[LessEqual[y, 1.1e-91]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(x / N[(z * (-t)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-49} \lor \neg \left(y \leq 1.1 \cdot 10^{-91}\right):\\
\;\;\;\;\frac{x}{y}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{z \cdot \left(-t\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.0499999999999999e-49 or 1.1e-91 < y

    1. Initial program 94.7%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 75.8%

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

    if -1.0499999999999999e-49 < y < 1.1e-91

    1. Initial program 98.8%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 77.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{t \cdot z}} \]
    4. Step-by-step derivation
      1. associate-*r/77.5%

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{t \cdot z}} \]
      2. neg-mul-177.5%

        \[\leadsto \frac{\color{blue}{-x}}{t \cdot z} \]
    5. Simplified77.5%

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

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

Alternative 4: 58.4% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y, z, t] = \mathsf{sort}([x, y, z, t])\\ \\ \begin{array}{l} \mathbf{if}\;t \leq -2.9 \cdot 10^{+23} \lor \neg \left(t \leq 9.4 \cdot 10^{+145}\right):\\ \;\;\;\;\frac{x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \end{array} \]
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (if (or (<= t -2.9e+23) (not (<= t 9.4e+145))) (/ x (* z t)) (/ x y)))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
	double tmp;
	if ((t <= -2.9e+23) || !(t <= 9.4e+145)) {
		tmp = x / (z * t);
	} else {
		tmp = x / y;
	}
	return tmp;
}
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((t <= (-2.9d+23)) .or. (.not. (t <= 9.4d+145))) then
        tmp = x / (z * t)
    else
        tmp = x / y
    end if
    code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((t <= -2.9e+23) || !(t <= 9.4e+145)) {
		tmp = x / (z * t);
	} else {
		tmp = x / y;
	}
	return tmp;
}
[x, y, z, t] = sort([x, y, z, t])
def code(x, y, z, t):
	tmp = 0
	if (t <= -2.9e+23) or not (t <= 9.4e+145):
		tmp = x / (z * t)
	else:
		tmp = x / y
	return tmp
x, y, z, t = sort([x, y, z, t])
function code(x, y, z, t)
	tmp = 0.0
	if ((t <= -2.9e+23) || !(t <= 9.4e+145))
		tmp = Float64(x / Float64(z * t));
	else
		tmp = Float64(x / y);
	end
	return tmp
end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((t <= -2.9e+23) || ~((t <= 9.4e+145)))
		tmp = x / (z * t);
	else
		tmp = x / y;
	end
	tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := If[Or[LessEqual[t, -2.9e+23], N[Not[LessEqual[t, 9.4e+145]], $MachinePrecision]], N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.9 \cdot 10^{+23} \lor \neg \left(t \leq 9.4 \cdot 10^{+145}\right):\\
\;\;\;\;\frac{x}{z \cdot t}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < -2.90000000000000013e23 or 9.4000000000000004e145 < t

    1. Initial program 91.8%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 63.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{t \cdot z}} \]
    4. Step-by-step derivation
      1. associate-*r/63.0%

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{t \cdot z}} \]
      2. neg-mul-163.0%

        \[\leadsto \frac{\color{blue}{-x}}{t \cdot z} \]
    5. Simplified63.0%

      \[\leadsto \color{blue}{\frac{-x}{t \cdot z}} \]
    6. Step-by-step derivation
      1. div-inv63.0%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{t \cdot z}} \]
      2. add-sqr-sqrt31.5%

        \[\leadsto \color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \cdot \frac{1}{t \cdot z} \]
      3. sqrt-unprod41.7%

        \[\leadsto \color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}} \cdot \frac{1}{t \cdot z} \]
      4. sqr-neg41.7%

        \[\leadsto \sqrt{\color{blue}{x \cdot x}} \cdot \frac{1}{t \cdot z} \]
      5. sqrt-unprod13.5%

        \[\leadsto \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \frac{1}{t \cdot z} \]
      6. add-sqr-sqrt32.4%

        \[\leadsto \color{blue}{x} \cdot \frac{1}{t \cdot z} \]
      7. *-commutative32.4%

        \[\leadsto x \cdot \frac{1}{\color{blue}{z \cdot t}} \]
    7. Applied egg-rr32.4%

      \[\leadsto \color{blue}{x \cdot \frac{1}{z \cdot t}} \]
    8. Step-by-step derivation
      1. associate-*r/32.4%

        \[\leadsto \color{blue}{\frac{x \cdot 1}{z \cdot t}} \]
      2. *-rgt-identity32.4%

        \[\leadsto \frac{\color{blue}{x}}{z \cdot t} \]
      3. *-commutative32.4%

        \[\leadsto \frac{x}{\color{blue}{t \cdot z}} \]
    9. Simplified32.4%

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

    if -2.90000000000000013e23 < t < 9.4000000000000004e145

    1. Initial program 98.7%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 70.0%

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

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

Alternative 5: 59.0% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y, z, t] = \mathsf{sort}([x, y, z, t])\\ \\ \begin{array}{l} \mathbf{if}\;t \leq -2.9 \cdot 10^{+23}:\\ \;\;\;\;\frac{x}{z \cdot t}\\ \mathbf{elif}\;t \leq 9.4 \cdot 10^{+145}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{z}\\ \end{array} \end{array} \]
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (if (<= t -2.9e+23) (/ x (* z t)) (if (<= t 9.4e+145) (/ x y) (/ (/ x t) z))))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= -2.9e+23) {
		tmp = x / (z * t);
	} else if (t <= 9.4e+145) {
		tmp = x / y;
	} else {
		tmp = (x / t) / z;
	}
	return tmp;
}
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (t <= (-2.9d+23)) then
        tmp = x / (z * t)
    else if (t <= 9.4d+145) then
        tmp = x / y
    else
        tmp = (x / t) / z
    end if
    code = tmp
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= -2.9e+23) {
		tmp = x / (z * t);
	} else if (t <= 9.4e+145) {
		tmp = x / y;
	} else {
		tmp = (x / t) / z;
	}
	return tmp;
}
[x, y, z, t] = sort([x, y, z, t])
def code(x, y, z, t):
	tmp = 0
	if t <= -2.9e+23:
		tmp = x / (z * t)
	elif t <= 9.4e+145:
		tmp = x / y
	else:
		tmp = (x / t) / z
	return tmp
x, y, z, t = sort([x, y, z, t])
function code(x, y, z, t)
	tmp = 0.0
	if (t <= -2.9e+23)
		tmp = Float64(x / Float64(z * t));
	elseif (t <= 9.4e+145)
		tmp = Float64(x / y);
	else
		tmp = Float64(Float64(x / t) / z);
	end
	return tmp
end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (t <= -2.9e+23)
		tmp = x / (z * t);
	elseif (t <= 9.4e+145)
		tmp = x / y;
	else
		tmp = (x / t) / z;
	end
	tmp_2 = tmp;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := If[LessEqual[t, -2.9e+23], N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 9.4e+145], N[(x / y), $MachinePrecision], N[(N[(x / t), $MachinePrecision] / z), $MachinePrecision]]]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.9 \cdot 10^{+23}:\\
\;\;\;\;\frac{x}{z \cdot t}\\

\mathbf{elif}\;t \leq 9.4 \cdot 10^{+145}:\\
\;\;\;\;\frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if t < -2.90000000000000013e23

    1. Initial program 91.2%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 56.1%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{t \cdot z}} \]
    4. Step-by-step derivation
      1. associate-*r/56.1%

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{t \cdot z}} \]
      2. neg-mul-156.1%

        \[\leadsto \frac{\color{blue}{-x}}{t \cdot z} \]
    5. Simplified56.1%

      \[\leadsto \color{blue}{\frac{-x}{t \cdot z}} \]
    6. Step-by-step derivation
      1. div-inv56.0%

        \[\leadsto \color{blue}{\left(-x\right) \cdot \frac{1}{t \cdot z}} \]
      2. add-sqr-sqrt28.2%

        \[\leadsto \color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \cdot \frac{1}{t \cdot z} \]
      3. sqrt-unprod37.4%

        \[\leadsto \color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}} \cdot \frac{1}{t \cdot z} \]
      4. sqr-neg37.4%

        \[\leadsto \sqrt{\color{blue}{x \cdot x}} \cdot \frac{1}{t \cdot z} \]
      5. sqrt-unprod10.8%

        \[\leadsto \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)} \cdot \frac{1}{t \cdot z} \]
      6. add-sqr-sqrt27.2%

        \[\leadsto \color{blue}{x} \cdot \frac{1}{t \cdot z} \]
      7. *-commutative27.2%

        \[\leadsto x \cdot \frac{1}{\color{blue}{z \cdot t}} \]
    7. Applied egg-rr27.2%

      \[\leadsto \color{blue}{x \cdot \frac{1}{z \cdot t}} \]
    8. Step-by-step derivation
      1. associate-*r/27.2%

        \[\leadsto \color{blue}{\frac{x \cdot 1}{z \cdot t}} \]
      2. *-rgt-identity27.2%

        \[\leadsto \frac{\color{blue}{x}}{z \cdot t} \]
      3. *-commutative27.2%

        \[\leadsto \frac{x}{\color{blue}{t \cdot z}} \]
    9. Simplified27.2%

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

    if -2.90000000000000013e23 < t < 9.4000000000000004e145

    1. Initial program 98.7%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 70.0%

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

    if 9.4000000000000004e145 < t

    1. Initial program 93.2%

      \[\frac{x}{y - z \cdot t} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 79.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{t \cdot z}} \]
    4. Step-by-step derivation
      1. associate-*r/79.3%

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{t \cdot z}} \]
      2. neg-mul-179.3%

        \[\leadsto \frac{\color{blue}{-x}}{t \cdot z} \]
    5. Simplified79.3%

      \[\leadsto \color{blue}{\frac{-x}{t \cdot z}} \]
    6. Step-by-step derivation
      1. neg-mul-179.3%

        \[\leadsto \frac{\color{blue}{-1 \cdot x}}{t \cdot z} \]
      2. *-commutative79.3%

        \[\leadsto \frac{-1 \cdot x}{\color{blue}{z \cdot t}} \]
      3. times-frac78.1%

        \[\leadsto \color{blue}{\frac{-1}{z} \cdot \frac{x}{t}} \]
    7. Applied egg-rr78.1%

      \[\leadsto \color{blue}{\frac{-1}{z} \cdot \frac{x}{t}} \]
    8. Step-by-step derivation
      1. frac-times79.3%

        \[\leadsto \color{blue}{\frac{-1 \cdot x}{z \cdot t}} \]
      2. neg-mul-179.3%

        \[\leadsto \frac{\color{blue}{-x}}{z \cdot t} \]
      3. associate-/l/78.0%

        \[\leadsto \color{blue}{\frac{\frac{-x}{t}}{z}} \]
      4. distribute-frac-neg78.0%

        \[\leadsto \frac{\color{blue}{-\frac{x}{t}}}{z} \]
      5. distribute-frac-neg278.0%

        \[\leadsto \frac{\color{blue}{\frac{x}{-t}}}{z} \]
      6. add-sqr-sqrt0.0%

        \[\leadsto \frac{\frac{x}{\color{blue}{\sqrt{-t} \cdot \sqrt{-t}}}}{z} \]
      7. sqrt-unprod45.3%

        \[\leadsto \frac{\frac{x}{\color{blue}{\sqrt{\left(-t\right) \cdot \left(-t\right)}}}}{z} \]
      8. sqr-neg45.3%

        \[\leadsto \frac{\frac{x}{\sqrt{\color{blue}{t \cdot t}}}}{z} \]
      9. sqrt-unprod44.7%

        \[\leadsto \frac{\frac{x}{\color{blue}{\sqrt{t} \cdot \sqrt{t}}}}{z} \]
      10. add-sqr-sqrt44.7%

        \[\leadsto \frac{\frac{x}{\color{blue}{t}}}{z} \]
    9. Applied egg-rr44.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -2.9 \cdot 10^{+23}:\\ \;\;\;\;\frac{x}{z \cdot t}\\ \mathbf{elif}\;t \leq 9.4 \cdot 10^{+145}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 54.6% accurate, 2.3× speedup?

\[\begin{array}{l} [x, y, z, t] = \mathsf{sort}([x, y, z, t])\\ \\ \frac{x}{y} \end{array} \]
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x y z t) :precision binary64 (/ x y))
assert(x < y && y < z && z < t);
double code(double x, double y, double z, double t) {
	return x / y;
}
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x / y
end function
assert x < y && y < z && z < t;
public static double code(double x, double y, double z, double t) {
	return x / y;
}
[x, y, z, t] = sort([x, y, z, t])
def code(x, y, z, t):
	return x / y
x, y, z, t = sort([x, y, z, t])
function code(x, y, z, t)
	return Float64(x / y)
end
x, y, z, t = num2cell(sort([x, y, z, t])){:}
function tmp = code(x, y, z, t)
	tmp = x / y;
end
NOTE: x, y, z, and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := N[(x / y), $MachinePrecision]
\begin{array}{l}
[x, y, z, t] = \mathsf{sort}([x, y, z, t])\\
\\
\frac{x}{y}
\end{array}
Derivation
  1. Initial program 96.2%

    \[\frac{x}{y - z \cdot t} \]
  2. Add Preprocessing
  3. Taylor expanded in y around inf 57.5%

    \[\leadsto \color{blue}{\frac{x}{y}} \]
  4. Final simplification57.5%

    \[\leadsto \frac{x}{y} \]
  5. Add Preprocessing

Developer target: 96.5% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{1}{\frac{y}{x} - \frac{z}{x} \cdot t}\\
\mathbf{if}\;x < -1.618195973607049 \cdot 10^{+50}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x < 2.1378306434876444 \cdot 10^{+131}:\\
\;\;\;\;\frac{x}{y - z \cdot t}\\

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


\end{array}
\end{array}

Reproduce

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

  :alt
  (if (< x -1.618195973607049e+50) (/ 1.0 (- (/ y x) (* (/ z x) t))) (if (< x 2.1378306434876444e+131) (/ x (- y (* z t))) (/ 1.0 (- (/ y x) (* (/ z x) t)))))

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