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

Percentage Accurate: 98.1% → 100.0%
Time: 4.1s
Alternatives: 7
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 7 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. distribute-rgt-out--98.8%

      \[\leadsto x \cdot y + \color{blue}{\left(x \cdot z - 1 \cdot z\right)} \]
    3. cancel-sign-sub-inv98.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: 59.1% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.52 \cdot 10^{+159}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -1860:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{-79}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq -3.2 \cdot 10^{-135}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 5.7 \cdot 10^{-39}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 2.35 \cdot 10^{+96} \lor \neg \left(x \leq 2.8 \cdot 10^{+136}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1.52e+159)
   (* x z)
   (if (<= x -1860.0)
     (* x y)
     (if (<= x -2.1e-79)
       (- z)
       (if (<= x -3.2e-135)
         (* x y)
         (if (<= x 5.7e-39)
           (- z)
           (if (or (<= x 2.35e+96) (not (<= x 2.8e+136)))
             (* x y)
             (* x z))))))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.52e+159) {
		tmp = x * z;
	} else if (x <= -1860.0) {
		tmp = x * y;
	} else if (x <= -2.1e-79) {
		tmp = -z;
	} else if (x <= -3.2e-135) {
		tmp = x * y;
	} else if (x <= 5.7e-39) {
		tmp = -z;
	} else if ((x <= 2.35e+96) || !(x <= 2.8e+136)) {
		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 <= (-1.52d+159)) then
        tmp = x * z
    else if (x <= (-1860.0d0)) then
        tmp = x * y
    else if (x <= (-2.1d-79)) then
        tmp = -z
    else if (x <= (-3.2d-135)) then
        tmp = x * y
    else if (x <= 5.7d-39) then
        tmp = -z
    else if ((x <= 2.35d+96) .or. (.not. (x <= 2.8d+136))) 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 <= -1.52e+159) {
		tmp = x * z;
	} else if (x <= -1860.0) {
		tmp = x * y;
	} else if (x <= -2.1e-79) {
		tmp = -z;
	} else if (x <= -3.2e-135) {
		tmp = x * y;
	} else if (x <= 5.7e-39) {
		tmp = -z;
	} else if ((x <= 2.35e+96) || !(x <= 2.8e+136)) {
		tmp = x * y;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.52e+159:
		tmp = x * z
	elif x <= -1860.0:
		tmp = x * y
	elif x <= -2.1e-79:
		tmp = -z
	elif x <= -3.2e-135:
		tmp = x * y
	elif x <= 5.7e-39:
		tmp = -z
	elif (x <= 2.35e+96) or not (x <= 2.8e+136):
		tmp = x * y
	else:
		tmp = x * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.52e+159)
		tmp = Float64(x * z);
	elseif (x <= -1860.0)
		tmp = Float64(x * y);
	elseif (x <= -2.1e-79)
		tmp = Float64(-z);
	elseif (x <= -3.2e-135)
		tmp = Float64(x * y);
	elseif (x <= 5.7e-39)
		tmp = Float64(-z);
	elseif ((x <= 2.35e+96) || !(x <= 2.8e+136))
		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 <= -1.52e+159)
		tmp = x * z;
	elseif (x <= -1860.0)
		tmp = x * y;
	elseif (x <= -2.1e-79)
		tmp = -z;
	elseif (x <= -3.2e-135)
		tmp = x * y;
	elseif (x <= 5.7e-39)
		tmp = -z;
	elseif ((x <= 2.35e+96) || ~((x <= 2.8e+136)))
		tmp = x * y;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.52e+159], N[(x * z), $MachinePrecision], If[LessEqual[x, -1860.0], N[(x * y), $MachinePrecision], If[LessEqual[x, -2.1e-79], (-z), If[LessEqual[x, -3.2e-135], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.7e-39], (-z), If[Or[LessEqual[x, 2.35e+96], N[Not[LessEqual[x, 2.8e+136]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.52 \cdot 10^{+159}:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;x \leq -1860:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq -2.1 \cdot 10^{-79}:\\
\;\;\;\;-z\\

\mathbf{elif}\;x \leq -3.2 \cdot 10^{-135}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 5.7 \cdot 10^{-39}:\\
\;\;\;\;-z\\

\mathbf{elif}\;x \leq 2.35 \cdot 10^{+96} \lor \neg \left(x \leq 2.8 \cdot 10^{+136}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.5199999999999999e159 or 2.35e96 < x < 2.8000000000000002e136

    1. Initial program 93.2%

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

      \[\leadsto \color{blue}{z \cdot \left(x - 1\right)} \]
    4. Taylor expanded in x around inf 73.7%

      \[\leadsto \color{blue}{x \cdot z} \]
    5. Step-by-step derivation
      1. *-commutative73.7%

        \[\leadsto \color{blue}{z \cdot x} \]
    6. Simplified73.7%

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

    if -1.5199999999999999e159 < x < -1860 or -2.0999999999999999e-79 < x < -3.2e-135 or 5.6999999999999997e-39 < x < 2.35e96 or 2.8000000000000002e136 < x

    1. Initial program 100.0%

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

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

    if -1860 < x < -2.0999999999999999e-79 or -3.2e-135 < x < 5.6999999999999997e-39

    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.5%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.52 \cdot 10^{+159}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -1860:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -2.1 \cdot 10^{-79}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq -3.2 \cdot 10^{-135}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 5.7 \cdot 10^{-39}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 2.35 \cdot 10^{+96} \lor \neg \left(x \leq 2.8 \cdot 10^{+136}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 81.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(z + y\right)\\ \mathbf{if}\;x \leq -1950:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-77}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-135}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-37}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y + x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ z y))))
   (if (<= x -1950.0)
     t_0
     (if (<= x -3e-77)
       (* z (+ x -1.0))
       (if (<= x -5.6e-135)
         t_0
         (if (<= x 1.8e-37) (- z) (+ (* x y) (* x z))))))))
