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

Percentage Accurate: 97.8% → 100.0%
Time: 6.6s
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: 97.8% 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(y + z\right) - z \end{array} \]
(FPCore (x y z) :precision binary64 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
	return (x * (y + z)) - 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 + z)) - z
end function
public static double code(double x, double y, double z) {
	return (x * (y + z)) - z;
}
def code(x, y, z):
	return (x * (y + z)) - z
function code(x, y, z)
	return Float64(Float64(x * Float64(y + z)) - z)
end
function tmp = code(x, y, z)
	tmp = (x * (y + z)) - z;
end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}

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

    \[x \cdot y + \left(x - 1\right) \cdot z \]
  2. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto x \cdot y + z \cdot \color{blue}{\left(x - 1\right)} \]
    2. sub-negN/A

      \[\leadsto x \cdot y + z \cdot \left(x + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right) \]
    3. distribute-rgt-inN/A

      \[\leadsto x \cdot y + \left(x \cdot z + \color{blue}{\left(\mathsf{neg}\left(1\right)\right) \cdot z}\right) \]
    4. associate-+r+N/A

      \[\leadsto \left(x \cdot y + x \cdot z\right) + \color{blue}{\left(\mathsf{neg}\left(1\right)\right) \cdot z} \]
    5. metadata-evalN/A

      \[\leadsto \left(x \cdot y + x \cdot z\right) + -1 \cdot z \]
    6. mul-1-negN/A

      \[\leadsto \left(x \cdot y + x \cdot z\right) + \left(\mathsf{neg}\left(z\right)\right) \]
    7. unsub-negN/A

      \[\leadsto \left(x \cdot y + x \cdot z\right) - \color{blue}{z} \]
    8. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\left(x \cdot y + x \cdot z\right), \color{blue}{z}\right) \]
    9. distribute-lft-outN/A

      \[\leadsto \mathsf{\_.f64}\left(\left(x \cdot \left(y + z\right)\right), z\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(x, \left(y + z\right)\right), z\right) \]
    11. +-lowering-+.f64100.0%

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(y, z\right)\right), z\right) \]
  3. Simplified100.0%

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

Alternative 2: 61.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1020:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-15}:\\ \;\;\;\;0 - z\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+137}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1020.0)
   (* x y)
   (if (<= x 1.35e-15) (- 0.0 z) (if (<= x 5e+137) (* x z) (* x y)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1020.0) {
		tmp = x * y;
	} else if (x <= 1.35e-15) {
		tmp = 0.0 - z;
	} else if (x <= 5e+137) {
		tmp = x * z;
	} else {
		tmp = x * y;
	}
	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 <= (-1020.0d0)) then
        tmp = x * y
    else if (x <= 1.35d-15) then
        tmp = 0.0d0 - z
    else if (x <= 5d+137) then
        tmp = x * z
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1020.0) {
		tmp = x * y;
	} else if (x <= 1.35e-15) {
		tmp = 0.0 - z;
	} else if (x <= 5e+137) {
		tmp = x * z;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1020.0:
		tmp = x * y
	elif x <= 1.35e-15:
		tmp = 0.0 - z
	elif x <= 5e+137:
		tmp = x * z
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1020.0)
		tmp = Float64(x * y);
	elseif (x <= 1.35e-15)
		tmp = Float64(0.0 - z);
	elseif (x <= 5e+137)
		tmp = Float64(x * z);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1020.0)
		tmp = x * y;
	elseif (x <= 1.35e-15)
		tmp = 0.0 - z;
	elseif (x <= 5e+137)
		tmp = x * z;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1020.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.35e-15], N[(0.0 - z), $MachinePrecision], If[LessEqual[x, 5e+137], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1020:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 1.35 \cdot 10^{-15}:\\
\;\;\;\;0 - z\\

\mathbf{elif}\;x \leq 5 \cdot 10^{+137}:\\
\;\;\;\;x \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1020 or 5.0000000000000002e137 < x

    1. Initial program 94.5%

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

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

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
    5. Simplified62.3%

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

    if -1020 < x < 1.35000000000000005e-15

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(z\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{z} \]
      3. --lowering--.f6474.5%

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{z}\right) \]
    5. Simplified74.5%

      \[\leadsto \color{blue}{0 - z} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(z\right) \]
      2. neg-lowering-neg.f6474.5%

        \[\leadsto \mathsf{neg.f64}\left(z\right) \]
    7. Applied egg-rr74.5%

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

    if 1.35000000000000005e-15 < x < 5.0000000000000002e137

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(y + z\right)} \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y + z\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(z + \color{blue}{y}\right)\right) \]
      3. +-lowering-+.f6493.9%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(z, \color{blue}{y}\right)\right) \]
    5. Simplified93.9%

      \[\leadsto \color{blue}{x \cdot \left(z + y\right)} \]
    6. Taylor expanded in z around inf

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

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{z}\right) \]
    8. Simplified56.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1020:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-15}:\\ \;\;\;\;0 - z\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+137}:\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(y + z\right)\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 0.07:\\ \;\;\;\;x \cdot y - z\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ y z))))
   (if (<= x -1.0) t_0 (if (<= x 0.07) (- (* x y) z) t_0))))
