Average Error: 6.8 → 0.5
Time: 9.2s
Precision: binary64
Cost: 9104
\[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
\[\begin{array}{l} t_1 := y \cdot z - z \cdot t\\ t_2 := \frac{x \cdot 2}{t_1}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{-186}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{-320}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+185}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;{\left(\left(\left(y - t\right) \cdot 0.5\right) \cdot \frac{z}{x}\right)}^{-1}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (- (* y z) (* z t))) (t_2 (/ (* x 2.0) t_1)))
   (if (<= t_1 (- INFINITY))
     (* (/ x (- y t)) (/ 2.0 z))
     (if (<= t_1 -5e-186)
       t_2
       (if (<= t_1 1e-320)
         (* 2.0 (/ (/ x z) (- y t)))
         (if (<= t_1 2e+185) t_2 (pow (* (* (- y t) 0.5) (/ z x)) -1.0)))))))
double code(double x, double y, double z, double t) {
	return (x * 2.0) / ((y * z) - (t * z));
}
double code(double x, double y, double z, double t) {
	double t_1 = (y * z) - (z * t);
	double t_2 = (x * 2.0) / t_1;
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = (x / (y - t)) * (2.0 / z);
	} else if (t_1 <= -5e-186) {
		tmp = t_2;
	} else if (t_1 <= 1e-320) {
		tmp = 2.0 * ((x / z) / (y - t));
	} else if (t_1 <= 2e+185) {
		tmp = t_2;
	} else {
		tmp = pow((((y - t) * 0.5) * (z / x)), -1.0);
	}
	return tmp;
}
public static double code(double x, double y, double z, double t) {
	return (x * 2.0) / ((y * z) - (t * z));
}
public static double code(double x, double y, double z, double t) {
	double t_1 = (y * z) - (z * t);
	double t_2 = (x * 2.0) / t_1;
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = (x / (y - t)) * (2.0 / z);
	} else if (t_1 <= -5e-186) {
		tmp = t_2;
	} else if (t_1 <= 1e-320) {
		tmp = 2.0 * ((x / z) / (y - t));
	} else if (t_1 <= 2e+185) {
		tmp = t_2;
	} else {
		tmp = Math.pow((((y - t) * 0.5) * (z / x)), -1.0);
	}
	return tmp;
}
def code(x, y, z, t):
	return (x * 2.0) / ((y * z) - (t * z))
def code(x, y, z, t):
	t_1 = (y * z) - (z * t)
	t_2 = (x * 2.0) / t_1
	tmp = 0
	if t_1 <= -math.inf:
		tmp = (x / (y - t)) * (2.0 / z)
	elif t_1 <= -5e-186:
		tmp = t_2
	elif t_1 <= 1e-320:
		tmp = 2.0 * ((x / z) / (y - t))
	elif t_1 <= 2e+185:
		tmp = t_2
	else:
		tmp = math.pow((((y - t) * 0.5) * (z / x)), -1.0)
	return tmp
function code(x, y, z, t)
	return Float64(Float64(x * 2.0) / Float64(Float64(y * z) - Float64(t * z)))
