Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3

Percentage Accurate: 98.1% → 100.0%
Time: 4.6s
Alternatives: 8
Speedup: 1.3×

Specification

?
\[\begin{array}{l} \\ x \cdot y + \left(x - 1\right) \cdot z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
	return (x * y) + ((x - 1.0) * z);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
	return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z):
	return (x * y) + ((x - 1.0) * z)
function code(x, y, z)
	return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z))
end
function tmp = code(x, y, z)
	tmp = (x * y) + ((x - 1.0) * z);
end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 98.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot y + \left(x - 1\right) \cdot z \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
	return (x * y) + ((x - 1.0) * z);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
	return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z):
	return (x * y) + ((x - 1.0) * z)
function code(x, y, z)
	return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z))
end
function tmp = code(x, y, z)
	tmp = (x * y) + ((x - 1.0) * z);
end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}

Alternative 1: 100.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ x \cdot \left(z + y\right) - z \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
	return (x * (z + y)) - z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * (z + y)) - z
end function
public static double code(double x, double y, double z) {
	return (x * (z + y)) - z;
}
def code(x, y, z):
	return (x * (z + y)) - z
function code(x, y, z)
	return Float64(Float64(x * Float64(z + y)) - z)
end
function tmp = code(x, y, z)
	tmp = (x * (z + y)) - z;
