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

Percentage Accurate: 97.8% → 100.0%
Time: 4.4s
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(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 99.2%

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

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

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

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

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

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

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

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

      \[\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: 60.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.2 \cdot 10^{+40}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -8.5 \cdot 10^{-100}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-36}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{+40} \lor \neg \left(x \leq 1.35 \cdot 10^{+101}\right) \land \left(x \leq 3.65 \cdot 10^{+140} \lor \neg \left(x \leq 3.8 \cdot 10^{+217}\right) \land x \leq 5.8 \cdot 10^{+278}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -1.2e+40)
   (* x z)
   (if (<= x -8.5e-100)
     (* x y)
     (if (<= x 9e-36)
       (- z)
       (if (or (<= x 7.8e+40)
               (and (not (<= x 1.35e+101))
                    (or (<= x 3.65e+140)
                        (and (not (<= x 3.8e+217)) (<= x 5.8e+278)))))
         (* x y)
         (* x z))))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -1.2e+40) {
		tmp = x * z;
	} else if (x <= -8.5e-100) {
		tmp = x * y;
	} else if (x <= 9e-36) {
		tmp = -z;
	} else if ((x <= 7.8e+40) || (!(x <= 1.35e+101) && ((x <= 3.65e+140) || (!(x <= 3.8e+217) && (x <= 5.8e+278))))) {
		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.2d+40)) then
        tmp = x * z
    else if (x <= (-8.5d-100)) then
        tmp = x * y
    else if (x <= 9d-36) then
        tmp = -z
    else if ((x <= 7.8d+40) .or. (.not. (x <= 1.35d+101)) .and. (x <= 3.65d+140) .or. (.not. (x <= 3.8d+217)) .and. (x <= 5.8d+278)) 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.2e+40) {
		tmp = x * z;
	} else if (x <= -8.5e-100) {
		tmp = x * y;
	} else if (x <= 9e-36) {
		tmp = -z;
	} else if ((x <= 7.8e+40) || (!(x <= 1.35e+101) && ((x <= 3.65e+140) || (!(x <= 3.8e+217) && (x <= 5.8e+278))))) {
		tmp = x * y;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -1.2e+40:
		tmp = x * z
	elif x <= -8.5e-100:
		tmp = x * y
	elif x <= 9e-36:
		tmp = -z
	elif (x <= 7.8e+40) or (not (x <= 1.35e+101) and ((x <= 3.65e+140) or (not (x <= 3.8e+217) and (x <= 5.8e+278)))):
		tmp = x * y
	else:
		tmp = x * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -1.2e+40)
		tmp = Float64(x * z);
	elseif (x <= -8.5e-100)
		tmp = Float64(x * y);
	elseif (x <= 9e-36)
		tmp = Float64(-z);
	elseif ((x <= 7.8e+40) || (!(x <= 1.35e+101) && ((x <= 3.65e+140) || (!(x <= 3.8e+217) && (x <= 5.8e+278)))))
		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.2e+40)
		tmp = x * z;
	elseif (x <= -8.5e-100)
		tmp = x * y;
	elseif (x <= 9e-36)
		tmp = -z;
	elseif ((x <= 7.8e+40) || (~((x <= 1.35e+101)) && ((x <= 3.65e+140) || (~((x <= 3.8e+217)) && (x <= 5.8e+278)))))
		tmp = x * y;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -1.2e+40], N[(x * z), $MachinePrecision], If[LessEqual[x, -8.5e-100], N[(x * y), $MachinePrecision], If[LessEqual[x, 9e-36], (-z), If[Or[LessEqual[x, 7.8e+40], And[N[Not[LessEqual[x, 1.35e+101]], $MachinePrecision], Or[LessEqual[x, 3.65e+140], And[N[Not[LessEqual[x, 3.8e+217]], $MachinePrecision], LessEqual[x, 5.8e+278]]]]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -8.5 \cdot 10^{-100}:\\
\;\;\;\;x \cdot y\\

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

\mathbf{elif}\;x \leq 7.8 \cdot 10^{+40} \lor \neg \left(x \leq 1.35 \cdot 10^{+101}\right) \land \left(x \leq 3.65 \cdot 10^{+140} \lor \neg \left(x \leq 3.8 \cdot 10^{+217}\right) \land x \leq 5.8 \cdot 10^{+278}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.2e40 or 7.8000000000000002e40 < x < 1.35000000000000003e101 or 3.6500000000000002e140 < x < 3.80000000000000002e217 or 5.7999999999999995e278 < x

    1. Initial program 98.1%

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

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

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

    if -1.2e40 < x < -8.50000000000000017e-100 or 9.00000000000000047e-36 < x < 7.8000000000000002e40 or 1.35000000000000003e101 < x < 3.6500000000000002e140 or 3.80000000000000002e217 < x < 5.7999999999999995e278

    1. Initial program 99.9%

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

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

    if -8.50000000000000017e-100 < x < 9.00000000000000047e-36

    1. Initial program 100.0%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.2 \cdot 10^{+40}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -8.5 \cdot 10^{-100}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 9 \cdot 10^{-36}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq 7.8 \cdot 10^{+40} \lor \neg \left(x \leq 1.35 \cdot 10^{+101}\right) \land \left(x \leq 3.65 \cdot 10^{+140} \lor \neg \left(x \leq 3.8 \cdot 10^{+217}\right) \land x \leq 5.8 \cdot 10^{+278}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 83.3% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;x \leq 245:\\
\;\;\;\;z \cdot \left(x + -1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.45e-109

    1. Initial program 97.8%

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

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

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

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

    if -1.45e-109 < x < 245

    1. Initial program 100.0%

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

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

    if 245 < 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 99.9%

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

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

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

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

Alternative 4: 84.0% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-111} \lor \neg \left(x \leq 4.6 \cdot 10^{-33}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.00000000000000035e-111 or 4.59999999999999971e-33 < x

    1. Initial program 98.8%

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

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

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

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

    if -4.00000000000000035e-111 < x < 4.59999999999999971e-33

    1. Initial program 100.0%

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

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

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

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

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

Alternative 5: 84.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3 \cdot 10^{-109} \lor \neg \left(x \leq 425\right):\\ \;\;\;\;x \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x + -1\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -3e-109) (not (<= x 425.0))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -3e-109) || !(x <= 425.0)) {
		tmp = x * (z + y);
	} else {
		tmp = z * (x + -1.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) :: tmp
    if ((x <= (-3d-109)) .or. (.not. (x <= 425.0d0))) then
        tmp = x * (z + y)
    else
        tmp = z * (x + (-1.0d0))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -3e-109) || !(x <= 425.0)) {
		tmp = x * (z + y);
	} else {
		tmp = z * (x + -1.0);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -3e-109) or not (x <= 425.0):
		tmp = x * (z + y)
	else:
		tmp = z * (x + -1.0)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -3e-109) || !(x <= 425.0))
		tmp = Float64(x * Float64(z + y));
	else
		tmp = Float64(z * Float64(x + -1.0));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -3e-109) || ~((x <= 425.0)))
		tmp = x * (z + y);
	else
		tmp = z * (x + -1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e-109], N[Not[LessEqual[x, 425.0]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-109} \lor \neg \left(x \leq 425\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\

\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.00000000000000021e-109 or 425 < x

    1. Initial program 98.7%

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

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

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

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

    if -3.00000000000000021e-109 < x < 425

    1. Initial program 100.0%

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

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

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

Alternative 6: 60.6% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{-100} \lor \neg \left(x \leq 1.15 \cdot 10^{-40}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -8.50000000000000017e-100 or 1.15e-40 < x

    1. Initial program 98.8%

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

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

    if -8.50000000000000017e-100 < x < 1.15e-40

    1. Initial program 100.0%

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

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

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

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

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

Alternative 7: 35.3% 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 99.2%

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

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

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

    \[\leadsto \color{blue}{-z} \]
  6. Final simplification30.9%

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

Reproduce

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