double code(double x, double y, double z) {
	double t_0 = x * (y + z);
	double tmp;
	if (x <= -1.0) {
		tmp = t_0;
	} else if (x <= 0.07) {
		tmp = (x * y) - z;
	} else {
		tmp = t_0;
	}
	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 * (y + z)
    if (x <= (-1.0d0)) then
        tmp = t_0
    else if (x <= 0.07d0) then
        tmp = (x * y) - z
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (y + z);
	double tmp;
	if (x <= -1.0) {
		tmp = t_0;
	} else if (x <= 0.07) {
		tmp = (x * y) - z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (y + z)
	tmp = 0
	if x <= -1.0:
		tmp = t_0
	elif x <= 0.07:
		tmp = (x * y) - z
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(y + z))
	tmp = 0.0
	if (x <= -1.0)
		tmp = t_0;
	elseif (x <= 0.07)
		tmp = Float64(Float64(x * y) - z);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (y + z);
	tmp = 0.0;
	if (x <= -1.0)
		tmp = t_0;
	elseif (x <= 0.07)
		tmp = (x * y) - z;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 0.07], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision], t$95$0]]]
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 95.9%

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

      \[\leadsto \color{blue}{x \cdot \left(y + z\right)} \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y + z\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(z + \color{blue}{y}\right)\right) \]
      3. +-lowering-+.f6497.5%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(z, \color{blue}{y}\right)\right) \]
    5. Simplified97.5%

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

    if -1 < x < 0.070000000000000007

    1. Initial program 100.0%

      \[x \cdot y + \left(x - 1\right) \cdot z \]
    2. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto x \cdot y + z \cdot \color{blue}{\left(x - 1\right)} \]
      2. sub-negN/A

        \[\leadsto x \cdot y + z \cdot \left(x + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right) \]
      3. distribute-rgt-inN/A

        \[\leadsto x \cdot y + \left(x \cdot z + \color{blue}{\left(\mathsf{neg}\left(1\right)\right) \cdot z}\right) \]
      4. associate-+r+N/A

        \[\leadsto \left(x \cdot y + x \cdot z\right) + \color{blue}{\left(\mathsf{neg}\left(1\right)\right) \cdot z} \]
      5. metadata-evalN/A

        \[\leadsto \left(x \cdot y + x \cdot z\right) + -1 \cdot z \]
      6. mul-1-negN/A

        \[\leadsto \left(x \cdot y + x \cdot z\right) + \left(\mathsf{neg}\left(z\right)\right) \]
      7. unsub-negN/A

        \[\leadsto \left(x \cdot y + x \cdot z\right) - \color{blue}{z} \]
      8. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\left(x \cdot y + x \cdot z\right), \color{blue}{z}\right) \]
      9. distribute-lft-outN/A

        \[\leadsto \mathsf{\_.f64}\left(\left(x \cdot \left(y + z\right)\right), z\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(x, \left(y + z\right)\right), z\right) \]
      11. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(y, z\right)\right), z\right) \]
    3. Simplified100.0%

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

      \[\leadsto \mathsf{\_.f64}\left(\color{blue}{\left(x \cdot y\right)}, z\right) \]
    6. Step-by-step derivation
      1. *-lowering-*.f6499.2%

        \[\leadsto \mathsf{\_.f64}\left(\mathsf{*.f64}\left(x, y\right), z\right) \]
    7. Simplified99.2%

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

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