end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(z + y\right) - z
\end{array}
Derivation
  1. Initial program 98.8%

    \[x \cdot y + \left(x - 1\right) \cdot z \]
  2. Step-by-step derivation
    1. *-commutative98.8%

      \[\leadsto x \cdot y + \color{blue}{z \cdot \left(x - 1\right)} \]
    2. sub-neg98.8%

      \[\leadsto x \cdot y + z \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
    3. distribute-rgt-in98.8%

      \[\leadsto x \cdot y + \color{blue}{\left(x \cdot z + \left(-1\right) \cdot z\right)} \]
    4. metadata-eval98.8%

      \[\leadsto x \cdot y + \left(x \cdot z + \color{blue}{-1} \cdot z\right) \]
    5. neg-mul-198.8%

      \[\leadsto x \cdot y + \left(x \cdot z + \color{blue}{\left(-z\right)}\right) \]
    6. associate-+r+98.8%

      \[\leadsto \color{blue}{\left(x \cdot y + x \cdot z\right) + \left(-z\right)} \]
    7. unsub-neg98.8%

      \[\leadsto \color{blue}{\left(x \cdot y + x \cdot z\right) - z} \]
    8. +-commutative98.8%

      \[\leadsto \color{blue}{\left(x \cdot z + x \cdot y\right)} - z \]
    9. distribute-lft-out100.0%

      \[\leadsto \color{blue}{x \cdot \left(z + y\right)} - z \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{x \cdot \left(z + y\right) - z} \]
  4. Add Preprocessing
  5. Final simplification100.0%

    \[\leadsto x \cdot \left(z + y\right) - z \]
  6. Add Preprocessing

Alternative 2: 61.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.5 \cdot 10^{-9}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-93}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{+23} \lor \neg \left(x \leq 7.8 \cdot 10^{+59}\right) \land x \leq 9.5 \cdot 10^{+86}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -4.5e-9)
   (* x y)
   (if (<= x 7.5e-93)
     (- z)
     (if (or (<= x 1.3e+23) (and (not (<= x 7.8e+59)) (<= x 9.5e+86)))
       (* x y)
       (* x z)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -4.5e-9) {
		tmp = x * y;
	} else if (x <= 7.5e-93) {
		tmp = -z;
	} else if ((x <= 1.3e+23) || (!(x <= 7.8e+59) && (x <= 9.5e+86))) {
		tmp = x * y;
	} else {
		tmp = x * z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-4.5d-9)) then
        tmp = x * y
    else if (x <= 7.5d-93) then
        tmp = -z
    else if ((x <= 1.3d+23) .or. (.not. (x <= 7.8d+59)) .and. (x <= 9.5d+86)) then
        tmp = x * y
    else
        tmp = x * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -4.5e-9) {
		tmp = x * y;
	} else if (x <= 7.5e-93) {
		tmp = -z;
	} else if ((x <= 1.3e+23) || (!(x <= 7.8e+59) && (x <= 9.5e+86))) {
		tmp = x * y;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -4.5e-9:
		tmp = x * y
	elif x <= 7.5e-93:
		tmp = -z
	elif (x <= 1.3e+23) or (not (x <= 7.8e+59) and (x <= 9.5e+86)):
		tmp = x * y
	else:
		tmp = x * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -4.5e-9)
		tmp = Float64(x * y);
	elseif (x <= 7.5e-93)
		tmp = Float64(-z);
	elseif ((x <= 1.3e+23) || (!(x <= 7.8e+59) && (x <= 9.5e+86)))
		tmp = Float64(x * y);
	else
		tmp = Float64(x * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -4.5e-9)
		tmp = x * y;
	elseif (x <= 7.5e-93)
		tmp = -z;
	elseif ((x <= 1.3e+23) || (~((x <= 7.8e+59)) && (x <= 9.5e+86)))
		tmp = x * y;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -4.5e-9], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.5e-93], (-z), If[Or[LessEqual[x, 1.3e+23], And[N[Not[LessEqual[x, 7.8e+59]], $MachinePrecision], LessEqual[x, 9.5e+86]]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-9}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 7.5 \cdot 10^{-93}:\\
\;\;\;\;-z\\

\mathbf{elif}\;x \leq 1.3 \cdot 10^{+23} \lor \neg \left(x \leq 7.8 \cdot 10^{+59}\right) \land x \leq 9.5 \cdot 10^{+86}:\\
\;\;\;\;x \cdot y\\

\mathbf{else}:\\
\;\;\;\;x \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.49999999999999976e-9 or 7.50000000000000034e-93 < x < 1.29999999999999996e23 or 7.80000000000000043e59 < x < 9.50000000000000028e86

    1. Initial program 98.0%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 63.2%

      \[\leadsto \color{blue}{x \cdot y} \]

    if -4.49999999999999976e-9 < x < 7.50000000000000034e-93

    1. Initial program 100.0%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 74.6%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. neg-mul-174.6%

        \[\leadsto \color{blue}{-z} \]
    5. Simplified74.6%

      \[\leadsto \color{blue}{-z} \]

    if 1.29999999999999996e23 < x < 7.80000000000000043e59 or 9.50000000000000028e86 < x

    1. Initial program 98.0%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Step-by-step derivation
      1. *-commutative98.0%

        \[\leadsto x \cdot y + \color{blue}{z \cdot \left(x - 1\right)} \]
      2. sub-neg98.0%

        \[\leadsto x \cdot y + z \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      3. distribute-rgt-in98.0%

        \[\leadsto x \cdot y + \color{blue}{\left(x \cdot z + \left(-1\right) \cdot z\right)} \]
      4. metadata-eval98.0%

        \[\leadsto x \cdot y + \left(x \cdot z + \color{blue}{-1} \cdot z\right) \]
      5. neg-mul-198.0%

        \[\leadsto x \cdot y + \left(x \cdot z + \color{blue}{\left(-z\right)}\right) \]
      6. associate-+r+98.0%

        \[\leadsto \color{blue}{\left(x \cdot y + x \cdot z\right) + \left(-z\right)} \]
      7. unsub-neg98.0%

        \[\leadsto \color{blue}{\left(x \cdot y + x \cdot z\right) - z} \]
      8. +-commutative98.0%

        \[\leadsto \color{blue}{\left(x \cdot z + x \cdot y\right)} - z \]
      9. distribute-lft-out100.0%

        \[\leadsto \color{blue}{x \cdot \left(z + y\right)} - z \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(z + y\right) - z} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 78.2%

      \[\leadsto \color{blue}{y \cdot \left(x + \frac{x \cdot z}{y}\right)} - z \]
    6. Taylor expanded in y around 0 71.4%

      \[\leadsto \color{blue}{x \cdot z} - z \]
    7. Taylor expanded in x around inf 71.4%

      \[\leadsto \color{blue}{x \cdot z} \]
    8. Step-by-step derivation
      1. *-commutative71.4%

        \[\leadsto \color{blue}{z \cdot x} \]
    9. Simplified71.4%

      \[\leadsto \color{blue}{z \cdot x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification69.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.5 \cdot 10^{-9}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 7.5 \cdot 10^{-93}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{+23} \lor \neg \left(x \leq 7.8 \cdot 10^{+59}\right) \land x \leq 9.5 \cdot 10^{+86}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{-9} \lor \neg \left(x \leq -2.8 \cdot 10^{-59}\right) \land \left(x \leq -1.1 \cdot 10^{-135} \lor \neg \left(x \leq 1.8 \cdot 10^{-92}\right)\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -7.2e-9)
         (and (not (<= x -2.8e-59))
              (or (<= x -1.1e-135) (not (<= x 1.8e-92)))))
   (* x (+ z y))
   (- z)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -7.2e-9) || (!(x <= -2.8e-59) && ((x <= -1.1e-135) || !(x <= 1.8e-92)))) {
		tmp = x * (z + y);
	} else {
		tmp = -z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-7.2d-9)) .or. (.not. (x <= (-2.8d-59))) .and. (x <= (-1.1d-135)) .or. (.not. (x <= 1.8d-92))) then
        tmp = x * (z + y)
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -7.2e-9) || (!(x <= -2.8e-59) && ((x <= -1.1e-135) || !(x <= 1.8e-92)))) {
		tmp = x * (z + y);
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -7.2e-9) or (not (x <= -2.8e-59) and ((x <= -1.1e-135) or not (x <= 1.8e-92))):
		tmp = x * (z + y)
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -7.2e-9) || (!(x <= -2.8e-59) && ((x <= -1.1e-135) || !(x <= 1.8e-92))))
		tmp = Float64(x * Float64(z + y));
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -7.2e-9) || (~((x <= -2.8e-59)) && ((x <= -1.1e-135) || ~((x <= 1.8e-92)))))
		tmp = x * (z + y);
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e-9], And[N[Not[LessEqual[x, -2.8e-59]], $MachinePrecision], Or[LessEqual[x, -1.1e-135], N[Not[LessEqual[x, 1.8e-92]], $MachinePrecision]]]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-9} \lor \neg \left(x \leq -2.8 \cdot 10^{-59}\right) \land \left(x \leq -1.1 \cdot 10^{-135} \lor \neg \left(x \leq 1.8 \cdot 10^{-92}\right)\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -7.2e-9 or -2.79999999999999981e-59 < x < -1.1e-135 or 1.80000000000000008e-92 < x

    1. Initial program 98.2%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 92.8%

      \[\leadsto \color{blue}{x \cdot \left(y + z\right)} \]
    4. Step-by-step derivation
      1. +-commutative92.8%

        \[\leadsto x \cdot \color{blue}{\left(z + y\right)} \]
    5. Simplified92.8%

      \[\leadsto \color{blue}{x \cdot \left(z + y\right)} \]

    if -7.2e-9 < x < -2.79999999999999981e-59 or -1.1e-135 < x < 1.80000000000000008e-92

    1. Initial program 100.0%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 81.8%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. neg-mul-181.8%

        \[\leadsto \color{blue}{-z} \]
    5. Simplified81.8%

      \[\leadsto \color{blue}{-z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{-9} \lor \neg \left(x \leq -2.8 \cdot 10^{-59}\right) \land \left(x \leq -1.1 \cdot 10^{-135} \lor \neg \left(x \leq 1.8 \cdot 10^{-92}\right)\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 82.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(z + y\right)\\ \mathbf{if}\;x \leq -1.45 \cdot 10^{-8}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-64}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \mathbf{elif}\;x \leq -2.05 \cdot 10^{-135} \lor \neg \left(x \leq 1.8 \cdot 10^{-92}\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ z y))))
   (if (<= x -1.45e-8)
     t_0
     (if (<= x -9.5e-64)
       (* z (+ x -1.0))
       (if (or (<= x -2.05e-135) (not (<= x 1.8e-92))) t_0 (- z))))))