double code(double x, double y, double z) {
	double t_0 = x * (z + y);
	double tmp;
	if (x <= -1950.0) {
		tmp = t_0;
	} else if (x <= -3e-77) {
		tmp = z * (x + -1.0);
	} else if (x <= -5.6e-135) {
		tmp = t_0;
	} else if (x <= 1.8e-37) {
		tmp = -z;
	} else {
		tmp = (x * y) + (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) :: t_0
    real(8) :: tmp
    t_0 = x * (z + y)
    if (x <= (-1950.0d0)) then
        tmp = t_0
    else if (x <= (-3d-77)) then
        tmp = z * (x + (-1.0d0))
    else if (x <= (-5.6d-135)) then
        tmp = t_0
    else if (x <= 1.8d-37) then
        tmp = -z
    else
        tmp = (x * y) + (x * 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 <= -1950.0) {
		tmp = t_0;
	} else if (x <= -3e-77) {
		tmp = z * (x + -1.0);
	} else if (x <= -5.6e-135) {
		tmp = t_0;
	} else if (x <= 1.8e-37) {
		tmp = -z;
	} else {
		tmp = (x * y) + (x * z);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (z + y)
	tmp = 0
	if x <= -1950.0:
		tmp = t_0
	elif x <= -3e-77:
		tmp = z * (x + -1.0)
	elif x <= -5.6e-135:
		tmp = t_0
	elif x <= 1.8e-37:
		tmp = -z
	else:
		tmp = (x * y) + (x * z)
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(z + y))
	tmp = 0.0
	if (x <= -1950.0)
		tmp = t_0;
	elseif (x <= -3e-77)
		tmp = Float64(z * Float64(x + -1.0));
	elseif (x <= -5.6e-135)
		tmp = t_0;
	elseif (x <= 1.8e-37)
		tmp = Float64(-z);
	else
		tmp = Float64(Float64(x * y) + Float64(x * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (z + y);
	tmp = 0.0;
	if (x <= -1950.0)
		tmp = t_0;
	elseif (x <= -3e-77)
		tmp = z * (x + -1.0);
	elseif (x <= -5.6e-135)
		tmp = t_0;
	elseif (x <= 1.8e-37)
		tmp = -z;
	else
		tmp = (x * y) + (x * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1950.0], t$95$0, If[LessEqual[x, -3e-77], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -5.6e-135], t$95$0, If[LessEqual[x, 1.8e-37], (-z), N[(N[(x * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -1950:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;x \leq -5.6 \cdot 10^{-135}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 1.8 \cdot 10^{-37}:\\
\;\;\;\;-z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -1950 or -3.00000000000000016e-77 < x < -5.60000000000000047e-135

    1. Initial program 96.3%

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

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

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

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

    if -1950 < x < -3.00000000000000016e-77

    1. Initial program 100.0%

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

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

    if -5.60000000000000047e-135 < x < 1.80000000000000004e-37

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{-z} \]
    5. Simplified83.4%

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

    if 1.80000000000000004e-37 < x

    1. Initial program 100.0%

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

      \[\leadsto x \cdot y + \color{blue}{x \cdot z} \]
    4. Step-by-step derivation
      1. *-commutative98.3%

        \[\leadsto x \cdot y + \color{blue}{z \cdot x} \]
    5. Simplified98.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1950:\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{elif}\;x \leq -3 \cdot 10^{-77}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-135}:\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-37}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y + x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 83.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.58 \cdot 10^{-9} \lor \neg \left(x \leq -1.05 \cdot 10^{-79} \lor \neg \left(x \leq -5.6 \cdot 10^{-135}\right) \land x \leq 1.35 \cdot 10^{-29}\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -1.58e-9)
         (not
          (or (<= x -1.05e-79) (and (not (<= x -5.6e-135)) (<= x 1.35e-29)))))
   (* x (+ z y))
   (- z)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.58e-9) || !((x <= -1.05e-79) || (!(x <= -5.6e-135) && (x <= 1.35e-29)))) {
		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 <= (-1.58d-9)) .or. (.not. (x <= (-1.05d-79)) .or. (.not. (x <= (-5.6d-135))) .and. (x <= 1.35d-29))) 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 <= -1.58e-9) || !((x <= -1.05e-79) || (!(x <= -5.6e-135) && (x <= 1.35e-29)))) {
		tmp = x * (z + y);
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -1.58e-9) or not ((x <= -1.05e-79) or (not (x <= -5.6e-135) and (x <= 1.35e-29))):
		tmp = x * (z + y)
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -1.58e-9) || !((x <= -1.05e-79) || (!(x <= -5.6e-135) && (x <= 1.35e-29))))
		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 <= -1.58e-9) || ~(((x <= -1.05e-79) || (~((x <= -5.6e-135)) && (x <= 1.35e-29)))))
		tmp = x * (z + y);
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.58e-9], N[Not[Or[LessEqual[x, -1.05e-79], And[N[Not[LessEqual[x, -5.6e-135]], $MachinePrecision], LessEqual[x, 1.35e-29]]]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.58 \cdot 10^{-9} \lor \neg \left(x \leq -1.05 \cdot 10^{-79} \lor \neg \left(x \leq -5.6 \cdot 10^{-135}\right) \land x \leq 1.35 \cdot 10^{-29}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.5799999999999999e-9 or -1.05e-79 < x < -5.60000000000000047e-135 or 1.35000000000000011e-29 < x

    1. Initial program 98.1%

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

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

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

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

    if -1.5799999999999999e-9 < x < -1.05e-79 or -5.60000000000000047e-135 < x < 1.35000000000000011e-29

    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.2%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.58 \cdot 10^{-9} \lor \neg \left(x \leq -1.05 \cdot 10^{-79} \lor \neg \left(x \leq -5.6 \cdot 10^{-135}\right) \land x \leq 1.35 \cdot 10^{-29}\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 82.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(z + y\right)\\ \mathbf{if}\;x \leq -2550:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-79}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-135} \lor \neg \left(x \leq 2 \cdot 10^{-26}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ z y))))
   (if (<= x -2550.0)
     t_0
     (if (<= x -1.1e-79)
       (* z (+ x -1.0))
       (if (or (<= x -5.6e-135) (not (<= x 2e-26))) t_0 (- z))))))
