?

Average Error: 4.32% → 0.17%
Time: 10.0s
Precision: binary64
Cost: 1608

?

\[ \begin{array}{c}[z, t] = \mathsf{sort}([z, t])\\ \end{array} \]
\[\frac{x}{y - z \cdot t} \]
\[\begin{array}{l} t_1 := \frac{x}{y - z \cdot t}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-322}:\\ \;\;\;\;\frac{x}{y - \frac{z}{\frac{1}{t}}}\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\frac{\frac{x}{t}}{\frac{y}{t} - z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (/ x (- y (* z t))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ x (- y (* z t)))))
   (if (<= t_1 -1e-322)
     (/ x (- y (/ z (/ 1.0 t))))
     (if (<= t_1 0.0) (/ (/ x t) (- (/ y t) z)) t_1))))
double code(double x, double y, double z, double t) {
	return x / (y - (z * t));
}
double code(double x, double y, double z, double t) {
	double t_1 = x / (y - (z * t));
	double tmp;
	if (t_1 <= -1e-322) {
		tmp = x / (y - (z / (1.0 / t)));
	} else if (t_1 <= 0.0) {
		tmp = (x / t) / ((y / t) - z);
	} 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
    code = x / (y - (z * t))
end 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) :: t_1
    real(8) :: tmp
    t_1 = x / (y - (z * t))
    if (t_1 <= (-1d-322)) then
        tmp = x / (y - (z / (1.0d0 / t)))
    else if (t_1 <= 0.0d0) then
        tmp = (x / t) / ((y / t) - z)
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return x / (y - (z * t));
}
public static double code(double x, double y, double z, double t) {
	double t_1 = x / (y - (z * t));
	double tmp;
	if (t_1 <= -1e-322) {
		tmp = x / (y - (z / (1.0 / t)));
	} else if (t_1 <= 0.0) {
		tmp = (x / t) / ((y / t) - z);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	return x / (y - (z * t))
def code(x, y, z, t):
	t_1 = x / (y - (z * t))
	tmp = 0
	if t_1 <= -1e-322:
		tmp = x / (y - (z / (1.0 / t)))
	elif t_1 <= 0.0:
		tmp = (x / t) / ((y / t) - z)
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t)
	return Float64(x / Float64(y - Float64(z * t)))
end
function code(x, y, z, t)
	t_1 = Float64(x / Float64(y - Float64(z * t)))
	tmp = 0.0
	if (t_1 <= -1e-322)
		tmp = Float64(x / Float64(y - Float64(z / Float64(1.0 / t))));
	elseif (t_1 <= 0.0)
		tmp = Float64(Float64(x / t) / Float64(Float64(y / t) - z));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x / (y - (z * t));
end
function tmp_2 = code(x, y, z, t)
	t_1 = x / (y - (z * t));
	tmp = 0.0;
	if (t_1 <= -1e-322)
		tmp = x / (y - (z / (1.0 / t)));
	elseif (t_1 <= 0.0)
		tmp = (x / t) / ((y / t) - z);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x / N[(y - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-322], N[(x / N[(y - N[(z / N[(1.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(N[(x / t), $MachinePrecision] / N[(N[(y / t), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\frac{x}{y - z \cdot t}
\begin{array}{l}
t_1 := \frac{x}{y - z \cdot t}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{-322}:\\
\;\;\;\;\frac{x}{y - \frac{z}{\frac{1}{t}}}\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\frac{\frac{x}{t}}{\frac{y}{t} - z}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original4.32%
Target2.42%
Herbie0.17%
\[\begin{array}{l} \mathbf{if}\;x < -1.618195973607049 \cdot 10^{+50}:\\ \;\;\;\;\frac{1}{\frac{y}{x} - \frac{z}{x} \cdot t}\\ \mathbf{elif}\;x < 2.1378306434876444 \cdot 10^{+131}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{y}{x} - \frac{z}{x} \cdot t}\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if (/.f64 x (-.f64 y (*.f64 z t))) < -9.88131e-323

    1. Initial program 0.18

      \[\frac{x}{y - z \cdot t} \]
    2. Applied egg-rr0.35

      \[\leadsto \frac{x}{\color{blue}{\frac{1}{\frac{1}{y - z \cdot t}}}} \]
    3. Applied egg-rr0.25

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

    if -9.88131e-323 < (/.f64 x (-.f64 y (*.f64 z t))) < -0.0

    1. Initial program 14.64

      \[\frac{x}{y - z \cdot t} \]
    2. Applied egg-rr14.64

      \[\leadsto \frac{x}{\color{blue}{\frac{1}{\frac{1}{y - z \cdot t}}}} \]
    3. Applied egg-rr14.64

      \[\leadsto \frac{x}{\color{blue}{\frac{y}{1} - \frac{z}{\frac{1}{t}}}} \]
    4. Applied egg-rr14.64

      \[\leadsto \frac{x}{\color{blue}{\left(\frac{y}{t} - z\right) \cdot t}} \]
    5. Taylor expanded in x around 0 14.64

      \[\leadsto \color{blue}{\frac{x}{t \cdot \left(\frac{y}{t} - z\right)}} \]
    6. Simplified0.06

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

      [Start]14.64

      \[ \frac{x}{t \cdot \left(\frac{y}{t} - z\right)} \]

      associate-/r* [=>]0.06

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

    if -0.0 < (/.f64 x (-.f64 y (*.f64 z t)))

    1. Initial program 0.18

      \[\frac{x}{y - z \cdot t} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.17

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

Alternatives

Alternative 1
Error0.15%
Cost1609
\[\begin{array}{l} t_1 := \frac{x}{y - z \cdot t}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-322} \lor \neg \left(t_1 \leq 0\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{\frac{y}{t} - z}\\ \end{array} \]
Alternative 2
Error30.88%
Cost1440
\[\begin{array}{l} t_1 := \frac{-x}{z \cdot t}\\ t_2 := -\frac{\frac{x}{t}}{z}\\ \mathbf{if}\;z \leq -9 \cdot 10^{+114}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2 \cdot 10^{+84}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;z \leq -6 \cdot 10^{+57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.5 \cdot 10^{+21}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;z \leq -6.8 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-151}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{-94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.0018:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error28.72%
Cost1372
\[\begin{array}{l} t_1 := -\frac{\frac{x}{t}}{z}\\ \mathbf{if}\;t \leq -6.6 \cdot 10^{-108}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \mathbf{elif}\;t \leq 4.6 \cdot 10^{-8}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;t \leq 4.6 \cdot 10^{+24}:\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{elif}\;t \leq 1.15 \cdot 10^{+103}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;t \leq 4.1 \cdot 10^{+163}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.2 \cdot 10^{+171}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;t \leq 6.5 \cdot 10^{+219}:\\ \;\;\;\;\frac{-1}{t} \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error31.18%
Cost914
\[\begin{array}{l} \mathbf{if}\;t \leq -6.6 \cdot 10^{-108} \lor \neg \left(t \leq 1.35 \cdot 10^{-8} \lor \neg \left(t \leq 2 \cdot 10^{+24}\right) \land t \leq 1.7 \cdot 10^{+106}\right):\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 5
Error28%
Cost912
\[\begin{array}{l} \mathbf{if}\;t \leq -6.6 \cdot 10^{-108}:\\ \;\;\;\;\frac{\frac{-x}{z}}{t}\\ \mathbf{elif}\;t \leq 2.25 \cdot 10^{-7}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;t \leq 5.7 \cdot 10^{+23}:\\ \;\;\;\;\frac{-x}{z \cdot t}\\ \mathbf{elif}\;t \leq 1.15 \cdot 10^{+103}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;-\frac{\frac{x}{t}}{z}\\ \end{array} \]
Alternative 6
Error2.52%
Cost772
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq 10^{+283}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{z}{x} \cdot \left(-t\right)}\\ \end{array} \]
Alternative 7
Error2.48%
Cost708
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq 10^{+285}:\\ \;\;\;\;\frac{x}{y - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;-\frac{\frac{x}{t}}{z}\\ \end{array} \]
Alternative 8
Error42.81%
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{+193} \lor \neg \left(z \leq 3.2 \cdot 10^{+47}\right):\\ \;\;\;\;\frac{x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 9
Error46.57%
Cost192
\[\frac{x}{y} \]

Error

Reproduce?

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

  :herbie-target
  (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))))