double code(double x, double y, double z) {
	double t_0 = x * (z + y);
	double tmp;
	if (x <= -1.45e-8) {
		tmp = t_0;
	} else if (x <= -9.5e-64) {
		tmp = z * (x + -1.0);
	} else if ((x <= -2.05e-135) || !(x <= 1.8e-92)) {
		tmp = t_0;
	} else {
		tmp = -z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x * (z + y)
    if (x <= (-1.45d-8)) then
        tmp = t_0
    else if (x <= (-9.5d-64)) then
        tmp = z * (x + (-1.0d0))
    else if ((x <= (-2.05d-135)) .or. (.not. (x <= 1.8d-92))) then
        tmp = t_0
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (z + y);
	double tmp;
	if (x <= -1.45e-8) {
		tmp = t_0;
	} else if (x <= -9.5e-64) {
		tmp = z * (x + -1.0);
	} else if ((x <= -2.05e-135) || !(x <= 1.8e-92)) {
		tmp = t_0;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (z + y)
	tmp = 0
	if x <= -1.45e-8:
		tmp = t_0
	elif x <= -9.5e-64:
		tmp = z * (x + -1.0)
	elif (x <= -2.05e-135) or not (x <= 1.8e-92):
		tmp = t_0
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(z + y))
	tmp = 0.0
	if (x <= -1.45e-8)
		tmp = t_0;
	elseif (x <= -9.5e-64)
		tmp = Float64(z * Float64(x + -1.0));
	elseif ((x <= -2.05e-135) || !(x <= 1.8e-92))
		tmp = t_0;
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (z + y);
	tmp = 0.0;
	if (x <= -1.45e-8)
		tmp = t_0;
	elseif (x <= -9.5e-64)
		tmp = z * (x + -1.0);
	elseif ((x <= -2.05e-135) || ~((x <= 1.8e-92)))
		tmp = t_0;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.45e-8], t$95$0, If[LessEqual[x, -9.5e-64], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -2.05e-135], N[Not[LessEqual[x, 1.8e-92]], $MachinePrecision]], t$95$0, (-z)]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -1.45 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -9.5 \cdot 10^{-64}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\

