?

Average Error: 11.35% → 2.12%
Time: 12.9s
Precision: binary64
Cost: 1608

?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{t_1}}{z}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original11.35%
Target3.63%
Herbie2.12%
\[\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)) < -2.00000000000000008e201

    1. Initial program 19.5

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

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

      [Start]19.5

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

      *-commutative [=>]19.5

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

      distribute-rgt-out-- [=>]19.5

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

      times-frac [=>]0.66

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

      associate-*r/ [=>]0.92

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

      associate-/l* [=>]0.65

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

    if -2.00000000000000008e201 < (-.f64 (*.f64 y z) (*.f64 t z)) < 1.9999999999999999e211

    1. Initial program 3.07

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

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

      [Start]3.07

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

      associate-/l* [=>]3.08

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

      distribute-rgt-out-- [=>]3.08

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

    if 1.9999999999999999e211 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 29.32

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

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

      [Start]29.32

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

      associate-*r/ [<=]29.36

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

      distribute-rgt-out-- [=>]21.05

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

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

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

Alternatives

Alternative 1
Error29.11%
Cost976
\[\begin{array}{l} t_1 := \frac{2}{z} \cdot \frac{x}{y}\\ t_2 := \frac{-2}{t \cdot \frac{z}{x}}\\ \mathbf{if}\;t \leq -2.05 \cdot 10^{+61}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -2.8 \cdot 10^{-252}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.4 \cdot 10^{+72}:\\ \;\;\;\;\frac{2 \cdot x}{y \cdot z}\\ \mathbf{elif}\;t \leq 3.15 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error29.01%
Cost976
\[\begin{array}{l} t_1 := \frac{2}{z} \cdot \frac{x}{y}\\ \mathbf{if}\;t \leq -2.4 \cdot 10^{+61}:\\ \;\;\;\;\frac{\frac{-2}{t}}{\frac{z}{x}}\\ \mathbf{elif}\;t \leq -4.6 \cdot 10^{-254}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.4 \cdot 10^{+74}:\\ \;\;\;\;\frac{2 \cdot x}{y \cdot z}\\ \mathbf{elif}\;t \leq 3.7 \cdot 10^{+91}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{t \cdot \frac{z}{x}}\\ \end{array} \]
Alternative 3
Error26.66%
Cost976
\[\begin{array}{l} \mathbf{if}\;t \leq -3.65 \cdot 10^{+62}:\\ \;\;\;\;\frac{\frac{-2}{t}}{\frac{z}{x}}\\ \mathbf{elif}\;t \leq -6 \cdot 10^{-252}:\\ \;\;\;\;\frac{\frac{2 \cdot x}{z}}{y}\\ \mathbf{elif}\;t \leq 5.5 \cdot 10^{-40}:\\ \;\;\;\;\frac{2 \cdot x}{y \cdot z}\\ \mathbf{elif}\;t \leq 95000:\\ \;\;\;\;\frac{2}{y \cdot \frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{t \cdot \frac{z}{x}}\\ \end{array} \]
Alternative 4
Error4.65%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -7.1 \cdot 10^{-68} \lor \neg \left(z \leq 6.4 \cdot 10^{+147}\right):\\ \;\;\;\;\frac{\frac{2}{z}}{\frac{y - t}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\ \end{array} \]
Alternative 5
Error11.67%
Cost836
\[\begin{array}{l} \mathbf{if}\;2 \cdot x \leq -1 \cdot 10^{+246}:\\ \;\;\;\;\frac{-2}{t \cdot \frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{2}{z \cdot \left(y - t\right)}\\ \end{array} \]
Alternative 6
Error27.92%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -1.9 \cdot 10^{+61} \lor \neg \left(t \leq 105000\right):\\ \;\;\;\;x \cdot \frac{\frac{-2}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{2}{y \cdot z}\\ \end{array} \]
Alternative 7
Error28.94%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -2.22 \cdot 10^{+61} \lor \neg \left(t \leq 4.6 \cdot 10^{+93}\right):\\ \;\;\;\;x \cdot \frac{\frac{-2}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y}\\ \end{array} \]
Alternative 8
Error29.12%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -1.95 \cdot 10^{+61} \lor \neg \left(t \leq 3 \cdot 10^{+93}\right):\\ \;\;\;\;\frac{-2}{t \cdot \frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y}\\ \end{array} \]
Alternative 9
Error28.5%
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -7 \cdot 10^{+61}:\\ \;\;\;\;\frac{x}{t} \cdot \frac{-2}{z}\\ \mathbf{elif}\;t \leq 3.15 \cdot 10^{+91}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{\frac{-2}{t}}{z}\\ \end{array} \]
Alternative 10
Error29.07%
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -1.9 \cdot 10^{+61}:\\ \;\;\;\;\frac{\frac{-2}{t}}{\frac{z}{x}}\\ \mathbf{elif}\;t \leq 3.15 \cdot 10^{+91}:\\ \;\;\;\;\frac{\frac{2}{z}}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{t \cdot \frac{z}{x}}\\ \end{array} \]
Alternative 11
Error9.53%
Cost708
\[\begin{array}{l} \mathbf{if}\;t \leq -1.95 \cdot 10^{+217}:\\ \;\;\;\;\frac{-2 \cdot \frac{x}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{\frac{2}{z}}{y - t}\\ \end{array} \]
Alternative 12
Error49.09%
Cost448
\[x \cdot \frac{2}{y \cdot z} \]

Error

Reproduce?

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