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

Percentage Accurate: 100.0% → 99.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: 99.0% accurate, 0.8× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \mathsf{fma}\left(1 + z, y, \mathsf{fma}\left(z, x, x\right)\right) \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 (fma (+ 1.0 z) y (fma z x x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return fma((1.0 + z), y, fma(z, x, x));
}
x, y, z = sort([x, y, z])
function code(x, y, z)
	return fma(Float64(1.0 + z), y, fma(z, x, x))
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := N[(N[(1.0 + z), $MachinePrecision] * y + N[(z * x + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(1 + z, y, \mathsf{fma}\left(z, x, x\right)\right)
\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 75.6% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{-15}:\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{elif}\;z \leq 1.56 \cdot 10^{-9}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{+49}:\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{+100}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \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 (<= z -3.8e-15)
   (fma z x x)
   (if (<= z 1.56e-9)
     (+ y x)
     (if (<= z 3.5e+49) (fma z x x) (if (<= z 4.8e+100) (* y z) (* x z))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (z <= -3.8e-15) {
		tmp = fma(z, x, x);
	} else if (z <= 1.56e-9) {
		tmp = y + x;
	} else if (z <= 3.5e+49) {
		tmp = fma(z, x, x);
	} else if (z <= 4.8e+100) {
		tmp = y * z;
	} else {
		tmp = x * z;
	}
	return tmp;
}
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (z <= -3.8e-15)
		tmp = fma(z, x, x);
	elseif (z <= 1.56e-9)
		tmp = Float64(y + x);
	elseif (z <= 3.5e+49)
		tmp = fma(z, x, x);
	elseif (z <= 4.8e+100)
		tmp = Float64(y * z);
	else
		tmp = Float64(x * z);
	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[z, -3.8e-15], N[(z * x + x), $MachinePrecision], If[LessEqual[z, 1.56e-9], N[(y + x), $MachinePrecision], If[LessEqual[z, 3.5e+49], N[(z * x + x), $MachinePrecision], If[LessEqual[z, 4.8e+100], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\

\mathbf{elif}\;z \leq 1.56 \cdot 10^{-9}:\\
\;\;\;\;y + x\\

\mathbf{elif}\;z \leq 3.5 \cdot 10^{+49}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\

\mathbf{elif}\;z \leq 4.8 \cdot 10^{+100}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if z < -3.8000000000000002e-15 or 1.56e-9 < z < 3.49999999999999975e49

    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.f6456.3

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

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

    if -3.8000000000000002e-15 < z < 1.56e-9

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

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

      \[\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-+.f6499.5

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

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

      if 3.49999999999999975e49 < z < 4.80000000000000023e100

      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-+.f64100.0

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

        \[\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 rewrites43.6%

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

        if 4.80000000000000023e100 < 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-+.f64100.0

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

          \[\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 rewrites49.2%

            \[\leadsto x \cdot \color{blue}{z} \]
        8. Recombined 4 regimes into one program.
        9. Add Preprocessing

        Alternative 3: 74.0% accurate, 0.5× speedup?

        \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;x \cdot z\\ \mathbf{elif}\;z \leq 2.2 \cdot 10^{+41}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{+100}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \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 (<= z -1.0)
           (* x z)
           (if (<= z 2.2e+41) (+ y x) (if (<= z 4.8e+100) (* y z) (* x z)))))
        assert(x < y && y < z);
        double code(double x, double y, double z) {
        	double tmp;
        	if (z <= -1.0) {
        		tmp = x * z;
        	} else if (z <= 2.2e+41) {
        		tmp = y + x;
        	} else if (z <= 4.8e+100) {
        		tmp = y * z;
        	} else {
        		tmp = x * z;
        	}
        	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)) then
                tmp = x * z
            else if (z <= 2.2d+41) then
                tmp = y + x
            else if (z <= 4.8d+100) then
                tmp = y * z
            else
                tmp = x * z
            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) {
        		tmp = x * z;
        	} else if (z <= 2.2e+41) {
        		tmp = y + x;
        	} else if (z <= 4.8e+100) {
        		tmp = y * z;
        	} else {
        		tmp = x * z;
        	}
        	return tmp;
        }
        
        [x, y, z] = sort([x, y, z])
        def code(x, y, z):
        	tmp = 0
        	if z <= -1.0:
        		tmp = x * z
        	elif z <= 2.2e+41:
        		tmp = y + x
        	elif z <= 4.8e+100:
        		tmp = y * z
        	else:
        		tmp = x * z
        	return tmp
        
        x, y, z = sort([x, y, z])
        function code(x, y, z)
        	tmp = 0.0
        	if (z <= -1.0)
        		tmp = Float64(x * z);
        	elseif (z <= 2.2e+41)
        		tmp = Float64(y + x);
        	elseif (z <= 4.8e+100)
        		tmp = Float64(y * z);
        	else
        		tmp = Float64(x * z);
        	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)
        		tmp = x * z;
        	elseif (z <= 2.2e+41)
        		tmp = y + x;
        	elseif (z <= 4.8e+100)
        		tmp = y * z;
        	else
        		tmp = x * z;
        	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[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 2.2e+41], N[(y + x), $MachinePrecision], If[LessEqual[z, 4.8e+100], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
        
        \begin{array}{l}
        [x, y, z] = \mathsf{sort}([x, y, z])\\
        \\
        \begin{array}{l}
        \mathbf{if}\;z \leq -1:\\
        \;\;\;\;x \cdot z\\
        
        \mathbf{elif}\;z \leq 2.2 \cdot 10^{+41}:\\
        \;\;\;\;y + x\\
        
        \mathbf{elif}\;z \leq 4.8 \cdot 10^{+100}:\\
        \;\;\;\;y \cdot z\\
        
        \mathbf{else}:\\
        \;\;\;\;x \cdot z\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if z < -1 or 4.80000000000000023e100 < 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-+.f6499.0

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

            \[\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.4%

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

            if -1 < z < 2.1999999999999999e41

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

                \[\leadsto \color{blue}{\left(y + x\right)} \cdot z \]
            5. Applied rewrites6.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 rewrites4.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-+.f6495.1

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

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

              if 2.1999999999999999e41 < z < 4.80000000000000023e100

              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-+.f64100.0

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

                \[\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 rewrites43.6%

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

              Alternative 4: 75.4% 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 6.4\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) (not (<= z 6.4))) (* x z) (+ y x)))
              assert(x < y && y < z);
              double code(double x, double y, double z) {
              	double tmp;
              	if ((z <= -1.0) || !(z <= 6.4)) {
              		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)) .or. (.not. (z <= 6.4d0))) 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) || !(z <= 6.4)) {
              		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) or not (z <= 6.4):
              		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 ((z <= -1.0) || !(z <= 6.4))
              		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) || ~((z <= 6.4)))
              		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[z, -1.0], N[Not[LessEqual[z, 6.4]], $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 \leq -1 \lor \neg \left(z \leq 6.4\right):\\
              \;\;\;\;x \cdot z\\
              
              \mathbf{else}:\\
              \;\;\;\;y + x\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if z < -1 or 6.4000000000000004 < 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.0

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

                  \[\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.0%

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

                  if -1 < z < 6.4000000000000004

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

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

                    \[\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.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-+.f6498.3

                        \[\leadsto \color{blue}{y + x} \]
                    4. Applied rewrites98.3%

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

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

                  Alternative 5: 98.0% accurate, 0.7× speedup?

                  \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;x + y \leq -4 \cdot 10^{-285}:\\ \;\;\;\;\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) -4e-285) (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) <= -4e-285) {
                  		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) <= -4e-285)
                  		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], -4e-285], 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 -4 \cdot 10^{-285}:\\
                  \;\;\;\;\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) < -4.0000000000000003e-285

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

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

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

                    if -4.0000000000000003e-285 < (+.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.f6452.4

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

                      \[\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: 50.4% 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-+.f6449.8

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

                    \[\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 rewrites27.6%

                      \[\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.8

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

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

                    Reproduce

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