Average Error: 6.6 → 1.7
Time: 7.4s
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\\ t_2 := \frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+299}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+82}:\\ \;\;\;\;\frac{x \cdot 2}{t_1}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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 (- y t)) (/ 2.0 z))))
   (if (<= t_1 -5e+299) t_2 (if (<= t_1 4e+82) (/ (* x 2.0) t_1) t_2))))
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 / (y - t)) * (2.0 / z);
	double tmp;
	if (t_1 <= -5e+299) {
		tmp = t_2;
	} else if (t_1 <= 4e+82) {
		tmp = (x * 2.0) / t_1;
	} else {
		tmp = t_2;
	}
	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) :: t_2
    real(8) :: tmp
    t_1 = (y * z) - (z * t)
    t_2 = (x / (y - t)) * (2.0d0 / z)
    if (t_1 <= (-5d+299)) then
        tmp = t_2
    else if (t_1 <= 4d+82) then
        tmp = (x * 2.0d0) / t_1
    else
        tmp = t_2
    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 t_2 = (x / (y - t)) * (2.0 / z);
	double tmp;
	if (t_1 <= -5e+299) {
		tmp = t_2;
	} else if (t_1 <= 4e+82) {
		tmp = (x * 2.0) / t_1;
	} else {
		tmp = t_2;
	}
	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 / (y - t)) * (2.0 / z)
	tmp = 0
	if t_1 <= -5e+299:
		tmp = t_2
	elif t_1 <= 4e+82:
		tmp = (x * 2.0) / t_1
	else:
		tmp = t_2
	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 / Float64(y - t)) * Float64(2.0 / z))
	tmp = 0.0
	if (t_1 <= -5e+299)
		tmp = t_2;
	elseif (t_1 <= 4e+82)
		tmp = Float64(Float64(x * 2.0) / t_1);
	else
		tmp = t_2;
	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 / (y - t)) * (2.0 / z);
	tmp = 0.0;
	if (t_1 <= -5e+299)
		tmp = t_2;
	elseif (t_1 <= 4e+82)
		tmp = (x * 2.0) / t_1;
	else
		tmp = t_2;
	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 / N[(y - t), $MachinePrecision]), $MachinePrecision] * N[(2.0 / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+299], t$95$2, If[LessEqual[t$95$1, 4e+82], N[(N[(x * 2.0), $MachinePrecision] / t$95$1), $MachinePrecision], t$95$2]]]]
\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}{y - t} \cdot \frac{2}{z}\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+299}:\\
\;\;\;\;t_2\\

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

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.6
Target2.1
Herbie1.7
\[\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 2 regimes
  2. if (-.f64 (*.f64 y z) (*.f64 t z)) < -5.0000000000000003e299 or 3.9999999999999999e82 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 13.8

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

      \[\leadsto \color{blue}{\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}} \]
      Proof
      (/.f64 x (/.f64 (*.f64 z (-.f64 y t)) 2)): 0 points increase in error, 0 points decrease in error
      (/.f64 x (/.f64 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 y z) (*.f64 t z))) 2)): 6 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x 2) (-.f64 (*.f64 y z) (*.f64 t z)))): 0 points increase in error, 1 points decrease in error
    3. Taylor expanded in x around 0 11.3

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

      \[\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))): 47 points increase in error, 43 points decrease in error
      (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 2 x)) (*.f64 (-.f64 y t) z)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 2 (/.f64 x (*.f64 (-.f64 y t) z)))): 0 points increase in error, 0 points decrease in error

    if -5.0000000000000003e299 < (-.f64 (*.f64 y z) (*.f64 t z)) < 3.9999999999999999e82

    1. Initial program 1.6

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

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

Alternatives

Alternative 1
Error18.1
Cost976
\[\begin{array}{l} t_1 := x \cdot \frac{\frac{2}{y}}{z}\\ \mathbf{if}\;t \leq -1 \cdot 10^{-71}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{-2}{t}\\ \mathbf{elif}\;t \leq 1.45 \cdot 10^{-258}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.2 \cdot 10^{-81}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y}\\ \mathbf{elif}\;t \leq 5.7 \cdot 10^{+49}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{z} \cdot -2\\ \end{array} \]
Alternative 2
Error18.2
Cost976
\[\begin{array}{l} t_1 := x \cdot \frac{\frac{2}{y}}{z}\\ \mathbf{if}\;t \leq -7.6 \cdot 10^{-72}:\\ \;\;\;\;-2 \cdot \frac{\frac{x}{z}}{t}\\ \mathbf{elif}\;t \leq 6 \cdot 10^{-253}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.8 \cdot 10^{-85}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y}\\ \mathbf{elif}\;t \leq 1.05 \cdot 10^{+50}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{z} \cdot -2\\ \end{array} \]
Alternative 3
Error16.9
Cost844
\[\begin{array}{l} t_1 := x \cdot \frac{\frac{2}{y}}{z}\\ \mathbf{if}\;y \leq -4.2 \cdot 10^{+72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.55 \cdot 10^{-292}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{-2}{t}\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \frac{\frac{-2}{z}}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error7.2
Cost840
\[\begin{array}{l} t_1 := 2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{if}\;y \leq -1.4 \cdot 10^{-133}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-212}:\\ \;\;\;\;\frac{\frac{x}{t}}{z} \cdot -2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error2.6
Cost840
\[\begin{array}{l} t_1 := \frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{if}\;x \leq -2.5 \cdot 10^{-141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+20}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error2.6
Cost840
\[\begin{array}{l} t_1 := \frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{if}\;x \leq -2.5 \cdot 10^{-141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+26}:\\ \;\;\;\;x \cdot \frac{\frac{2}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error2.3
Cost840
\[\begin{array}{l} t_1 := \frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{if}\;z \leq -5 \cdot 10^{+84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.25 \cdot 10^{-24}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error17.0
Cost712
\[\begin{array}{l} t_1 := x \cdot \frac{\frac{2}{y}}{z}\\ \mathbf{if}\;y \leq -4.4 \cdot 10^{+72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-5}:\\ \;\;\;\;x \cdot \frac{\frac{-2}{z}}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error18.2
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -8.6 \cdot 10^{-72}:\\ \;\;\;\;-2 \cdot \frac{\frac{x}{z}}{t}\\ \mathbf{elif}\;t \leq 3.9 \cdot 10^{+49}:\\ \;\;\;\;\frac{2}{\frac{y \cdot z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{z} \cdot -2\\ \end{array} \]
Alternative 10
Error18.2
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -3.7 \cdot 10^{-72}:\\ \;\;\;\;\frac{\frac{x}{z}}{t \cdot -0.5}\\ \mathbf{elif}\;t \leq 3.9 \cdot 10^{+49}:\\ \;\;\;\;\frac{2}{\frac{y \cdot z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{z} \cdot -2\\ \end{array} \]
Alternative 11
Error4.0
Cost708
\[\begin{array}{l} \mathbf{if}\;z \leq 1.95 \cdot 10^{-62}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \end{array} \]
Alternative 12
Error30.8
Cost448
\[x \cdot \frac{\frac{-2}{t}}{z} \]
Alternative 13
Error30.8
Cost448
\[x \cdot \frac{\frac{-2}{z}}{t} \]

Error

Reproduce

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