Average Error: 6.6 → 1.3
Time: 12.5s
Precision: binary64
Cost: 1736
\[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
\[\begin{array}{l} t_1 := y \cdot z - z \cdot t\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+255}:\\ \;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+273}:\\ \;\;\;\;\frac{x \cdot 2}{t_1}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \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))))
   (if (<= t_1 -1e+255)
     (* (/ x (- y t)) (/ 2.0 z))
     (if (<= t_1 2e+273) (/ (* x 2.0) t_1) (* 2.0 (/ (/ x z) (- y t)))))))
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 tmp;
	if (t_1 <= -1e+255) {
		tmp = (x / (y - t)) * (2.0 / z);
	} else if (t_1 <= 2e+273) {
		tmp = (x * 2.0) / t_1;
	} else {
		tmp = 2.0 * ((x / z) / (y - t));
	}
	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 * 2.0d0) / ((y * z) - (t * z))
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 = (y * z) - (z * t)
    if (t_1 <= (-1d+255)) then
        tmp = (x / (y - t)) * (2.0d0 / z)
    else if (t_1 <= 2d+273) then
        tmp = (x * 2.0d0) / t_1
    else
        tmp = 2.0d0 * ((x / z) / (y - t))
    end if
    code = tmp
end function
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 tmp;
	if (t_1 <= -1e+255) {
		tmp = (x / (y - t)) * (2.0 / z);
	} else if (t_1 <= 2e+273) {
		tmp = (x * 2.0) / t_1;
	} else {
		tmp = 2.0 * ((x / z) / (y - t));
	}
	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)
	tmp = 0
	if t_1 <= -1e+255:
		tmp = (x / (y - t)) * (2.0 / z)
	elif t_1 <= 2e+273:
		tmp = (x * 2.0) / t_1
	else:
		tmp = 2.0 * ((x / z) / (y - t))
	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))
	tmp = 0.0
	if (t_1 <= -1e+255)
		tmp = Float64(Float64(x / Float64(y - t)) * Float64(2.0 / z));
	elseif (t_1 <= 2e+273)
		tmp = Float64(Float64(x * 2.0) / t_1);
	else
		tmp = Float64(2.0 * Float64(Float64(x / z) / Float64(y - t)));
	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);
	tmp = 0.0;
	if (t_1 <= -1e+255)
		tmp = (x / (y - t)) * (2.0 / z);
	elseif (t_1 <= 2e+273)
		tmp = (x * 2.0) / t_1;
	else
		tmp = 2.0 * ((x / z) / (y - t));
	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]}, If[LessEqual[t$95$1, -1e+255], N[(N[(x / N[(y - t), $MachinePrecision]), $MachinePrecision] * N[(2.0 / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+273], N[(N[(x * 2.0), $MachinePrecision] / t$95$1), $MachinePrecision], N[(2.0 * N[(N[(x / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := y \cdot z - z \cdot t\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{+255}:\\
\;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+273}:\\
\;\;\;\;\frac{x \cdot 2}{t_1}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.6
Target2.2
Herbie1.3
\[\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 3 regimes
  2. if (-.f64 (*.f64 y z) (*.f64 t z)) < -9.99999999999999988e254

    1. Initial program 14.2

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

      \[\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))))): 18 points increase in error, 18 points decrease in error
      (*.f64 x (/.f64 2 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 y z) (*.f64 t z))))): 11 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x 2) (-.f64 (*.f64 y z) (*.f64 t z)))): 16 points increase in error, 23 points decrease in error
    3. Applied egg-rr0.2

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

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

      \[\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))): 40 points increase in error, 41 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x (*.f64 (-.f64 y t) z)) 2)): 2 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 -9.99999999999999988e254 < (-.f64 (*.f64 y z) (*.f64 t z)) < 1.99999999999999989e273

    1. Initial program 1.7

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

    if 1.99999999999999989e273 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 23.9

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

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

      \[\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))))): 45 points increase in error, 31 points decrease in error
      (*.f64 2 (/.f64 x (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 y z) (*.f64 t z))))): 9 points increase in error, 1 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification1.3

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

Alternatives

Alternative 1
Error4.5
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \cdot 2 \leq 5 \cdot 10^{+52}:\\ \;\;\;\;\frac{2}{\left(y - t\right) \cdot \frac{z}{x}}\\ \mathbf{elif}\;x \cdot 2 \leq 10^{+297}:\\ \;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z}\\ \end{array} \]
Alternative 2
Error5.9
Cost840
\[\begin{array}{l} t_1 := \frac{2}{\frac{y - t}{\frac{x}{z}}}\\ \mathbf{if}\;z \leq -2.0450825929668832 \cdot 10^{-114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 10^{-254}:\\ \;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error5.7
Cost840
\[\begin{array}{l} t_1 := \frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{if}\;y \leq -1.9913748680364533 \cdot 10^{+161}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 10^{-200}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error2.4
Cost840
\[\begin{array}{l} t_1 := 2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{if}\;z \leq -5.197620378212601 \cdot 10^{-23}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.2451130779536973 \cdot 10^{-66}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error18.0
Cost712
\[\begin{array}{l} t_1 := \frac{-2}{z \cdot \frac{t}{x}}\\ \mathbf{if}\;t \leq -3.651134722568841 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.8584292923167928 \cdot 10^{-40}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error17.6
Cost712
\[\begin{array}{l} t_1 := \frac{-2}{z \cdot \frac{t}{x}}\\ \mathbf{if}\;t \leq -3.651134722568841 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.8584292923167928 \cdot 10^{-40}:\\ \;\;\;\;\frac{2}{y \cdot \frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error17.5
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -3.651134722568841 \cdot 10^{+80}:\\ \;\;\;\;\frac{\frac{x \cdot -2}{z}}{t}\\ \mathbf{elif}\;t \leq 1.8584292923167928 \cdot 10^{-40}:\\ \;\;\;\;\frac{2}{y \cdot \frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{z \cdot \frac{t}{x}}\\ \end{array} \]
Alternative 8
Error17.5
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -3.651134722568841 \cdot 10^{+80}:\\ \;\;\;\;\frac{\frac{x \cdot -2}{z}}{t}\\ \mathbf{elif}\;t \leq 1.8584292923167928 \cdot 10^{-40}:\\ \;\;\;\;\frac{2}{y \cdot \frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t} \cdot \frac{-2}{z}\\ \end{array} \]
Alternative 9
Error17.5
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -3.651134722568841 \cdot 10^{+80}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{-2}{t}\\ \mathbf{elif}\;t \leq 1.8584292923167928 \cdot 10^{-40}:\\ \;\;\;\;\frac{2}{y \cdot \frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t} \cdot \frac{-2}{z}\\ \end{array} \]
Alternative 10
Error6.0
Cost576
\[\frac{2}{\frac{y - t}{\frac{x}{z}}} \]
Alternative 11
Error31.5
Cost448
\[\frac{-2}{z \cdot \frac{t}{x}} \]

Error

Reproduce

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