Alternative 4: 85.1% accurate, 0.6× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3850 or 1.35e-16 < x

    1. Initial program 95.9%

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

      \[\leadsto \color{blue}{x \cdot \left(y + z\right)} \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y + z\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(z + \color{blue}{y}\right)\right) \]
      3. +-lowering-+.f6498.4%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(z, \color{blue}{y}\right)\right) \]
    5. Simplified98.4%

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

    if -3850 < x < 1.35e-16

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{z \cdot \left(x - 1\right)} \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(z, \color{blue}{\left(x - 1\right)}\right) \]
      2. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(z, \left(x + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)}\right)\right) \]
      3. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(z, \left(x + -1\right)\right) \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(z, \left(-1 + \color{blue}{x}\right)\right) \]
      5. +-lowering-+.f6476.6%

        \[\leadsto \mathsf{*.f64}\left(z, \mathsf{+.f64}\left(-1, \color{blue}{x}\right)\right) \]
    5. Simplified76.6%

      \[\leadsto \color{blue}{z \cdot \left(-1 + x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3850:\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-16}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 84.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(y + z\right)\\ \mathbf{if}\;x \leq -0.05:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-16}:\\ \;\;\;\;0 - z\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (+ y z))))
   (if (<= x -0.05) t_0 (if (<= x 8.5e-16) (- 0.0 z) t_0))))
double code(double x, double y, double z) {
	double t_0 = x * (y + z);
	double tmp;
	if (x <= -0.05) {
		tmp = t_0;
	} else if (x <= 8.5e-16) {
		tmp = 0.0 - z;
	} else {
		tmp = t_0;
	}
	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 * (y + z)
    if (x <= (-0.05d0)) then
        tmp = t_0
    else if (x <= 8.5d-16) then
        tmp = 0.0d0 - z
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = x * (y + z);
	double tmp;
	if (x <= -0.05) {
		tmp = t_0;
	} else if (x <= 8.5e-16) {
		tmp = 0.0 - z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x * (y + z)
	tmp = 0
	if x <= -0.05:
		tmp = t_0
	elif x <= 8.5e-16:
		tmp = 0.0 - z
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x * Float64(y + z))
	tmp = 0.0
	if (x <= -0.05)
		tmp = t_0;
	elseif (x <= 8.5e-16)
		tmp = Float64(0.0 - z);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x * (y + z);
	tmp = 0.0;
	if (x <= -0.05)
		tmp = t_0;
	elseif (x <= 8.5e-16)
		tmp = 0.0 - z;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.05], t$95$0, If[LessEqual[x, 8.5e-16], N[(0.0 - z), $MachinePrecision], t$95$0]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq 8.5 \cdot 10^{-16}:\\
