Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C

Percentage Accurate: 99.9% → 100.0%
Time: 5.4s
Alternatives: 6
Speedup: 1.1×

Specification

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

\\
x \cdot \left(y + z\right) + z \cdot 5
\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 6 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: 99.9% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(z, 5, \left(z + y\right) \cdot x\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma z 5.0 (* (+ z y) x)))
double code(double x, double y, double z) {
	return fma(z, 5.0, ((z + y) * x));
}
function code(x, y, z)
	return fma(z, 5.0, Float64(Float64(z + y) * x))
end
code[x_, y_, z_] := N[(z * 5.0 + N[(N[(z + y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(z, 5, \left(z + y\right) \cdot x\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[x \cdot \left(y + z\right) + z \cdot 5 \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

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

      \[\leadsto \color{blue}{z \cdot 5 + x \cdot \left(y + z\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \color{blue}{z \cdot 5} + x \cdot \left(y + z\right) \]
    4. lower-fma.f64100.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, 5, x \cdot \left(y + z\right)\right)} \]
    5. lift-*.f64N/A

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

      \[\leadsto \mathsf{fma}\left(z, 5, \color{blue}{\left(y + z\right) \cdot x}\right) \]
    7. lower-*.f64100.0

      \[\leadsto \mathsf{fma}\left(z, 5, \color{blue}{\left(y + z\right) \cdot x}\right) \]
    8. lift-+.f64N/A

      \[\leadsto \mathsf{fma}\left(z, 5, \color{blue}{\left(y + z\right)} \cdot x\right) \]
    9. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(z, 5, \color{blue}{\left(z + y\right)} \cdot x\right) \]
    10. lower-+.f64100.0

      \[\leadsto \mathsf{fma}\left(z, 5, \color{blue}{\left(z + y\right)} \cdot x\right) \]
  4. Applied rewrites100.0%

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

Alternative 2: 62.3% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;x \leq -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 3.2 \cdot 10^{-29}\right):\\
\;\;\;\;y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -5.4e16

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{5 \cdot z + x \cdot z} \]
    4. Step-by-step derivation
      1. distribute-rgt-inN/A

        \[\leadsto \color{blue}{z \cdot \left(5 + x\right)} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
      3. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
      4. +-commutativeN/A

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

        \[\leadsto \left(x + \color{blue}{\left(\mathsf{neg}\left(-5\right)\right)}\right) \cdot z \]
      6. sub-negN/A

        \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
      7. lower--.f6464.4

        \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
    5. Applied rewrites64.4%

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

      \[\leadsto x \cdot \color{blue}{z} \]
    7. Step-by-step derivation
      1. Applied rewrites64.4%

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

      if -5.4e16 < x < -3.19999999999999976e-23 or 3.2e-29 < x

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{x \cdot y} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{y \cdot x} \]
        2. lower-*.f6462.5

          \[\leadsto \color{blue}{y \cdot x} \]
      5. Applied rewrites62.5%

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

      if -3.19999999999999976e-23 < x < 3.2e-29

      1. Initial program 99.9%

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

        \[\leadsto \color{blue}{5 \cdot z} \]
      4. Step-by-step derivation
        1. lower-*.f6476.8

          \[\leadsto \color{blue}{5 \cdot z} \]
      5. Applied rewrites76.8%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.4 \cdot 10^{+16}:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;x \leq -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 3.2 \cdot 10^{-29}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;5 \cdot z\\ \end{array} \]
    10. Add Preprocessing

    Alternative 3: 84.7% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 3.2 \cdot 10^{-62}\right):\\ \;\;\;\;\left(y + z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, 5, x \cdot z\right)\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (or (<= x -3.2e-23) (not (<= x 3.2e-62)))
       (* (+ y z) x)
       (fma z 5.0 (* x z))))
    double code(double x, double y, double z) {
    	double tmp;
    	if ((x <= -3.2e-23) || !(x <= 3.2e-62)) {
    		tmp = (y + z) * x;
    	} else {
    		tmp = fma(z, 5.0, (x * z));
    	}
    	return tmp;
    }
    
    function code(x, y, z)
    	tmp = 0.0
    	if ((x <= -3.2e-23) || !(x <= 3.2e-62))
    		tmp = Float64(Float64(y + z) * x);
    	else
    		tmp = fma(z, 5.0, Float64(x * z));
    	end
    	return tmp
    end
    
    code[x_, y_, z_] := If[Or[LessEqual[x, -3.2e-23], N[Not[LessEqual[x, 3.2e-62]], $MachinePrecision]], N[(N[(y + z), $MachinePrecision] * x), $MachinePrecision], N[(z * 5.0 + N[(x * z), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 3.2 \cdot 10^{-62}\right):\\
    \;\;\;\;\left(y + z\right) \cdot x\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(z, 5, x \cdot z\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -3.19999999999999976e-23 or 3.20000000000000021e-62 < x

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{5 \cdot z + x \cdot z} \]
      4. Step-by-step derivation
        1. distribute-rgt-inN/A

          \[\leadsto \color{blue}{z \cdot \left(5 + x\right)} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
        3. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
        4. +-commutativeN/A

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

          \[\leadsto \left(x + \color{blue}{\left(\mathsf{neg}\left(-5\right)\right)}\right) \cdot z \]
        6. sub-negN/A

          \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
        7. lower--.f6453.0

          \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
      5. Applied rewrites53.0%

        \[\leadsto \color{blue}{\left(x - -5\right) \cdot z} \]
      6. Step-by-step derivation
        1. Applied rewrites53.0%

          \[\leadsto \mathsf{fma}\left(z, \color{blue}{5}, x \cdot z\right) \]
        2. Taylor expanded in x around inf

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

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

            \[\leadsto \color{blue}{\left(y + z\right) \cdot x} \]
          3. lower-+.f6495.2

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

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

        if -3.19999999999999976e-23 < x < 3.20000000000000021e-62

        1. Initial program 99.9%

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

          \[\leadsto \color{blue}{5 \cdot z + x \cdot z} \]
        4. Step-by-step derivation
          1. distribute-rgt-inN/A

            \[\leadsto \color{blue}{z \cdot \left(5 + x\right)} \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
          3. lower-*.f64N/A

            \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
          4. +-commutativeN/A

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

            \[\leadsto \left(x + \color{blue}{\left(\mathsf{neg}\left(-5\right)\right)}\right) \cdot z \]
          6. sub-negN/A

            \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
          7. lower--.f6478.1

            \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
        5. Applied rewrites78.1%

          \[\leadsto \color{blue}{\left(x - -5\right) \cdot z} \]
        6. Step-by-step derivation
          1. Applied rewrites78.2%

            \[\leadsto \mathsf{fma}\left(z, \color{blue}{5}, x \cdot z\right) \]
        7. Recombined 2 regimes into one program.
        8. Final simplification87.9%

          \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{-23} \lor \neg \left(x \leq 3.2 \cdot 10^{-62}\right):\\ \;\;\;\;\left(y + z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, 5, x \cdot z\right)\\ \end{array} \]
        9. Add Preprocessing

        Alternative 4: 84.7% accurate, 0.8× speedup?

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

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{5 \cdot z + x \cdot z} \]
          4. Step-by-step derivation
            1. distribute-rgt-inN/A

              \[\leadsto \color{blue}{z \cdot \left(5 + x\right)} \]
            2. *-commutativeN/A

              \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
            3. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
            4. +-commutativeN/A

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

              \[\leadsto \left(x + \color{blue}{\left(\mathsf{neg}\left(-5\right)\right)}\right) \cdot z \]
            6. sub-negN/A

              \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
            7. lower--.f6453.0

              \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
          5. Applied rewrites53.0%

            \[\leadsto \color{blue}{\left(x - -5\right) \cdot z} \]
          6. Step-by-step derivation
            1. Applied rewrites53.0%

              \[\leadsto \mathsf{fma}\left(z, \color{blue}{5}, x \cdot z\right) \]
            2. Taylor expanded in x around inf

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

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

                \[\leadsto \color{blue}{\left(y + z\right) \cdot x} \]
              3. lower-+.f6495.2

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

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

            if -3.19999999999999976e-23 < x < 3.20000000000000021e-62

            1. Initial program 99.9%

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

              \[\leadsto \color{blue}{5 \cdot z} \]
            4. Step-by-step derivation
              1. lower-*.f6478.1

                \[\leadsto \color{blue}{5 \cdot z} \]
            5. Applied rewrites78.1%

              \[\leadsto \color{blue}{5 \cdot z} \]
          7. Recombined 2 regimes into one program.
          8. Final simplification87.8%

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

          Alternative 5: 61.7% accurate, 0.9× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.23 \lor \neg \left(x \leq 0.92\right):\\ \;\;\;\;x \cdot z\\ \mathbf{else}:\\ \;\;\;\;5 \cdot z\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (or (<= x -0.23) (not (<= x 0.92))) (* x z) (* 5.0 z)))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((x <= -0.23) || !(x <= 0.92)) {
          		tmp = x * z;
          	} else {
          		tmp = 5.0 * 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 <= (-0.23d0)) .or. (.not. (x <= 0.92d0))) then
                  tmp = x * z
              else
                  tmp = 5.0d0 * z
              end if
              code = tmp
          end function
          
          public static double code(double x, double y, double z) {
          	double tmp;
          	if ((x <= -0.23) || !(x <= 0.92)) {
          		tmp = x * z;
          	} else {
          		tmp = 5.0 * z;
          	}
          	return tmp;
          }
          
          def code(x, y, z):
          	tmp = 0
          	if (x <= -0.23) or not (x <= 0.92):
          		tmp = x * z
          	else:
          		tmp = 5.0 * z
          	return tmp
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((x <= -0.23) || !(x <= 0.92))
          		tmp = Float64(x * z);
          	else
          		tmp = Float64(5.0 * z);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z)
          	tmp = 0.0;
          	if ((x <= -0.23) || ~((x <= 0.92)))
          		tmp = x * z;
          	else
          		tmp = 5.0 * z;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[x, -0.23], N[Not[LessEqual[x, 0.92]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(5.0 * z), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;x \leq -0.23 \lor \neg \left(x \leq 0.92\right):\\
          \;\;\;\;x \cdot z\\
          
          \mathbf{else}:\\
          \;\;\;\;5 \cdot z\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if x < -0.23000000000000001 or 0.92000000000000004 < x

            1. Initial program 100.0%

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

              \[\leadsto \color{blue}{5 \cdot z + x \cdot z} \]
            4. Step-by-step derivation
              1. distribute-rgt-inN/A

                \[\leadsto \color{blue}{z \cdot \left(5 + x\right)} \]
              2. *-commutativeN/A

                \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
              3. lower-*.f64N/A

                \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
              4. +-commutativeN/A

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

                \[\leadsto \left(x + \color{blue}{\left(\mathsf{neg}\left(-5\right)\right)}\right) \cdot z \]
              6. sub-negN/A

                \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
              7. lower--.f6455.5

                \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
            5. Applied rewrites55.5%

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

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

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

              if -0.23000000000000001 < x < 0.92000000000000004

              1. Initial program 99.9%

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

                \[\leadsto \color{blue}{5 \cdot z} \]
              4. Step-by-step derivation
                1. lower-*.f6471.0

                  \[\leadsto \color{blue}{5 \cdot z} \]
              5. Applied rewrites71.0%

                \[\leadsto \color{blue}{5 \cdot z} \]
            8. Recombined 2 regimes into one program.
            9. Final simplification63.2%

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

            Alternative 6: 28.2% accurate, 2.8× speedup?

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

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

              \[\leadsto \color{blue}{5 \cdot z + x \cdot z} \]
            4. Step-by-step derivation
              1. distribute-rgt-inN/A

                \[\leadsto \color{blue}{z \cdot \left(5 + x\right)} \]
              2. *-commutativeN/A

                \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
              3. lower-*.f64N/A

                \[\leadsto \color{blue}{\left(5 + x\right) \cdot z} \]
              4. +-commutativeN/A

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

                \[\leadsto \left(x + \color{blue}{\left(\mathsf{neg}\left(-5\right)\right)}\right) \cdot z \]
              6. sub-negN/A

                \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
              7. lower--.f6463.8

                \[\leadsto \color{blue}{\left(x - -5\right)} \cdot z \]
            5. Applied rewrites63.8%

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

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

                \[\leadsto x \cdot \color{blue}{z} \]
              2. Add Preprocessing

              Developer Target 1: 97.5% accurate, 1.0× speedup?

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

              Reproduce

              ?
              herbie shell --seed 2024324 
              (FPCore (x y z)
                :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendOutside from plot-0.2.3.4, C"
                :precision binary64
              
                :alt
                (! :herbie-platform default (+ (* (+ x 5) z) (* x y)))
              
                (+ (* x (+ y z)) (* z 5.0)))