Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3

Percentage Accurate: 88.2% → 99.1%
Time: 4.3s
Alternatives: 7
Speedup: 0.7×

Specification

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

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

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

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

Alternative 1: 99.1% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+42} \lor \neg \left(y \leq 4.2 \cdot 10^{-9}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{-x}{z}, y, y\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.00000000000000029e42 or 4.20000000000000039e-9 < y

    1. Initial program 78.5%

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

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

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

        \[\leadsto \frac{\color{blue}{y \cdot \left(z - x\right) + x}}{z} \]
      4. div-addN/A

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{y}{z}}, z - x, \frac{x}{z}\right) \]
      11. lower-/.f6483.1

        \[\leadsto \mathsf{fma}\left(\frac{y}{z}, z - x, \color{blue}{\frac{x}{z}}\right) \]
    4. Applied rewrites83.1%

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

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

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

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

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

      if -3.00000000000000029e42 < y < 4.20000000000000039e-9

      1. Initial program 99.9%

        \[\frac{x + y \cdot \left(z - x\right)}{z} \]
      2. Add Preprocessing
    9. Recombined 2 regimes into one program.
    10. Final simplification99.9%

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

    Alternative 2: 98.7% accurate, 0.7× speedup?

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

      1. Initial program 78.9%

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

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

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

          \[\leadsto \frac{\color{blue}{y \cdot \left(z - x\right) + x}}{z} \]
        4. div-addN/A

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{y}{z}}, z - x, \frac{x}{z}\right) \]
        11. lower-/.f6483.3

          \[\leadsto \mathsf{fma}\left(\frac{y}{z}, z - x, \color{blue}{\frac{x}{z}}\right) \]
      4. Applied rewrites83.3%

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

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

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

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

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

        if -6.8e7 < y < 4.20000000000000039e-9

        1. Initial program 99.9%

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

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

            \[\leadsto \frac{x + y \cdot \color{blue}{z}}{z} \]
          2. Step-by-step derivation
            1. lift-+.f64N/A

              \[\leadsto \frac{\color{blue}{x + y \cdot z}}{z} \]
            2. +-commutativeN/A

              \[\leadsto \frac{\color{blue}{y \cdot z + x}}{z} \]
            3. lift-*.f64N/A

              \[\leadsto \frac{\color{blue}{y \cdot z} + x}{z} \]
            4. *-commutativeN/A

              \[\leadsto \frac{\color{blue}{z \cdot y} + x}{z} \]
            5. lower-fma.f6499.5

              \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(z, y, x\right)}}{z} \]
          3. Applied rewrites99.5%

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

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

        Alternative 3: 94.9% accurate, 0.7× speedup?

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

          1. Initial program 78.9%

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

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

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

              \[\leadsto \frac{\color{blue}{y \cdot \left(z - x\right) + x}}{z} \]
            4. div-addN/A

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{y}{z}}, z - x, \frac{x}{z}\right) \]
            11. lower-/.f6483.3

              \[\leadsto \mathsf{fma}\left(\frac{y}{z}, z - x, \color{blue}{\frac{x}{z}}\right) \]
          4. Applied rewrites83.3%

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

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

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

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

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

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

              if -6.8e7 < y < 4.20000000000000039e-9

              1. Initial program 99.9%

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

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

                  \[\leadsto \frac{x + y \cdot \color{blue}{z}}{z} \]
                2. Step-by-step derivation
                  1. lift-+.f64N/A

                    \[\leadsto \frac{\color{blue}{x + y \cdot z}}{z} \]
                  2. +-commutativeN/A

                    \[\leadsto \frac{\color{blue}{y \cdot z + x}}{z} \]
                  3. lift-*.f64N/A

                    \[\leadsto \frac{\color{blue}{y \cdot z} + x}{z} \]
                  4. *-commutativeN/A

                    \[\leadsto \frac{\color{blue}{z \cdot y} + x}{z} \]
                  5. lower-fma.f6499.5

                    \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(z, y, x\right)}}{z} \]
                3. Applied rewrites99.5%

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

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

              Alternative 4: 72.1% accurate, 0.9× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 2.35 \cdot 10^{+27}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-y\right) \cdot x}{z}\\ \end{array} \end{array} \]
              (FPCore (x y z)
               :precision binary64
               (if (<= y 2.35e+27) (/ (fma z y x) z) (/ (* (- y) x) z)))
              double code(double x, double y, double z) {
              	double tmp;
              	if (y <= 2.35e+27) {
              		tmp = fma(z, y, x) / z;
              	} else {
              		tmp = (-y * x) / z;
              	}
              	return tmp;
              }
              
              function code(x, y, z)
              	tmp = 0.0
              	if (y <= 2.35e+27)
              		tmp = Float64(fma(z, y, x) / z);
              	else
              		tmp = Float64(Float64(Float64(-y) * x) / z);
              	end
              	return tmp
              end
              
              code[x_, y_, z_] := If[LessEqual[y, 2.35e+27], N[(N[(z * y + x), $MachinePrecision] / z), $MachinePrecision], N[(N[((-y) * x), $MachinePrecision] / z), $MachinePrecision]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;y \leq 2.35 \cdot 10^{+27}:\\
              \;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\
              
              \mathbf{else}:\\
              \;\;\;\;\frac{\left(-y\right) \cdot x}{z}\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if y < 2.34999999999999988e27

                1. Initial program 94.7%

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

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

                    \[\leadsto \frac{x + y \cdot \color{blue}{z}}{z} \]
                  2. Step-by-step derivation
                    1. lift-+.f64N/A

                      \[\leadsto \frac{\color{blue}{x + y \cdot z}}{z} \]
                    2. +-commutativeN/A

                      \[\leadsto \frac{\color{blue}{y \cdot z + x}}{z} \]
                    3. lift-*.f64N/A

                      \[\leadsto \frac{\color{blue}{y \cdot z} + x}{z} \]
                    4. *-commutativeN/A

                      \[\leadsto \frac{\color{blue}{z \cdot y} + x}{z} \]
                    5. lower-fma.f6487.0

                      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(z, y, x\right)}}{z} \]
                  3. Applied rewrites87.0%

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

                  if 2.34999999999999988e27 < y

                  1. Initial program 74.9%

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

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

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

                      \[\leadsto \frac{\left(-1 \cdot y\right) \cdot x}{z} \]
                    3. Step-by-step derivation
                      1. Applied rewrites58.4%

                        \[\leadsto \frac{\left(-y\right) \cdot x}{z} \]
                    4. Recombined 2 regimes into one program.
                    5. Add Preprocessing

                    Alternative 5: 56.8% accurate, 1.0× speedup?

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

                      1. Initial program 93.8%

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

                        \[\leadsto \frac{\color{blue}{x}}{z} \]
                      4. Step-by-step derivation
                        1. Applied rewrites56.5%

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

                        if -1.21999999999999998e-91 < x < 1.9999999999999999e-40

                        1. Initial program 85.2%

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

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

                            \[\leadsto \color{blue}{y} \]
                        5. Recombined 2 regimes into one program.
                        6. Final simplification64.6%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.22 \cdot 10^{-91} \lor \neg \left(x \leq 2 \cdot 10^{-40}\right):\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
                        7. Add Preprocessing

                        Alternative 6: 73.3% accurate, 1.0× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 4.2 \cdot 10^{-9}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
                        (FPCore (x y z) :precision binary64 (if (<= y 4.2e-9) (/ (fma z y x) z) y))
                        double code(double x, double y, double z) {
                        	double tmp;
                        	if (y <= 4.2e-9) {
                        		tmp = fma(z, y, x) / z;
                        	} else {
                        		tmp = y;
                        	}
                        	return tmp;
                        }
                        
                        function code(x, y, z)
                        	tmp = 0.0
                        	if (y <= 4.2e-9)
                        		tmp = Float64(fma(z, y, x) / z);
                        	else
                        		tmp = y;
                        	end
                        	return tmp
                        end
                        
                        code[x_, y_, z_] := If[LessEqual[y, 4.2e-9], N[(N[(z * y + x), $MachinePrecision] / z), $MachinePrecision], y]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;y \leq 4.2 \cdot 10^{-9}:\\
                        \;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;y\\
                        
                        
                        \end{array}
                        \end{array}
                        
                        Derivation
                        1. Split input into 2 regimes
                        2. if y < 4.20000000000000039e-9

                          1. Initial program 94.6%

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

                            \[\leadsto \frac{x + y \cdot \color{blue}{z}}{z} \]
                          4. Step-by-step derivation
                            1. Applied rewrites86.6%

                              \[\leadsto \frac{x + y \cdot \color{blue}{z}}{z} \]
                            2. Step-by-step derivation
                              1. lift-+.f64N/A

                                \[\leadsto \frac{\color{blue}{x + y \cdot z}}{z} \]
                              2. +-commutativeN/A

                                \[\leadsto \frac{\color{blue}{y \cdot z + x}}{z} \]
                              3. lift-*.f64N/A

                                \[\leadsto \frac{\color{blue}{y \cdot z} + x}{z} \]
                              4. *-commutativeN/A

                                \[\leadsto \frac{\color{blue}{z \cdot y} + x}{z} \]
                              5. lower-fma.f6486.6

                                \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(z, y, x\right)}}{z} \]
                            3. Applied rewrites86.6%

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

                            if 4.20000000000000039e-9 < y

                            1. Initial program 77.3%

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

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

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

                              \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 4.2 \cdot 10^{-9}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
                            7. Add Preprocessing

                            Alternative 7: 40.9% accurate, 23.0× speedup?

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

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

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

                                \[\leadsto \color{blue}{y} \]
                              2. Final simplification39.4%

                                \[\leadsto y \]
                              3. Add Preprocessing

                              Developer Target 1: 93.9% accurate, 0.6× speedup?

                              \[\begin{array}{l} \\ \left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}} \end{array} \]
                              (FPCore (x y z) :precision binary64 (- (+ y (/ x z)) (/ y (/ z x))))
                              double code(double x, double y, double z) {
                              	return (y + (x / z)) - (y / (z / x));
                              }
                              
                              module fmin_fmax_functions
                                  implicit none
                                  private
                                  public fmax
                                  public fmin
                              
                                  interface fmax
                                      module procedure fmax88
                                      module procedure fmax44
                                      module procedure fmax84
                                      module procedure fmax48
                                  end interface
                                  interface fmin
                                      module procedure fmin88
                                      module procedure fmin44
                                      module procedure fmin84
                                      module procedure fmin48
                                  end interface
                              contains
                                  real(8) function fmax88(x, y) result (res)
                                      real(8), intent (in) :: x
                                      real(8), intent (in) :: y
                                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                  end function
                                  real(4) function fmax44(x, y) result (res)
                                      real(4), intent (in) :: x
                                      real(4), intent (in) :: y
                                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                  end function
                                  real(8) function fmax84(x, y) result(res)
                                      real(8), intent (in) :: x
                                      real(4), intent (in) :: y
                                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                  end function
                                  real(8) function fmax48(x, y) result(res)
                                      real(4), intent (in) :: x
                                      real(8), intent (in) :: y
                                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                  end function
                                  real(8) function fmin88(x, y) result (res)
                                      real(8), intent (in) :: x
                                      real(8), intent (in) :: y
                                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                  end function
                                  real(4) function fmin44(x, y) result (res)
                                      real(4), intent (in) :: x
                                      real(4), intent (in) :: y
                                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                  end function
                                  real(8) function fmin84(x, y) result(res)
                                      real(8), intent (in) :: x
                                      real(4), intent (in) :: y
                                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                  end function
                                  real(8) function fmin48(x, y) result(res)
                                      real(4), intent (in) :: x
                                      real(8), intent (in) :: y
                                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                  end function
                              end module
                              
                              real(8) function code(x, y, z)
                              use fmin_fmax_functions
                                  real(8), intent (in) :: x
                                  real(8), intent (in) :: y
                                  real(8), intent (in) :: z
                                  code = (y + (x / z)) - (y / (z / x))
                              end function
                              
                              public static double code(double x, double y, double z) {
                              	return (y + (x / z)) - (y / (z / x));
                              }
                              
                              def code(x, y, z):
                              	return (y + (x / z)) - (y / (z / x))
                              
                              function code(x, y, z)
                              	return Float64(Float64(y + Float64(x / z)) - Float64(y / Float64(z / x)))
                              end
                              
                              function tmp = code(x, y, z)
                              	tmp = (y + (x / z)) - (y / (z / x));
                              end
                              
                              code[x_, y_, z_] := N[(N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
                              
                              \begin{array}{l}
                              
                              \\
                              \left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}}
                              \end{array}
                              

                              Reproduce

                              ?
                              herbie shell --seed 2025022 
                              (FPCore (x y z)
                                :name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
                                :precision binary64
                              
                                :alt
                                (! :herbie-platform default (- (+ y (/ x z)) (/ y (/ z x))))
                              
                                (/ (+ x (* y (- z x))) z))