\mathbf{elif}\;x \leq -2.05 \cdot 10^{-135} \lor \neg \left(x \leq 1.8 \cdot 10^{-92}\right):\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.4500000000000001e-8 or -9.50000000000000043e-64 < x < -2.05000000000000005e-135 or 1.80000000000000008e-92 < x

    1. Initial program 98.2%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 92.8%

      \[\leadsto \color{blue}{x \cdot \left(y + z\right)} \]
    4. Step-by-step derivation
      1. +-commutative92.8%

        \[\leadsto x \cdot \color{blue}{\left(z + y\right)} \]
    5. Simplified92.8%

      \[\leadsto \color{blue}{x \cdot \left(z + y\right)} \]

    if -1.4500000000000001e-8 < x < -9.50000000000000043e-64

    1. Initial program 99.7%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 80.1%

      \[\leadsto \color{blue}{z \cdot \left(x - 1\right)} \]

    if -2.05000000000000005e-135 < x < 1.80000000000000008e-92

    1. Initial program 100.0%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 82.8%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. neg-mul-182.8%

        \[\leadsto \color{blue}{-z} \]
    5. Simplified82.8%

      \[\leadsto \color{blue}{-z} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification89.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.45 \cdot 10^{-8}:\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{elif}\;x \leq -9.5 \cdot 10^{-64}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \mathbf{elif}\;x \leq -2.05 \cdot 10^{-135} \lor \neg \left(x \leq 1.8 \cdot 10^{-92}\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 82.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(z + y\right)\\ \mathbf{if}\;x \leq -8.5 \cdot 10^{-9}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-62}:\\ \;\;\;\;x \cdot z - z\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-136} \lor \neg \left(x \leq 1.8 \cdot 10^{-92}\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ z y))))
   (if (<= x -8.5e-9)
     t_0
     (if (<= x -9e-62)
       (- (* x z) z)
       (if (or (<= x -6.2e-136) (not (<= x 1.8e-92))) t_0 (- z))))))
