Average Error: 6.9 → 2.0
Time: 10.4s
Precision: binary64
Cost: 2640
\[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
\[\begin{array}{l} t_1 := y \cdot z - z \cdot t\\ t_2 := \frac{\frac{x \cdot 2}{z}}{y - t}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+256}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq -1 \cdot 10^{-100}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{-138}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+15}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \frac{x}{y - t}}{z}\\ \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) z) (- y t))))
   (if (<= t_1 -2e+256)
     t_2
     (if (<= t_1 -1e-100)
       (/ x (/ (* z (- y t)) 2.0))
       (if (<= t_1 4e-138)
         t_2
         (if (<= t_1 1e+15)
           (* x (/ (/ 2.0 (- y t)) z))
           (/ (* 2.0 (/ x (- y t))) z)))))))
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) / z) / (y - t);
	double tmp;
	if (t_1 <= -2e+256) {
		tmp = t_2;
	} else if (t_1 <= -1e-100) {
		tmp = x / ((z * (y - t)) / 2.0);
	} else if (t_1 <= 4e-138) {
		tmp = t_2;
	} else if (t_1 <= 1e+15) {
		tmp = x * ((2.0 / (y - t)) / z);
	} else {
		tmp = (2.0 * (x / (y - t))) / z;
	}
	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 * 2.0d0) / z) / (y - t)
    if (t_1 <= (-2d+256)) then
        tmp = t_2
    else if (t_1 <= (-1d-100)) then
        tmp = x / ((z * (y - t)) / 2.0d0)
    else if (t_1 <= 4d-138) then
        tmp = t_2
    else if (t_1 <= 1d+15) then
        tmp = x * ((2.0d0 / (y - t)) / z)
    else
        tmp = (2.0d0 * (x / (y - t))) / z
    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 * 2.0) / z) / (y - t);
	double tmp;
	if (t_1 <= -2e+256) {
		tmp = t_2;
	} else if (t_1 <= -1e-100) {
		tmp = x / ((z * (y - t)) / 2.0);
	} else if (t_1 <= 4e-138) {
		tmp = t_2;
	} else if (t_1 <= 1e+15) {
		tmp = x * ((2.0 / (y - t)) / z);
	} else {
		tmp = (2.0 * (x / (y - t))) / z;
	}
	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) / z) / (y - t)
	tmp = 0
	if t_1 <= -2e+256:
		tmp = t_2
	elif t_1 <= -1e-100:
		tmp = x / ((z * (y - t)) / 2.0)
	elif t_1 <= 4e-138:
		tmp = t_2
	elif t_1 <= 1e+15:
		tmp = x * ((2.0 / (y - t)) / z)
	else:
		tmp = (2.0 * (x / (y - t))) / z
	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(Float64(x * 2.0) / z) / Float64(y - t))
	tmp = 0.0
	if (t_1 <= -2e+256)
		tmp = t_2;
	elseif (t_1 <= -1e-100)
		tmp = Float64(x / Float64(Float64(z * Float64(y - t)) / 2.0));
	elseif (t_1 <= 4e-138)
		tmp = t_2;
	elseif (t_1 <= 1e+15)
		tmp = Float64(x * Float64(Float64(2.0 / Float64(y - t)) / z));
	else
		tmp = Float64(Float64(2.0 * Float64(x / Float64(y - t))) / z);
	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) / z) / (y - t);
	tmp = 0.0;
	if (t_1 <= -2e+256)
		tmp = t_2;
	elseif (t_1 <= -1e-100)
		tmp = x / ((z * (y - t)) / 2.0);
	elseif (t_1 <= 4e-138)
		tmp = t_2;
	elseif (t_1 <= 1e+15)
		tmp = x * ((2.0 / (y - t)) / z);
	else
		tmp = (2.0 * (x / (y - t))) / z;
	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[(N[(x * 2.0), $MachinePrecision] / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+256], t$95$2, If[LessEqual[t$95$1, -1e-100], N[(x / N[(N[(z * N[(y - t), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e-138], t$95$2, If[LessEqual[t$95$1, 1e+15], N[(x * N[(N[(2.0 / N[(y - t), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[(x / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $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{\frac{x \cdot 2}{z}}{y - t}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+256}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq -1 \cdot 10^{-100}:\\
\;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\

\mathbf{elif}\;t_1 \leq 4 \cdot 10^{-138}:\\
\;\;\;\;t_2\\

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

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.9
Target2.1
Herbie2.0
\[\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)) < -2.0000000000000001e256 or -1e-100 < (-.f64 (*.f64 y z) (*.f64 t z)) < 4.00000000000000027e-138

    1. Initial program 12.2

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

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

    if -2.0000000000000001e256 < (-.f64 (*.f64 y z) (*.f64 t z)) < -1e-100

    1. Initial program 0.3

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

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

    if 4.00000000000000027e-138 < (-.f64 (*.f64 y z) (*.f64 t z)) < 1e15

    1. Initial program 0.3

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

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

      \[\leadsto \color{blue}{2 \cdot \frac{x}{\left(y - t\right) \cdot z}} \]
    4. Simplified0.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-/r*_binary64 (/.f64 2 (*.f64 (-.f64 y t) z)))): 8 points increase in error, 0 points decrease in error
      (*.f64 x (/.f64 2 (Rewrite<= *-commutative_binary64 (*.f64 z (-.f64 y t))))): 1 points increase in error, 6 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x 2) (*.f64 z (-.f64 y t)))): 9 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 x 2) (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (*.f64 z (-.f64 y t)))))): 0 points increase in error, 9 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x (neg.f64 (neg.f64 (*.f64 z (-.f64 y t))))) 2)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> *-commutative_binary64 (*.f64 2 (/.f64 x (neg.f64 (neg.f64 (*.f64 z (-.f64 y t))))))): 0 points increase in error, 0 points decrease in error
      (*.f64 2 (/.f64 x (Rewrite=> remove-double-neg_binary64 (*.f64 z (-.f64 y t))))): 8 points increase in error, 0 points decrease in error
      (*.f64 2 (/.f64 x (Rewrite=> *-commutative_binary64 (*.f64 (-.f64 y t) z)))): 0 points increase in error, 8 points decrease in error

    if 1e15 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 10.0

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

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

      \[\leadsto \color{blue}{2 \cdot \frac{x}{\left(y - t\right) \cdot z}} \]
    4. Simplified6.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-/r*_binary64 (/.f64 2 (*.f64 (-.f64 y t) z)))): 8 points increase in error, 0 points decrease in error
      (*.f64 x (/.f64 2 (Rewrite<= *-commutative_binary64 (*.f64 z (-.f64 y t))))): 1 points increase in error, 6 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x 2) (*.f64 z (-.f64 y t)))): 9 points increase in error, 0 points decrease in error
      (/.f64 (*.f64 x 2) (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (*.f64 z (-.f64 y t)))))): 0 points increase in error, 9 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x (neg.f64 (neg.f64 (*.f64 z (-.f64 y t))))) 2)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> *-commutative_binary64 (*.f64 2 (/.f64 x (neg.f64 (neg.f64 (*.f64 z (-.f64 y t))))))): 0 points increase in error, 0 points decrease in error
      (*.f64 2 (/.f64 x (Rewrite=> remove-double-neg_binary64 (*.f64 z (-.f64 y t))))): 8 points increase in error, 0 points decrease in error
      (*.f64 2 (/.f64 x (Rewrite=> *-commutative_binary64 (*.f64 (-.f64 y t) z)))): 0 points increase in error, 8 points decrease in error
    5. Applied egg-rr3.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -2 \cdot 10^{+256}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq -1 \cdot 10^{-100}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 4 \cdot 10^{-138}:\\ \;\;\;\;\frac{\frac{x \cdot 2}{z}}{y - t}\\ \mathbf{elif}\;y \cdot z - z \cdot t \leq 10^{+15}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \frac{x}{y - t}}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error4.5
