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

Percentage Accurate: 99.9% → 100.0%
Time: 7.9s
Alternatives: 8
Speedup: 1.2×

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: 100.0% accurate, 1.2× speedup?

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

\\
\mathsf{fma}\left(x, 3, z + \left(y + y\right)\right)
\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 x around 0

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(2, y, \color{blue}{x \cdot 3} + z\right) \]
    13. lower-fma.f6499.9

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

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

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

    Alternative 2: 78.8% accurate, 0.5× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.7 \cdot 10^{+171}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{+50}:\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \mathbf{elif}\;x \leq 1.15 \cdot 10^{+129}:\\ \;\;\;\;x \cdot 3\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{+197}:\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot 3\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (<= x -4.7e+171)
       (* x 3.0)
       (if (<= x 1.05e+50)
         (fma 2.0 y z)
         (if (<= x 1.15e+129)
           (* x 3.0)
           (if (<= x 1.7e+197) (fma 2.0 y z) (* x 3.0))))))
    double code(double x, double y, double z) {
    	double tmp;
    	if (x <= -4.7e+171) {
    		tmp = x * 3.0;
    	} else if (x <= 1.05e+50) {
    		tmp = fma(2.0, y, z);
    	} else if (x <= 1.15e+129) {
    		tmp = x * 3.0;
    	} else if (x <= 1.7e+197) {
    		tmp = fma(2.0, y, z);
    	} else {
    		tmp = x * 3.0;
    	}
    	return tmp;
    }
    
    function code(x, y, z)
    	tmp = 0.0
    	if (x <= -4.7e+171)
    		tmp = Float64(x * 3.0);
    	elseif (x <= 1.05e+50)
    		tmp = fma(2.0, y, z);
    	elseif (x <= 1.15e+129)
    		tmp = Float64(x * 3.0);
    	elseif (x <= 1.7e+197)
    		tmp = fma(2.0, y, z);
    	else
    		tmp = Float64(x * 3.0);
    	end
    	return tmp
    end
    
    code[x_, y_, z_] := If[LessEqual[x, -4.7e+171], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 1.05e+50], N[(2.0 * y + z), $MachinePrecision], If[LessEqual[x, 1.15e+129], N[(x * 3.0), $MachinePrecision], If[LessEqual[x, 1.7e+197], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0), $MachinePrecision]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -4.7 \cdot 10^{+171}:\\
    \;\;\;\;x \cdot 3\\
    
    \mathbf{elif}\;x \leq 1.05 \cdot 10^{+50}:\\
    \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
    
    \mathbf{elif}\;x \leq 1.15 \cdot 10^{+129}:\\
    \;\;\;\;x \cdot 3\\
    
    \mathbf{elif}\;x \leq 1.7 \cdot 10^{+197}:\\
    \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;x \cdot 3\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -4.7000000000000001e171 or 1.05e50 < x < 1.14999999999999995e129 or 1.70000000000000008e197 < 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. *-commutativeN/A

          \[\leadsto \color{blue}{x \cdot 3} \]
        2. lower-*.f6478.1

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

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

      if -4.7000000000000001e171 < x < 1.05e50 or 1.14999999999999995e129 < x < 1.70000000000000008e197

      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}{z + 2 \cdot y} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

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

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

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

    Alternative 3: 84.9% accurate, 0.8× speedup?

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

      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 x around 0

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(2, y, \color{blue}{x \cdot 3} + z\right) \]
        13. lower-fma.f6499.9

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

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

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

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

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

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

            if -0.0140000000000000003 < y < 1.44999999999999994e41

            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 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. *-commutativeN/A

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

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

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

            if 1.44999999999999994e41 < y

            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 x around 0

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

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

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

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

          Alternative 4: 84.9% accurate, 0.8× speedup?

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

            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. +-commutativeN/A

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

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

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

                \[\leadsto \mathsf{fma}\left(2, \color{blue}{y + x}, x\right) \]
              5. lower-+.f6488.4

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

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

            if -0.0140000000000000003 < y < 1.44999999999999994e41

            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 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. *-commutativeN/A

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

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

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

            if 1.44999999999999994e41 < y

            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 x around 0

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

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

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

              \[\leadsto \color{blue}{\mathsf{fma}\left(2, y, z\right)} \]
          3. Recombined 3 regimes into one program.
          4. Final simplification90.7%

            \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.014:\\ \;\;\;\;\mathsf{fma}\left(2, x + y, x\right)\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+41}:\\ \;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \end{array} \]
          5. Add Preprocessing

          Alternative 5: 86.3% accurate, 0.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -6.4 \cdot 10^{+63}:\\ \;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\ \mathbf{elif}\;x \leq 10^{+46}:\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (<= x -6.4e+63)
             (fma x 3.0 z)
             (if (<= x 1e+46) (fma 2.0 y z) (fma x 3.0 z))))
          double code(double x, double y, double z) {
          	double tmp;
          	if (x <= -6.4e+63) {
          		tmp = fma(x, 3.0, z);
          	} else if (x <= 1e+46) {
          		tmp = fma(2.0, y, z);
          	} else {
          		tmp = fma(x, 3.0, z);
          	}
          	return tmp;
          }
          
          function code(x, y, z)
          	tmp = 0.0
          	if (x <= -6.4e+63)
          		tmp = fma(x, 3.0, z);
          	elseif (x <= 1e+46)
          		tmp = fma(2.0, y, z);
          	else
          		tmp = fma(x, 3.0, z);
          	end
          	return tmp
          end
          
          code[x_, y_, z_] := If[LessEqual[x, -6.4e+63], N[(x * 3.0 + z), $MachinePrecision], If[LessEqual[x, 1e+46], N[(2.0 * y + z), $MachinePrecision], N[(x * 3.0 + z), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;x \leq -6.4 \cdot 10^{+63}:\\
          \;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
          
          \mathbf{elif}\;x \leq 10^{+46}:\\
          \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(x, 3, z\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if x < -6.40000000000000022e63 or 9.9999999999999999e45 < 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 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. *-commutativeN/A

                \[\leadsto \color{blue}{x \cdot 3} + z \]
              6. lower-fma.f6485.2

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

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

            if -6.40000000000000022e63 < x < 9.9999999999999999e45

            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 x around 0

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

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

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

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

          Alternative 6: 53.7% accurate, 0.9× speedup?

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

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

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

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

            if -3.49999999999999998e34 < x < 7.8000000000000002e48

            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 inf

              \[\leadsto \color{blue}{2 \cdot y} \]
            4. Step-by-step derivation
              1. lower-*.f6448.1

                \[\leadsto \color{blue}{2 \cdot y} \]
            5. Applied rewrites48.1%

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

                \[\leadsto y + \color{blue}{y} \]
            7. Recombined 2 regimes into one program.
            8. Add Preprocessing

            Alternative 7: 100.0% accurate, 1.2× speedup?

            \[\begin{array}{l} \\ \mathsf{fma}\left(2, y, \mathsf{fma}\left(x, 3, z\right)\right) \end{array} \]
            (FPCore (x y z) :precision binary64 (fma 2.0 y (fma x 3.0 z)))
            double code(double x, double y, double z) {
            	return fma(2.0, y, fma(x, 3.0, z));
            }
            
            function code(x, y, z)
            	return fma(2.0, y, fma(x, 3.0, z))
            end
            
            code[x_, y_, z_] := N[(2.0 * y + N[(x * 3.0 + z), $MachinePrecision]), $MachinePrecision]
            
            \begin{array}{l}
            
            \\
            \mathsf{fma}\left(2, y, \mathsf{fma}\left(x, 3, z\right)\right)
            \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 x around 0

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(2, y, \color{blue}{x \cdot 3} + z\right) \]
              13. lower-fma.f6499.9

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

              \[\leadsto \color{blue}{\mathsf{fma}\left(2, y, \mathsf{fma}\left(x, 3, z\right)\right)} \]
            6. Add Preprocessing

            Alternative 8: 34.9% 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 y around inf

              \[\leadsto \color{blue}{2 \cdot y} \]
            4. Step-by-step derivation
              1. lower-*.f6434.4

                \[\leadsto \color{blue}{2 \cdot y} \]
            5. Applied rewrites34.4%

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

                \[\leadsto y + \color{blue}{y} \]
              2. Add Preprocessing

              Reproduce

              ?
              herbie shell --seed 2024220 
              (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))