double code(double x, double y, double z) {
	double t_0 = x * (z + y);
	double tmp;
	if (x <= -2550.0) {
		tmp = t_0;
	} else if (x <= -1.1e-79) {
		tmp = z * (x + -1.0);
	} else if ((x <= -5.6e-135) || !(x <= 2e-26)) {
		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 <= (-2550.0d0)) then
        tmp = t_0
    else if (x <= (-1.1d-79)) then
        tmp = z * (x + (-1.0d0))
    else if ((x <= (-5.6d-135)) .or. (.not. (x <= 2d-26))) 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 <= -2550.0) {
		tmp = t_0;
	} else if (x <= -1.1e-79) {
		tmp = z * (x + -1.0);
	} else if ((x <= -5.6e-135) || !(x <= 2e-26)) {
		tmp = t_0;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (z + y)
	tmp = 0
	if x <= -2550.0:
		tmp = t_0
	elif x <= -1.1e-79:
		tmp = z * (x + -1.0)
	elif (x <= -5.6e-135) or not (x <= 2e-26):
		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 <= -2550.0)
		tmp = t_0;
	elseif (x <= -1.1e-79)
		tmp = Float64(z * Float64(x + -1.0));
	elseif ((x <= -5.6e-135) || !(x <= 2e-26))
		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 <= -2550.0)
		tmp = t_0;
	elseif (x <= -1.1e-79)
		tmp = z * (x + -1.0);
	elseif ((x <= -5.6e-135) || ~((x <= 2e-26)))
		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, -2550.0], t$95$0, If[LessEqual[x, -1.1e-79], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -5.6e-135], N[Not[LessEqual[x, 2e-26]], $MachinePrecision]], t$95$0, (-z)]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(z + y\right)\\
