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

Percentage Accurate: 98.0% → 100.0%
Time: 6.3s
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: 98.0% 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 98.8%

    \[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: 76.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-z\right) \cdot y\\ \mathbf{if}\;y \leq -2.5 \cdot 10^{+237}:\\ \;\;\;\;\mathsf{fma}\left(x, y, z\right)\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{+63}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+20}:\\ \;\;\;\;\mathsf{fma}\left(x, y, z\right)\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{+242}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (- z) y)))
   (if (<= y -2.5e+237)
     (fma x y z)
     (if (<= y -1.6e+63)
       t_0
       (if (<= y 4.2e+20) (fma x y z) (if (<= y 2.6e+242) t_0 (* y x)))))))
double code(double x, double y, double z) {
	double t_0 = -z * y;
	double tmp;
	if (y <= -2.5e+237) {
		tmp = fma(x, y, z);
	} else if (y <= -1.6e+63) {
		tmp = t_0;
	} else if (y <= 4.2e+20) {
		tmp = fma(x, y, z);
	} else if (y <= 2.6e+242) {
		tmp = t_0;
	} else {
		tmp = y * x;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(Float64(-z) * y)
	tmp = 0.0
	if (y <= -2.5e+237)
		tmp = fma(x, y, z);
	elseif (y <= -1.6e+63)
		tmp = t_0;
	elseif (y <= 4.2e+20)
		tmp = fma(x, y, z);
	elseif (y <= 2.6e+242)
		tmp = t_0;
	else
		tmp = Float64(y * x);
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * y), $MachinePrecision]}, If[LessEqual[y, -2.5e+237], N[(x * y + z), $MachinePrecision], If[LessEqual[y, -1.6e+63], t$95$0, If[LessEqual[y, 4.2e+20], N[(x * y + z), $MachinePrecision], If[LessEqual[y, 2.6e+242], t$95$0, N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot y\\
\mathbf{if}\;y \leq -2.5 \cdot 10^{+237}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\

\mathbf{elif}\;y \leq -1.6 \cdot 10^{+63}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 4.2 \cdot 10^{+20}:\\
\;\;\;\;\mathsf{fma}\left(x, y, z\right)\\

\mathbf{elif}\;y \leq 2.6 \cdot 10^{+242}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -2.5000000000000001e237 or -1.60000000000000006e63 < y < 4.2e20

    1. Initial program 98.8%

      \[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 rewrites92.6%

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

      if -2.5000000000000001e237 < y < -1.60000000000000006e63 or 4.2e20 < y < 2.5999999999999998e242

      1. Initial program 98.5%

        \[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 rewrites100.0%

          \[\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 rewrites70.9%

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

          if 2.5999999999999998e242 < y

          1. Initial program 100.0%

            \[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 rewrites86.1%

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

          Alternative 3: 99.0% accurate, 0.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.09\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 -1.0) (not (<= y 0.09))) (* (- x z) y) (fma x y z)))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((y <= -1.0) || !(y <= 0.09)) {
          		tmp = (x - z) * y;
          	} else {
          		tmp = fma(x, y, z);
          	}
          	return tmp;
          }
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((y <= -1.0) || !(y <= 0.09))
          		tmp = Float64(Float64(x - z) * y);
          	else
          		tmp = fma(x, y, z);
          	end
          	return tmp
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.09]], $MachinePrecision]], N[(N[(x - z), $MachinePrecision] * y), $MachinePrecision], N[(x * y + z), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.09\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 < -1 or 0.089999999999999997 < y

            1. Initial program 97.4%

              \[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 rewrites99.6%

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

              if -1 < y < 0.089999999999999997

              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 rewrites98.7%

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

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

              Alternative 4: 86.1% accurate, 0.8× speedup?

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

                1. Initial program 97.8%

                  \[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 rewrites91.2%

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

                  if -8.50000000000000014e36 < x < 1.3e-76

                  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}{z \cdot \left(1 - y\right)} \]
                  4. Step-by-step derivation
                    1. Applied rewrites87.1%

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

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

                  Alternative 5: 61.8% accurate, 0.9× speedup?

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

                    1. Initial program 97.8%

                      \[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 rewrites52.2%

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

                      if -5.8000000000000003e-22 < y < 2.25e-73

                      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 rewrites80.8%

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

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

                      Alternative 6: 76.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 98.8%

                        \[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 rewrites77.2%

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

                        Alternative 7: 36.9% 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 98.8%

                          \[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 rewrites41.4%

                            \[\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 2025018 
                          (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))))