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

Percentage Accurate: 100.0% → 100.0%
Time: 2.2s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(x + y\right) \cdot \left(z + 1\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
	return (x + y) * (z + 1.0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x + y) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
	return (x + y) * (z + 1.0);
}
def code(x, y, z):
	return (x + y) * (z + 1.0)
function code(x, y, z)
	return Float64(Float64(x + y) * Float64(z + 1.0))
end
function tmp = code(x, y, z)
	tmp = (x + y) * (z + 1.0);
end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + y\right) \cdot \left(z + 1\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
	return (x + y) * (z + 1.0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x + y) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
	return (x + y) * (z + 1.0);
}
def code(x, y, z):
	return (x + y) * (z + 1.0)
function code(x, y, z)
	return Float64(Float64(x + y) * Float64(z + 1.0))
end
function tmp = code(x, y, z)
	tmp = (x + y) * (z + 1.0);
end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + y\right) \cdot \left(z + 1\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
	return (x + y) * (z + 1.0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x + y) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
	return (x + y) * (z + 1.0);
}
def code(x, y, z):
	return (x + y) * (z + 1.0)
function code(x, y, z)
	return Float64(Float64(x + y) * Float64(z + 1.0))
end
function tmp = code(x, y, z)
	tmp = (x + y) * (z + 1.0);
end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

Alternative 2: 74.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 17.5:\\ \;\;\;\;y + x\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+87}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.0)
   (* y z)
   (if (<= z 17.5) (+ y x) (if (<= z 3e+87) (* y z) (* x z)))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 17.5) {
		tmp = y + x;
	} else if (z <= 3e+87) {
		tmp = y * z;
	} else {
		tmp = x * 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 (z <= (-1.0d0)) then
        tmp = y * z
    else if (z <= 17.5d0) then
        tmp = y + x
    else if (z <= 3d+87) then
        tmp = y * z
    else
        tmp = x * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.0) {
		tmp = y * z;
	} else if (z <= 17.5) {
		tmp = y + x;
	} else if (z <= 3e+87) {
		tmp = y * z;
	} else {
		tmp = x * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.0:
		tmp = y * z
	elif z <= 17.5:
		tmp = y + x
	elif z <= 3e+87:
		tmp = y * z
	else:
		tmp = x * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.0)
		tmp = Float64(y * z);
	elseif (z <= 17.5)
		tmp = Float64(y + x);
	elseif (z <= 3e+87)
		tmp = Float64(y * z);
	else
		tmp = Float64(x * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -1.0)
		tmp = y * z;
	elseif (z <= 17.5)
		tmp = y + x;
	elseif (z <= 3e+87)
		tmp = y * z;
	else
		tmp = x * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 17.5], N[(y + x), $MachinePrecision], If[LessEqual[z, 3e+87], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;y \cdot z\\

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

\mathbf{elif}\;z \leq 3 \cdot 10^{+87}:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1 or 17.5 < z < 2.9999999999999999e87

    1. Initial program 100.0%

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

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

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

        \[\leadsto z \cdot y + \color{blue}{1 \cdot y} \]
      3. *-lft-identityN/A

        \[\leadsto z \cdot y + y \]
      4. lower-fma.f6453.2

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

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

      \[\leadsto y \cdot \color{blue}{z} \]
    7. Step-by-step derivation
      1. lower-*.f6451.3

        \[\leadsto y \cdot z \]
    8. Applied rewrites51.3%

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

    if -1 < z < 17.5

    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. +-commutativeN/A

        \[\leadsto y + \color{blue}{x} \]
      2. lower-+.f6497.3

        \[\leadsto y + \color{blue}{x} \]
    5. Applied rewrites97.3%

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

    if 2.9999999999999999e87 < z

    1. Initial program 100.0%

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

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

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

        \[\leadsto z \cdot x + \color{blue}{1 \cdot x} \]
      3. *-lft-identityN/A

        \[\leadsto z \cdot x + x \]
      4. lower-fma.f6446.6

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

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

      \[\leadsto x \cdot \color{blue}{z} \]
    7. Step-by-step derivation
      1. lower-*.f6446.6

        \[\leadsto x \cdot z \]
    8. Applied rewrites46.6%

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

Alternative 3: 75.3% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;y \cdot z\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\


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

    1. Initial program 100.0%

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

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

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

        \[\leadsto z \cdot y + \color{blue}{1 \cdot y} \]
      3. *-lft-identityN/A

        \[\leadsto z \cdot y + y \]
      4. lower-fma.f6446.4

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

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

      \[\leadsto y \cdot \color{blue}{z} \]
    7. Step-by-step derivation
      1. lower-*.f6444.5

        \[\leadsto y \cdot z \]
    8. Applied rewrites44.5%

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

    if -1 < z < 9.50000000000000029e-17

    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. +-commutativeN/A

        \[\leadsto y + \color{blue}{x} \]
      2. lower-+.f6498.2

        \[\leadsto y + \color{blue}{x} \]
    5. Applied rewrites98.2%

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

    if 9.50000000000000029e-17 < 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. +-commutativeN/A

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

        \[\leadsto z \cdot x + \color{blue}{1 \cdot x} \]
      3. *-lft-identityN/A

        \[\leadsto z \cdot x + x \]
      4. lower-fma.f6440.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, x, x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 75.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 800000000000\right):\\