Cost836
\[\begin{array}{l} \mathbf{if}\;x \cdot 2 \leq 5 \cdot 10^{-139}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{y - t}}{z}\\ \end{array} \]
Alternative 2
Error4.5
Cost836
\[\begin{array}{l} \mathbf{if}\;x \cdot 2 \leq 5 \cdot 10^{-139}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \frac{x}{y - t}}{z}\\ \end{array} \]
Alternative 3
Error4.6
Cost836
\[\begin{array}{l} \mathbf{if}\;x \cdot 2 \leq 10^{-147}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{z}}{\frac{y - t}{x}}\\ \end{array} \]
Alternative 4
Error16.9
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -950000000 \lor \neg \left(y \leq 9500000\right):\\ \;\;\;\;x \cdot \frac{2}{y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{t} \cdot \frac{-2}{z}\\ \end{array} \]
Alternative 5
Error16.6
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1800000000 \lor \neg \left(y \leq 2800000\right):\\ \;\;\;\;x \cdot \frac{2}{y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{-2}{t}\\ \end{array} \]
Alternative 6
Error16.6
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -2050000000 \lor \neg \left(y \leq 440000\right):\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{-2}{t}\\ \end{array} \]
Alternative 7
Error16.6
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1200000000 \lor \neg \left(y \leq 1650000\right):\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x \cdot -2}{z}}{t}\\ \end{array} \]
Alternative 8
Error5.6
Cost576
\[x \cdot \frac{\frac{2}{z}}{y - t} \]
Alternative 9
Error31.5
Cost448
\[x \cdot \frac{2}{y \cdot z} \]

Error

Reproduce

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