end
function code(x, y, z, t)
	t_1 = Float64(Float64(y * z) - Float64(z * t))
	t_2 = Float64(Float64(x * 2.0) / t_1)
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(x / Float64(y - t)) * Float64(2.0 / z));
	elseif (t_1 <= -5e-186)
		tmp = t_2;
	elseif (t_1 <= 1e-320)
		tmp = Float64(2.0 * Float64(Float64(x / z) / Float64(y - t)));
	elseif (t_1 <= 2e+185)
		tmp = t_2;
	else
		tmp = Float64(Float64(Float64(y - t) * 0.5) * Float64(z / x)) ^ -1.0;
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = (x * 2.0) / ((y * z) - (t * z));
end
function tmp_2 = code(x, y, z, t)
	t_1 = (y * z) - (z * t);
	t_2 = (x * 2.0) / t_1;
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = (x / (y - t)) * (2.0 / z);
	elseif (t_1 <= -5e-186)
		tmp = t_2;
	elseif (t_1 <= 1e-320)
		tmp = 2.0 * ((x / z) / (y - t));
	elseif (t_1 <= 2e+185)
		tmp = t_2;
	else
		tmp = (((y - t) * 0.5) * (z / x)) ^ -1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(N[(x * 2.0), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y * z), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * 2.0), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(x / N[(y - t), $MachinePrecision]), $MachinePrecision] * N[(2.0 / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -5e-186], t$95$2, If[LessEqual[t$95$1, 1e-320], N[(2.0 * N[(N[(x / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+185], t$95$2, N[Power[N[(N[(N[(y - t), $MachinePrecision] * 0.5), $MachinePrecision] * N[(z / x), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]]]]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := y \cdot z - z \cdot t\\
t_2 := \frac{x \cdot 2}{t_1}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\

\mathbf{elif}\;t_1 \leq -5 \cdot 10^{-186}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 10^{-320}:\\
\;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+185}:\\
\;\;\;\;t_2\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.8
Target2.2
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} < -2.559141628295061 \cdot 10^{-13}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \mathbf{elif}\;\frac{x \cdot 2}{y \cdot z - t \cdot z} < 1.045027827330126 \cdot 10^{-269}:\\ \;\;\;\;\frac{\frac{x}{z} \cdot 2}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if (-.f64 (*.f64 y z) (*.f64 t z)) < -inf.0

    1. Initial program 20.0

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
    2. Simplified18.5

      \[\leadsto \color{blue}{x \cdot \frac{\frac{2}{y - t}}{z}} \]
      Proof
      (*.f64 x (/.f64 (/.f64 2 (-.f64 y t)) z)): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite=> associate-/l/_binary64 (/.f64 2 (*.f64 z (-.f64 y t))))): 29 points increase in error, 29 points decrease in error
      (*.f64 x (/.f64 2 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 y z) (*.f64 t z))))): 3 points increase in error, 2 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x 2) (-.f64 (*.f64 y z) (*.f64 t z)))): 13 points increase in error, 31 points decrease in error
    3. Applied egg-rr0.1

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

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

      \[\leadsto \color{blue}{\frac{x}{y - t} \cdot \frac{2}{z}} \]
      Proof
      (*.f64 (/.f64 x (-.f64 y t)) (/.f64 2 z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 x 2) (*.f64 (-.f64 y t) z))): 45 points increase in error, 59 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x (*.f64 (-.f64 y t) z)) 2)): 3 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 2 (/.f64 x (*.f64 (-.f64 y t) z)))): 0 points increase in error, 0 points decrease in error

    if -inf.0 < (-.f64 (*.f64 y z) (*.f64 t z)) < -5e-186 or 9.99989e-321 < (-.f64 (*.f64 y z) (*.f64 t z)) < 2e185

    1. Initial program 0.3

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

    if -5e-186 < (-.f64 (*.f64 y z) (*.f64 t z)) < 9.99989e-321

    1. Initial program 24.1

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

      \[\leadsto \color{blue}{2 \cdot \frac{x}{y \cdot z - t \cdot z}} \]
    3. Simplified1.0

      \[\leadsto \color{blue}{2 \cdot \frac{\frac{x}{z}}{y - t}} \]
      Proof
      (*.f64 2 (/.f64 (/.f64 x z) (-.f64 y t))): 0 points increase in error, 0 points decrease in error
      (*.f64 2 (Rewrite<= associate-/r*_binary64 (/.f64 x (*.f64 z (-.f64 y t))))): 49 points increase in error, 50 points decrease in error
      (*.f64 2 (/.f64 x (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 y z) (*.f64 t z))))): 3 points increase in error, 2 points decrease in error

    if 2e185 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 16.4

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
    2. Simplified11.3

      \[\leadsto \color{blue}{x \cdot \frac{\frac{2}{y - t}}{z}} \]
      Proof
      (*.f64 x (/.f64 (/.f64 2 (-.f64 y t)) z)): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite=> associate-/l/_binary64 (/.f64 2 (*.f64 z (-.f64 y t))))): 29 points increase in error, 29 points decrease in error
      (*.f64 x (/.f64 2 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 y z) (*.f64 t z))))): 3 points increase in error, 2 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x 2) (-.f64 (*.f64 y z) (*.f64 t z)))): 13 points increase in error, 31 points decrease in error
    3. Applied egg-rr0.6

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

      \[\leadsto \color{blue}{{\left(\left(\left(y - t\right) \cdot 0.5\right) \cdot \frac{z}{x}\right)}^{-1}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -\infty:\\ \;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq -5 \cdot 10^{-186}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - z \cdot t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 10^{-320}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 2 \cdot 10^{+185}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z - z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;{\left(\left(\left(y - t\right) \cdot 0.5\right) \cdot \frac{z}{x}\right)}^{-1}\\ \end{array} \]

Alternatives

Alternative 1
Error0.5
Cost2768
\[\begin{array}{l} t_1 := y \cdot z - z \cdot t\\ t_2 := \frac{x \cdot 2}{t_1}\\ t_3 := 2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{-186}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{-320}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+167}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Error2.9
Cost1096
\[\begin{array}{l} t_1 := \frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{if}\;x \cdot 2 \leq -1 \cdot 10^{+57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot 2 \leq 10^{-121}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error4.2
Cost840
\[\begin{array}{l} t_1 := \frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{if}\;z \leq -1 \cdot 10^{-267}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.871176885554388 \cdot 10^{+133}:\\ \;\;\;\;x \cdot \frac{\frac{2}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error17.7
Cost712
\[\begin{array}{l} t_1 := \frac{2 \cdot \frac{x}{y}}{z}\\ \mathbf{if}\;y \leq -1 \cdot 10^{-79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1821643236207725:\\ \;\;\;\;\frac{-2}{t \cdot \frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error30.1
Cost580
\[\begin{array}{l} \mathbf{if}\;t \leq -2.3493347437443197 \cdot 10^{-94}:\\ \;\;\;\;\frac{-2}{\frac{z \cdot t}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{t \cdot \frac{z}{x}}\\ \end{array} \]
Alternative 6
Error5.6
Cost576
\[\frac{x}{y - t} \cdot \frac{2}{z} \]
Alternative 7
Error31.8
Cost448
\[\frac{-2}{\frac{z \cdot t}{x}} \]

Error

Reproduce

herbie shell --seed 2022294 
(FPCore (x y z t)
  :name "Linear.Projection:infinitePerspective from linear-1.19.1.3, A"
  :precision binary64

  :herbie-target
  (if (< (/ (* x 2.0) (- (* y z) (* t z))) -2.559141628295061e-13) (* (/ x (* (- y t) z)) 2.0) (if (< (/ (* x 2.0) (- (* y z) (* t z))) 1.045027827330126e-269) (/ (* (/ x z) 2.0) (- y t)) (* (/ x (* (- y t) z)) 2.0)))

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