\;\;\;\;x \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1 or 8e11 < z

    1. Initial program 100.0%

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

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

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

        \[\leadsto z \cdot x + \color{blue}{1 \cdot x} \]
      3. *-lft-identityN/A

        \[\leadsto z \cdot x + x \]
      4. lower-fma.f6447.0

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

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

      \[\leadsto x \cdot \color{blue}{z} \]
    7. Step-by-step derivation
      1. lower-*.f6446.9

        \[\leadsto x \cdot z \]
    8. Applied rewrites46.9%

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

    if -1 < z < 8e11

    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. +-commutativeN/A

        \[\leadsto y + \color{blue}{x} \]
      2. lower-+.f6496.7

        \[\leadsto y + \color{blue}{x} \]
    5. Applied rewrites96.7%

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

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

Alternative 5: 26.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x + y\right) \cdot \left(z + 1\right) \leq -1 \cdot 10^{-258}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (* (+ x y) (+ z 1.0)) -1e-258) x y))
double code(double x, double y, double z) {
	double tmp;
	if (((x + y) * (z + 1.0)) <= -1e-258) {
		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)) <= (-1d-258)) 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)) <= -1e-258) {
		tmp = x;
	} else {
		tmp = y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if ((x + y) * (z + 1.0)) <= -1e-258:
		tmp = x
	else:
		tmp = y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(Float64(x + y) * Float64(z + 1.0)) <= -1e-258)
		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)) <= -1e-258)
		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], -1e-258], x, y]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) \cdot \left(z + 1\right) \leq -1 \cdot 10^{-258}:\\
\;\;\;\;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))) < -9.99999999999999954e-259

    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. +-commutativeN/A

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

        \[\leadsto z \cdot x + \color{blue}{1 \cdot x} \]
      3. *-lft-identityN/A

        \[\leadsto z \cdot x + x \]
      4. lower-fma.f6449.7

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

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

      \[\leadsto x \]
    7. Step-by-step derivation
      1. Applied rewrites26.0%

        \[\leadsto x \]

      if -9.99999999999999954e-259 < (*.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. +-commutativeN/A

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

          \[\leadsto z \cdot y + \color{blue}{1 \cdot y} \]
        3. *-lft-identityN/A

          \[\leadsto z \cdot y + y \]
        4. lower-fma.f6453.8

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

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

        \[\leadsto y \]
      7. Step-by-step derivation
        1. Applied rewrites34.2%

          \[\leadsto y \]
      8. Recombined 2 regimes into one program.
      9. Add Preprocessing

      Alternative 6: 51.7% accurate, 0.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x + y \leq -2 \cdot 10^{-275}:\\ \;\;\;\;\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-275) (fma z x x) (fma z y y)))
      double code(double x, double y, double z) {
      	double tmp;
      	if ((x + y) <= -2e-275) {
      		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-275)
      		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-275], N[(z * x + x), $MachinePrecision], N[(z * y + y), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x + y \leq -2 \cdot 10^{-275}:\\
      \;\;\;\;\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.99999999999999987e-275

        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. +-commutativeN/A

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

            \[\leadsto z \cdot x + \color{blue}{1 \cdot x} \]
          3. *-lft-identityN/A

            \[\leadsto z \cdot x + x \]
          4. lower-fma.f6450.7

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

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

        if -1.99999999999999987e-275 < (+.f64 x y)

        1. Initial program 100.0%

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

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

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

            \[\leadsto z \cdot y + \color{blue}{1 \cdot y} \]
          3. *-lft-identityN/A

            \[\leadsto z \cdot y + y \]
          4. lower-fma.f6454.6

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

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

      Alternative 7: 51.1% 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. +-commutativeN/A

          \[\leadsto y + \color{blue}{x} \]
        2. lower-+.f6455.4

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

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

      Alternative 8: 26.2% accurate, 12.0× speedup?

      \[\begin{array}{l} \\ x \end{array} \]
      (FPCore (x y z) :precision binary64 x)
      double code(double x, double y, double z) {
      	return x;
      }
      
      module fmin_fmax_functions
          implicit none
          private
          public fmax
          public fmin
      
          interface fmax
              module procedure fmax88
              module procedure fmax44
              module procedure fmax84
              module procedure fmax48
          end interface
          interface fmin
              module procedure fmin88
              module procedure fmin44
              module procedure fmin84
              module procedure fmin48
          end interface
      contains
          real(8) function fmax88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(4) function fmax44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(8) function fmax84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmax48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
          end function
          real(8) function fmin88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(4) function fmin44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(8) function fmin84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmin48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
          end function
      end module
      
      real(8) function code(x, y, z)
      use fmin_fmax_functions
          real(8), intent (in) :: x
          real(8), intent (in) :: y
          real(8), intent (in) :: z
          code = x
      end function
      
      public static double code(double x, double y, double z) {
      	return x;
      }
      
      def code(x, y, z):
      	return x
      
      function code(x, y, z)
      	return x
      end
      
      function tmp = code(x, y, z)
      	tmp = x;
      end
      
      code[x_, y_, z_] := x
      
      \begin{array}{l}
      
      \\
      x
      \end{array}
      
      Derivation
      1. Initial program 100.0%

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

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

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

          \[\leadsto z \cdot x + \color{blue}{1 \cdot x} \]
        3. *-lft-identityN/A

          \[\leadsto z \cdot x + x \]
        4. lower-fma.f6449.0

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

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

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

          \[\leadsto x \]
        2. Add Preprocessing

        Reproduce

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