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

Percentage Accurate: 100.0% → 100.0%
Time: 4.4s
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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    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, 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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    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}
Derivation
  1. Initial program 100.0%

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

Alternative 2: 75.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{elif}\;z \leq 0.00033:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 2.25 \cdot 10^{+67}:\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -4e-7)
   (fma z x x)
   (if (<= z 0.00033) (+ y x) (if (<= z 2.25e+67) (fma z x x) (* z y)))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -4e-7) {
		tmp = fma(z, x, x);
	} else if (z <= 0.00033) {
		tmp = y + x;
	} else if (z <= 2.25e+67) {
		tmp = fma(z, x, x);
	} else {
		tmp = z * y;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (z <= -4e-7)
		tmp = fma(z, x, x);
	elseif (z <= 0.00033)
		tmp = Float64(y + x);
	elseif (z <= 2.25e+67)
		tmp = fma(z, x, x);
	else
		tmp = Float64(z * y);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[z, -4e-7], N[(z * x + x), $MachinePrecision], If[LessEqual[z, 0.00033], N[(y + x), $MachinePrecision], If[LessEqual[z, 2.25e+67], N[(z * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\

\mathbf{elif}\;z \leq 0.00033:\\
\;\;\;\;y + x\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -3.9999999999999998e-7 or 3.3e-4 < z < 2.2499999999999999e67

    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. Applied rewrites47.6%

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

      if -3.9999999999999998e-7 < z < 3.3e-4

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{x + y} \]
      4. Step-by-step derivation
        1. Applied rewrites99.4%

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

        if 2.2499999999999999e67 < z

        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. Applied rewrites53.4%

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

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

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

          Alternative 3: 74.1% accurate, 0.7× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 20\right):\\ \;\;\;\;z \cdot x\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (or (<= z -1.0) (not (<= z 20.0))) (* z x) (+ y x)))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((z <= -1.0) || !(z <= 20.0)) {
          		tmp = z * x;
          	} else {
          		tmp = y + x;
          	}
          	return tmp;
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(x, y, z)
          use fmin_fmax_functions
              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 <= 20.0d0))) then
                  tmp = z * x
              else
                  tmp = y + x
              end if
              code = tmp
          end function
          
          public static double code(double x, double y, double z) {
          	double tmp;
          	if ((z <= -1.0) || !(z <= 20.0)) {
          		tmp = z * x;
          	} else {
          		tmp = y + x;
          	}
          	return tmp;
          }
          
          def code(x, y, z):
          	tmp = 0
          	if (z <= -1.0) or not (z <= 20.0):
          		tmp = z * x
          	else:
          		tmp = y + x
          	return tmp
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((z <= -1.0) || !(z <= 20.0))
          		tmp = Float64(z * x);
          	else
          		tmp = Float64(y + x);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z)
          	tmp = 0.0;
          	if ((z <= -1.0) || ~((z <= 20.0)))
          		tmp = z * x;
          	else
          		tmp = y + x;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 20.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], N[(y + x), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 20\right):\\
          \;\;\;\;z \cdot x\\
          
          \mathbf{else}:\\
          \;\;\;\;y + x\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if z < -1 or 20 < z

            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. Applied rewrites51.0%

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

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

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

                if -1 < z < 20

                1. Initial program 100.0%

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

                  \[\leadsto \color{blue}{x + y} \]
                4. Step-by-step derivation
                  1. Applied rewrites97.7%

                    \[\leadsto \color{blue}{y + x} \]
                5. Recombined 2 regimes into one program.
                6. Final simplification72.2%

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

                Alternative 4: 74.9% accurate, 0.7× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;z \leq 9000000:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \end{array} \]
                (FPCore (x y z)
                 :precision binary64
                 (if (<= z -1.0) (* z x) (if (<= z 9000000.0) (+ y x) (* z y))))
                double code(double x, double y, double z) {
                	double tmp;
                	if (z <= -1.0) {
                		tmp = z * x;
                	} else if (z <= 9000000.0) {
                		tmp = y + x;
                	} else {
                		tmp = z * y;
                	}
                	return tmp;
                }
                
                module fmin_fmax_functions
                    implicit none
                    private
                    public fmax
                    public fmin
                
                    interface fmax
                        module procedure fmax88
                        module procedure fmax44
                        module procedure fmax84
                        module procedure fmax48
                    end interface
                    interface fmin
                        module procedure fmin88
                        module procedure fmin44
                        module procedure fmin84
                        module procedure fmin48
                    end interface
                contains
                    real(8) function fmax88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmax44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmax84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmax48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                    end function
                    real(8) function fmin88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmin44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmin84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmin48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                    end function
                end module
                
                real(8) function code(x, y, z)
                use fmin_fmax_functions
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    real(8), intent (in) :: z
                    real(8) :: tmp
                    if (z <= (-1.0d0)) then
                        tmp = z * x
                    else if (z <= 9000000.0d0) then
                        tmp = y + x
                    else
                        tmp = z * y
                    end if
                    code = tmp
                end function
                
                public static double code(double x, double y, double z) {
                	double tmp;
                	if (z <= -1.0) {
                		tmp = z * x;
                	} else if (z <= 9000000.0) {
                		tmp = y + x;
                	} else {
                		tmp = z * y;
                	}
                	return tmp;
                }
                
                def code(x, y, z):
                	tmp = 0
                	if z <= -1.0:
                		tmp = z * x
                	elif z <= 9000000.0:
                		tmp = y + x
                	else:
                		tmp = z * y
                	return tmp
                
                function code(x, y, z)
                	tmp = 0.0
                	if (z <= -1.0)
                		tmp = Float64(z * x);
                	elseif (z <= 9000000.0)
                		tmp = Float64(y + x);
                	else
                		tmp = Float64(z * y);
                	end
                	return tmp
                end
                
                function tmp_2 = code(x, y, z)
                	tmp = 0.0;
                	if (z <= -1.0)
                		tmp = z * x;
                	elseif (z <= 9000000.0)
                		tmp = y + x;
                	else
                		tmp = z * y;
                	end
                	tmp_2 = tmp;
                end
                
                code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(z * x), $MachinePrecision], If[LessEqual[z, 9000000.0], N[(y + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;z \leq -1:\\
                \;\;\;\;z \cdot x\\
                
                \mathbf{elif}\;z \leq 9000000:\\
                \;\;\;\;y + x\\
                
                \mathbf{else}:\\
                \;\;\;\;z \cdot y\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 3 regimes
                2. if z < -1

                  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. Applied rewrites47.3%

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

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

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

                      if -1 < z < 9e6

                      1. Initial program 100.0%

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

                        \[\leadsto \color{blue}{x + y} \]
                      4. Step-by-step derivation
                        1. Applied rewrites97.0%

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

                        if 9e6 < z

                        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. Applied rewrites53.7%

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

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

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

                          Alternative 5: 26.1% accurate, 0.7× speedup?

                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x + y\right) \cdot \left(z + 1\right) \leq -5 \cdot 10^{-225}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
                          (FPCore (x y z)
                           :precision binary64
                           (if (<= (* (+ x y) (+ z 1.0)) -5e-225) x y))
                          double code(double x, double y, double z) {
                          	double tmp;
                          	if (((x + y) * (z + 1.0)) <= -5e-225) {
                          		tmp = x;
                          	} else {
                          		tmp = y;
                          	}
                          	return tmp;
                          }
                          
                          module fmin_fmax_functions
                              implicit none
                              private
                              public fmax
                              public fmin
                          
                              interface fmax
                                  module procedure fmax88
                                  module procedure fmax44
                                  module procedure fmax84
                                  module procedure fmax48
                              end interface
                              interface fmin
                                  module procedure fmin88
                                  module procedure fmin44
                                  module procedure fmin84
                                  module procedure fmin48
                              end interface
                          contains
                              real(8) function fmax88(x, y) result (res)
                                  real(8), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                              end function
                              real(4) function fmax44(x, y) result (res)
                                  real(4), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                              end function
                              real(8) function fmax84(x, y) result(res)
                                  real(8), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                              end function
                              real(8) function fmax48(x, y) result(res)
                                  real(4), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                              end function
                              real(8) function fmin88(x, y) result (res)
                                  real(8), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                              end function
                              real(4) function fmin44(x, y) result (res)
                                  real(4), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                              end function
                              real(8) function fmin84(x, y) result(res)
                                  real(8), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                              end function
                              real(8) function fmin48(x, y) result(res)
                                  real(4), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                              end function
                          end module
                          
                          real(8) function code(x, y, z)
                          use fmin_fmax_functions
                              real(8), intent (in) :: x
                              real(8), intent (in) :: y
                              real(8), intent (in) :: z
                              real(8) :: tmp
                              if (((x + y) * (z + 1.0d0)) <= (-5d-225)) then
                                  tmp = x
                              else
                                  tmp = y
                              end if
                              code = tmp
                          end function
                          
                          public static double code(double x, double y, double z) {
                          	double tmp;
                          	if (((x + y) * (z + 1.0)) <= -5e-225) {
                          		tmp = x;
                          	} else {
                          		tmp = y;
                          	}
                          	return tmp;
                          }
                          
                          def code(x, y, z):
                          	tmp = 0
                          	if ((x + y) * (z + 1.0)) <= -5e-225:
                          		tmp = x
                          	else:
                          		tmp = y
                          	return tmp
                          
                          function code(x, y, z)
                          	tmp = 0.0
                          	if (Float64(Float64(x + y) * Float64(z + 1.0)) <= -5e-225)
                          		tmp = x;
                          	else
                          		tmp = y;
                          	end
                          	return tmp
                          end
                          
                          function tmp_2 = code(x, y, z)
                          	tmp = 0.0;
                          	if (((x + y) * (z + 1.0)) <= -5e-225)
                          		tmp = x;
                          	else
                          		tmp = y;
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          code[x_, y_, z_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], -5e-225], x, y]
                          
                          \begin{array}{l}
                          
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;\left(x + y\right) \cdot \left(z + 1\right) \leq -5 \cdot 10^{-225}:\\
                          \;\;\;\;x\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;y\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if (*.f64 (+.f64 x y) (+.f64 z #s(literal 1 binary64))) < -5.0000000000000001e-225

                            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. Applied rewrites54.4%

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

                                \[\leadsto x \]
                              3. Step-by-step derivation
                                1. Applied rewrites28.4%

                                  \[\leadsto x \]

                                if -5.0000000000000001e-225 < (*.f64 (+.f64 x y) (+.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 x around 0

                                  \[\leadsto \color{blue}{y \cdot \left(1 + z\right)} \]
                                4. Step-by-step derivation
                                  1. Applied rewrites56.0%

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

                                    \[\leadsto y \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites24.9%

                                      \[\leadsto y \]
                                  4. Recombined 2 regimes into one program.
                                  5. Add Preprocessing

                                  Alternative 6: 51.6% accurate, 0.7× speedup?

                                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x + y \leq -1 \cdot 10^{-264}:\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, y\right)\\ \end{array} \end{array} \]
                                  (FPCore (x y z)
                                   :precision binary64
                                   (if (<= (+ x y) -1e-264) (fma z x x) (fma z y y)))
                                  double code(double x, double y, double z) {
                                  	double tmp;
                                  	if ((x + y) <= -1e-264) {
                                  		tmp = fma(z, x, x);
                                  	} else {
                                  		tmp = fma(z, y, y);
                                  	}
                                  	return tmp;
                                  }
                                  
                                  function code(x, y, z)
                                  	tmp = 0.0
                                  	if (Float64(x + y) <= -1e-264)
                                  		tmp = fma(z, x, x);
                                  	else
                                  		tmp = fma(z, y, y);
                                  	end
                                  	return tmp
                                  end
                                  
                                  code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -1e-264], N[(z * x + x), $MachinePrecision], N[(z * y + y), $MachinePrecision]]
                                  
                                  \begin{array}{l}
                                  
                                  \\
                                  \begin{array}{l}
                                  \mathbf{if}\;x + y \leq -1 \cdot 10^{-264}:\\
                                  \;\;\;\;\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) < -1e-264

                                    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. Applied rewrites51.7%

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

                                      if -1e-264 < (+.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. Applied rewrites54.6%

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

                                      Alternative 7: 50.5% accurate, 3.0× speedup?

                                      \[\begin{array}{l} \\ y + x \end{array} \]
                                      (FPCore (x y z) :precision binary64 (+ y x))
                                      double code(double x, double y, double z) {
                                      	return y + x;
                                      }
                                      
                                      module fmin_fmax_functions
                                          implicit none
                                          private
                                          public fmax
                                          public fmin
                                      
                                          interface fmax
                                              module procedure fmax88
                                              module procedure fmax44
                                              module procedure fmax84
                                              module procedure fmax48
                                          end interface
                                          interface fmin
                                              module procedure fmin88
                                              module procedure fmin44
                                              module procedure fmin84
                                              module procedure fmin48
                                          end interface
                                      contains
                                          real(8) function fmax88(x, y) result (res)
                                              real(8), intent (in) :: x
                                              real(8), intent (in) :: y
                                              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                          end function
                                          real(4) function fmax44(x, y) result (res)
                                              real(4), intent (in) :: x
                                              real(4), intent (in) :: y
                                              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                          end function
                                          real(8) function fmax84(x, y) result(res)
                                              real(8), intent (in) :: x
                                              real(4), intent (in) :: y
                                              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                          end function
                                          real(8) function fmax48(x, y) result(res)
                                              real(4), intent (in) :: x
                                              real(8), intent (in) :: y
                                              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                          end function
                                          real(8) function fmin88(x, y) result (res)
                                              real(8), intent (in) :: x
                                              real(8), intent (in) :: y
                                              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                          end function
                                          real(4) function fmin44(x, y) result (res)
                                              real(4), intent (in) :: x
                                              real(4), intent (in) :: y
                                              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                          end function
                                          real(8) function fmin84(x, y) result(res)
                                              real(8), intent (in) :: x
                                              real(4), intent (in) :: y
                                              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                          end function
                                          real(8) function fmin48(x, y) result(res)
                                              real(4), intent (in) :: x
                                              real(8), intent (in) :: y
                                              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                          end function
                                      end module
                                      
                                      real(8) function code(x, y, z)
                                      use fmin_fmax_functions
                                          real(8), intent (in) :: x
                                          real(8), intent (in) :: y
                                          real(8), intent (in) :: z
                                          code = y + x
                                      end function
                                      
                                      public static double code(double x, double y, double z) {
                                      	return y + x;
                                      }
                                      
                                      def code(x, y, z):
                                      	return y + x
                                      
                                      function code(x, y, z)
                                      	return Float64(y + x)
                                      end
                                      
                                      function tmp = code(x, y, z)
                                      	tmp = y + x;
                                      end
                                      
                                      code[x_, y_, z_] := N[(y + x), $MachinePrecision]
                                      
                                      \begin{array}{l}
                                      
                                      \\
                                      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 0

                                        \[\leadsto \color{blue}{x + y} \]
                                      4. Step-by-step derivation
                                        1. Applied rewrites46.9%

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

                                        Alternative 8: 26.1% accurate, 12.0× speedup?

                                        \[\begin{array}{l} \\ x \end{array} \]
                                        (FPCore (x y z) :precision binary64 x)
                                        double code(double x, double y, double z) {
                                        	return x;
                                        }
                                        
                                        module fmin_fmax_functions
                                            implicit none
                                            private
                                            public fmax
                                            public fmin
                                        
                                            interface fmax
                                                module procedure fmax88
                                                module procedure fmax44
                                                module procedure fmax84
                                                module procedure fmax48
                                            end interface
                                            interface fmin
                                                module procedure fmin88
                                                module procedure fmin44
                                                module procedure fmin84
                                                module procedure fmin48
                                            end interface
                                        contains
                                            real(8) function fmax88(x, y) result (res)
                                                real(8), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                            end function
                                            real(4) function fmax44(x, y) result (res)
                                                real(4), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                            end function
                                            real(8) function fmax84(x, y) result(res)
                                                real(8), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                            end function
                                            real(8) function fmax48(x, y) result(res)
                                                real(4), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                            end function
                                            real(8) function fmin88(x, y) result (res)
                                                real(8), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                            end function
                                            real(4) function fmin44(x, y) result (res)
                                                real(4), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                            end function
                                            real(8) function fmin84(x, y) result(res)
                                                real(8), intent (in) :: x
                                                real(4), intent (in) :: y
                                                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                            end function
                                            real(8) function fmin48(x, y) result(res)
                                                real(4), intent (in) :: x
                                                real(8), intent (in) :: y
                                                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                            end function
                                        end module
                                        
                                        real(8) function code(x, y, z)
                                        use fmin_fmax_functions
                                            real(8), intent (in) :: x
                                            real(8), intent (in) :: y
                                            real(8), intent (in) :: z
                                            code = x
                                        end function
                                        
                                        public static double code(double x, double y, double z) {
                                        	return x;
                                        }
                                        
                                        def code(x, y, z):
                                        	return x
                                        
                                        function code(x, y, z)
                                        	return x
                                        end
                                        
                                        function tmp = code(x, y, z)
                                        	tmp = x;
                                        end
                                        
                                        code[x_, y_, z_] := x
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        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 x around inf

                                          \[\leadsto \color{blue}{x \cdot \left(1 + z\right)} \]
                                        4. Step-by-step derivation
                                          1. Applied rewrites50.5%

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

                                            \[\leadsto x \]
                                          3. Step-by-step derivation
                                            1. Applied rewrites24.0%

                                              \[\leadsto x \]
                                            2. Add Preprocessing

                                            Reproduce

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