\mathbf{if}\;x \leq -2550:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;x \leq -5.6 \cdot 10^{-135} \lor \neg \left(x \leq 2 \cdot 10^{-26}\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2550 or -1.0999999999999999e-79 < x < -5.60000000000000047e-135 or 2.0000000000000001e-26 < x

    1. Initial program 98.1%

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

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

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

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

    if -2550 < x < -1.0999999999999999e-79

    1. Initial program 100.0%

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

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

    if -5.60000000000000047e-135 < x < 2.0000000000000001e-26

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{-z} \]
    5. Simplified83.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2550:\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-79}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-135} \lor \neg \left(x \leq 2 \cdot 10^{-26}\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 58.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1860 \lor \neg \left(x \leq -1.55 \cdot 10^{-78} \lor \neg \left(x \leq -5.5 \cdot 10^{-135}\right) \land x \leq 3.1 \cdot 10^{-28}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -1860.0)
         (not
          (or (<= x -1.55e-78) (and (not (<= x -5.5e-135)) (<= x 3.1e-28)))))
   (* x y)
   (- z)))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1860.0) || !((x <= -1.55e-78) || (!(x <= -5.5e-135) && (x <= 3.1e-28)))) {
		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 <= (-1860.0d0)) .or. (.not. (x <= (-1.55d-78)) .or. (.not. (x <= (-5.5d-135))) .and. (x <= 3.1d-28))) 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 <= -1860.0) || !((x <= -1.55e-78) || (!(x <= -5.5e-135) && (x <= 3.1e-28)))) {
		tmp = x * y;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -1860.0) or not ((x <= -1.55e-78) or (not (x <= -5.5e-135) and (x <= 3.1e-28))):
		tmp = x * y
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -1860.0) || !((x <= -1.55e-78) || (!(x <= -5.5e-135) && (x <= 3.1e-28))))
		tmp = Float64(x * y);
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -1860.0) || ~(((x <= -1.55e-78) || (~((x <= -5.5e-135)) && (x <= 3.1e-28)))))
		tmp = x * y;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -1860.0], N[Not[Or[LessEqual[x, -1.55e-78], And[N[Not[LessEqual[x, -5.5e-135]], $MachinePrecision], LessEqual[x, 3.1e-28]]]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1860 \lor \neg \left(x \leq -1.55 \cdot 10^{-78} \lor \neg \left(x \leq -5.5 \cdot 10^{-135}\right) \land x \leq 3.1 \cdot 10^{-28}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1860 or -1.55000000000000009e-78 < x < -5.4999999999999999e-135 or 3.09999999999999992e-28 < x

    1. Initial program 98.1%

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

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

    if -1860 < x < -1.55000000000000009e-78 or -5.4999999999999999e-135 < x < 3.09999999999999992e-28

    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.5%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1860 \lor \neg \left(x \leq -1.55 \cdot 10^{-78} \lor \neg \left(x \leq -5.5 \cdot 10^{-135}\right) \land x \leq 3.1 \cdot 10^{-28}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 35.9% 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 34.4%

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

      \[\leadsto \color{blue}{-z} \]
  5. Simplified34.4%

    \[\leadsto \color{blue}{-z} \]
  6. Final simplification34.4%

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

Reproduce

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