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

Percentage Accurate: 100.0% → 100.0%
Time: 5.3s
Alternatives: 8
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 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: 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, x\right) + y \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) x) y))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return fma(z, (y + x), x) + y;
}
x, y, z = sort([x, y, z])
function code(x, y, z)
	return Float64(fma(z, Float64(y + x), x) + y)
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] + x), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z, y + x, x\right) + y
\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. associate-+r+N/A

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

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

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

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

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

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

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

Alternative 2: 74.2% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z + 1 \leq -5000000 \lor \neg \left(z + 1 \leq 200\right):\\ \;\;\;\;z \cdot y\\ \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) -5000000.0) (not (<= (+ z 1.0) 200.0)))
   (* z y)
   (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (((z + 1.0) <= -5000000.0) || !((z + 1.0) <= 200.0)) {
		tmp = z * y;
	} 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) <= (-5000000.0d0)) .or. (.not. ((z + 1.0d0) <= 200.0d0))) then
        tmp = z * y
    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) <= -5000000.0) || !((z + 1.0) <= 200.0)) {
		tmp = z * y;
	} else {
		tmp = y + x;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if ((z + 1.0) <= -5000000.0) or not ((z + 1.0) <= 200.0):
		tmp = z * y
	else:
		tmp = y + x
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if ((Float64(z + 1.0) <= -5000000.0) || !(Float64(z + 1.0) <= 200.0))
		tmp = Float64(z * y);
	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) <= -5000000.0) || ~(((z + 1.0) <= 200.0)))
		tmp = z * y;
	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[N[(z + 1.0), $MachinePrecision], -5000000.0], N[Not[LessEqual[N[(z + 1.0), $MachinePrecision], 200.0]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -5000000 \lor \neg \left(z + 1 \leq 200\right):\\
\;\;\;\;z \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 z #s(literal 1 binary64)) < -5e6 or 200 < (+.f64 z #s(literal 1 binary64))

    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-+.f6499.1

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

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

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

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

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

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

        if -5e6 < (+.f64 z #s(literal 1 binary64)) < 200

        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.6

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

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

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

            \[\leadsto x \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.5

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

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

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

        Alternative 3: 74.5% accurate, 0.5× speedup?

        \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z + 1 \leq -5000000 \lor \neg \left(z + 1 \leq 10^{+39}\right):\\ \;\;\;\;x \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) -5000000.0) (not (<= (+ z 1.0) 1e+39)))
           (* x z)
           (+ y x)))
        assert(x < y && y < z);
        double code(double x, double y, double z) {
        	double tmp;
        	if (((z + 1.0) <= -5000000.0) || !((z + 1.0) <= 1e+39)) {
        		tmp = x * 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) <= (-5000000.0d0)) .or. (.not. ((z + 1.0d0) <= 1d+39))) then
                tmp = x * 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) <= -5000000.0) || !((z + 1.0) <= 1e+39)) {
        		tmp = x * 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) <= -5000000.0) or not ((z + 1.0) <= 1e+39):
        		tmp = x * z
        	else:
        		tmp = y + x
        	return tmp
        
        x, y, z = sort([x, y, z])
        function code(x, y, z)
        	tmp = 0.0
        	if ((Float64(z + 1.0) <= -5000000.0) || !(Float64(z + 1.0) <= 1e+39))
        		tmp = Float64(x * 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) <= -5000000.0) || ~(((z + 1.0) <= 1e+39)))
        		tmp = x * 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[N[(z + 1.0), $MachinePrecision], -5000000.0], N[Not[LessEqual[N[(z + 1.0), $MachinePrecision], 1e+39]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(y + x), $MachinePrecision]]
        
        \begin{array}{l}
        [x, y, z] = \mathsf{sort}([x, y, z])\\
        \\
        \begin{array}{l}
        \mathbf{if}\;z + 1 \leq -5000000 \lor \neg \left(z + 1 \leq 10^{+39}\right):\\
        \;\;\;\;x \cdot z\\
        
        \mathbf{else}:\\
        \;\;\;\;y + x\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (+.f64 z #s(literal 1 binary64)) < -5e6 or 9.9999999999999994e38 < (+.f64 z #s(literal 1 binary64))

          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-+.f6499.6

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

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

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

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

            if -5e6 < (+.f64 z #s(literal 1 binary64)) < 9.9999999999999994e38

            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-+.f647.4

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

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

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

                \[\leadsto x \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-+.f6493.6

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

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

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

            Alternative 4: 73.6% accurate, 0.5× speedup?

            \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;x + y \leq -2 \cdot 10^{-220}:\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{elif}\;x + y \leq 2 \cdot 10^{+76}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \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-220) (fma z x x) (if (<= (+ x y) 2e+76) (+ y x) (* z y))))
            assert(x < y && y < z);
            double code(double x, double y, double z) {
            	double tmp;
            	if ((x + y) <= -2e-220) {
            		tmp = fma(z, x, x);
            	} else if ((x + y) <= 2e+76) {
            		tmp = y + x;
            	} else {
            		tmp = z * y;
            	}
            	return tmp;
            }
            
            x, y, z = sort([x, y, z])
            function code(x, y, z)
            	tmp = 0.0
            	if (Float64(x + y) <= -2e-220)
            		tmp = fma(z, x, x);
            	elseif (Float64(x + y) <= 2e+76)
            		tmp = Float64(y + x);
            	else
            		tmp = Float64(z * 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-220], N[(z * x + x), $MachinePrecision], If[LessEqual[N[(x + y), $MachinePrecision], 2e+76], N[(y + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
            
            \begin{array}{l}
            [x, y, z] = \mathsf{sort}([x, y, z])\\
            \\
            \begin{array}{l}
            \mathbf{if}\;x + y \leq -2 \cdot 10^{-220}:\\
            \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
            
            \mathbf{elif}\;x + y \leq 2 \cdot 10^{+76}:\\
            \;\;\;\;y + x\\
            
            \mathbf{else}:\\
            \;\;\;\;z \cdot y\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 3 regimes
            2. if (+.f64 x y) < -1.99999999999999998e-220

              1. Initial program 100.0%

                \[\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.f6454.9

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

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

              if -1.99999999999999998e-220 < (+.f64 x y) < 2.0000000000000001e76

              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-+.f6443.1

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

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

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

                  \[\leadsto x \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-+.f6457.9

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

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

                if 2.0000000000000001e76 < (+.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-+.f6457.4

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

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

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

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

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

                      \[\leadsto z \cdot \color{blue}{y} \]
                  4. Recombined 3 regimes into one program.
                  5. Add Preprocessing

                  Alternative 5: 97.6% 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^{-220}:\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + z\right) \cdot y\\ \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-220) (fma z x x) (* (+ 1.0 z) y)))
                  assert(x < y && y < z);
                  double code(double x, double y, double z) {
                  	double tmp;
                  	if ((x + y) <= -2e-220) {
                  		tmp = fma(z, x, x);
                  	} else {
                  		tmp = (1.0 + z) * y;
                  	}
                  	return tmp;
                  }
                  
                  x, y, z = sort([x, y, z])
                  function code(x, y, z)
                  	tmp = 0.0
                  	if (Float64(x + y) <= -2e-220)
                  		tmp = fma(z, x, x);
                  	else
                  		tmp = Float64(Float64(1.0 + z) * 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-220], N[(z * x + x), $MachinePrecision], N[(N[(1.0 + z), $MachinePrecision] * y), $MachinePrecision]]
                  
                  \begin{array}{l}
                  [x, y, z] = \mathsf{sort}([x, y, z])\\
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;x + y \leq -2 \cdot 10^{-220}:\\
                  \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\left(1 + z\right) \cdot y\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (+.f64 x y) < -1.99999999999999998e-220

                    1. Initial program 100.0%

                      \[\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.f6454.9

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

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

                    if -1.99999999999999998e-220 < (+.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.f6451.8

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

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

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

                    Alternative 6: 97.6% 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^{-220}:\\ \;\;\;\;\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-220) (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-220) {
                    		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-220)
                    		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-220], 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^{-220}:\\
                    \;\;\;\;\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.99999999999999998e-220

                      1. Initial program 100.0%

                        \[\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.f6454.9

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

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

                      if -1.99999999999999998e-220 < (+.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.f6451.8

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

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

                    Alternative 7: 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 8: 51.3% 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-+.f6450.3

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

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

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

                        \[\leadsto x \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-+.f6451.5

                          \[\leadsto \color{blue}{y + x} \]
                      4. Applied rewrites51.5%

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

                      Reproduce

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