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

Percentage Accurate: 88.1% → 99.9%
Time: 2.0s
Alternatives: 5
Speedup: 1.1×

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}

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 5 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.1% 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.9% accurate, 1.1× speedup?

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

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

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

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

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

      \[\leadsto x \cdot \left(\frac{-1 \cdot y}{z} + \frac{1}{z}\right) + y \]
    3. div-add-revN/A

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

      \[\leadsto x \cdot \frac{1 + -1 \cdot y}{z} + y \]
    5. associate-/l*N/A

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

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

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

      \[\leadsto \mathsf{fma}\left(1 + -1 \cdot y, \color{blue}{\frac{x}{z}}, y\right) \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \mathsf{fma}\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot y, \frac{\color{blue}{x}}{z}, y\right) \]
    10. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(1 - 1 \cdot y, \frac{x}{z}, y\right) \]
    11. *-lft-identityN/A

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

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

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

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

Alternative 2: 99.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{if}\;y \leq -3800:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 0.39:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (- 1.0 (/ x z)) y)))
   (if (<= y -3800.0) t_0 (if (<= y 0.39) (/ (fma z y x) z) t_0))))
double code(double x, double y, double z) {
	double t_0 = (1.0 - (x / z)) * y;
	double tmp;
	if (y <= -3800.0) {
		tmp = t_0;
	} else if (y <= 0.39) {
		tmp = fma(z, y, x) / z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(Float64(1.0 - Float64(x / z)) * y)
	tmp = 0.0
	if (y <= -3800.0)
		tmp = t_0;
	elseif (y <= 0.39)
		tmp = Float64(fma(z, y, x) / z);
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -3800.0], t$95$0, If[LessEqual[y, 0.39], N[(N[(z * y + x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(1 - \frac{x}{z}\right) \cdot y\\
\mathbf{if}\;y \leq -3800:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 0.39:\\
\;\;\;\;\frac{\mathsf{fma}\left(z, y, x\right)}{z}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 88.1%

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

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

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

        \[\leadsto x \cdot \left(\frac{-1 \cdot y}{z} + \frac{1}{z}\right) + y \]
      3. div-add-revN/A

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

        \[\leadsto x \cdot \frac{1 + -1 \cdot y}{z} + y \]
      5. associate-/l*N/A

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

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

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

        \[\leadsto \mathsf{fma}\left(1 + -1 \cdot y, \color{blue}{\frac{x}{z}}, y\right) \]
      9. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot y, \frac{\color{blue}{x}}{z}, y\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(1 - 1 \cdot y, \frac{x}{z}, y\right) \]
      11. *-lft-identityN/A

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

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

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

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

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

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

        \[\leadsto \left(1 + -1 \cdot \frac{x}{z}\right) \cdot y \]
      3. fp-cancel-sign-sub-invN/A

        \[\leadsto \left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \frac{x}{z}\right) \cdot y \]
      4. distribute-lft-neg-outN/A

        \[\leadsto \left(1 - \left(\mathsf{neg}\left(-1 \cdot \frac{x}{z}\right)\right)\right) \cdot y \]
      5. associate-*r/N/A

        \[\leadsto \left(1 - \left(\mathsf{neg}\left(\frac{-1 \cdot x}{z}\right)\right)\right) \cdot y \]
      6. distribute-frac-neg2N/A

        \[\leadsto \left(1 - \frac{-1 \cdot x}{\mathsf{neg}\left(z\right)}\right) \cdot y \]
      7. mul-1-negN/A

        \[\leadsto \left(1 - \frac{\mathsf{neg}\left(x\right)}{\mathsf{neg}\left(z\right)}\right) \cdot y \]
      8. frac-2negN/A

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

        \[\leadsto \left(1 - \frac{x}{z}\right) \cdot y \]
      10. lift-/.f6468.6

        \[\leadsto \left(1 - \frac{x}{z}\right) \cdot y \]
    7. Applied rewrites68.6%

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

    if -3800 < y < 0.39000000000000001

    1. Initial program 88.1%

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

      \[\leadsto \frac{x + y \cdot \color{blue}{z}}{z} \]
    3. Step-by-step derivation
      1. Applied rewrites68.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.f6468.6

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

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(z, y, x\right)}{z}} \]
    4. Recombined 2 regimes into one program.
    5. Add Preprocessing

    Alternative 3: 77.9% accurate, 1.4× speedup?

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

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

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

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

        \[\leadsto x \cdot \left(\frac{-1 \cdot y}{z} + \frac{1}{z}\right) + y \]
      3. div-add-revN/A

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

        \[\leadsto x \cdot \frac{1 + -1 \cdot y}{z} + y \]
      5. associate-/l*N/A

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

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

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

        \[\leadsto \mathsf{fma}\left(1 + -1 \cdot y, \color{blue}{\frac{x}{z}}, y\right) \]
      9. fp-cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot y, \frac{\color{blue}{x}}{z}, y\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(1 - 1 \cdot y, \frac{x}{z}, y\right) \]
      11. *-lft-identityN/A

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

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

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

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

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

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

      Alternative 4: 60.5% accurate, 1.1× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-11}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-28}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (<= y -5e-11) y (if (<= y 4.5e-28) (/ x z) y)))
      double code(double x, double y, double z) {
      	double tmp;
      	if (y <= -5e-11) {
      		tmp = y;
      	} else if (y <= 4.5e-28) {
      		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 (y <= (-5d-11)) then
              tmp = y
          else if (y <= 4.5d-28) 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 (y <= -5e-11) {
      		tmp = y;
      	} else if (y <= 4.5e-28) {
      		tmp = x / z;
      	} else {
      		tmp = y;
      	}
      	return tmp;
      }
      
      def code(x, y, z):
      	tmp = 0
      	if y <= -5e-11:
      		tmp = y
      	elif y <= 4.5e-28:
      		tmp = x / z
      	else:
      		tmp = y
      	return tmp
      
      function code(x, y, z)
      	tmp = 0.0
      	if (y <= -5e-11)
      		tmp = y;
      	elseif (y <= 4.5e-28)
      		tmp = Float64(x / z);
      	else
      		tmp = y;
      	end
      	return tmp
      end
      
      function tmp_2 = code(x, y, z)
      	tmp = 0.0;
      	if (y <= -5e-11)
      		tmp = y;
      	elseif (y <= 4.5e-28)
      		tmp = x / z;
      	else
      		tmp = y;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_, y_, z_] := If[LessEqual[y, -5e-11], y, If[LessEqual[y, 4.5e-28], N[(x / z), $MachinePrecision], y]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;y \leq -5 \cdot 10^{-11}:\\
      \;\;\;\;y\\
      
      \mathbf{elif}\;y \leq 4.5 \cdot 10^{-28}:\\
      \;\;\;\;\frac{x}{z}\\
      
      \mathbf{else}:\\
      \;\;\;\;y\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if y < -5.00000000000000018e-11 or 4.4999999999999998e-28 < y

        1. Initial program 88.1%

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

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

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

          if -5.00000000000000018e-11 < y < 4.4999999999999998e-28

          1. Initial program 88.1%

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

            \[\leadsto \color{blue}{\frac{x}{z}} \]
          3. Step-by-step derivation
            1. lower-/.f6439.2

              \[\leadsto \frac{x}{\color{blue}{z}} \]
          4. Applied rewrites39.2%

            \[\leadsto \color{blue}{\frac{x}{z}} \]
        4. Recombined 2 regimes into one program.
        5. Add Preprocessing

        Alternative 5: 41.2% accurate, 12.7× 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 88.1%

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

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

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

          Reproduce

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