Average Error: 7.2 → 0.8
Time: 8.4s
Precision: binary64
Cost: 2640
\[ \begin{array}{c}[y, t] = \mathsf{sort}([y, t])\\ \end{array} \]
\[\left(x \cdot y - z \cdot y\right) \cdot t \]
\[\begin{array}{l} t_1 := x \cdot y - y \cdot z\\ t_2 := y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+191}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq -1 \cdot 10^{-119}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+181}:\\ \;\;\;\;t_1 \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (- (* x y) (* y z))) (t_2 (* y (* t (- x z)))))
   (if (<= t_1 -2e+191)
     t_2
     (if (<= t_1 -1e-119)
       (* t (* y (- x z)))
       (if (<= t_1 0.0)
         (* (- x z) (* y t))
         (if (<= t_1 5e+181) (* t_1 t) t_2))))))
double code(double x, double y, double z, double t) {
	return ((x * y) - (z * y)) * t;
}
double code(double x, double y, double z, double t) {
	double t_1 = (x * y) - (y * z);
	double t_2 = y * (t * (x - z));
	double tmp;
	if (t_1 <= -2e+191) {
		tmp = t_2;
	} else if (t_1 <= -1e-119) {
		tmp = t * (y * (x - z));
	} else if (t_1 <= 0.0) {
		tmp = (x - z) * (y * t);
	} else if (t_1 <= 5e+181) {
		tmp = t_1 * t;
	} 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 * y) - (z * y)) * t
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 = (x * y) - (y * z)
    t_2 = y * (t * (x - z))
    if (t_1 <= (-2d+191)) then
        tmp = t_2
    else if (t_1 <= (-1d-119)) then
        tmp = t * (y * (x - z))
    else if (t_1 <= 0.0d0) then
        tmp = (x - z) * (y * t)
    else if (t_1 <= 5d+181) then
        tmp = t_1 * t
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return ((x * y) - (z * y)) * t;
}
public static double code(double x, double y, double z, double t) {
	double t_1 = (x * y) - (y * z);
	double t_2 = y * (t * (x - z));
	double tmp;
	if (t_1 <= -2e+191) {
		tmp = t_2;
	} else if (t_1 <= -1e-119) {
		tmp = t * (y * (x - z));
	} else if (t_1 <= 0.0) {
		tmp = (x - z) * (y * t);
	} else if (t_1 <= 5e+181) {
		tmp = t_1 * t;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t):
	return ((x * y) - (z * y)) * t
def code(x, y, z, t):
	t_1 = (x * y) - (y * z)
	t_2 = y * (t * (x - z))
	tmp = 0
	if t_1 <= -2e+191:
		tmp = t_2
	elif t_1 <= -1e-119:
		tmp = t * (y * (x - z))
	elif t_1 <= 0.0:
		tmp = (x - z) * (y * t)
	elif t_1 <= 5e+181:
		tmp = t_1 * t
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t)
	return Float64(Float64(Float64(x * y) - Float64(z * y)) * t)
end
function code(x, y, z, t)
	t_1 = Float64(Float64(x * y) - Float64(y * z))
	t_2 = Float64(y * Float64(t * Float64(x - z)))
	tmp = 0.0
	if (t_1 <= -2e+191)
		tmp = t_2;
	elseif (t_1 <= -1e-119)
		tmp = Float64(t * Float64(y * Float64(x - z)));
	elseif (t_1 <= 0.0)
		tmp = Float64(Float64(x - z) * Float64(y * t));
	elseif (t_1 <= 5e+181)
		tmp = Float64(t_1 * t);
	else
		tmp = t_2;
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = ((x * y) - (z * y)) * t;
end
function tmp_2 = code(x, y, z, t)
	t_1 = (x * y) - (y * z);
	t_2 = y * (t * (x - z));
	tmp = 0.0;
	if (t_1 <= -2e+191)
		tmp = t_2;
	elseif (t_1 <= -1e-119)
		tmp = t * (y * (x - z));
	elseif (t_1 <= 0.0)
		tmp = (x - z) * (y * t);
	elseif (t_1 <= 5e+181)
		tmp = t_1 * t;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+191], t$95$2, If[LessEqual[t$95$1, -1e-119], N[(t * N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(N[(x - z), $MachinePrecision] * N[(y * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+181], N[(t$95$1 * t), $MachinePrecision], t$95$2]]]]]]
