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

Percentage Accurate: 100.0% → 100.0%
Time: 3.8s
Alternatives: 6
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.0× speedup?

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

\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

Alternative 2: 46.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x + y \leq -5 \cdot 10^{-226}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{elif}\;x + y \leq 5 \cdot 10^{+17} \lor \neg \left(x + y \leq 5 \cdot 10^{+205}\right):\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (+ x y) -5e-226)
   (* x (- 1.0 z))
   (if (or (<= (+ x y) 5e+17) (not (<= (+ x y) 5e+205))) (+ y x) (* y (- z)))))
double code(double x, double y, double z) {
	double tmp;
	if ((x + y) <= -5e-226) {
		tmp = x * (1.0 - z);
	} else if (((x + y) <= 5e+17) || !((x + y) <= 5e+205)) {
		tmp = y + x;
	} else {
		tmp = y * -z;
	}
	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) <= (-5d-226)) then
        tmp = x * (1.0d0 - z)
    else if (((x + y) <= 5d+17) .or. (.not. ((x + y) <= 5d+205))) then
        tmp = y + x
    else
        tmp = y * -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x + y) <= -5e-226) {
		tmp = x * (1.0 - z);
	} else if (((x + y) <= 5e+17) || !((x + y) <= 5e+205)) {
		tmp = y + x;
	} else {
		tmp = y * -z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x + y) <= -5e-226:
		tmp = x * (1.0 - z)
	elif ((x + y) <= 5e+17) or not ((x + y) <= 5e+205):
		tmp = y + x
	else:
		tmp = y * -z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(x + y) <= -5e-226)
		tmp = Float64(x * Float64(1.0 - z));
	elseif ((Float64(x + y) <= 5e+17) || !(Float64(x + y) <= 5e+205))
		tmp = Float64(y + x);
	else
		tmp = Float64(y * Float64(-z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x + y) <= -5e-226)
		tmp = x * (1.0 - z);
	elseif (((x + y) <= 5e+17) || ~(((x + y) <= 5e+205)))
		tmp = y + x;
	else
		tmp = y * -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -5e-226], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(x + y), $MachinePrecision], 5e+17], N[Not[LessEqual[N[(x + y), $MachinePrecision], 5e+205]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(y * (-z)), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -5 \cdot 10^{-226}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\

\mathbf{elif}\;x + y \leq 5 \cdot 10^{+17} \lor \neg \left(x + y \leq 5 \cdot 10^{+205}\right):\\
\;\;\;\;y + x\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 x y) < -4.9999999999999998e-226

    1. Initial program 100.0%

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

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

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

      if -4.9999999999999998e-226 < (+.f64 x y) < 5e17 or 5.0000000000000002e205 < (+.f64 x y)

      1. Initial program 100.0%

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

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

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

        if 5e17 < (+.f64 x y) < 5.0000000000000002e205

        1. Initial program 100.0%

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

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

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

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

              \[\leadsto \color{blue}{y} \cdot \left(-z\right) \]
          4. Recombined 3 regimes into one program.
          5. Final simplification51.1%

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

          Alternative 3: 75.0% accurate, 0.4× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(-z\right)\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{+16}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+115} \lor \neg \left(z \leq 4.8 \cdot 10^{+204}\right):\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (let* ((t_0 (* x (- z))))
             (if (<= z -2.5e+16)
               t_0
               (if (<= z 1.0)
                 (+ y x)
                 (if (or (<= z 6e+115) (not (<= z 4.8e+204))) t_0 (* y (- z)))))))
          double code(double x, double y, double z) {
          	double t_0 = x * -z;
          	double tmp;
          	if (z <= -2.5e+16) {
          		tmp = t_0;
          	} else if (z <= 1.0) {
          		tmp = y + x;
          	} else if ((z <= 6e+115) || !(z <= 4.8e+204)) {
          		tmp = t_0;
          	} else {
          		tmp = y * -z;
          	}
          	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) :: t_0
              real(8) :: tmp
              t_0 = x * -z
              if (z <= (-2.5d+16)) then
                  tmp = t_0
              else if (z <= 1.0d0) then
                  tmp = y + x
              else if ((z <= 6d+115) .or. (.not. (z <= 4.8d+204))) then
                  tmp = t_0
              else
                  tmp = y * -z
              end if
              code = tmp
          end function
          
          public static double code(double x, double y, double z) {
          	double t_0 = x * -z;
          	double tmp;
          	if (z <= -2.5e+16) {
          		tmp = t_0;
          	} else if (z <= 1.0) {
          		tmp = y + x;
          	} else if ((z <= 6e+115) || !(z <= 4.8e+204)) {
          		tmp = t_0;
          	} else {
          		tmp = y * -z;
          	}
          	return tmp;
          }
          
          def code(x, y, z):
          	t_0 = x * -z
          	tmp = 0
          	if z <= -2.5e+16:
          		tmp = t_0
          	elif z <= 1.0:
          		tmp = y + x
          	elif (z <= 6e+115) or not (z <= 4.8e+204):
          		tmp = t_0
          	else:
          		tmp = y * -z
          	return tmp
          
          function code(x, y, z)
          	t_0 = Float64(x * Float64(-z))
          	tmp = 0.0
          	if (z <= -2.5e+16)
          		tmp = t_0;
          	elseif (z <= 1.0)
          		tmp = Float64(y + x);
          	elseif ((z <= 6e+115) || !(z <= 4.8e+204))
          		tmp = t_0;
          	else
          		tmp = Float64(y * Float64(-z));
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z)
          	t_0 = x * -z;
          	tmp = 0.0;
          	if (z <= -2.5e+16)
          		tmp = t_0;
          	elseif (z <= 1.0)
          		tmp = y + x;
          	elseif ((z <= 6e+115) || ~((z <= 4.8e+204)))
          		tmp = t_0;
          	else
          		tmp = y * -z;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -2.5e+16], t$95$0, If[LessEqual[z, 1.0], N[(y + x), $MachinePrecision], If[Or[LessEqual[z, 6e+115], N[Not[LessEqual[z, 4.8e+204]], $MachinePrecision]], t$95$0, N[(y * (-z)), $MachinePrecision]]]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := x \cdot \left(-z\right)\\
          \mathbf{if}\;z \leq -2.5 \cdot 10^{+16}:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;z \leq 1:\\
          \;\;\;\;y + x\\
          
          \mathbf{elif}\;z \leq 6 \cdot 10^{+115} \lor \neg \left(z \leq 4.8 \cdot 10^{+204}\right):\\
          \;\;\;\;t\_0\\
          
          \mathbf{else}:\\
          \;\;\;\;y \cdot \left(-z\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if z < -2.5e16 or 1 < z < 6.0000000000000001e115 or 4.7999999999999999e204 < z

            1. Initial program 100.0%

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

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

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

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

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

                if -2.5e16 < z < 1

                1. Initial program 100.0%

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

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

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

                  if 6.0000000000000001e115 < z < 4.7999999999999999e204

                  1. Initial program 100.0%

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

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

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

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

                        \[\leadsto \color{blue}{y} \cdot \left(-z\right) \]
                    4. Recombined 3 regimes into one program.
                    5. Final simplification74.8%

                      \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.5 \cdot 10^{+16}:\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+115} \lor \neg \left(z \leq 4.8 \cdot 10^{+204}\right):\\ \;\;\;\;x \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(-z\right)\\ \end{array} \]
                    6. Add Preprocessing

                    Alternative 4: 75.0% accurate, 0.6× speedup?

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

                      1. Initial program 100.0%

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

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

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

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

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

                          if -2.5e16 < z < 1

                          1. Initial program 100.0%

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

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

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

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

                          Alternative 5: 51.9% accurate, 0.7× speedup?

                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x + y \leq -5 \cdot 10^{-226}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - z\right)\\ \end{array} \end{array} \]
                          (FPCore (x y z)
                           :precision binary64
                           (if (<= (+ x y) -5e-226) (* x (- 1.0 z)) (* y (- 1.0 z))))
                          double code(double x, double y, double z) {
                          	double tmp;
                          	if ((x + y) <= -5e-226) {
                          		tmp = x * (1.0 - z);
                          	} else {
                          		tmp = y * (1.0 - z);
                          	}
                          	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) <= (-5d-226)) then
                                  tmp = x * (1.0d0 - z)
                              else
                                  tmp = y * (1.0d0 - z)
                              end if
                              code = tmp
                          end function
                          
                          public static double code(double x, double y, double z) {
                          	double tmp;
                          	if ((x + y) <= -5e-226) {
                          		tmp = x * (1.0 - z);
                          	} else {
                          		tmp = y * (1.0 - z);
                          	}
                          	return tmp;
                          }
                          
                          def code(x, y, z):
                          	tmp = 0
                          	if (x + y) <= -5e-226:
                          		tmp = x * (1.0 - z)
                          	else:
                          		tmp = y * (1.0 - z)
                          	return tmp
                          
                          function code(x, y, z)
                          	tmp = 0.0
                          	if (Float64(x + y) <= -5e-226)
                          		tmp = Float64(x * Float64(1.0 - z));
                          	else
                          		tmp = Float64(y * Float64(1.0 - z));
                          	end
                          	return tmp
                          end
                          
                          function tmp_2 = code(x, y, z)
                          	tmp = 0.0;
                          	if ((x + y) <= -5e-226)
                          		tmp = x * (1.0 - z);
                          	else
                          		tmp = y * (1.0 - z);
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -5e-226], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
                          
                          \begin{array}{l}
                          
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;x + y \leq -5 \cdot 10^{-226}:\\
                          \;\;\;\;x \cdot \left(1 - z\right)\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;y \cdot \left(1 - z\right)\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if (+.f64 x y) < -4.9999999999999998e-226

                            1. Initial program 100.0%

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

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

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

                              if -4.9999999999999998e-226 < (+.f64 x y)

                              1. Initial program 100.0%

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

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

                                  \[\leadsto \color{blue}{y} \cdot \left(1 - z\right) \]
                              5. Recombined 2 regimes into one program.
                              6. Final simplification49.3%

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

                              Alternative 6: 50.9% 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(1 - z\right) \]
                              2. Add Preprocessing
                              3. Taylor expanded in z around 0

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

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

                                Reproduce

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