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

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

Specification

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

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

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

Alternative 1: 99.0% accurate, 0.7× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \mathsf{fma}\left(1 - z, y, \left(1 - z\right) \cdot x\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 (* (- 1.0 z) x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return fma((1.0 - z), y, ((1.0 - z) * x));
}
x, y, z = sort([x, y, z])
function code(x, y, z)
	return fma(Float64(1.0 - z), y, Float64(Float64(1.0 - z) * 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[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(1 - z, y, \left(1 - z\right) \cdot x\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

Alternative 2: 75.2% accurate, 0.3× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} t_0 := \left(-z\right) \cdot x\\ \mathbf{if}\;1 - z \leq -5 \cdot 10^{+104}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;1 - z \leq -100:\\ \;\;\;\;\left(-z\right) \cdot y\\ \mathbf{elif}\;1 - z \leq 400000000:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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
 (let* ((t_0 (* (- z) x)))
   (if (<= (- 1.0 z) -5e+104)
     t_0
     (if (<= (- 1.0 z) -100.0)
       (* (- z) y)
       (if (<= (- 1.0 z) 400000000.0) (+ y x) t_0)))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double t_0 = -z * x;
	double tmp;
	if ((1.0 - z) <= -5e+104) {
		tmp = t_0;
	} else if ((1.0 - z) <= -100.0) {
		tmp = -z * y;
	} else if ((1.0 - z) <= 400000000.0) {
		tmp = y + x;
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = -z * x
    if ((1.0d0 - z) <= (-5d+104)) then
        tmp = t_0
    else if ((1.0d0 - z) <= (-100.0d0)) then
        tmp = -z * y
    else if ((1.0d0 - z) <= 400000000.0d0) then
        tmp = y + x
    else
        tmp = t_0
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double t_0 = -z * x;
	double tmp;
	if ((1.0 - z) <= -5e+104) {
		tmp = t_0;
	} else if ((1.0 - z) <= -100.0) {
		tmp = -z * y;
	} else if ((1.0 - z) <= 400000000.0) {
		tmp = y + x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	t_0 = -z * x
	tmp = 0
	if (1.0 - z) <= -5e+104:
		tmp = t_0
	elif (1.0 - z) <= -100.0:
		tmp = -z * y
	elif (1.0 - z) <= 400000000.0:
		tmp = y + x
	else:
		tmp = t_0
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	t_0 = Float64(Float64(-z) * x)
	tmp = 0.0
	if (Float64(1.0 - z) <= -5e+104)
		tmp = t_0;
	elseif (Float64(1.0 - z) <= -100.0)
		tmp = Float64(Float64(-z) * y);
	elseif (Float64(1.0 - z) <= 400000000.0)
		tmp = Float64(y + x);
	else
		tmp = t_0;
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	t_0 = -z * x;
	tmp = 0.0;
	if ((1.0 - z) <= -5e+104)
		tmp = t_0;
	elseif ((1.0 - z) <= -100.0)
		tmp = -z * y;
	elseif ((1.0 - z) <= 400000000.0)
		tmp = y + x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[N[(1.0 - z), $MachinePrecision], -5e+104], t$95$0, If[LessEqual[N[(1.0 - z), $MachinePrecision], -100.0], N[((-z) * y), $MachinePrecision], If[LessEqual[N[(1.0 - z), $MachinePrecision], 400000000.0], N[(y + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;1 - z \leq -5 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;1 - z \leq -100:\\
\;\;\;\;\left(-z\right) \cdot y\\

\mathbf{elif}\;1 - z \leq 400000000:\\
\;\;\;\;y + x\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (-.f64 #s(literal 1 binary64) z) < -4.9999999999999997e104 or 4e8 < (-.f64 #s(literal 1 binary64) z)

    1. Initial program 100.0%

      \[\left(x + y\right) \cdot \left(1 - z\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 \color{blue}{\left(1 - z\right) \cdot x} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]
      3. lower--.f6453.8

        \[\leadsto \color{blue}{\left(1 - z\right)} \cdot x \]
    5. Applied rewrites53.8%

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

      \[\leadsto -1 \cdot \color{blue}{\left(x \cdot z\right)} \]
    7. Step-by-step derivation
      1. Applied rewrites53.8%

        \[\leadsto \left(-z\right) \cdot \color{blue}{x} \]

      if -4.9999999999999997e104 < (-.f64 #s(literal 1 binary64) z) < -100

      1. Initial program 100.0%

        \[\left(x + y\right) \cdot \left(1 - z\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 \color{blue}{\left(1 - z\right) \cdot y} \]
        2. lower-*.f64N/A

          \[\leadsto \color{blue}{\left(1 - z\right) \cdot y} \]
        3. lower--.f6449.5

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

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

        \[\leadsto -1 \cdot \color{blue}{\left(y \cdot z\right)} \]
      7. Step-by-step derivation
        1. Applied rewrites44.8%

          \[\leadsto \left(-z\right) \cdot \color{blue}{y} \]

        if -100 < (-.f64 #s(literal 1 binary64) z) < 4e8

        1. Initial program 100.0%

          \[\left(x + y\right) \cdot \left(1 - z\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 \color{blue}{\left(1 - z\right) \cdot x} \]
          2. lower-*.f64N/A

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

            \[\leadsto \color{blue}{\left(1 - z\right)} \cdot x \]
        5. Applied rewrites52.4%

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

          \[\leadsto \left(z \cdot \left(\frac{1}{z} - 1\right)\right) \cdot x \]
        7. Step-by-step derivation
          1. Applied rewrites52.3%

            \[\leadsto \left(\left(\frac{1}{z} - 1\right) \cdot z\right) \cdot x \]
          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.0

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

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

        Alternative 3: 75.5% accurate, 0.4× speedup?

        \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} t_0 := \left(-z\right) \cdot x\\ \mathbf{if}\;z \leq -240000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-9}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{+49}:\\ \;\;\;\;\left(1 - z\right) \cdot x\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{+100}:\\ \;\;\;\;\left(-z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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
         (let* ((t_0 (* (- z) x)))
           (if (<= z -240000000.0)
             t_0
             (if (<= z 2.5e-9)
               (+ y x)
               (if (<= z 3.5e+49)
                 (* (- 1.0 z) x)
                 (if (<= z 4.8e+100) (* (- z) y) t_0))))))
        assert(x < y && y < z);
        double code(double x, double y, double z) {
        	double t_0 = -z * x;
        	double tmp;
        	if (z <= -240000000.0) {
        		tmp = t_0;
        	} else if (z <= 2.5e-9) {
        		tmp = y + x;
        	} else if (z <= 3.5e+49) {
        		tmp = (1.0 - z) * x;
        	} else if (z <= 4.8e+100) {
        		tmp = -z * y;
        	} else {
        		tmp = t_0;
        	}
        	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) :: t_0
            real(8) :: tmp
            t_0 = -z * x
            if (z <= (-240000000.0d0)) then
                tmp = t_0
            else if (z <= 2.5d-9) then
                tmp = y + x
            else if (z <= 3.5d+49) then
                tmp = (1.0d0 - z) * x
            else if (z <= 4.8d+100) then
                tmp = -z * y
            else
                tmp = t_0
            end if
            code = tmp
        end function
        
        assert x < y && y < z;
        public static double code(double x, double y, double z) {
        	double t_0 = -z * x;
        	double tmp;
        	if (z <= -240000000.0) {
        		tmp = t_0;
        	} else if (z <= 2.5e-9) {
        		tmp = y + x;
        	} else if (z <= 3.5e+49) {
        		tmp = (1.0 - z) * x;
        	} else if (z <= 4.8e+100) {
        		tmp = -z * y;
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        [x, y, z] = sort([x, y, z])
        def code(x, y, z):
        	t_0 = -z * x
        	tmp = 0
        	if z <= -240000000.0:
        		tmp = t_0
        	elif z <= 2.5e-9:
        		tmp = y + x
        	elif z <= 3.5e+49:
        		tmp = (1.0 - z) * x
        	elif z <= 4.8e+100:
        		tmp = -z * y
        	else:
        		tmp = t_0
        	return tmp
        
        x, y, z = sort([x, y, z])
        function code(x, y, z)
        	t_0 = Float64(Float64(-z) * x)
        	tmp = 0.0
        	if (z <= -240000000.0)
        		tmp = t_0;
        	elseif (z <= 2.5e-9)
        		tmp = Float64(y + x);
        	elseif (z <= 3.5e+49)
        		tmp = Float64(Float64(1.0 - z) * x);
        	elseif (z <= 4.8e+100)
        		tmp = Float64(Float64(-z) * y);
        	else
        		tmp = t_0;
        	end
        	return tmp
        end
        
        x, y, z = num2cell(sort([x, y, z])){:}
        function tmp_2 = code(x, y, z)
        	t_0 = -z * x;
        	tmp = 0.0;
        	if (z <= -240000000.0)
        		tmp = t_0;
        	elseif (z <= 2.5e-9)
        		tmp = y + x;
        	elseif (z <= 3.5e+49)
        		tmp = (1.0 - z) * x;
        	elseif (z <= 4.8e+100)
        		tmp = -z * y;
        	else
        		tmp = t_0;
        	end
        	tmp_2 = tmp;
        end
        
        NOTE: x, y, and z should be sorted in increasing order before calling this function.
        code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[z, -240000000.0], t$95$0, If[LessEqual[z, 2.5e-9], N[(y + x), $MachinePrecision], If[LessEqual[z, 3.5e+49], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[z, 4.8e+100], N[((-z) * y), $MachinePrecision], t$95$0]]]]]
        
        \begin{array}{l}
        [x, y, z] = \mathsf{sort}([x, y, z])\\
        \\
        \begin{array}{l}
        t_0 := \left(-z\right) \cdot x\\
        \mathbf{if}\;z \leq -240000000:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;z \leq 2.5 \cdot 10^{-9}:\\
        \;\;\;\;y + x\\
        
        \mathbf{elif}\;z \leq 3.5 \cdot 10^{+49}:\\
        \;\;\;\;\left(1 - z\right) \cdot x\\
        
        \mathbf{elif}\;z \leq 4.8 \cdot 10^{+100}:\\
        \;\;\;\;\left(-z\right) \cdot y\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 4 regimes
        2. if z < -2.4e8 or 4.80000000000000023e100 < z

          1. Initial program 100.0%

            \[\left(x + y\right) \cdot \left(1 - z\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 \color{blue}{\left(1 - z\right) \cdot x} \]
            2. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]
            3. lower--.f6453.8

              \[\leadsto \color{blue}{\left(1 - z\right)} \cdot x \]
          5. Applied rewrites53.8%

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

            \[\leadsto -1 \cdot \color{blue}{\left(x \cdot z\right)} \]
          7. Step-by-step derivation
            1. Applied rewrites53.8%

              \[\leadsto \left(-z\right) \cdot \color{blue}{x} \]

            if -2.4e8 < z < 2.5000000000000001e-9

            1. Initial program 100.0%

              \[\left(x + y\right) \cdot \left(1 - z\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 \color{blue}{\left(1 - z\right) \cdot x} \]
              2. lower-*.f64N/A

                \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]
              3. lower--.f6452.1

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

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

              \[\leadsto \left(z \cdot \left(\frac{1}{z} - 1\right)\right) \cdot x \]
            7. Step-by-step derivation
              1. Applied rewrites51.9%

                \[\leadsto \left(\left(\frac{1}{z} - 1\right) \cdot z\right) \cdot x \]
              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} \]

              if 2.5000000000000001e-9 < z < 3.49999999999999975e49

              1. Initial program 99.7%

                \[\left(x + y\right) \cdot \left(1 - z\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 \color{blue}{\left(1 - z\right) \cdot x} \]
                2. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]
                3. lower--.f6452.0

                  \[\leadsto \color{blue}{\left(1 - z\right)} \cdot x \]
              5. Applied rewrites52.0%

                \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]

              if 3.49999999999999975e49 < z < 4.80000000000000023e100

              1. Initial program 100.0%

                \[\left(x + y\right) \cdot \left(1 - z\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 \color{blue}{\left(1 - z\right) \cdot y} \]
                2. lower-*.f64N/A

                  \[\leadsto \color{blue}{\left(1 - z\right) \cdot y} \]
                3. lower--.f6443.6

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

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

                \[\leadsto -1 \cdot \color{blue}{\left(y \cdot z\right)} \]
              7. Step-by-step derivation
                1. Applied rewrites43.6%

                  \[\leadsto \left(-z\right) \cdot \color{blue}{y} \]
              8. Recombined 4 regimes into one program.
              9. Add Preprocessing

              Alternative 4: 75.4% accurate, 0.5× speedup?

              \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;1 - z \leq -100 \lor \neg \left(1 - z \leq 400000000\right):\\ \;\;\;\;\left(-z\right) \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 (<= (- 1.0 z) -100.0) (not (<= (- 1.0 z) 400000000.0)))
                 (* (- z) x)
                 (+ y x)))
              assert(x < y && y < z);
              double code(double x, double y, double z) {
              	double tmp;
              	if (((1.0 - z) <= -100.0) || !((1.0 - z) <= 400000000.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 (((1.0d0 - z) <= (-100.0d0)) .or. (.not. ((1.0d0 - z) <= 400000000.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 (((1.0 - z) <= -100.0) || !((1.0 - z) <= 400000000.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 ((1.0 - z) <= -100.0) or not ((1.0 - z) <= 400000000.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 ((Float64(1.0 - z) <= -100.0) || !(Float64(1.0 - z) <= 400000000.0))
              		tmp = Float64(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 (((1.0 - z) <= -100.0) || ~(((1.0 - z) <= 400000000.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[N[(1.0 - z), $MachinePrecision], -100.0], N[Not[LessEqual[N[(1.0 - z), $MachinePrecision], 400000000.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}\;1 - z \leq -100 \lor \neg \left(1 - z \leq 400000000\right):\\
              \;\;\;\;\left(-z\right) \cdot x\\
              
              \mathbf{else}:\\
              \;\;\;\;y + x\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if (-.f64 #s(literal 1 binary64) z) < -100 or 4e8 < (-.f64 #s(literal 1 binary64) z)

                1. Initial program 100.0%

                  \[\left(x + y\right) \cdot \left(1 - z\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 \color{blue}{\left(1 - z\right) \cdot x} \]
                  2. lower-*.f64N/A

                    \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]
                  3. lower--.f6453.9

                    \[\leadsto \color{blue}{\left(1 - z\right)} \cdot x \]
                5. Applied rewrites53.9%

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

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

                    \[\leadsto \left(-z\right) \cdot \color{blue}{x} \]

                  if -100 < (-.f64 #s(literal 1 binary64) z) < 4e8

                  1. Initial program 100.0%

                    \[\left(x + y\right) \cdot \left(1 - z\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 \color{blue}{\left(1 - z\right) \cdot x} \]
                    2. lower-*.f64N/A

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

                      \[\leadsto \color{blue}{\left(1 - z\right)} \cdot x \]
                  5. Applied rewrites52.4%

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

                    \[\leadsto \left(z \cdot \left(\frac{1}{z} - 1\right)\right) \cdot x \]
                  7. Step-by-step derivation
                    1. Applied rewrites52.3%

                      \[\leadsto \left(\left(\frac{1}{z} - 1\right) \cdot z\right) \cdot x \]
                    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.0

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

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - z \leq -100 \lor \neg \left(1 - z \leq 400000000\right):\\ \;\;\;\;\left(-z\right) \cdot x\\ \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}:\\ \;\;\;\;\left(1 - z\right) \cdot x\\ \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) -4e-285) (* (- 1.0 z) x) (* (- 1.0 z) y)))
                  assert(x < y && y < z);
                  double code(double x, double y, double z) {
                  	double tmp;
                  	if ((x + y) <= -4e-285) {
                  		tmp = (1.0 - z) * x;
                  	} else {
                  		tmp = (1.0 - z) * y;
                  	}
                  	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 ((x + y) <= (-4d-285)) then
                          tmp = (1.0d0 - z) * x
                      else
                          tmp = (1.0d0 - z) * y
                      end if
                      code = tmp
                  end function
                  
                  assert x < y && y < z;
                  public static double code(double x, double y, double z) {
                  	double tmp;
                  	if ((x + y) <= -4e-285) {
                  		tmp = (1.0 - z) * x;
                  	} else {
                  		tmp = (1.0 - z) * y;
                  	}
                  	return tmp;
                  }
                  
                  [x, y, z] = sort([x, y, z])
                  def code(x, y, z):
                  	tmp = 0
                  	if (x + y) <= -4e-285:
                  		tmp = (1.0 - z) * 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) <= -4e-285)
                  		tmp = Float64(Float64(1.0 - z) * x);
                  	else
                  		tmp = Float64(Float64(1.0 - z) * y);
                  	end
                  	return tmp
                  end
                  
                  x, y, z = num2cell(sort([x, y, z])){:}
                  function tmp_2 = code(x, y, z)
                  	tmp = 0.0;
                  	if ((x + y) <= -4e-285)
                  		tmp = (1.0 - z) * x;
                  	else
                  		tmp = (1.0 - z) * y;
                  	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[N[(x + y), $MachinePrecision], -4e-285], N[(N[(1.0 - z), $MachinePrecision] * 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 -4 \cdot 10^{-285}:\\
                  \;\;\;\;\left(1 - z\right) \cdot x\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\left(1 - z\right) \cdot y\\
                  
                  
                  \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(1 - z\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 \color{blue}{\left(1 - z\right) \cdot x} \]
                      2. lower-*.f64N/A

                        \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]
                      3. lower--.f6454.3

                        \[\leadsto \color{blue}{\left(1 - z\right)} \cdot x \]
                    5. Applied rewrites54.3%

                      \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]

                    if -4.0000000000000003e-285 < (+.f64 x y)

                    1. Initial program 100.0%

                      \[\left(x + y\right) \cdot \left(1 - z\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 \color{blue}{\left(1 - z\right) \cdot y} \]
                      2. lower-*.f64N/A

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

                        \[\leadsto \color{blue}{\left(1 - z\right)} \cdot y \]
                    5. Applied rewrites52.4%

                      \[\leadsto \color{blue}{\left(1 - z\right) \cdot y} \]
                  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(1 - z\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) (- 1.0 z)))
                  assert(x < y && y < z);
                  double code(double x, double y, double z) {
                  	return (x + y) * (1.0 - z);
                  }
                  
                  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) * (1.0d0 - z)
                  end function
                  
                  assert x < y && y < z;
                  public static double code(double x, double y, double z) {
                  	return (x + y) * (1.0 - z);
                  }
                  
                  [x, y, z] = sort([x, y, z])
                  def code(x, y, z):
                  	return (x + y) * (1.0 - z)
                  
                  x, y, z = sort([x, y, z])
                  function code(x, y, z)
                  	return Float64(Float64(x + y) * Float64(1.0 - z))
                  end
                  
                  x, y, z = num2cell(sort([x, y, z])){:}
                  function tmp = code(x, y, z)
                  	tmp = (x + y) * (1.0 - z);
                  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[(1.0 - z), $MachinePrecision]), $MachinePrecision]
                  
                  \begin{array}{l}
                  [x, y, z] = \mathsf{sort}([x, y, z])\\
                  \\
                  \left(x + y\right) \cdot \left(1 - z\right)
                  \end{array}
                  
                  Derivation
                  1. Initial program 100.0%

                    \[\left(x + y\right) \cdot \left(1 - z\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(1 - z\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 \color{blue}{\left(1 - z\right) \cdot x} \]
                    2. lower-*.f64N/A

                      \[\leadsto \color{blue}{\left(1 - z\right) \cdot x} \]
                    3. lower--.f6453.1

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

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

                    \[\leadsto \left(z \cdot \left(\frac{1}{z} - 1\right)\right) \cdot x \]
                  7. Step-by-step derivation
                    1. Applied rewrites53.1%

                      \[\leadsto \left(\left(\frac{1}{z} - 1\right) \cdot z\right) \cdot x \]
                    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-+.f6452.3

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

                      \[\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, H"
                      :precision binary64
                      (* (+ x y) (- 1.0 z)))