?

Average Error: 6.5 → 0.9
Time: 1.9min
Precision: binary64
Cost: 2768

?

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

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

\mathbf{elif}\;t_2 \leq 5 \cdot 10^{-293}:\\
\;\;\;\;t_1\\

\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

Original6.5
Target2.0
Herbie0.9
\[\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.00000000000000008e192

    1. Initial program 11.3

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
    2. Applied egg-rr0.5

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

    if -2.00000000000000008e192 < (-.f64 (*.f64 y z) (*.f64 t z)) < -2e-131 or 5.0000000000000003e-293 < (-.f64 (*.f64 y z) (*.f64 t z)) < 2.00000000000000003e122

    1. Initial program 0.3

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

    if -2e-131 < (-.f64 (*.f64 y z) (*.f64 t z)) < 5.0000000000000003e-293 or 2.00000000000000003e122 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 13.5

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

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

Alternatives

Alternative 1
Error2.7
Cost1096
\[\begin{array}{l} t_1 := \frac{\frac{2 \cdot x}{y - t}}{z}\\ \mathbf{if}\;x \cdot 2 \leq -0.0005:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot 2 \leq 2 \cdot 10^{+107}:\\ \;\;\;\;\frac{\frac{2}{z} \cdot x}{y - t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error17.7
Cost712
\[\begin{array}{l} t_1 := \frac{-2 \cdot x}{t \cdot z}\\ \mathbf{if}\;t \leq -1.22 \cdot 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{+102}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error18.0
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -1.5 \cdot 10^{-5}:\\ \;\;\;\;\frac{-2 \cdot x}{t \cdot z}\\ \mathbf{elif}\;t \leq 1.4 \cdot 10^{+102}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-2}{z} \cdot x}{t}\\ \end{array} \]
Alternative 4
Error18.0
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -1.38 \cdot 10^{-5}:\\ \;\;\;\;\frac{-2 \cdot x}{t \cdot z}\\ \mathbf{elif}\;t \leq 1.5 \cdot 10^{+102}:\\ \;\;\;\;\frac{\frac{2}{z} \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-2}{z} \cdot x}{t}\\ \end{array} \]
Alternative 5
Error18.0
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -1.65 \cdot 10^{-5}:\\ \;\;\;\;\frac{-2 \cdot x}{t \cdot z}\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{+102}:\\ \;\;\;\;\frac{\frac{\frac{x}{z}}{0.5}}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-2}{z} \cdot x}{t}\\ \end{array} \]
Alternative 6
Error29.6
Cost580
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-7}:\\ \;\;\;\;\frac{x}{y} \cdot \frac{2}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \frac{2}{y}\\ \end{array} \]
Alternative 7
Error5.9
Cost576
\[\frac{x}{z} \cdot \frac{2}{y - t} \]
Alternative 8
Error5.9
Cost576
\[\frac{\frac{2}{z} \cdot x}{y - t} \]
Alternative 9
Error31.9
Cost448
\[\frac{x}{y} \cdot \frac{2}{z} \]

Error

Reproduce?

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