Linear.Projection:infinitePerspective from linear-1.19.1.3, A

?

Percentage Accurate: 89.6% → 99.1%
Time: 11.5s
Precision: binary64
Cost: 2642

?

\[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
\[\begin{array}{l} t_1 := y \cdot z - z \cdot t\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{+198} \lor \neg \left(t_1 \leq -1 \cdot 10^{-118}\right) \land \left(t_1 \leq 0 \lor \neg \left(t_1 \leq 5 \cdot 10^{+268}\right)\right):\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{\frac{-2}{t - y}}{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))))
   (if (or (<= t_1 -4e+198)
           (and (not (<= t_1 -1e-118))
                (or (<= t_1 0.0) (not (<= t_1 5e+268)))))
     (* 2.0 (/ (/ x z) (- y t)))
     (* x (/ (/ -2.0 (- t y)) 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 tmp;
	if ((t_1 <= -4e+198) || (!(t_1 <= -1e-118) && ((t_1 <= 0.0) || !(t_1 <= 5e+268)))) {
		tmp = 2.0 * ((x / z) / (y - t));
	} else {
		tmp = x * ((-2.0 / (t - y)) / 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) :: tmp
    t_1 = (y * z) - (z * t)
    if ((t_1 <= (-4d+198)) .or. (.not. (t_1 <= (-1d-118))) .and. (t_1 <= 0.0d0) .or. (.not. (t_1 <= 5d+268))) then
        tmp = 2.0d0 * ((x / z) / (y - t))
    else
        tmp = x * (((-2.0d0) / (t - y)) / 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 tmp;
	if ((t_1 <= -4e+198) || (!(t_1 <= -1e-118) && ((t_1 <= 0.0) || !(t_1 <= 5e+268)))) {
		tmp = 2.0 * ((x / z) / (y - t));
	} else {
		tmp = x * ((-2.0 / (t - y)) / 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)
	tmp = 0
	if (t_1 <= -4e+198) or (not (t_1 <= -1e-118) and ((t_1 <= 0.0) or not (t_1 <= 5e+268))):
		tmp = 2.0 * ((x / z) / (y - t))
	else:
		tmp = x * ((-2.0 / (t - y)) / 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))
	tmp = 0.0
	if ((t_1 <= -4e+198) || (!(t_1 <= -1e-118) && ((t_1 <= 0.0) || !(t_1 <= 5e+268))))
		tmp = Float64(2.0 * Float64(Float64(x / z) / Float64(y - t)));
	else
		tmp = Float64(x * Float64(Float64(-2.0 / Float64(t - y)) / 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);
	tmp = 0.0;
	if ((t_1 <= -4e+198) || (~((t_1 <= -1e-118)) && ((t_1 <= 0.0) || ~((t_1 <= 5e+268)))))
		tmp = 2.0 * ((x / z) / (y - t));
	else
		tmp = x * ((-2.0 / (t - y)) / 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]}, If[Or[LessEqual[t$95$1, -4e+198], And[N[Not[LessEqual[t$95$1, -1e-118]], $MachinePrecision], Or[LessEqual[t$95$1, 0.0], N[Not[LessEqual[t$95$1, 5e+268]], $MachinePrecision]]]], N[(2.0 * N[(N[(x / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(-2.0 / N[(t - y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := y \cdot z - z \cdot t\\
\mathbf{if}\;t_1 \leq -4 \cdot 10^{+198} \lor \neg \left(t_1 \leq -1 \cdot 10^{-118}\right) \land \left(t_1 \leq 0 \lor \neg \left(t_1 \leq 5 \cdot 10^{+268}\right)\right):\\
\;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\

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


\end{array}

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original89.6%
Target96.9%
Herbie99.1%
\[\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 2 regimes
  2. if (-.f64 (*.f64 y z) (*.f64 t z)) < -4.00000000000000007e198 or -9.99999999999999985e-119 < (-.f64 (*.f64 y z) (*.f64 t z)) < -0.0 or 5.0000000000000002e268 < (-.f64 (*.f64 y z) (*.f64 t z))

    1. Initial program 76.4%

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

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

      [Start]76.4

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

      associate-*l/ [<=]76.4

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

      *-commutative [=>]76.4

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

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

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

      associate-/r* [=>]99.8

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

    if -4.00000000000000007e198 < (-.f64 (*.f64 y z) (*.f64 t z)) < -9.99999999999999985e-119 or -0.0 < (-.f64 (*.f64 y z) (*.f64 t z)) < 5.0000000000000002e268

    1. Initial program 99.5%

      \[\frac{x \cdot 2}{y \cdot z - t \cdot z} \]
    2. Simplified99.7%

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

      [Start]99.5

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

      associate-*r/ [<=]99.5

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

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

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

      associate-/l/ [<=]99.7

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

      sub-neg [=>]99.7

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

      +-commutative [=>]99.7

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

      neg-sub0 [=>]99.7

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

      associate-+l- [=>]99.7

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

      sub0-neg [=>]99.7

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

      neg-mul-1 [=>]99.7

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

      associate-/r* [=>]99.7

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

      metadata-eval [=>]99.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z - z \cdot t \leq -4 \cdot 10^{+198} \lor \neg \left(y \cdot z - z \cdot t \leq -1 \cdot 10^{-118}\right) \land \left(y \cdot z - z \cdot t \leq 0 \lor \neg \left(y \cdot z - z \cdot t \leq 5 \cdot 10^{+268}\right)\right):\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{\frac{-2}{t - y}}{z}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy73.2%
Cost976
\[\begin{array}{l} t_1 := \frac{x}{t} \cdot \frac{-2}{z}\\ \mathbf{if}\;t \leq -8 \cdot 10^{+18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.5 \cdot 10^{-72}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y}\\ \mathbf{elif}\;t \leq 2.1 \cdot 10^{-143}:\\ \;\;\;\;\frac{2 \cdot x}{y \cdot z}\\ \mathbf{elif}\;t \leq 6.6 \cdot 10^{-23}:\\ \;\;\;\;\frac{2 \cdot \frac{x}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Accuracy73.2%
Cost976
\[\begin{array}{l} t_1 := \frac{\frac{x}{\frac{t}{-2}}}{z}\\ \mathbf{if}\;t \leq -1.3 \cdot 10^{+19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -4 \cdot 10^{-72}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y}\\ \mathbf{elif}\;t \leq 7.4 \cdot 10^{-143}:\\ \;\;\;\;\frac{2 \cdot x}{y \cdot z}\\ \mathbf{elif}\;t \leq 2.2 \cdot 10^{-23}:\\ \;\;\;\;\frac{2 \cdot \frac{x}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy74.1%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -5.8 \cdot 10^{+26} \lor \neg \left(t \leq 2.1 \cdot 10^{-20}\right):\\ \;\;\;\;x \cdot \frac{\frac{-2}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y}\\ \end{array} \]
Alternative 4
Accuracy73.7%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -1.82 \cdot 10^{+19} \lor \neg \left(t \leq 1.8 \cdot 10^{-22}\right):\\ \;\;\;\;\frac{x}{t} \cdot \frac{-2}{z}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y}\\ \end{array} \]
Alternative 5
Accuracy90.6%
Cost708
\[\begin{array}{l} \mathbf{if}\;t \leq 1.45 \cdot 10^{+120}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{\frac{t}{-2}}}{z}\\ \end{array} \]
Alternative 6
Accuracy93.9%
Cost708
\[\begin{array}{l} \mathbf{if}\;z \leq 2.5 \cdot 10^{+52}:\\ \;\;\;\;x \cdot \frac{2}{z \cdot \left(y - t\right)}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\ \end{array} \]
Alternative 7
Accuracy55.7%
Cost448
\[2 \cdot \frac{\frac{x}{z}}{y} \]

Error

Reproduce?

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