Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3

Percentage Accurate: 97.5% → 100.0%
Time: 4.5s
Alternatives: 6
Speedup: 1.4×

Specification

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

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

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 6 alternatives:

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

Initial Program: 97.5% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 100.0% accurate, 1.4× speedup?

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

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

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

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

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

Alternative 2: 60.6% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{+150}:\\
\;\;\;\;x \cdot z\\

\mathbf{elif}\;x \leq -2.45 \cdot 10^{-48}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;x \leq 1:\\
\;\;\;\;-z\\

\mathbf{elif}\;x \leq 3.6 \cdot 10^{+107}:\\
\;\;\;\;x \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.15000000000000001e150 or 1 < x < 3.5999999999999998e107

    1. Initial program 96.3%

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

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

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

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

        \[\leadsto \color{blue}{\left(z + y\right)} \cdot x \]
      4. lower-+.f6499.9

        \[\leadsto \color{blue}{\left(z + y\right)} \cdot x \]
    5. Applied rewrites99.9%

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

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

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

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

        if -1.15000000000000001e150 < x < -2.4500000000000001e-48 or 3.5999999999999998e107 < x

        1. Initial program 97.7%

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

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

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

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

            \[\leadsto \color{blue}{\left(z + y\right)} \cdot x \]
          4. lower-+.f6495.5

            \[\leadsto \color{blue}{\left(z + y\right)} \cdot x \]
        5. Applied rewrites95.5%

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

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

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

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

              \[\leadsto \color{blue}{x \cdot y} \]
            3. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{y \cdot x} \]
              2. lower-*.f6463.1

                \[\leadsto \color{blue}{y \cdot x} \]
            4. Applied rewrites63.1%

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

            if -2.4500000000000001e-48 < x < 1

            1. Initial program 100.0%

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

              \[\leadsto \color{blue}{-1 \cdot z} \]
            4. Step-by-step derivation
              1. mul-1-negN/A

                \[\leadsto \color{blue}{\mathsf{neg}\left(z\right)} \]
              2. lower-neg.f6472.2

                \[\leadsto \color{blue}{-z} \]
            5. Applied rewrites72.2%

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

          Alternative 3: 85.3% accurate, 0.8× speedup?

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

            1. Initial program 97.2%

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

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

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

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

                \[\leadsto \color{blue}{\left(z + y\right)} \cdot x \]
              4. lower-+.f6497.2

                \[\leadsto \color{blue}{\left(z + y\right)} \cdot x \]
            5. Applied rewrites97.2%

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

            if -1.40000000000000002e-48 < x < 8.59999999999999979e-4

            1. Initial program 100.0%

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

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

                \[\leadsto \color{blue}{\left(x - 1\right) \cdot z} \]
              2. lower-*.f64N/A

                \[\leadsto \color{blue}{\left(x - 1\right) \cdot z} \]
              3. lower--.f6473.0

                \[\leadsto \color{blue}{\left(x - 1\right)} \cdot z \]
            5. Applied rewrites73.0%

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

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

          Alternative 4: 85.1% accurate, 0.8× speedup?

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

            1. Initial program 97.2%

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

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

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

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

                \[\leadsto \color{blue}{\left(z + y\right)} \cdot x \]
              4. lower-+.f6497.2

                \[\leadsto \color{blue}{\left(z + y\right)} \cdot x \]
            5. Applied rewrites97.2%

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

            if -1.40000000000000002e-48 < x < 1.99999999999999991e-6

            1. Initial program 100.0%

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

              \[\leadsto \color{blue}{-1 \cdot z} \]
            4. Step-by-step derivation
              1. mul-1-negN/A

                \[\leadsto \color{blue}{\mathsf{neg}\left(z\right)} \]
              2. lower-neg.f6472.2

                \[\leadsto \color{blue}{-z} \]
            5. Applied rewrites72.2%

              \[\leadsto \color{blue}{-z} \]
          3. Recombined 2 regimes into one program.
          4. Final simplification86.2%

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

          Alternative 5: 60.9% accurate, 0.9× speedup?

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

            1. Initial program 97.0%

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

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

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

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

                \[\leadsto \color{blue}{\left(z + y\right)} \cdot x \]
              4. lower-+.f64100.0

                \[\leadsto \color{blue}{\left(z + y\right)} \cdot x \]
            5. Applied rewrites100.0%

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

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

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

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

                if -1 < x < 1

                1. Initial program 99.9%

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

                  \[\leadsto \color{blue}{-1 \cdot z} \]
                4. Step-by-step derivation
                  1. mul-1-negN/A

                    \[\leadsto \color{blue}{\mathsf{neg}\left(z\right)} \]
                  2. lower-neg.f6469.5

                    \[\leadsto \color{blue}{-z} \]
                5. Applied rewrites69.5%

                  \[\leadsto \color{blue}{-z} \]
              4. Recombined 2 regimes into one program.
              5. Final simplification60.0%

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

              Alternative 6: 36.4% accurate, 5.7× 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 Float64(-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 98.4%

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

                \[\leadsto \color{blue}{-1 \cdot z} \]
              4. Step-by-step derivation
                1. mul-1-negN/A

                  \[\leadsto \color{blue}{\mathsf{neg}\left(z\right)} \]
                2. lower-neg.f6434.8

                  \[\leadsto \color{blue}{-z} \]
              5. Applied rewrites34.8%

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

              Reproduce

              ?
              herbie shell --seed 2025015 
              (FPCore (x y z)
                :name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
                :precision binary64
                (+ (* x y) (* (- x 1.0) z)))