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

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

Specification

?
\[\begin{array}{l} \\ \left(x + y\right) \cdot \left(z + 1\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
	return (x + y) * (z + 1.0);
}
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 7 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + y\right) \cdot \left(z + 1\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
	return (x + y) * (z + 1.0);
}
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.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{+149}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.6 \cdot 10^{-6} \lor \neg \left(z \leq 0.03\right):\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.7e+149)
   (* y z)
   (if (or (<= z -3.6e-6) (not (<= z 0.03))) (fma z x x) (+ y x))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.7e+149) {
		tmp = y * z;
	} else if ((z <= -3.6e-6) || !(z <= 0.03)) {
		tmp = fma(z, x, x);
	} else {
		tmp = y + x;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.7e+149)
		tmp = Float64(y * z);
	elseif ((z <= -3.6e-6) || !(z <= 0.03))
		tmp = fma(z, x, x);
	else
		tmp = Float64(y + x);
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[z, -1.7e+149], N[(y * z), $MachinePrecision], If[Or[LessEqual[z, -3.6e-6], N[Not[LessEqual[z, 0.03]], $MachinePrecision]], N[(z * x + x), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+149}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;z \leq -3.6 \cdot 10^{-6} \lor \neg \left(z \leq 0.03\right):\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1.6999999999999999e149

    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 rewrites46.8%

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

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

        if -1.6999999999999999e149 < z < -3.59999999999999984e-6 or 0.029999999999999999 < z

        1. Initial program 99.9%

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

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

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

          if -3.59999999999999984e-6 < z < 0.029999999999999999

          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.8%

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{+149}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq -3.6 \cdot 10^{-6} \lor \neg \left(z \leq 0.03\right):\\ \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
          7. Add Preprocessing

          Alternative 3: 73.8% accurate, 0.7× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 8 \cdot 10^{+35}\right):\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (or (<= z -1.0) (not (<= z 8e+35))) (* y z) (+ y x)))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((z <= -1.0) || !(z <= 8e+35)) {
          		tmp = y * z;
          	} 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 <= 8d+35))) then
                  tmp = y * z
              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 <= 8e+35)) {
          		tmp = y * z;
          	} else {
          		tmp = y + x;
          	}
          	return tmp;
          }
          
          def code(x, y, z):
          	tmp = 0
          	if (z <= -1.0) or not (z <= 8e+35):
          		tmp = y * z
          	else:
          		tmp = y + x
          	return tmp
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((z <= -1.0) || !(z <= 8e+35))
          		tmp = Float64(y * z);
          	else
          		tmp = Float64(y + x);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z)
          	tmp = 0.0;
          	if ((z <= -1.0) || ~((z <= 8e+35)))
          		tmp = y * z;
          	else
          		tmp = y + x;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 8e+35]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y + x), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 8 \cdot 10^{+35}\right):\\
          \;\;\;\;y \cdot z\\
          
          \mathbf{else}:\\
          \;\;\;\;y + x\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if z < -1 or 7.9999999999999997e35 < 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 rewrites52.3%

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

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

                if -1 < z < 7.9999999999999997e35

                1. Initial program 99.9%

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

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

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

                Alternative 4: 26.5% 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^{-194}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
                (FPCore (x y z)
                 :precision binary64
                 (if (<= (* (+ x y) (+ z 1.0)) -5e-194) x y))
                double code(double x, double y, double z) {
                	double tmp;
                	if (((x + y) * (z + 1.0)) <= -5e-194) {
                		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-194)) 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-194) {
                		tmp = x;
                	} else {
                		tmp = y;
                	}
                	return tmp;
                }
                
                def code(x, y, z):
                	tmp = 0
                	if ((x + y) * (z + 1.0)) <= -5e-194:
                		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-194)
                		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-194)
                		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-194], x, y]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;\left(x + y\right) \cdot \left(z + 1\right) \leq -5 \cdot 10^{-194}:\\
                \;\;\;\;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.0000000000000002e-194

                  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 rewrites50.3%

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

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

                        \[\leadsto x \]

                      if -5.0000000000000002e-194 < (*.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 rewrites55.3%

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

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

                        Alternative 5: 51.2% accurate, 0.7× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x + y \leq -2 \cdot 10^{-223}:\\ \;\;\;\;\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) -2e-223) (fma z x x) (fma z y y)))
                        double code(double x, double y, double z) {
                        	double tmp;
                        	if ((x + y) <= -2e-223) {
                        		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) <= -2e-223)
                        		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], -2e-223], N[(z * x + x), $MachinePrecision], N[(z * y + y), $MachinePrecision]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;x + y \leq -2 \cdot 10^{-223}:\\
                        \;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\mathsf{fma}\left(z, y, y\right)\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if (+.f64 x y) < -1.9999999999999999e-223

                          1. Initial program 99.9%

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

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

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

                            if -1.9999999999999999e-223 < (+.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 rewrites55.0%

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

                            Alternative 6: 50.7% 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 rewrites53.4%

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

                              Alternative 7: 26.3% 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 z around 0

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

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

                                  \[\leadsto x \]
                                3. Step-by-step derivation
                                  1. Applied rewrites25.9%

                                    \[\leadsto x \]
                                  2. Add Preprocessing

                                  Reproduce

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