\;\;\;\;0 - z\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.050000000000000003 or 8.5000000000000001e-16 < x

    1. Initial program 96.0%

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

      \[\leadsto \color{blue}{x \cdot \left(y + z\right)} \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{\left(y + z\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(x, \left(z + \color{blue}{y}\right)\right) \]
      3. +-lowering-+.f6497.3%

        \[\leadsto \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(z, \color{blue}{y}\right)\right) \]
    5. Simplified97.3%

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

    if -0.050000000000000003 < x < 8.5000000000000001e-16

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(z\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{z} \]
      3. --lowering--.f6475.4%

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{z}\right) \]
    5. Simplified75.4%

      \[\leadsto \color{blue}{0 - z} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(z\right) \]
      2. neg-lowering-neg.f6475.4%

        \[\leadsto \mathsf{neg.f64}\left(z\right) \]
    7. Applied egg-rr75.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.05:\\ \;\;\;\;x \cdot \left(y + z\right)\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-16}:\\ \;\;\;\;0 - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y + z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 61.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1020:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{-17}:\\ \;\;\;\;0 - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1020.0) (* x y) (if (<= x 9.2e-17) (- 0.0 z) (* x y))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1020.0) {
		tmp = x * y;
	} else if (x <= 9.2e-17) {
		tmp = 0.0 - z;
	} else {
		tmp = x * y;
	}
	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 <= (-1020.0d0)) then
        tmp = x * y
    else if (x <= 9.2d-17) then
        tmp = 0.0d0 - z
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -1020.0) {
		tmp = x * y;
	} else if (x <= 9.2e-17) {
		tmp = 0.0 - z;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1020.0:
		tmp = x * y
	elif x <= 9.2e-17:
		tmp = 0.0 - z
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1020.0)
		tmp = Float64(x * y);
	elseif (x <= 9.2e-17)
		tmp = Float64(0.0 - z);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -1020.0)
		tmp = x * y;
	elseif (x <= 9.2e-17)
		tmp = 0.0 - z;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1020.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 9.2e-17], N[(0.0 - z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1020:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;x \leq 9.2 \cdot 10^{-17}:\\
\;\;\;\;0 - z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1020 or 9.20000000000000035e-17 < x

    1. Initial program 95.9%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-lowering-*.f6457.0%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
    5. Simplified57.0%

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

    if -1020 < x < 9.20000000000000035e-17

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1 \cdot z} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(z\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{z} \]
      3. --lowering--.f6474.5%

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{z}\right) \]
    5. Simplified74.5%

      \[\leadsto \color{blue}{0 - z} \]
    6. Step-by-step derivation
      1. sub0-negN/A

        \[\leadsto \mathsf{neg}\left(z\right) \]
      2. neg-lowering-neg.f6474.5%

        \[\leadsto \mathsf{neg.f64}\left(z\right) \]
    7. Applied egg-rr74.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1020:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{-17}:\\ \;\;\;\;0 - z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 36.1% accurate, 3.0× speedup?

\[\begin{array}{l} \\ 0 - z \end{array} \]
(FPCore (x y z) :precision binary64 (- 0.0 z))
double code(double x, double y, double z) {
	return 0.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 = 0.0d0 - z
end function
public static double code(double x, double y, double z) {
	return 0.0 - z;
}
def code(x, y, z):
	return 0.0 - z
function code(x, y, z)
	return Float64(0.0 - z)
end
function tmp = code(x, y, z)
	tmp = 0.0 - z;
end
code[x_, y_, z_] := N[(0.0 - z), $MachinePrecision]
\begin{array}{l}

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

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

    \[\leadsto \color{blue}{-1 \cdot z} \]
  4. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{neg}\left(z\right) \]
    2. neg-sub0N/A

      \[\leadsto 0 - \color{blue}{z} \]
    3. --lowering--.f6439.9%

      \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{z}\right) \]
  5. Simplified39.9%

    \[\leadsto \color{blue}{0 - z} \]
  6. Step-by-step derivation
    1. sub0-negN/A

      \[\leadsto \mathsf{neg}\left(z\right) \]
    2. neg-lowering-neg.f6439.9%

      \[\leadsto \mathsf{neg.f64}\left(z\right) \]
  7. Applied egg-rr39.9%

    \[\leadsto \color{blue}{-z} \]
  8. Final simplification39.9%

    \[\leadsto 0 - z \]
  9. Add Preprocessing

Reproduce

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