Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4

Percentage Accurate: 99.9% → 99.9%
Time: 4.6s
Alternatives: 8
Speedup: 1.2×

Specification

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

\\
\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x
\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: 99.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(2, y + x, z + x\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma 2.0 (+ y x) (+ z x)))
double code(double x, double y, double z) {
	return fma(2.0, (y + x), (z + x));
}
function code(x, y, z)
	return fma(2.0, Float64(y + x), Float64(z + x))
end
code[x_, y_, z_] := N[(2.0 * N[(y + x), $MachinePrecision] + N[(z + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(2, y + x, z + x\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right) + x} \]
    2. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(\left(\left(\left(x + y\right) + y\right) + x\right) + z\right)} + x \]
    3. associate-+l+N/A

      \[\leadsto \color{blue}{\left(\left(\left(x + y\right) + y\right) + x\right) + \left(z + x\right)} \]
    4. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(\left(\left(x + y\right) + y\right) + x\right)} + \left(z + x\right) \]
    5. lift-+.f64N/A

      \[\leadsto \left(\color{blue}{\left(\left(x + y\right) + y\right)} + x\right) + \left(z + x\right) \]
    6. associate-+l+N/A

      \[\leadsto \color{blue}{\left(\left(x + y\right) + \left(y + x\right)\right)} + \left(z + x\right) \]
    7. +-commutativeN/A

      \[\leadsto \left(\left(x + y\right) + \color{blue}{\left(x + y\right)}\right) + \left(z + x\right) \]
    8. lift-+.f64N/A

      \[\leadsto \left(\left(x + y\right) + \color{blue}{\left(x + y\right)}\right) + \left(z + x\right) \]
    9. count-2N/A

      \[\leadsto \color{blue}{2 \cdot \left(x + y\right)} + \left(z + x\right) \]
    10. +-commutativeN/A

      \[\leadsto 2 \cdot \left(x + y\right) + \color{blue}{\left(x + z\right)} \]
    11. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, x + y, x + z\right)} \]
    12. lift-+.f64N/A

      \[\leadsto \mathsf{fma}\left(2, \color{blue}{x + y}, x + z\right) \]
    13. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(2, \color{blue}{y + x}, x + z\right) \]
    14. lower-+.f64N/A

      \[\leadsto \mathsf{fma}\left(2, \color{blue}{y + x}, x + z\right) \]
    15. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(2, y + x, \color{blue}{z + x}\right) \]
    16. lower-+.f6499.9

      \[\leadsto \mathsf{fma}\left(2, y + x, \color{blue}{z + x}\right) \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(2, y + x, z + x\right)} \]
  5. Add Preprocessing

Alternative 2: 53.6% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.3:\\
\;\;\;\;z + x\\

\mathbf{elif}\;z \leq -1.65 \cdot 10^{-180}:\\
\;\;\;\;y + y\\

