Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G

Percentage Accurate: 100.0% → 100.0%
Time: 5.6s
Alternatives: 7
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 0.9× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \mathsf{fma}\left(z, y + x, y\right) + x \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 (+ (fma z (+ y x) y) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return fma(z, (y + x), y) + x;
}
x, y, z = sort([x, y, z])
function code(x, y, z)
	return Float64(fma(z, Float64(y + x), y) + x)
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := N[(N[(z * N[(y + x), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z, y + x, y\right) + x
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{z \cdot \left(x + y\right) + 1 \cdot \left(x + y\right)} \]
    4. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

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

Alternative 2: 73.5% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;x + y \leq -2 \cdot 10^{-254}:\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{elif}\;x + y \leq 2 \cdot 10^{-28} \lor \neg \left(x + y \leq 4 \cdot 10^{+137}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= (+ x y) -2e-254)
   (fma z x x)
   (if (or (<= (+ x y) 2e-28) (not (<= (+ x y) 4e+137))) (* y z) (+ y x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((x + y) <= -2e-254) {
		tmp = fma(z, x, x);
	} else if (((x + y) <= 2e-28) || !((x + y) <= 4e+137)) {
		tmp = y * z;
	} else {
		tmp = y + x;
	}
	return tmp;
}
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (Float64(x + y) <= -2e-254)
		tmp = fma(z, x, x);
	elseif ((Float64(x + y) <= 2e-28) || !(Float64(x + y) <= 4e+137))
		tmp = Float64(y * z);
	else
		tmp = Float64(y + x);
	end
	return tmp
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-254], N[(z * x + x), $MachinePrecision], If[Or[LessEqual[N[(x + y), $MachinePrecision], 2e-28], N[Not[LessEqual[N[(x + y), $MachinePrecision], 4e+137]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-254}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\

\mathbf{elif}\;x + y \leq 2 \cdot 10^{-28} \lor \neg \left(x + y \leq 4 \cdot 10^{+137}\right):\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 x y) < -1.9999999999999998e-254

    1. Initial program 99.9%

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

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

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

        \[\leadsto \color{blue}{z \cdot x + 1 \cdot x} \]
      3. *-lft-identityN/A

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

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

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

    if -1.9999999999999998e-254 < (+.f64 x y) < 1.99999999999999994e-28 or 4.0000000000000001e137 < (+.f64 x y)

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

      if 1.99999999999999994e-28 < (+.f64 x y) < 4.0000000000000001e137

      1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{y + x} \]
          2. lower-+.f6473.0

            \[\leadsto \color{blue}{y + x} \]
        4. Applied rewrites73.0%

          \[\leadsto \color{blue}{y + x} \]
      8. Recombined 3 regimes into one program.
      9. Final simplification45.8%

        \[\leadsto \begin{array}{l} \mathbf{if}\;x + y \leq -2 \cdot 10^{-254}:\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{elif}\;x + y \leq 2 \cdot 10^{-28} \lor \neg \left(x + y \leq 4 \cdot 10^{+137}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
      10. Add Preprocessing

      Alternative 3: 75.0% accurate, 0.7× speedup?

      \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 12\right):\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \end{array} \]
      NOTE: x, y, and z should be sorted in increasing order before calling this function.
      (FPCore (x y z)
       :precision binary64
       (if (or (<= z -1.0) (not (<= z 12.0))) (* z x) (+ y x)))
      assert(x < y && y < z);
      double code(double x, double y, double z) {
      	double tmp;
      	if ((z <= -1.0) || !(z <= 12.0)) {
      		tmp = z * x;
      	} else {
      		tmp = y + x;
      	}
      	return tmp;
      }
      
      NOTE: x, y, and z should be sorted in increasing order before calling this function.
      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 ((z <= (-1.0d0)) .or. (.not. (z <= 12.0d0))) then
              tmp = z * x
          else
              tmp = y + x
          end if
          code = tmp
      end function
      
      assert x < y && y < z;
      public static double code(double x, double y, double z) {
      	double tmp;
      	if ((z <= -1.0) || !(z <= 12.0)) {
      		tmp = z * x;
      	} else {
      		tmp = y + x;
      	}
      	return tmp;
      }
      
      [x, y, z] = sort([x, y, z])
      def code(x, y, z):
      	tmp = 0
      	if (z <= -1.0) or not (z <= 12.0):
      		tmp = z * x
      	else:
      		tmp = y + x
      	return tmp
      
      x, y, z = sort([x, y, z])
      function code(x, y, z)
      	tmp = 0.0
      	if ((z <= -1.0) || !(z <= 12.0))
      		tmp = Float64(z * x);
      	else
      		tmp = Float64(y + x);
      	end
      	return tmp
      end
      
      x, y, z = num2cell(sort([x, y, z])){:}
      function tmp_2 = code(x, y, z)
      	tmp = 0.0;
      	if ((z <= -1.0) || ~((z <= 12.0)))
      		tmp = z * x;
      	else
      		tmp = y + x;
      	end
      	tmp_2 = tmp;
      end
      
      NOTE: x, y, and z should be sorted in increasing order before calling this function.
      code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 12.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], N[(y + x), $MachinePrecision]]
      
      \begin{array}{l}
      [x, y, z] = \mathsf{sort}([x, y, z])\\
      \\
      \begin{array}{l}
      \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 12\right):\\
      \;\;\;\;z \cdot x\\
      
      \mathbf{else}:\\
      \;\;\;\;y + x\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if z < -1 or 12 < z

        1. Initial program 100.0%

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

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

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

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

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

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

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

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

            \[\leadsto y \cdot \color{blue}{z} \]
          2. Taylor expanded in x around inf

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

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

            if -1 < z < 12

            1. Initial program 100.0%

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

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

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

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

                \[\leadsto \color{blue}{\left(y + x\right)} \cdot z \]
              4. lower-+.f643.1

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

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

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

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

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

                  \[\leadsto \color{blue}{y + x} \]
                2. lower-+.f6497.6

                  \[\leadsto \color{blue}{y + x} \]
              4. Applied rewrites97.6%

                \[\leadsto \color{blue}{y + x} \]
            8. Recombined 2 regimes into one program.
            9. Final simplification75.9%

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

            Alternative 4: 74.5% accurate, 0.7× speedup?

            \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 600000000000\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \end{array} \]
            NOTE: x, y, and z should be sorted in increasing order before calling this function.
            (FPCore (x y z)
             :precision binary64
             (if (or (<= z -1.0) (not (<= z 600000000000.0))) (* y z) (+ y x)))
            assert(x < y && y < z);
            double code(double x, double y, double z) {
            	double tmp;
            	if ((z <= -1.0) || !(z <= 600000000000.0)) {
            		tmp = y * z;
            	} else {
            		tmp = y + x;
            	}
            	return tmp;
            }
            
            NOTE: x, y, and z should be sorted in increasing order before calling this function.
            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 ((z <= (-1.0d0)) .or. (.not. (z <= 600000000000.0d0))) then
                    tmp = y * z
                else
                    tmp = y + x
                end if
                code = tmp
            end function
            
            assert x < y && y < z;
            public static double code(double x, double y, double z) {
            	double tmp;
            	if ((z <= -1.0) || !(z <= 600000000000.0)) {
            		tmp = y * z;
            	} else {
            		tmp = y + x;
            	}
            	return tmp;
            }
            
            [x, y, z] = sort([x, y, z])
            def code(x, y, z):
            	tmp = 0
            	if (z <= -1.0) or not (z <= 600000000000.0):
            		tmp = y * z
            	else:
            		tmp = y + x
            	return tmp
            
            x, y, z = sort([x, y, z])
            function code(x, y, z)
            	tmp = 0.0
            	if ((z <= -1.0) || !(z <= 600000000000.0))
            		tmp = Float64(y * z);
            	else
            		tmp = Float64(y + x);
            	end
            	return tmp
            end
            
            x, y, z = num2cell(sort([x, y, z])){:}
            function tmp_2 = code(x, y, z)
            	tmp = 0.0;
            	if ((z <= -1.0) || ~((z <= 600000000000.0)))
            		tmp = y * z;
            	else
            		tmp = y + x;
            	end
            	tmp_2 = tmp;
            end
            
            NOTE: x, y, and z should be sorted in increasing order before calling this function.
            code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 600000000000.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y + x), $MachinePrecision]]
            
            \begin{array}{l}
            [x, y, z] = \mathsf{sort}([x, y, z])\\
            \\
            \begin{array}{l}
            \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 600000000000\right):\\
            \;\;\;\;y \cdot z\\
            
            \mathbf{else}:\\
            \;\;\;\;y + x\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if z < -1 or 6e11 < z

              1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

                if -1 < z < 6e11

                1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \color{blue}{y + x} \]
                    2. lower-+.f6496.9

                      \[\leadsto \color{blue}{y + x} \]
                  4. Applied rewrites96.9%

                    \[\leadsto \color{blue}{y + x} \]
                8. Recombined 2 regimes into one program.
                9. Final simplification74.3%

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

                Alternative 5: 97.7% accurate, 0.7× speedup?

                \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;x + y \leq -2 \cdot 10^{-254}:\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, y\right)\\ \end{array} \end{array} \]
                NOTE: x, y, and z should be sorted in increasing order before calling this function.
                (FPCore (x y z)
                 :precision binary64
                 (if (<= (+ x y) -2e-254) (fma z x x) (fma z y y)))
                assert(x < y && y < z);
                double code(double x, double y, double z) {
                	double tmp;
                	if ((x + y) <= -2e-254) {
                		tmp = fma(z, x, x);
                	} else {
                		tmp = fma(z, y, y);
                	}
                	return tmp;
                }
                
                x, y, z = sort([x, y, z])
                function code(x, y, z)
                	tmp = 0.0
                	if (Float64(x + y) <= -2e-254)
                		tmp = fma(z, x, x);
                	else
                		tmp = fma(z, y, y);
                	end
                	return tmp
                end
                
                NOTE: x, y, and z should be sorted in increasing order before calling this function.
                code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-254], N[(z * x + x), $MachinePrecision], N[(z * y + y), $MachinePrecision]]
                
                \begin{array}{l}
                [x, y, z] = \mathsf{sort}([x, y, z])\\
                \\
                \begin{array}{l}
                \mathbf{if}\;x + y \leq -2 \cdot 10^{-254}:\\
                \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;\mathsf{fma}\left(z, y, y\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if (+.f64 x y) < -1.9999999999999998e-254

                  1. Initial program 99.9%

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

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

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

                      \[\leadsto \color{blue}{z \cdot x + 1 \cdot x} \]
                    3. *-lft-identityN/A

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

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

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

                  if -1.9999999999999998e-254 < (+.f64 x y)

                  1. Initial program 100.0%

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

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

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

                      \[\leadsto \color{blue}{z \cdot y + 1 \cdot y} \]
                    3. *-lft-identityN/A

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

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

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

                Alternative 6: 100.0% accurate, 1.0× speedup?

                \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \left(x + y\right) \cdot \left(z + 1\right) \end{array} \]
                NOTE: x, y, and z should be sorted in increasing order before calling this function.
                (FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
                assert(x < y && y < z);
                double code(double x, double y, double z) {
                	return (x + y) * (z + 1.0);
                }
                
                NOTE: x, y, and z should be sorted in increasing order before calling this function.
                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 + 1.0d0)
                end function
                
                assert x < y && y < z;
                public static double code(double x, double y, double z) {
                	return (x + y) * (z + 1.0);
                }
                
                [x, y, z] = sort([x, y, z])
                def code(x, y, z):
                	return (x + y) * (z + 1.0)
                
                x, y, z = sort([x, y, z])
                function code(x, y, z)
                	return Float64(Float64(x + y) * Float64(z + 1.0))
                end
                
                x, y, z = num2cell(sort([x, y, z])){:}
                function tmp = code(x, y, z)
                	tmp = (x + y) * (z + 1.0);
                end
                
                NOTE: x, y, and z should be sorted in increasing order before calling this function.
                code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
                
                \begin{array}{l}
                [x, y, z] = \mathsf{sort}([x, y, z])\\
                \\
                \left(x + y\right) \cdot \left(z + 1\right)
                \end{array}
                
                Derivation
                1. Initial program 100.0%

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

                Alternative 7: 51.1% accurate, 3.0× speedup?

                \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ y + x \end{array} \]
                NOTE: x, y, and z should be sorted in increasing order before calling this function.
                (FPCore (x y z) :precision binary64 (+ y x))
                assert(x < y && y < z);
                double code(double x, double y, double z) {
                	return y + x;
                }
                
                NOTE: x, y, and z should be sorted in increasing order before calling this function.
                real(8) function code(x, y, z)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    real(8), intent (in) :: z
                    code = y + x
                end function
                
                assert x < y && y < z;
                public static double code(double x, double y, double z) {
                	return y + x;
                }
                
                [x, y, z] = sort([x, y, z])
                def code(x, y, z):
                	return y + x
                
                x, y, z = sort([x, y, z])
                function code(x, y, z)
                	return Float64(y + x)
                end
                
                x, y, z = num2cell(sort([x, y, z])){:}
                function tmp = code(x, y, z)
                	tmp = y + x;
                end
                
                NOTE: x, y, and z should be sorted in increasing order before calling this function.
                code[x_, y_, z_] := N[(y + x), $MachinePrecision]
                
                \begin{array}{l}
                [x, y, z] = \mathsf{sort}([x, y, z])\\
                \\
                y + x
                \end{array}
                
                Derivation
                1. Initial program 100.0%

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

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

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

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

                    \[\leadsto \color{blue}{\left(y + x\right)} \cdot z \]
                  4. lower-+.f6451.1

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

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

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

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

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

                      \[\leadsto \color{blue}{y + x} \]
                    2. lower-+.f6450.1

                      \[\leadsto \color{blue}{y + x} \]
                  4. Applied rewrites50.1%

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

                  Reproduce

                  ?
                  herbie shell --seed 2024339 
                  (FPCore (x y z)
                    :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
                    :precision binary64
                    (* (+ x y) (+ z 1.0)))