\left(x \cdot y - z \cdot y\right) \cdot t
\begin{array}{l}
t_1 := x \cdot y - y \cdot z\\
t_2 := y \cdot \left(t \cdot \left(x - z\right)\right)\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+191}:\\
\;\;\;\;t_2\\

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

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+181}:\\
\;\;\;\;t_1 \cdot t\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.2
Target3.4
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;t < -9.231879582886777 \cdot 10^{-80}:\\ \;\;\;\;\left(y \cdot t\right) \cdot \left(x - z\right)\\ \mathbf{elif}\;t < 2.543067051564877 \cdot 10^{+83}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot \left(x - z\right)\right) \cdot t\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 z y)) < -2.00000000000000015e191 or 5.0000000000000003e181 < (-.f64 (*.f64 x y) (*.f64 z y))

    1. Initial program 26.1

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Simplified1.6

      \[\leadsto \color{blue}{y \cdot \left(t \cdot \left(x - z\right)\right)} \]
      Proof
      (*.f64 y (*.f64 t (-.f64 x z))): 0 points increase in error, 0 points decrease in error
      (*.f64 y (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 x z) t))): 0 points increase in error, 2 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y (-.f64 x z)) t)): 2 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 x y) (*.f64 z y))) t): 0 points increase in error, 2 points decrease in error

    if -2.00000000000000015e191 < (-.f64 (*.f64 x y) (*.f64 z y)) < -1.00000000000000001e-119

    1. Initial program 0.3

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Simplified0.3

      \[\leadsto \color{blue}{\left(y \cdot \left(x - z\right)\right) \cdot t} \]
      Proof
      (*.f64 y (*.f64 t (-.f64 x z))): 0 points increase in error, 0 points decrease in error
      (*.f64 y (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 x z) t))): 0 points increase in error, 2 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y (-.f64 x z)) t)): 2 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 x y) (*.f64 z y))) t): 0 points increase in error, 2 points decrease in error

    if -1.00000000000000001e-119 < (-.f64 (*.f64 x y) (*.f64 z y)) < -0.0

    1. Initial program 8.5

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Simplified2.2

      \[\leadsto \color{blue}{y \cdot \left(t \cdot \left(x - z\right)\right)} \]
      Proof
      (*.f64 y (*.f64 t (-.f64 x z))): 0 points increase in error, 0 points decrease in error
      (*.f64 y (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 x z) t))): 0 points increase in error, 2 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y (-.f64 x z)) t)): 2 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 x y) (*.f64 z y))) t): 0 points increase in error, 2 points decrease in error
    3. Taylor expanded in x around 0 2.2

      \[\leadsto \color{blue}{y \cdot \left(t \cdot x\right) + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right)} \]
    4. Simplified1.7

      \[\leadsto \color{blue}{\left(x - z\right) \cdot \left(y \cdot t\right)} \]
      Proof
      (*.f64 (-.f64 x z) (*.f64 y t)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 y t) (-.f64 x z))): 0 points increase in error, 2 points decrease in error
      (*.f64 (*.f64 y t) (Rewrite=> sub-neg_binary64 (+.f64 x (neg.f64 z)))): 8 points increase in error, 0 points decrease in error
      (Rewrite=> distribute-lft-in_binary64 (+.f64 (*.f64 (*.f64 y t) x) (*.f64 (*.f64 y t) (neg.f64 z)))): 0 points increase in error, 4 points decrease in error
      (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 t x))) (*.f64 (*.f64 y t) (neg.f64 z))): 0 points increase in error, 8 points decrease in error
      (+.f64 (*.f64 y (*.f64 t x)) (Rewrite=> distribute-rgt-neg-out_binary64 (neg.f64 (*.f64 (*.f64 y t) z)))): 8 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 y (*.f64 t x)) (neg.f64 (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 t z))))): 0 points increase in error, 8 points decrease in error
      (+.f64 (*.f64 y (*.f64 t x)) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (*.f64 y (*.f64 t z))))): 0 points increase in error, 0 points decrease in error

    if -0.0 < (-.f64 (*.f64 x y) (*.f64 z y)) < 5.0000000000000003e181

    1. Initial program 0.4

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
  3. Recombined 4 regimes into one program.
  4. Final simplification0.8

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

Alternatives

Alternative 1
Error19.7
Cost1376
\[\begin{array}{l} t_1 := y \cdot \left(x \cdot t\right)\\ t_2 := x \cdot \left(y \cdot t\right)\\ t_3 := \left(y \cdot z\right) \cdot \left(-t\right)\\ t_4 := z \cdot \left(y \cdot \left(-t\right)\right)\\ \mathbf{if}\;x \leq -4.2 \cdot 10^{+24}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -42000000000:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq -4 \cdot 10^{-46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.32 \cdot 10^{-278}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-54}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;x \leq 1900000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.15 \cdot 10^{+27}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 10^{+256}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error20.3
Cost913
\[\begin{array}{l} t_1 := \left(y \cdot z\right) \cdot \left(-t\right)\\ \mathbf{if}\;z \leq -9.5 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-66}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;z \leq -4.4 \cdot 10^{-95} \lor \neg \left(z \leq 1.2 \cdot 10^{+77}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(x \cdot y\right)\\ \end{array} \]
Alternative 3
Error20.3
Cost912
\[\begin{array}{l} t_1 := \left(y \cdot z\right) \cdot \left(-t\right)\\ \mathbf{if}\;z \leq -2.12 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -7.2 \cdot 10^{-64}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{-95}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-t\right)\right)\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{+77}:\\ \;\;\;\;t \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error2.9
Cost580
\[\begin{array}{l} \mathbf{if}\;t \leq 8.5 \cdot 10^{+73}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \end{array} \]
Alternative 5
Error2.3
Cost580
\[\begin{array}{l} \mathbf{if}\;t \leq 2 \cdot 10^{+36}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 6
Error29.2
Cost452
\[\begin{array}{l} \mathbf{if}\;y \leq -3 \cdot 10^{+16}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(x \cdot y\right)\\ \end{array} \]
Alternative 7
Error29.1
Cost452
\[\begin{array}{l} \mathbf{if}\;t \leq 3.5 \cdot 10^{+38}:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 8
Error7.4
Cost448
\[y \cdot \left(t \cdot \left(x - z\right)\right) \]
Alternative 9
Error31.7
Cost320
\[t \cdot \left(x \cdot y\right) \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y z t)
  :name "Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3"
  :precision binary64

  :herbie-target
  (if (< t -9.231879582886777e-80) (* (* y t) (- x z)) (if (< t 2.543067051564877e+83) (* y (* t (- x z))) (* (* y (- x z)) t)))

  (* (- (* x y) (* z y)) t))