\mathbf{elif}\;z \leq 1.86 \cdot 10^{+79}:\\
\;\;\;\;3 \cdot x\\

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


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

    1. Initial program 99.9%

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

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

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

      if -4.29999999999999982 < z < -1.64999999999999999e-180

      1. Initial program 99.9%

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

        \[\leadsto \color{blue}{2 \cdot y} \]
      4. Step-by-step derivation
        1. Applied rewrites62.0%

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

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

          if -1.64999999999999999e-180 < z < 1.8599999999999999e79

          1. Initial program 99.8%

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

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

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

          Alternative 3: 86.5% accurate, 0.7× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -8.6 \cdot 10^{+85} \lor \neg \left(y \leq 1.55 \cdot 10^{+40}\right):\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right) + x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (or (<= y -8.6e+85) (not (<= y 1.55e+40)))
             (+ (fma 2.0 y z) x)
             (fma 3.0 x z)))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((y <= -8.6e+85) || !(y <= 1.55e+40)) {
          		tmp = fma(2.0, y, z) + x;
          	} else {
          		tmp = fma(3.0, x, z);
          	}
          	return tmp;
          }
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((y <= -8.6e+85) || !(y <= 1.55e+40))
          		tmp = Float64(fma(2.0, y, z) + x);
          	else
          		tmp = fma(3.0, x, z);
          	end
          	return tmp
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[y, -8.6e+85], N[Not[LessEqual[y, 1.55e+40]], $MachinePrecision]], N[(N[(2.0 * y + z), $MachinePrecision] + x), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;y \leq -8.6 \cdot 10^{+85} \lor \neg \left(y \leq 1.55 \cdot 10^{+40}\right):\\
          \;\;\;\;\mathsf{fma}\left(2, y, z\right) + x\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if y < -8.5999999999999998e85 or 1.5499999999999999e40 < y

            1. Initial program 100.0%

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

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

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

              if -8.5999999999999998e85 < y < 1.5499999999999999e40

              1. Initial program 99.8%

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

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

                  \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
              5. Recombined 2 regimes into one program.
              6. Final simplification91.4%

                \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8.6 \cdot 10^{+85} \lor \neg \left(y \leq 1.55 \cdot 10^{+40}\right):\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right) + x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\ \end{array} \]
              7. Add Preprocessing

              Alternative 4: 84.5% accurate, 0.8× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -9.2 \cdot 10^{+104} \lor \neg \left(y \leq 1.9 \cdot 10^{+130}\right):\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\ \end{array} \end{array} \]
              (FPCore (x y z)
               :precision binary64
               (if (or (<= y -9.2e+104) (not (<= y 1.9e+130))) (fma 2.0 y z) (fma 3.0 x z)))
              double code(double x, double y, double z) {
              	double tmp;
              	if ((y <= -9.2e+104) || !(y <= 1.9e+130)) {
              		tmp = fma(2.0, y, z);
              	} else {
              		tmp = fma(3.0, x, z);
              	}
              	return tmp;
              }
              
              function code(x, y, z)
              	tmp = 0.0
              	if ((y <= -9.2e+104) || !(y <= 1.9e+130))
              		tmp = fma(2.0, y, z);
              	else
              		tmp = fma(3.0, x, z);
              	end
              	return tmp
              end
              
              code[x_, y_, z_] := If[Or[LessEqual[y, -9.2e+104], N[Not[LessEqual[y, 1.9e+130]], $MachinePrecision]], N[(2.0 * y + z), $MachinePrecision], N[(3.0 * x + z), $MachinePrecision]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;y \leq -9.2 \cdot 10^{+104} \lor \neg \left(y \leq 1.9 \cdot 10^{+130}\right):\\
              \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
              
              \mathbf{else}:\\
              \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if y < -9.19999999999999938e104 or 1.9000000000000001e130 < y

                1. Initial program 99.9%

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

                  \[\leadsto \color{blue}{z + 2 \cdot y} \]
                4. Step-by-step derivation
                  1. Applied rewrites92.7%

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

                  if -9.19999999999999938e104 < y < 1.9000000000000001e130

                  1. Initial program 99.9%

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

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

                      \[\leadsto \color{blue}{\mathsf{fma}\left(3, x, z\right)} \]
                  5. Recombined 2 regimes into one program.
                  6. Final simplification90.9%

                    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9.2 \cdot 10^{+104} \lor \neg \left(y \leq 1.9 \cdot 10^{+130}\right):\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(3, x, z\right)\\ \end{array} \]
                  7. Add Preprocessing

                  Alternative 5: 80.0% accurate, 0.8× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{+137} \lor \neg \left(x \leq 10^{+122}\right):\\ \;\;\;\;3 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \end{array} \end{array} \]
                  (FPCore (x y z)
                   :precision binary64
                   (if (or (<= x -5.8e+137) (not (<= x 1e+122))) (* 3.0 x) (fma 2.0 y z)))
                  double code(double x, double y, double z) {
                  	double tmp;
                  	if ((x <= -5.8e+137) || !(x <= 1e+122)) {
                  		tmp = 3.0 * x;
                  	} else {
                  		tmp = fma(2.0, y, z);
                  	}
                  	return tmp;
                  }
                  
                  function code(x, y, z)
                  	tmp = 0.0
                  	if ((x <= -5.8e+137) || !(x <= 1e+122))
                  		tmp = Float64(3.0 * x);
                  	else
                  		tmp = fma(2.0, y, z);
                  	end
                  	return tmp
                  end
                  
                  code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e+137], N[Not[LessEqual[x, 1e+122]], $MachinePrecision]], N[(3.0 * x), $MachinePrecision], N[(2.0 * y + z), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;x \leq -5.8 \cdot 10^{+137} \lor \neg \left(x \leq 10^{+122}\right):\\
                  \;\;\;\;3 \cdot x\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if x < -5.79999999999999969e137 or 1.00000000000000001e122 < x

                    1. Initial program 99.7%

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

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

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

                      if -5.79999999999999969e137 < x < 1.00000000000000001e122

                      1. Initial program 99.9%

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

                        \[\leadsto \color{blue}{z + 2 \cdot y} \]
                      4. Step-by-step derivation
                        1. Applied rewrites82.0%

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

                        \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{+137} \lor \neg \left(x \leq 10^{+122}\right):\\ \;\;\;\;3 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, y, z\right)\\ \end{array} \]
                      7. Add Preprocessing

                      Alternative 6: 56.4% accurate, 1.0× speedup?

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

                        1. Initial program 99.9%

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

                          \[\leadsto \color{blue}{2 \cdot y} \]
                        4. Step-by-step derivation
                          1. Applied rewrites76.9%

                            \[\leadsto \color{blue}{2 \cdot y} \]
                          2. Step-by-step derivation
                            1. Applied rewrites76.9%

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

                            if -3.90000000000000008e74 < y < 1.25000000000000002e140

                            1. Initial program 99.9%

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

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

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

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

                            Alternative 7: 52.2% accurate, 1.0× speedup?

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

                              1. Initial program 99.9%

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

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

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

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

                                  if -9.4999999999999999e54 < y < 6.99999999999999957e139

                                  1. Initial program 99.9%

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

                                    \[\leadsto \color{blue}{z} \]
                                  4. Step-by-step derivation
                                    1. Applied rewrites45.1%

                                      \[\leadsto \color{blue}{z} \]
                                  5. Recombined 2 regimes into one program.
                                  6. Final simplification54.3%

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

                                  Alternative 8: 34.6% accurate, 16.0× speedup?

                                  \[\begin{array}{l} \\ z \end{array} \]
                                  (FPCore (x y z) :precision binary64 z)
                                  double code(double x, double y, double z) {
                                  	return 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 = z
                                  end function
                                  
                                  public static double code(double x, double y, double z) {
                                  	return z;
                                  }
                                  
                                  def code(x, y, z):
                                  	return z
                                  
                                  function code(x, y, z)
                                  	return z
                                  end
                                  
                                  function tmp = code(x, y, z)
                                  	tmp = z;
                                  end
                                  
                                  code[x_, y_, z_] := z
                                  
                                  \begin{array}{l}
                                  
                                  \\
                                  z
                                  \end{array}
                                  
                                  Derivation
                                  1. Initial program 99.9%

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

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

                                      \[\leadsto \color{blue}{z} \]
                                    2. Add Preprocessing

                                    Reproduce

                                    ?
                                    herbie shell --seed 2025021 
                                    (FPCore (x y z)
                                      :name "Graphics.Rendering.Plot.Render.Plot.Legend:renderLegendInside from plot-0.2.3.4"
                                      :precision binary64
                                      (+ (+ (+ (+ (+ x y) y) x) z) x))