Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4

Percentage Accurate: 99.9% → 99.9%
Time: 5.4s
Alternatives: 8
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 99.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 1.0× speedup?

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

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

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

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

      \[\leadsto \left(\left(\color{blue}{\left(\left(x + y\right) + y\right)} + x\right) + z\right) + x \]
    3. associate-+l+N/A

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

      \[\leadsto \left(\left(\left(x + y\right) + \color{blue}{\left(x + y\right)}\right) + z\right) + x \]
    5. associate-+r+N/A

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

      \[\leadsto \left(\color{blue}{\left(\left(\left(x + y\right) + x\right) + y\right)} + z\right) + x \]
    7. lower-+.f6499.9

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

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

      \[\leadsto \left(\left(\left(\color{blue}{\left(y + x\right)} + x\right) + y\right) + z\right) + x \]
    10. lower-+.f6499.9

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

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

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

Alternative 2: 86.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.55 \cdot 10^{+67}:\\ \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+15}:\\ \;\;\;\;\mathsf{fma}\left(x, 3, y\right) + y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right) + x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.55e+67)
   (fma 3.0 x z)
   (if (<= z 9e+15) (+ (fma x 3.0 y) y) (+ (fma 2.0 y z) x))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.55e+67) {
		tmp = fma(3.0, x, z);
	} else if (z <= 9e+15) {
		tmp = fma(x, 3.0, y) + y;
	} else {
		tmp = fma(2.0, y, z) + x;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.55e+67)
		tmp = fma(3.0, x, z);
	elseif (z <= 9e+15)
		tmp = Float64(fma(x, 3.0, y) + y);
	else
		tmp = Float64(fma(2.0, y, z) + x);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[z, -1.55e+67], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[z, 9e+15], N[(N[(x * 3.0 + y), $MachinePrecision] + y), $MachinePrecision], N[(N[(2.0 * y + z), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{+67}:\\
\;\;\;\;\mathsf{fma}\left(3, x, z\right)\\

\mathbf{elif}\;z \leq 9 \cdot 10^{+15}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, y\right) + y\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, y, z\right) + x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.54999999999999998e67

    1. Initial program 99.9%

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

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

        \[\leadsto x + \color{blue}{\left(2 \cdot x + z\right)} \]
      2. associate-+r+N/A

        \[\leadsto \color{blue}{\left(x + 2 \cdot x\right) + z} \]
      3. distribute-rgt1-inN/A

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

        \[\leadsto \color{blue}{3} \cdot x + z \]
      5. lower-fma.f6489.0

        \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
    5. Applied rewrites89.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]

    if -1.54999999999999998e67 < z < 9e15

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{x + \left(2 \cdot x + 2 \cdot y\right)} \]
    4. Step-by-step derivation
      1. associate-+r+N/A

        \[\leadsto \color{blue}{\left(x + 2 \cdot x\right) + 2 \cdot y} \]
      2. distribute-rgt1-inN/A

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot x} + 2 \cdot y \]
      3. metadata-evalN/A

        \[\leadsto \color{blue}{3} \cdot x + 2 \cdot y \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, 2 \cdot y\right)} \]
      5. lower-*.f6490.9

        \[\leadsto \mathsf{fma}\left(3, x, \color{blue}{2 \cdot y}\right) \]
    5. Applied rewrites90.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, 2 \cdot y\right)} \]
    6. Step-by-step derivation
      1. Applied rewrites90.9%

        \[\leadsto \mathsf{fma}\left(3, x, y + y\right) \]
      2. Step-by-step derivation
        1. Applied rewrites90.9%

          \[\leadsto \mathsf{fma}\left(x, 3, y\right) + \color{blue}{y} \]

        if 9e15 < z

        1. Initial program 99.9%

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(2, y, z\right)} + x \]
        5. Applied rewrites84.7%

          \[\leadsto \color{blue}{\mathsf{fma}\left(2, y, z\right)} + x \]
      3. Recombined 3 regimes into one program.
      4. Add Preprocessing

      Alternative 3: 85.6% accurate, 0.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.55 \cdot 10^{+67}:\\ \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+15}:\\ \;\;\;\;\mathsf{fma}\left(x, 3, y\right) + y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (<= z -1.55e+67)
         (fma 3.0 x z)
         (if (<= z 9e+15) (+ (fma x 3.0 y) y) (fma 2.0 y z))))
      double code(double x, double y, double z) {
      	double tmp;
      	if (z <= -1.55e+67) {
      		tmp = fma(3.0, x, z);
      	} else if (z <= 9e+15) {
      		tmp = fma(x, 3.0, y) + y;
      	} else {
      		tmp = fma(2.0, y, z);
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	tmp = 0.0
      	if (z <= -1.55e+67)
      		tmp = fma(3.0, x, z);
      	elseif (z <= 9e+15)
      		tmp = Float64(fma(x, 3.0, y) + y);
      	else
      		tmp = fma(2.0, y, z);
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := If[LessEqual[z, -1.55e+67], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[z, 9e+15], N[(N[(x * 3.0 + y), $MachinePrecision] + y), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;z \leq -1.55 \cdot 10^{+67}:\\
      \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
      
      \mathbf{elif}\;z \leq 9 \cdot 10^{+15}:\\
      \;\;\;\;\mathsf{fma}\left(x, 3, y\right) + y\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if z < -1.54999999999999998e67

        1. Initial program 99.9%

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

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

            \[\leadsto x + \color{blue}{\left(2 \cdot x + z\right)} \]
          2. associate-+r+N/A

            \[\leadsto \color{blue}{\left(x + 2 \cdot x\right) + z} \]
          3. distribute-rgt1-inN/A

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

            \[\leadsto \color{blue}{3} \cdot x + z \]
          5. lower-fma.f6489.0

            \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
        5. Applied rewrites89.0%

          \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]

        if -1.54999999999999998e67 < z < 9e15

        1. Initial program 99.9%

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

          \[\leadsto \color{blue}{x + \left(2 \cdot x + 2 \cdot y\right)} \]
        4. Step-by-step derivation
          1. associate-+r+N/A

            \[\leadsto \color{blue}{\left(x + 2 \cdot x\right) + 2 \cdot y} \]
          2. distribute-rgt1-inN/A

            \[\leadsto \color{blue}{\left(2 + 1\right) \cdot x} + 2 \cdot y \]
          3. metadata-evalN/A

            \[\leadsto \color{blue}{3} \cdot x + 2 \cdot y \]
          4. lower-fma.f64N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, 2 \cdot y\right)} \]
          5. lower-*.f6490.9

            \[\leadsto \mathsf{fma}\left(3, x, \color{blue}{2 \cdot y}\right) \]
        5. Applied rewrites90.9%

          \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, 2 \cdot y\right)} \]
        6. Step-by-step derivation
          1. Applied rewrites90.9%

            \[\leadsto \mathsf{fma}\left(3, x, y + y\right) \]
          2. Step-by-step derivation
            1. Applied rewrites90.9%

              \[\leadsto \mathsf{fma}\left(x, 3, y\right) + \color{blue}{y} \]

            if 9e15 < z

            1. Initial program 99.9%

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

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

                \[\leadsto x + \color{blue}{\left(2 \cdot x + z\right)} \]
              2. associate-+r+N/A

                \[\leadsto \color{blue}{\left(x + 2 \cdot x\right) + z} \]
              3. distribute-rgt1-inN/A

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

                \[\leadsto \color{blue}{3} \cdot x + z \]
              5. lower-fma.f6477.7

                \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
            5. Applied rewrites77.7%

              \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
            6. Step-by-step derivation
              1. Applied rewrites77.7%

                \[\leadsto 3 \cdot x + \color{blue}{z} \]
              2. Taylor expanded in x around 0

                \[\leadsto \color{blue}{z + 2 \cdot y} \]
              3. Step-by-step derivation
                1. +-commutativeN/A

                  \[\leadsto \color{blue}{2 \cdot y + z} \]
                2. lower-fma.f6482.5

                  \[\leadsto \color{blue}{\mathsf{fma}\left(2, y, z\right)} \]
              4. Applied rewrites82.5%

                \[\leadsto \color{blue}{\mathsf{fma}\left(2, y, z\right)} \]
            7. Recombined 3 regimes into one program.
            8. Add Preprocessing

            Alternative 4: 85.1% accurate, 0.8× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{+47}:\\ \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\ \mathbf{elif}\;x \leq 6.8 \cdot 10^{+125}:\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\ \end{array} \end{array} \]
            (FPCore (x y z)
             :precision binary64
             (if (<= x -3.4e+47)
               (fma 3.0 x z)
               (if (<= x 6.8e+125) (fma 2.0 y z) (fma 3.0 x z))))
            double code(double x, double y, double z) {
            	double tmp;
            	if (x <= -3.4e+47) {
            		tmp = fma(3.0, x, z);
            	} else if (x <= 6.8e+125) {
            		tmp = fma(2.0, y, z);
            	} else {
            		tmp = fma(3.0, x, z);
            	}
            	return tmp;
            }
            
            function code(x, y, z)
            	tmp = 0.0
            	if (x <= -3.4e+47)
            		tmp = fma(3.0, x, z);
            	elseif (x <= 6.8e+125)
            		tmp = fma(2.0, y, z);
            	else
            		tmp = fma(3.0, x, z);
            	end
            	return tmp
            end
            
            code[x_, y_, z_] := If[LessEqual[x, -3.4e+47], N[(3.0 * x + z), $MachinePrecision], If[LessEqual[x, 6.8e+125], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;x \leq -3.4 \cdot 10^{+47}:\\
            \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
            
            \mathbf{elif}\;x \leq 6.8 \cdot 10^{+125}:\\
            \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
            
            \mathbf{else}:\\
            \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if x < -3.3999999999999998e47 or 6.7999999999999998e125 < x

              1. Initial program 99.9%

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

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

                  \[\leadsto x + \color{blue}{\left(2 \cdot x + z\right)} \]
                2. associate-+r+N/A

                  \[\leadsto \color{blue}{\left(x + 2 \cdot x\right) + z} \]
                3. distribute-rgt1-inN/A

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

                  \[\leadsto \color{blue}{3} \cdot x + z \]
                5. lower-fma.f6486.5

                  \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
              5. Applied rewrites86.5%

                \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]

              if -3.3999999999999998e47 < x < 6.7999999999999998e125

              1. Initial program 100.0%

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

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

                  \[\leadsto x + \color{blue}{\left(2 \cdot x + z\right)} \]
                2. associate-+r+N/A

                  \[\leadsto \color{blue}{\left(x + 2 \cdot x\right) + z} \]
                3. distribute-rgt1-inN/A

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

                  \[\leadsto \color{blue}{3} \cdot x + z \]
                5. lower-fma.f6453.8

                  \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
              5. Applied rewrites53.8%

                \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
              6. Step-by-step derivation
                1. Applied rewrites53.8%

                  \[\leadsto 3 \cdot x + \color{blue}{z} \]
                2. Taylor expanded in x around 0

                  \[\leadsto \color{blue}{z + 2 \cdot y} \]
                3. Step-by-step derivation
                  1. +-commutativeN/A

                    \[\leadsto \color{blue}{2 \cdot y + z} \]
                  2. lower-fma.f6486.3

                    \[\leadsto \color{blue}{\mathsf{fma}\left(2, y, z\right)} \]
                4. Applied rewrites86.3%

                  \[\leadsto \color{blue}{\mathsf{fma}\left(2, y, z\right)} \]
              7. Recombined 2 regimes into one program.
              8. Add Preprocessing

              Alternative 5: 79.9% accurate, 0.8× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{+146}:\\ \;\;\;\;3 \cdot x\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{+139}:\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \mathbf{else}:\\ \;\;\;\;3 \cdot x\\ \end{array} \end{array} \]
              (FPCore (x y z)
               :precision binary64
               (if (<= x -1.7e+146) (* 3.0 x) (if (<= x 2.2e+139) (fma 2.0 y z) (* 3.0 x))))
              double code(double x, double y, double z) {
              	double tmp;
              	if (x <= -1.7e+146) {
              		tmp = 3.0 * x;
              	} else if (x <= 2.2e+139) {
              		tmp = fma(2.0, y, z);
              	} else {
              		tmp = 3.0 * x;
              	}
              	return tmp;
              }
              
              function code(x, y, z)
              	tmp = 0.0
              	if (x <= -1.7e+146)
              		tmp = Float64(3.0 * x);
              	elseif (x <= 2.2e+139)
              		tmp = fma(2.0, y, z);
              	else
              		tmp = Float64(3.0 * x);
              	end
              	return tmp
              end
              
              code[x_, y_, z_] := If[LessEqual[x, -1.7e+146], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 2.2e+139], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;x \leq -1.7 \cdot 10^{+146}:\\
              \;\;\;\;3 \cdot x\\
              
              \mathbf{elif}\;x \leq 2.2 \cdot 10^{+139}:\\
              \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
              
              \mathbf{else}:\\
              \;\;\;\;3 \cdot x\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if x < -1.69999999999999995e146 or 2.1999999999999999e139 < x

                1. Initial program 99.8%

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

                  \[\leadsto \color{blue}{3 \cdot x} \]
                4. Step-by-step derivation
                  1. lower-*.f6475.7

                    \[\leadsto \color{blue}{3 \cdot x} \]
                5. Applied rewrites75.7%

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

                if -1.69999999999999995e146 < x < 2.1999999999999999e139

                1. Initial program 100.0%

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

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

                    \[\leadsto x + \color{blue}{\left(2 \cdot x + z\right)} \]
                  2. associate-+r+N/A

                    \[\leadsto \color{blue}{\left(x + 2 \cdot x\right) + z} \]
                  3. distribute-rgt1-inN/A

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

                    \[\leadsto \color{blue}{3} \cdot x + z \]
                  5. lower-fma.f6456.9

                    \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
                5. Applied rewrites56.9%

                  \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
                6. Step-by-step derivation
                  1. Applied rewrites56.8%

                    \[\leadsto 3 \cdot x + \color{blue}{z} \]
                  2. Taylor expanded in x around 0

                    \[\leadsto \color{blue}{z + 2 \cdot y} \]
                  3. Step-by-step derivation
                    1. +-commutativeN/A

                      \[\leadsto \color{blue}{2 \cdot y + z} \]
                    2. lower-fma.f6483.0

                      \[\leadsto \color{blue}{\mathsf{fma}\left(2, y, z\right)} \]
                  4. Applied rewrites83.0%

                    \[\leadsto \color{blue}{\mathsf{fma}\left(2, y, z\right)} \]
                7. Recombined 2 regimes into one program.
                8. Add Preprocessing

                Alternative 6: 52.2% accurate, 0.9× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{+59}:\\ \;\;\;\;3 \cdot x\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-19}:\\ \;\;\;\;y + y\\ \mathbf{else}:\\ \;\;\;\;3 \cdot x\\ \end{array} \end{array} \]
                (FPCore (x y z)
                 :precision binary64
                 (if (<= x -3.2e+59) (* 3.0 x) (if (<= x 1.4e-19) (+ y y) (* 3.0 x))))
                double code(double x, double y, double z) {
                	double tmp;
                	if (x <= -3.2e+59) {
                		tmp = 3.0 * x;
                	} else if (x <= 1.4e-19) {
                		tmp = y + y;
                	} else {
                		tmp = 3.0 * x;
                	}
                	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+59)) then
                        tmp = 3.0d0 * x
                    else if (x <= 1.4d-19) then
                        tmp = y + y
                    else
                        tmp = 3.0d0 * x
                    end if
                    code = tmp
                end function
                
                public static double code(double x, double y, double z) {
                	double tmp;
                	if (x <= -3.2e+59) {
                		tmp = 3.0 * x;
                	} else if (x <= 1.4e-19) {
                		tmp = y + y;
                	} else {
                		tmp = 3.0 * x;
                	}
                	return tmp;
                }
                
                def code(x, y, z):
                	tmp = 0
                	if x <= -3.2e+59:
                		tmp = 3.0 * x
                	elif x <= 1.4e-19:
                		tmp = y + y
                	else:
                		tmp = 3.0 * x
                	return tmp
                
                function code(x, y, z)
                	tmp = 0.0
                	if (x <= -3.2e+59)
                		tmp = Float64(3.0 * x);
                	elseif (x <= 1.4e-19)
                		tmp = Float64(y + y);
                	else
                		tmp = Float64(3.0 * x);
                	end
                	return tmp
                end
                
                function tmp_2 = code(x, y, z)
                	tmp = 0.0;
                	if (x <= -3.2e+59)
                		tmp = 3.0 * x;
                	elseif (x <= 1.4e-19)
                		tmp = y + y;
                	else
                		tmp = 3.0 * x;
                	end
                	tmp_2 = tmp;
                end
                
                code[x_, y_, z_] := If[LessEqual[x, -3.2e+59], N[(3.0 * x), $MachinePrecision], If[LessEqual[x, 1.4e-19], N[(y + y), $MachinePrecision], N[(3.0 * x), $MachinePrecision]]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;x \leq -3.2 \cdot 10^{+59}:\\
                \;\;\;\;3 \cdot x\\
                
                \mathbf{elif}\;x \leq 1.4 \cdot 10^{-19}:\\
                \;\;\;\;y + y\\
                
                \mathbf{else}:\\
                \;\;\;\;3 \cdot x\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if x < -3.19999999999999982e59 or 1.40000000000000001e-19 < x

                  1. Initial program 99.9%

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

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

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

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

                  if -3.19999999999999982e59 < x < 1.40000000000000001e-19

                  1. Initial program 100.0%

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

                    \[\leadsto \color{blue}{x + \left(2 \cdot x + 2 \cdot y\right)} \]
                  4. Step-by-step derivation
                    1. associate-+r+N/A

                      \[\leadsto \color{blue}{\left(x + 2 \cdot x\right) + 2 \cdot y} \]
                    2. distribute-rgt1-inN/A

                      \[\leadsto \color{blue}{\left(2 + 1\right) \cdot x} + 2 \cdot y \]
                    3. metadata-evalN/A

                      \[\leadsto \color{blue}{3} \cdot x + 2 \cdot y \]
                    4. lower-fma.f64N/A

                      \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, 2 \cdot y\right)} \]
                    5. lower-*.f6458.1

                      \[\leadsto \mathsf{fma}\left(3, x, \color{blue}{2 \cdot y}\right) \]
                  5. Applied rewrites58.1%

                    \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, 2 \cdot y\right)} \]
                  6. Step-by-step derivation
                    1. Applied rewrites58.1%

                      \[\leadsto \mathsf{fma}\left(3, x, y + y\right) \]
                    2. Taylor expanded in x around 0

                      \[\leadsto 2 \cdot \color{blue}{y} \]
                    3. Step-by-step derivation
                      1. Applied rewrites48.7%

                        \[\leadsto 2 \cdot \color{blue}{y} \]
                      2. Step-by-step derivation
                        1. Applied rewrites48.7%

                          \[\leadsto y + y \]
                      3. Recombined 2 regimes into one program.
                      4. Add Preprocessing

                      Alternative 7: 99.9% accurate, 1.0× speedup?

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

                        \[\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x \]
                      2. Add Preprocessing
                      3. Add Preprocessing

                      Alternative 8: 34.1% accurate, 4.0× speedup?

                      \[\begin{array}{l} \\ y + y \end{array} \]
                      (FPCore (x y z) :precision binary64 (+ y y))
                      double code(double x, double y, double z) {
                      	return y + y;
                      }
                      
                      real(8) function code(x, y, z)
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          real(8), intent (in) :: z
                          code = y + y
                      end function
                      
                      public static double code(double x, double y, double z) {
                      	return y + y;
                      }
                      
                      def code(x, y, z):
                      	return y + y
                      
                      function code(x, y, z)
                      	return Float64(y + y)
                      end
                      
                      function tmp = code(x, y, z)
                      	tmp = y + y;
                      end
                      
                      code[x_, y_, z_] := N[(y + y), $MachinePrecision]
                      
                      \begin{array}{l}
                      
                      \\
                      y + y
                      \end{array}
                      
                      Derivation
                      1. Initial program 99.9%

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

                        \[\leadsto \color{blue}{x + \left(2 \cdot x + 2 \cdot y\right)} \]
                      4. Step-by-step derivation
                        1. associate-+r+N/A

                          \[\leadsto \color{blue}{\left(x + 2 \cdot x\right) + 2 \cdot y} \]
                        2. distribute-rgt1-inN/A

                          \[\leadsto \color{blue}{\left(2 + 1\right) \cdot x} + 2 \cdot y \]
                        3. metadata-evalN/A

                          \[\leadsto \color{blue}{3} \cdot x + 2 \cdot y \]
                        4. lower-fma.f64N/A

                          \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, 2 \cdot y\right)} \]
                        5. lower-*.f6468.2

                          \[\leadsto \mathsf{fma}\left(3, x, \color{blue}{2 \cdot y}\right) \]
                      5. Applied rewrites68.2%

                        \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, 2 \cdot y\right)} \]
                      6. Step-by-step derivation
                        1. Applied rewrites68.2%

                          \[\leadsto \mathsf{fma}\left(3, x, y + y\right) \]
                        2. Taylor expanded in x around 0

                          \[\leadsto 2 \cdot \color{blue}{y} \]
                        3. Step-by-step derivation
                          1. Applied rewrites34.9%

                            \[\leadsto 2 \cdot \color{blue}{y} \]
                          2. Step-by-step derivation
                            1. Applied rewrites34.9%

                              \[\leadsto y + y \]
                            2. Add Preprocessing

                            Reproduce

                            ?
                            herbie shell --seed 2024332 
                            (FPCore (x y z)
                              :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
                              :precision binary64
                              (+ (+ (+ (+ (+ x y) y) x) z) x))