?

Average Error: 6.9 → 1.8
Time: 19.3s
Precision: binary64
Cost: 2640

?

\[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
\[\begin{array}{l} t_1 := y \cdot z - t \cdot z\\ t_2 := \frac{2 \cdot \frac{x}{z}}{y - t}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+299}:\\ \;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{elif}\;t_1 \leq -2 \cdot 10^{-264}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \mathbf{elif}\;t_1 \leq 10^{-78}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+46}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \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) (* t z))) (t_2 (/ (* 2.0 (/ x z)) (- y t))))
   (if (<= t_1 -2e+299)
     (* (/ x (- y t)) (/ 2.0 z))
     (if (<= t_1 -2e-264)
       (* (/ x (* (- y t) z)) 2.0)
       (if (<= t_1 1e-78)
         t_2
         (if (<= t_1 4e+46) (* x (/ (/ 2.0 (- y t)) z)) 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) - (t * z);
	double t_2 = (2.0 * (x / z)) / (y - t);
	double tmp;
	if (t_1 <= -2e+299) {
		tmp = (x / (y - t)) * (2.0 / z);
	} else if (t_1 <= -2e-264) {
		tmp = (x / ((y - t) * z)) * 2.0;
	} else if (t_1 <= 1e-78) {
		tmp = t_2;
	} else if (t_1 <= 4e+46) {
		tmp = x * ((2.0 / (y - t)) / z);
	} 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) - (t * z)
    t_2 = (2.0d0 * (x / z)) / (y - t)
    if (t_1 <= (-2d+299)) then
        tmp = (x / (y - t)) * (2.0d0 / z)
    else if (t_1 <= (-2d-264)) then
        tmp = (x / ((y - t) * z)) * 2.0d0
    else if (t_1 <= 1d-78) then
        tmp = t_2
    else if (t_1 <= 4d+46) then
        tmp = x * ((2.0d0 / (y - t)) / z)
    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) - (t * z);
	double t_2 = (2.0 * (x / z)) / (y - t);
	double tmp;
	if (t_1 <= -2e+299) {
		tmp = (x / (y - t)) * (2.0 / z);
	} else if (t_1 <= -2e-264) {
		tmp = (x / ((y - t) * z)) * 2.0;
	} else if (t_1 <= 1e-78) {
		tmp = t_2;
	} else if (t_1 <= 4e+46) {
		tmp = x * ((2.0 / (y - t)) / z);
	} 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) - (t * z)
	t_2 = (2.0 * (x / z)) / (y - t)
	tmp = 0
	if t_1 <= -2e+299:
		tmp = (x / (y - t)) * (2.0 / z)
	elif t_1 <= -2e-264:
		tmp = (x / ((y - t) * z)) * 2.0
	elif t_1 <= 1e-78:
		tmp = t_2
	elif t_1 <= 4e+46:
		tmp = x * ((2.0 / (y - t)) / z)
	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(t * z))
	t_2 = Float64(Float64(2.0 * Float64(x / z)) / Float64(y - t))
	tmp = 0.0
	if (t_1 <= -2e+299)
		tmp = Float64(Float64(x / Float64(y - t)) * Float64(2.0 / z));
	elseif (t_1 <= -2e-264)
		tmp = Float64(Float64(x / Float64(Float64(y - t) * z)) * 2.0);
	elseif (t_1 <= 1e-78)
		tmp = t_2;
	elseif (t_1 <= 4e+46)
		tmp = Float64(x * Float64(Float64(2.0 / Float64(y - t)) / z));
	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) - (t * z);
	t_2 = (2.0 * (x / z)) / (y - t);
	tmp = 0.0;
	if (t_1 <= -2e+299)
		tmp = (x / (y - t)) * (2.0 / z);
	elseif (t_1 <= -2e-264)
		tmp = (x / ((y - t) * z)) * 2.0;
	elseif (t_1 <= 1e-78)
		tmp = t_2;
	elseif (t_1 <= 4e+46)
		tmp = x * ((2.0 / (y - t)) / z);
	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[(t * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(2.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+299], N[(N[(x / N[(y - t), $MachinePrecision]), $MachinePrecision] * N[(2.0 / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -2e-264], N[(N[(x / N[(N[(y - t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], If[LessEqual[t$95$1, 1e-78], t$95$2, If[LessEqual[t$95$1, 4e+46], N[(x * N[(N[(2.0 / N[(y - t), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := y \cdot z - t \cdot z\\
t_2 := \frac{2 \cdot \frac{x}{z}}{y - t}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+299}:\\
\;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\

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

\mathbf{elif}\;t_1 \leq 10^{-78}:\\
\;\;\;\;t_2\\

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.9
Target2.3
Herbie1.8
\[\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.0000000000000001e299

    1. Initial program 18.5

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

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

      [Start]18.5

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

      rational.json-simplify-2 [=>]18.5

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

      rational.json-simplify-52 [=>]18.5

      \[ \frac{x \cdot 2}{\color{blue}{z \cdot \left(y - t\right)}} \]
    3. Applied egg-rr0.1

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

    if -2.0000000000000001e299 < (-.f64 (*.f64 y z) (*.f64 t z)) < -2e-264

    1. Initial program 0.2

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

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

      [Start]0.2

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

      rational.json-simplify-2 [=>]0.2

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

      rational.json-simplify-52 [=>]0.2

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

      rational.json-simplify-46 [=>]8.2

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

      rational.json-simplify-49 [=>]8.2

      \[ \frac{\color{blue}{2 \cdot \frac{x}{z}}}{y - t} \]
    3. Applied egg-rr7.9

      \[\leadsto \color{blue}{\frac{\frac{2}{y - t}}{\frac{z}{x}} + 0} \]
    4. Simplified8.2

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

      [Start]7.9

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

      rational.json-simplify-4 [=>]7.9

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

      rational.json-simplify-47 [=>]8.2

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

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

    if -2e-264 < (-.f64 (*.f64 y z) (*.f64 t z)) < 9.99999999999999999e-79 or 4e46 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 10.9

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

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

      [Start]10.9

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

      rational.json-simplify-2 [=>]10.9

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

      rational.json-simplify-52 [=>]8.5

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

      rational.json-simplify-46 [=>]3.9

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

      rational.json-simplify-49 [=>]3.9

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

    if 9.99999999999999999e-79 < (-.f64 (*.f64 y z) (*.f64 t z)) < 4e46

    1. Initial program 0.4

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

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

      [Start]0.4

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

      rational.json-simplify-2 [=>]0.4

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

      rational.json-simplify-49 [=>]0.3

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

      rational.json-simplify-2 [=>]0.3

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

      rational.json-simplify-52 [=>]0.3

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

      rational.json-simplify-46 [=>]0.3

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

      rational.json-simplify-44 [=>]0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - t \cdot z \leq -2 \cdot 10^{+299}:\\ \;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{elif}\;y \cdot z - t \cdot z \leq -2 \cdot 10^{-264}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \mathbf{elif}\;y \cdot z - t \cdot z \leq 10^{-78}:\\ \;\;\;\;\frac{2 \cdot \frac{x}{z}}{y - t}\\ \mathbf{elif}\;y \cdot z - t \cdot z \leq 4 \cdot 10^{+46}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot \frac{x}{z}}{y - t}\\ \end{array} \]

Alternatives

Alternative 1
Error2.4
Cost1096
\[\begin{array}{l} t_1 := \frac{x}{y - t} \cdot \frac{2}{z}\\ \mathbf{if}\;x \cdot 2 \leq -4 \cdot 10^{+78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot 2 \leq 5 \cdot 10^{-20}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error2.7
Cost840
\[\begin{array}{l} t_1 := \frac{2}{\left(y - t\right) \cdot \frac{z}{x}}\\ \mathbf{if}\;z \leq -3.5 \cdot 10^{+15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{+18}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error2.7
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{+15}:\\ \;\;\;\;\frac{2}{\left(y - t\right) \cdot \frac{z}{x}}\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{+19}:\\ \;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{\frac{y - t}{\frac{x}{z}}}\\ \end{array} \]
Alternative 4
Error17.6
Cost712
\[\begin{array}{l} t_1 := x \cdot \frac{\frac{2}{y}}{z}\\ \mathbf{if}\;y \leq -2.55 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-65}:\\ \;\;\;\;x \cdot \frac{\frac{-2}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error17.7
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.1 \cdot 10^{+19}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y}}{z}\\ \mathbf{elif}\;y \leq 3.3 \cdot 10^{-65}:\\ \;\;\;\;x \cdot \frac{\frac{-2}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z}\\ \end{array} \]
Alternative 6
Error17.4
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -7.2 \cdot 10^{+19}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y}}{z}\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+79}:\\ \;\;\;\;\frac{\frac{-2}{t}}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{y \cdot z}\\ \end{array} \]
Alternative 7
Error17.4
Cost712
\[\begin{array}{l} t_1 := \frac{\frac{2}{z}}{\frac{y}{x}}\\ \mathbf{if}\;y \leq -1.15 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.9 \cdot 10^{+76}:\\ \;\;\;\;\frac{\frac{-2}{t}}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error17.2
Cost712
\[\begin{array}{l} t_1 := \frac{\frac{x}{y}}{z \cdot 0.5}\\ \mathbf{if}\;y \leq -1.1 \cdot 10^{+18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+75}:\\ \;\;\;\;\frac{\frac{-2}{t}}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error6.0
Cost708
\[\begin{array}{l} \mathbf{if}\;t \leq 8 \cdot 10^{+184}:\\ \;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{t}}{\frac{z}{-2}}\\ \end{array} \]
Alternative 10
Error31.5
Cost448
\[-2 \cdot \frac{x}{t \cdot z} \]
Alternative 11
Error31.4
Cost448
\[x \cdot \frac{\frac{-2}{t}}{z} \]

Error

Reproduce?

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