?

Average Error: 10.78% → 1.89%
Time: 10.6s
Precision: binary64
Cost: 2640

?

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

\mathbf{elif}\;t_2 \leq -2 \cdot 10^{-69}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;\frac{\frac{2 \cdot x}{z}}{y - t}\\

\mathbf{elif}\;t_2 \leq 2 \cdot 10^{+122}:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.78%
Target3.85%
Herbie1.89%
\[\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.999999999999999e258 or 2.00000000000000003e122 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 21.65

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

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

      [Start]21.65

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

      *-commutative [=>]21.65

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

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

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

      times-frac [=>]1.8

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

      associate-*r/ [=>]1.67

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

      associate-/l* [=>]1.84

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

    if -9.999999999999999e258 < (-.f64 (*.f64 y z) (*.f64 t z)) < -1.9999999999999999e-69 or -0.0 < (-.f64 (*.f64 y z) (*.f64 t z)) < 2.00000000000000003e122

    1. Initial program 0.64

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

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

      [Start]0.64

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

      associate-/l* [=>]0.57

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

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

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

    if -1.9999999999999999e-69 < (-.f64 (*.f64 y z) (*.f64 t z)) < -0.0

    1. Initial program 18.14

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

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

      [Start]18.14

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

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

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

      associate-/r* [=>]9.06

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

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

Alternatives

Alternative 1
Error4.03%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+91} \lor \neg \left(z \leq 1.58 \cdot 10^{+63}\right):\\ \;\;\;\;\frac{\frac{2}{z}}{\frac{y - t}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\ \end{array} \]
Alternative 2
Error4.18%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{+91} \lor \neg \left(z \leq 8.2 \cdot 10^{+63}\right):\\ \;\;\;\;\frac{\frac{x}{y - t}}{z \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\ \end{array} \]
Alternative 3
Error26.86%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -8.5 \cdot 10^{+34} \lor \neg \left(t \leq 2.9 \cdot 10^{-10}\right):\\ \;\;\;\;x \cdot \frac{-2}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{2}{y \cdot z}\\ \end{array} \]
Alternative 4
Error27.88%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -5.5 \cdot 10^{+27} \lor \neg \left(t \leq 1.08 \cdot 10^{+101}\right):\\ \;\;\;\;x \cdot \frac{-2}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y}\\ \end{array} \]
Alternative 5
Error27.66%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -3.7 \cdot 10^{+24} \lor \neg \left(t \leq 1.08 \cdot 10^{+101}\right):\\ \;\;\;\;\frac{-2}{z} \cdot \frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{z} \cdot \frac{x}{y}\\ \end{array} \]
Alternative 6
Error26.5%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -1.4 \cdot 10^{+33} \lor \neg \left(t \leq 1.95 \cdot 10^{+101}\right):\\ \;\;\;\;\frac{-2}{z} \cdot \frac{x}{t}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y}\\ \end{array} \]
Alternative 7
Error26.59%
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -1.5 \cdot 10^{+31}:\\ \;\;\;\;\frac{-2}{z} \cdot \frac{x}{t}\\ \mathbf{elif}\;t \leq 1.08 \cdot 10^{+101}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-2}{z}}{\frac{t}{x}}\\ \end{array} \]
Alternative 8
Error26.56%
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -8.5 \cdot 10^{+24}:\\ \;\;\;\;\frac{\frac{\frac{x}{t}}{z}}{-0.5}\\ \mathbf{elif}\;t \leq 4.1 \cdot 10^{+101}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-2}{z}}{\frac{t}{x}}\\ \end{array} \]
Alternative 9
Error10.11%
Cost708
\[\begin{array}{l} \mathbf{if}\;t \leq 2.1 \cdot 10^{+152}:\\ \;\;\;\;x \cdot \frac{\frac{2}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-2}{z}}{\frac{t}{x}}\\ \end{array} \]
Alternative 10
Error48.98%
Cost448
\[x \cdot \frac{-2}{z \cdot t} \]

Error

Reproduce?

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