Average Error: 10.6 → 2.1
Time: 5.0s
Precision: binary64
\[\frac{x - y \cdot z}{t - a \cdot z} \]
\[\begin{array}{l} t_1 := t - z \cdot a\\ t_2 := \frac{x}{t_1}\\ t_3 := t_2 - \frac{y}{\frac{t}{z} - a}\\ \mathbf{if}\;z \leq -1 \cdot 10^{-104}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 10^{-196}:\\ \;\;\;\;t_2 - \frac{z \cdot y}{t_1}\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \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)) (t_3 (- t_2 (/ y (- (/ t z) a)))))
   (if (<= z -1e-104) t_3 (if (<= z 1e-196) (- t_2 (/ (* z y) t_1)) t_3))))
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;
	double t_3 = t_2 - (y / ((t / z) - a));
	double tmp;
	if (z <= -1e-104) {
		tmp = t_3;
	} else if (z <= 1e-196) {
		tmp = t_2 - ((z * y) / t_1);
	} else {
		tmp = t_3;
	}
	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
    code = (x - (y * z)) / (t - (a * z))
end function
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) :: t_3
    real(8) :: tmp
    t_1 = t - (z * a)
    t_2 = x / t_1
    t_3 = t_2 - (y / ((t / z) - a))
    if (z <= (-1d-104)) then
        tmp = t_3
    else if (z <= 1d-196) then
        tmp = t_2 - ((z * y) / t_1)
    else
        tmp = t_3
    end if
    code = tmp
end function
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;
	double t_3 = t_2 - (y / ((t / z) - a));
	double tmp;
	if (z <= -1e-104) {
		tmp = t_3;
	} else if (z <= 1e-196) {
		tmp = t_2 - ((z * y) / t_1);
	} else {
		tmp = t_3;
	}
	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
	t_3 = t_2 - (y / ((t / z) - a))
	tmp = 0
	if z <= -1e-104:
		tmp = t_3
	elif z <= 1e-196:
		tmp = t_2 - ((z * y) / t_1)
	else:
		tmp = t_3
	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(x / t_1)
	t_3 = Float64(t_2 - Float64(y / Float64(Float64(t / z) - a)))
	tmp = 0.0
	if (z <= -1e-104)
		tmp = t_3;
	elseif (z <= 1e-196)
		tmp = Float64(t_2 - Float64(Float64(z * y) / t_1));
	else
		tmp = t_3;
	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;
	t_3 = t_2 - (y / ((t / z) - a));
	tmp = 0.0;
	if (z <= -1e-104)
		tmp = t_3;
	elseif (z <= 1e-196)
		tmp = t_2 - ((z * y) / t_1);
	else
		tmp = t_3;
	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[(x / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 - N[(y / N[(N[(t / z), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1e-104], t$95$3, If[LessEqual[z, 1e-196], N[(t$95$2 - N[(N[(z * y), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]
\frac{x - y \cdot z}{t - a \cdot z}
\begin{array}{l}
t_1 := t - z \cdot a\\
t_2 := \frac{x}{t_1}\\
t_3 := t_2 - \frac{y}{\frac{t}{z} - a}\\
\mathbf{if}\;z \leq -1 \cdot 10^{-104}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;z \leq 10^{-196}:\\
\;\;\;\;t_2 - \frac{z \cdot y}{t_1}\\

\mathbf{else}:\\
\;\;\;\;t_3\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.6
Target1.6
Herbie2.1
\[\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 2 regimes
  2. if z < -9.99999999999999927e-105 or 1e-196 < z

    1. Initial program 14.3

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

      \[\leadsto \color{blue}{\frac{x}{t - a \cdot z} + -1 \cdot \frac{y \cdot z}{t - a \cdot z}} \]
    3. Simplified9.6

      \[\leadsto \color{blue}{\frac{x}{t - z \cdot a} - \frac{y}{\frac{t - z \cdot a}{z}}} \]
    4. Taylor expanded in t around 0 2.8

      \[\leadsto \frac{x}{t - z \cdot a} - \frac{y}{\color{blue}{\frac{t}{z} + -1 \cdot a}} \]
    5. Simplified2.8

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

    if -9.99999999999999927e-105 < z < 1e-196

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\frac{x}{t - a \cdot z} + -1 \cdot \frac{y \cdot z}{t - a \cdot z}} \]
    3. Simplified3.8

      \[\leadsto \color{blue}{\frac{x}{t - z \cdot a} - \frac{y}{\frac{t - z \cdot a}{z}}} \]
    4. Taylor expanded in y around 0 0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{-104}:\\ \;\;\;\;\frac{x}{t - z \cdot a} - \frac{y}{\frac{t}{z} - a}\\ \mathbf{elif}\;z \leq 10^{-196}:\\ \;\;\;\;\frac{x}{t - z \cdot a} - \frac{z \cdot y}{t - z \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t - z \cdot a} - \frac{y}{\frac{t}{z} - a}\\ \end{array} \]

Reproduce

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