Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3

Percentage Accurate: 97.6% → 100.0%
Time: 4.4s
Alternatives: 7
Speedup: 1.7×

Specification

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

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

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 97.6% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 100.0% accurate, 1.7× speedup?

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

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

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

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

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

Alternative 2: 98.8% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 94.6%

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

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

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

      if -4.1e11 < y < 1

      1. Initial program 100.0%

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

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

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

        \[\leadsto \mathsf{fma}\left(x, y, z\right) \]
      6. Step-by-step derivation
        1. Applied rewrites99.6%

          \[\leadsto \mathsf{fma}\left(x, y, z\right) \]
      7. Recombined 2 regimes into one program.
      8. Final simplification99.0%

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

      Alternative 3: 85.9% accurate, 0.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -21000000000 \lor \neg \left(z \leq 3.3 \cdot 10^{+106}\right):\\ \;\;\;\;\left(1 - y\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y, z\right)\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (or (<= z -21000000000.0) (not (<= z 3.3e+106)))
         (* (- 1.0 y) z)
         (fma x y z)))
      double code(double x, double y, double z) {
      	double tmp;
      	if ((z <= -21000000000.0) || !(z <= 3.3e+106)) {
      		tmp = (1.0 - y) * z;
      	} else {
      		tmp = fma(x, y, z);
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	tmp = 0.0
      	if ((z <= -21000000000.0) || !(z <= 3.3e+106))
      		tmp = Float64(Float64(1.0 - y) * z);
      	else
      		tmp = fma(x, y, z);
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := If[Or[LessEqual[z, -21000000000.0], N[Not[LessEqual[z, 3.3e+106]], $MachinePrecision]], N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision], N[(x * y + z), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;z \leq -21000000000 \lor \neg \left(z \leq 3.3 \cdot 10^{+106}\right):\\
      \;\;\;\;\left(1 - y\right) \cdot z\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if z < -2.1e10 or 3.30000000000000008e106 < z

        1. Initial program 94.6%

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

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

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

          if -2.1e10 < z < 3.30000000000000008e106

          1. Initial program 99.3%

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

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

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

            \[\leadsto \mathsf{fma}\left(x, y, z\right) \]
          6. Step-by-step derivation
            1. Applied rewrites87.9%

              \[\leadsto \mathsf{fma}\left(x, y, z\right) \]
          7. Recombined 2 regimes into one program.
          8. Final simplification89.4%

            \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -21000000000 \lor \neg \left(z \leq 3.3 \cdot 10^{+106}\right):\\ \;\;\;\;\left(1 - y\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y, z\right)\\ \end{array} \]
          9. Add Preprocessing

          Alternative 4: 74.7% accurate, 0.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -7.5 \cdot 10^{+249} \lor \neg \left(z \leq 1.75 \cdot 10^{+257}\right):\\ \;\;\;\;\left(-z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y, z\right)\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (or (<= z -7.5e+249) (not (<= z 1.75e+257))) (* (- z) y) (fma x y z)))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((z <= -7.5e+249) || !(z <= 1.75e+257)) {
          		tmp = -z * y;
          	} else {
          		tmp = fma(x, y, z);
          	}
          	return tmp;
          }
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((z <= -7.5e+249) || !(z <= 1.75e+257))
          		tmp = Float64(Float64(-z) * y);
          	else
          		tmp = fma(x, y, z);
          	end
          	return tmp
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[z, -7.5e+249], N[Not[LessEqual[z, 1.75e+257]], $MachinePrecision]], N[((-z) * y), $MachinePrecision], N[(x * y + z), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;z \leq -7.5 \cdot 10^{+249} \lor \neg \left(z \leq 1.75 \cdot 10^{+257}\right):\\
          \;\;\;\;\left(-z\right) \cdot y\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(x, y, z\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if z < -7.49999999999999941e249 or 1.74999999999999989e257 < z

            1. Initial program 100.0%

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

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

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

                \[\leadsto \left(-1 \cdot z\right) \cdot y \]
              3. Step-by-step derivation
                1. Applied rewrites76.9%

                  \[\leadsto \left(-z\right) \cdot y \]

                if -7.49999999999999941e249 < z < 1.74999999999999989e257

                1. Initial program 96.9%

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

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

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

                  \[\leadsto \mathsf{fma}\left(x, y, z\right) \]
                6. Step-by-step derivation
                  1. Applied rewrites78.5%

                    \[\leadsto \mathsf{fma}\left(x, y, z\right) \]
                7. Recombined 2 regimes into one program.
                8. Final simplification78.4%

                  \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -7.5 \cdot 10^{+249} \lor \neg \left(z \leq 1.75 \cdot 10^{+257}\right):\\ \;\;\;\;\left(-z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y, z\right)\\ \end{array} \]
                9. Add Preprocessing

                Alternative 5: 59.6% accurate, 0.9× speedup?

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

                  1. Initial program 95.5%

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

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

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

                    if -3.8e-19 < y < 1.35999999999999997e-104

                    1. Initial program 100.0%

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

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

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

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

                    Alternative 6: 75.4% accurate, 2.4× speedup?

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(x, y, z\right) \]
                    6. Step-by-step derivation
                      1. Applied rewrites73.9%

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

                      Alternative 7: 35.7% accurate, 17.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 97.2%

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

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

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

                        Developer Target 1: 100.0% accurate, 1.4× speedup?

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

                        Reproduce

                        ?
                        herbie shell --seed 2025019 
                        (FPCore (x y z)
                          :name "Diagrams.TwoD.Segment:bezierClip from diagrams-lib-1.3.0.3"
                          :precision binary64
                        
                          :alt
                          (! :herbie-platform default (- z (* (- z x) y)))
                        
                          (+ (* x y) (* z (- 1.0 y))))