double code(double x, double y, double z) {
	double t_0 = x * (z + y);
	double tmp;
	if (x <= -8.5e-9) {
		tmp = t_0;
	} else if (x <= -9e-62) {
		tmp = (x * z) - z;
	} else if ((x <= -6.2e-136) || !(x <= 1.8e-92)) {
		tmp = t_0;
	} else {
		tmp = -z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x * (z + y)
    if (x <= (-8.5d-9)) then
        tmp = t_0
    else if (x <= (-9d-62)) then
        tmp = (x * z) - z
    else if ((x <= (-6.2d-136)) .or. (.not. (x <= 1.8d-92))) then
        tmp = t_0
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (z + y);
	double tmp;
	if (x <= -8.5e-9) {
		tmp = t_0;
	} else if (x <= -9e-62) {
		tmp = (x * z) - z;
	} else if ((x <= -6.2e-136) || !(x <= 1.8e-92)) {
		tmp = t_0;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (z + y)
	tmp = 0
	if x <= -8.5e-9:
		tmp = t_0
	elif x <= -9e-62:
		tmp = (x * z) - z
	elif (x <= -6.2e-136) or not (x <= 1.8e-92):
		tmp = t_0
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(z + y))
	tmp = 0.0
	if (x <= -8.5e-9)
		tmp = t_0;
	elseif (x <= -9e-62)
		tmp = Float64(Float64(x * z) - z);
	elseif ((x <= -6.2e-136) || !(x <= 1.8e-92))
		tmp = t_0;
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (z + y);
	tmp = 0.0;
	if (x <= -8.5e-9)
		tmp = t_0;
	elseif (x <= -9e-62)
		tmp = (x * z) - z;
	elseif ((x <= -6.2e-136) || ~((x <= 1.8e-92)))
		tmp = t_0;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8.5e-9], t$95$0, If[LessEqual[x, -9e-62], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision], If[Or[LessEqual[x, -6.2e-136], N[Not[LessEqual[x, 1.8e-92]], $MachinePrecision]], t$95$0, (-z)]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -8.5 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -9 \cdot 10^{-62}:\\
\;\;\;\;x \cdot z - z\\

\mathbf{elif}\;x \leq -6.2 \cdot 10^{-136} \lor \neg \left(x \leq 1.8 \cdot 10^{-92}\right):\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -8.5e-9 or -9.00000000000000036e-62 < x < -6.2e-136 or 1.80000000000000008e-92 < x

    1. Initial program 98.2%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 92.8%

      \[\leadsto \color{blue}{x \cdot \left(y + z\right)} \]
    4. Step-by-step derivation
      1. +-commutative92.8%

        \[\leadsto x \cdot \color{blue}{\left(z + y\right)} \]
    5. Simplified92.8%

      \[\leadsto \color{blue}{x \cdot \left(z + y\right)} \]

    if -8.5e-9 < x < -9.00000000000000036e-62

    1. Initial program 99.7%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Step-by-step derivation
      1. *-commutative99.7%

        \[\leadsto x \cdot y + \color{blue}{z \cdot \left(x - 1\right)} \]
      2. sub-neg99.7%

        \[\leadsto x \cdot y + z \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      3. distribute-rgt-in100.0%

        \[\leadsto x \cdot y + \color{blue}{\left(x \cdot z + \left(-1\right) \cdot z\right)} \]
      4. metadata-eval100.0%

        \[\leadsto x \cdot y + \left(x \cdot z + \color{blue}{-1} \cdot z\right) \]
      5. neg-mul-1100.0%

        \[\leadsto x \cdot y + \left(x \cdot z + \color{blue}{\left(-z\right)}\right) \]
      6. associate-+r+100.0%

        \[\leadsto \color{blue}{\left(x \cdot y + x \cdot z\right) + \left(-z\right)} \]
      7. unsub-neg100.0%

        \[\leadsto \color{blue}{\left(x \cdot y + x \cdot z\right) - z} \]
      8. +-commutative100.0%

        \[\leadsto \color{blue}{\left(x \cdot z + x \cdot y\right)} - z \]
      9. distribute-lft-out100.0%

        \[\leadsto \color{blue}{x \cdot \left(z + y\right)} - z \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(z + y\right) - z} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 100.0%

      \[\leadsto \color{blue}{y \cdot \left(x + \frac{x \cdot z}{y}\right)} - z \]
    6. Taylor expanded in y around 0 80.4%

      \[\leadsto \color{blue}{x \cdot z} - z \]

    if -6.2e-136 < x < 1.80000000000000008e-92

    1. Initial program 100.0%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 82.8%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. neg-mul-182.8%

        \[\leadsto \color{blue}{-z} \]
    5. Simplified82.8%

      \[\leadsto \color{blue}{-z} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification89.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{-9}:\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{elif}\;x \leq -9 \cdot 10^{-62}:\\ \;\;\;\;x \cdot z - z\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-136} \lor \neg \left(x \leq 1.8 \cdot 10^{-92}\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 99.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -180000 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y - z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -180000.0) (not (<= x 1.0))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -180000.0) || !(x <= 1.0)) {
		tmp = x * (z + y);
	} else {
		tmp = (x * y) - z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-180000.0d0)) .or. (.not. (x <= 1.0d0))) then
        tmp = x * (z + y)
    else
        tmp = (x * y) - z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -180000.0) || !(x <= 1.0)) {
		tmp = x * (z + y);
	} else {
		tmp = (x * y) - z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -180000.0) or not (x <= 1.0):
		tmp = x * (z + y)
	else:
		tmp = (x * y) - z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -180000.0) || !(x <= 1.0))
		tmp = Float64(x * Float64(z + y));
	else
		tmp = Float64(Float64(x * y) - z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -180000.0) || ~((x <= 1.0)))
		tmp = x * (z + y);
	else
		tmp = (x * y) - z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -180000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -180000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.8e5 or 1 < x

    1. Initial program 97.7%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 99.2%

      \[\leadsto \color{blue}{x \cdot \left(y + z\right)} \]
    4. Step-by-step derivation
      1. +-commutative99.2%

        \[\leadsto x \cdot \color{blue}{\left(z + y\right)} \]
    5. Simplified99.2%

      \[\leadsto \color{blue}{x \cdot \left(z + y\right)} \]

    if -1.8e5 < x < 1

    1. Initial program 100.0%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto x \cdot y + \color{blue}{z \cdot \left(x - 1\right)} \]
      2. sub-neg100.0%

        \[\leadsto x \cdot y + z \cdot \color{blue}{\left(x + \left(-1\right)\right)} \]
      3. distribute-rgt-in100.0%

        \[\leadsto x \cdot y + \color{blue}{\left(x \cdot z + \left(-1\right) \cdot z\right)} \]
      4. metadata-eval100.0%

        \[\leadsto x \cdot y + \left(x \cdot z + \color{blue}{-1} \cdot z\right) \]
      5. neg-mul-1100.0%

        \[\leadsto x \cdot y + \left(x \cdot z + \color{blue}{\left(-z\right)}\right) \]
      6. associate-+r+100.0%

        \[\leadsto \color{blue}{\left(x \cdot y + x \cdot z\right) + \left(-z\right)} \]
      7. unsub-neg100.0%

        \[\leadsto \color{blue}{\left(x \cdot y + x \cdot z\right) - z} \]
      8. +-commutative100.0%

        \[\leadsto \color{blue}{\left(x \cdot z + x \cdot y\right)} - z \]
      9. distribute-lft-out100.0%

        \[\leadsto \color{blue}{x \cdot \left(z + y\right)} - z \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{x \cdot \left(z + y\right) - z} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 97.6%

      \[\leadsto \color{blue}{y \cdot \left(x + \frac{x \cdot z}{y}\right)} - z \]
    6. Taylor expanded in z around 0 98.3%

      \[\leadsto y \cdot \color{blue}{x} - z \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -180000 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y - z\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 61.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{-9} \lor \neg \left(x \leq 1.9 \cdot 10^{-93}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -7.2e-9) (not (<= x 1.9e-93))) (* x y) (- z)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -7.2e-9) || !(x <= 1.9e-93)) {
		tmp = x * y;
	} else {
		tmp = -z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-7.2d-9)) .or. (.not. (x <= 1.9d-93))) then
        tmp = x * y
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -7.2e-9) || !(x <= 1.9e-93)) {
		tmp = x * y;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -7.2e-9) or not (x <= 1.9e-93):
		tmp = x * y
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -7.2e-9) || !(x <= 1.9e-93))
		tmp = Float64(x * y);
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -7.2e-9) || ~((x <= 1.9e-93)))
		tmp = x * y;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e-9], N[Not[LessEqual[x, 1.9e-93]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-9} \lor \neg \left(x \leq 1.9 \cdot 10^{-93}\right):\\
\;\;\;\;x \cdot y\\

\mathbf{else}:\\
\;\;\;\;-z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -7.2e-9 or 1.8999999999999999e-93 < x

    1. Initial program 98.0%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 55.7%

      \[\leadsto \color{blue}{x \cdot y} \]

    if -7.2e-9 < x < 1.8999999999999999e-93

    1. Initial program 100.0%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 74.6%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. neg-mul-174.6%

        \[\leadsto \color{blue}{-z} \]
    5. Simplified74.6%

      \[\leadsto \color{blue}{-z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification63.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{-9} \lor \neg \left(x \leq 1.9 \cdot 10^{-93}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 36.6% accurate, 4.5× speedup?

\[\begin{array}{l} \\ -z \end{array} \]
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
	return -z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = -z
end function
public static double code(double x, double y, double z) {
	return -z;
}
def code(x, y, z):
	return -z
function code(x, y, z)
	return Float64(-z)
end
function tmp = code(x, y, z)
	tmp = -z;
end
code[x_, y_, z_] := (-z)
\begin{array}{l}

\\
-z
\end{array}
Derivation
  1. Initial program 98.8%

    \[x \cdot y + \left(x - 1\right) \cdot z \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 33.0%

    \[\leadsto \color{blue}{-1 \cdot z} \]
  4. Step-by-step derivation
    1. neg-mul-133.0%

      \[\leadsto \color{blue}{-z} \]
  5. Simplified33.0%

    \[\leadsto \color{blue}{-z} \]
  6. Final simplification33.0%

    \[\leadsto -z \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024078 
(FPCore (x y z)
  :name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
  :precision binary64
  (+ (* x y) (* (- x 1.0) z)))