ENA, Section 1.4, Mentioned, A

Percentage Accurate: 52.9% → 100.0%
Time: 4.6s
Alternatives: 7
Speedup: 9.5×

Specification

?
\[-0.01 \leq x \land x \leq 0.01\]
\[\begin{array}{l} \\ 1 - \cos x \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
double code(double x) {
	return 1.0 - cos(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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = 1.0d0 - cos(x)
end function
public static double code(double x) {
	return 1.0 - Math.cos(x);
}
def code(x):
	return 1.0 - math.cos(x)
function code(x)
	return Float64(1.0 - cos(x))
end
function tmp = code(x)
	tmp = 1.0 - cos(x);
end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - \cos x
\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: 52.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 - \cos x \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (cos x)))
double code(double x) {
	return 1.0 - cos(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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = 1.0d0 - cos(x)
end function
public static double code(double x) {
	return 1.0 - Math.cos(x);
}
def code(x):
	return 1.0 - math.cos(x)
function code(x)
	return Float64(1.0 - cos(x))
end
function tmp = code(x)
	tmp = 1.0 - cos(x);
end
code[x_] := N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - \cos x
\end{array}

Alternative 1: 100.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(0.5 \cdot x, x, {x}^{4} \cdot \left(\left(\mathsf{fma}\left(x \cdot x, -2.48015873015873 \cdot 10^{-5}, 0.001388888888888889\right) \cdot x\right) \cdot x - 0.041666666666666664\right)\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (fma
  (* 0.5 x)
  x
  (*
   (pow x 4.0)
   (-
    (* (* (fma (* x x) -2.48015873015873e-5 0.001388888888888889) x) x)
    0.041666666666666664))))
double code(double x) {
	return fma((0.5 * x), x, (pow(x, 4.0) * (((fma((x * x), -2.48015873015873e-5, 0.001388888888888889) * x) * x) - 0.041666666666666664)));
}
function code(x)
	return fma(Float64(0.5 * x), x, Float64((x ^ 4.0) * Float64(Float64(Float64(fma(Float64(x * x), -2.48015873015873e-5, 0.001388888888888889) * x) * x) - 0.041666666666666664)))
end
code[x_] := N[(N[(0.5 * x), $MachinePrecision] * x + N[(N[Power[x, 4.0], $MachinePrecision] * N[(N[(N[(N[(N[(x * x), $MachinePrecision] * -2.48015873015873e-5 + 0.001388888888888889), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] - 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(0.5 \cdot x, x, {x}^{4} \cdot \left(\left(\mathsf{fma}\left(x \cdot x, -2.48015873015873 \cdot 10^{-5}, 0.001388888888888889\right) \cdot x\right) \cdot x - 0.041666666666666664\right)\right)
\end{array}
Derivation
  1. Initial program 52.6%

    \[1 - \cos x \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left({x}^{2} \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right) - \frac{1}{24}\right)\right)} \]
  4. Step-by-step derivation
    1. Applied rewrites100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\mathsf{fma}\left(-2.48015873015873 \cdot 10^{-5}, x \cdot x, 0.001388888888888889\right) \cdot x\right) \cdot x - 0.041666666666666664, x \cdot x, 0.5\right) \cdot \left(x \cdot x\right)} \]
    2. Applied rewrites100.0%

      \[\leadsto \mathsf{fma}\left(0.5 \cdot x, \color{blue}{x}, {x}^{4} \cdot \left(\left(\mathsf{fma}\left(x \cdot x, -2.48015873015873 \cdot 10^{-5}, 0.001388888888888889\right) \cdot x\right) \cdot x - 0.041666666666666664\right)\right) \]
    3. Add Preprocessing

    Alternative 2: 100.0% accurate, 3.2× speedup?

    \[\begin{array}{l} \\ \left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.001388888888888889, -0.041666666666666664\right), x \cdot x, 0.5\right) \cdot x\right) \cdot x \end{array} \]
    (FPCore (x)
     :precision binary64
     (*
      (*
       (fma (fma (* x x) 0.001388888888888889 -0.041666666666666664) (* x x) 0.5)
       x)
      x))
    double code(double x) {
    	return (fma(fma((x * x), 0.001388888888888889, -0.041666666666666664), (x * x), 0.5) * x) * x;
    }
    
    function code(x)
    	return Float64(Float64(fma(fma(Float64(x * x), 0.001388888888888889, -0.041666666666666664), Float64(x * x), 0.5) * x) * x)
    end
    
    code[x_] := N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 0.001388888888888889 + -0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.001388888888888889, -0.041666666666666664\right), x \cdot x, 0.5\right) \cdot x\right) \cdot x
    \end{array}
    
    Derivation
    1. Initial program 52.6%

      \[1 - \cos x \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{1 - \cos x} \]
      2. lift-cos.f64N/A

        \[\leadsto 1 - \color{blue}{\cos x} \]
      3. flip--N/A

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}} \]
      4. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}} \]
      5. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{1} - \cos x \cdot \cos x}{1 + \cos x} \]
      6. 1-sub-cosN/A

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x} \]
      7. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x} \]
      8. lower-sin.f64N/A

        \[\leadsto \frac{\color{blue}{\sin x} \cdot \sin x}{1 + \cos x} \]
      9. lower-sin.f64N/A

        \[\leadsto \frac{\sin x \cdot \color{blue}{\sin x}}{1 + \cos x} \]
      10. +-commutativeN/A

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\cos x + 1}} \]
      11. lower-+.f64N/A

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\cos x + 1}} \]
      12. lift-cos.f64100.0

        \[\leadsto \frac{\sin x \cdot \sin x}{\color{blue}{\cos x} + 1} \]
    4. Applied rewrites100.0%

      \[\leadsto \color{blue}{\frac{\sin x \cdot \sin x}{\cos x + 1}} \]
    5. Taylor expanded in x around 0

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left(\frac{1}{720} \cdot {x}^{2} - \frac{1}{24}\right)\right)} \]
    6. Step-by-step derivation
      1. Applied rewrites100.0%

        \[\leadsto \color{blue}{\left(\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.001388888888888889 - 0.041666666666666664, x \cdot x, 0.5\right) \cdot x\right) \cdot x} \]
      2. Step-by-step derivation
        1. Applied rewrites100.0%

          \[\leadsto \left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.001388888888888889, -0.041666666666666664\right), x \cdot x, 0.5\right) \cdot x\right) \cdot x \]
        2. Add Preprocessing

        Alternative 3: 99.9% accurate, 3.3× speedup?

        \[\begin{array}{l} \\ \mathsf{fma}\left(0.5 \cdot x, x, \left(\left(-0.041666666666666664 \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)\right) \end{array} \]
        (FPCore (x)
         :precision binary64
         (fma (* 0.5 x) x (* (* (* -0.041666666666666664 x) x) (* x x))))
        double code(double x) {
        	return fma((0.5 * x), x, (((-0.041666666666666664 * x) * x) * (x * x)));
        }
        
        function code(x)
        	return fma(Float64(0.5 * x), x, Float64(Float64(Float64(-0.041666666666666664 * x) * x) * Float64(x * x)))
        end
        
        code[x_] := N[(N[(0.5 * x), $MachinePrecision] * x + N[(N[(N[(-0.041666666666666664 * x), $MachinePrecision] * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \mathsf{fma}\left(0.5 \cdot x, x, \left(\left(-0.041666666666666664 \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)\right)
        \end{array}
        
        Derivation
        1. Initial program 52.6%

          \[1 - \cos x \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left({x}^{2} \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right) - \frac{1}{24}\right)\right)} \]
        4. Step-by-step derivation
          1. Applied rewrites100.0%

            \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\mathsf{fma}\left(-2.48015873015873 \cdot 10^{-5}, x \cdot x, 0.001388888888888889\right) \cdot x\right) \cdot x - 0.041666666666666664, x \cdot x, 0.5\right) \cdot \left(x \cdot x\right)} \]
          2. Taylor expanded in x around 0

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

              \[\leadsto \mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right) \cdot \left(x \cdot x\right) \]
            2. Step-by-step derivation
              1. Applied rewrites99.9%

                \[\leadsto \mathsf{fma}\left(0.5 \cdot x, \color{blue}{x}, \left(\left(-0.041666666666666664 \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)\right) \]
              2. Add Preprocessing

              Alternative 4: 99.9% accurate, 4.7× speedup?

              \[\begin{array}{l} \\ \mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right) \cdot \left(x \cdot x\right) \end{array} \]
              (FPCore (x)
               :precision binary64
               (* (fma -0.041666666666666664 (* x x) 0.5) (* x x)))
              double code(double x) {
              	return fma(-0.041666666666666664, (x * x), 0.5) * (x * x);
              }
              
              function code(x)
              	return Float64(fma(-0.041666666666666664, Float64(x * x), 0.5) * Float64(x * x))
              end
              
              code[x_] := N[(N[(-0.041666666666666664 * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              \mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right) \cdot \left(x \cdot x\right)
              \end{array}
              
              Derivation
              1. Initial program 52.6%

                \[1 - \cos x \]
              2. Add Preprocessing
              3. Taylor expanded in x around 0

                \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + {x}^{2} \cdot \left({x}^{2} \cdot \left(\frac{1}{720} + \frac{-1}{40320} \cdot {x}^{2}\right) - \frac{1}{24}\right)\right)} \]
              4. Step-by-step derivation
                1. Applied rewrites100.0%

                  \[\leadsto \color{blue}{\mathsf{fma}\left(\left(\mathsf{fma}\left(-2.48015873015873 \cdot 10^{-5}, x \cdot x, 0.001388888888888889\right) \cdot x\right) \cdot x - 0.041666666666666664, x \cdot x, 0.5\right) \cdot \left(x \cdot x\right)} \]
                2. Taylor expanded in x around 0

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

                    \[\leadsto \mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right) \cdot \left(x \cdot x\right) \]
                  2. Add Preprocessing

                  Alternative 5: 99.9% accurate, 4.7× speedup?

                  \[\begin{array}{l} \\ \left(\mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right) \cdot x\right) \cdot x \end{array} \]
                  (FPCore (x)
                   :precision binary64
                   (* (* (fma -0.041666666666666664 (* x x) 0.5) x) x))
                  double code(double x) {
                  	return (fma(-0.041666666666666664, (x * x), 0.5) * x) * x;
                  }
                  
                  function code(x)
                  	return Float64(Float64(fma(-0.041666666666666664, Float64(x * x), 0.5) * x) * x)
                  end
                  
                  code[x_] := N[(N[(N[(-0.041666666666666664 * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]
                  
                  \begin{array}{l}
                  
                  \\
                  \left(\mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right) \cdot x\right) \cdot x
                  \end{array}
                  
                  Derivation
                  1. Initial program 52.6%

                    \[1 - \cos x \]
                  2. Add Preprocessing
                  3. Taylor expanded in x around 0

                    \[\leadsto \color{blue}{{x}^{2} \cdot \left(\frac{1}{2} + \frac{-1}{24} \cdot {x}^{2}\right)} \]
                  4. Step-by-step derivation
                    1. Applied rewrites99.8%

                      \[\leadsto \color{blue}{\left(\mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right) \cdot x\right) \cdot x} \]
                    2. Add Preprocessing

                    Alternative 6: 99.4% accurate, 9.5× speedup?

                    \[\begin{array}{l} \\ \left(x \cdot x\right) \cdot 0.5 \end{array} \]
                    (FPCore (x) :precision binary64 (* (* x x) 0.5))
                    double code(double x) {
                    	return (x * x) * 0.5;
                    }
                    
                    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)
                    use fmin_fmax_functions
                        real(8), intent (in) :: x
                        code = (x * x) * 0.5d0
                    end function
                    
                    public static double code(double x) {
                    	return (x * x) * 0.5;
                    }
                    
                    def code(x):
                    	return (x * x) * 0.5
                    
                    function code(x)
                    	return Float64(Float64(x * x) * 0.5)
                    end
                    
                    function tmp = code(x)
                    	tmp = (x * x) * 0.5;
                    end
                    
                    code[x_] := N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision]
                    
                    \begin{array}{l}
                    
                    \\
                    \left(x \cdot x\right) \cdot 0.5
                    \end{array}
                    
                    Derivation
                    1. Initial program 52.6%

                      \[1 - \cos x \]
                    2. Add Preprocessing
                    3. Taylor expanded in x around 0

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

                        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot 0.5} \]
                      2. Add Preprocessing

                      Alternative 7: 51.9% accurate, 26.0× speedup?

                      \[\begin{array}{l} \\ 1 - 1 \end{array} \]
                      (FPCore (x) :precision binary64 (- 1.0 1.0))
                      double code(double x) {
                      	return 1.0 - 1.0;
                      }
                      
                      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)
                      use fmin_fmax_functions
                          real(8), intent (in) :: x
                          code = 1.0d0 - 1.0d0
                      end function
                      
                      public static double code(double x) {
                      	return 1.0 - 1.0;
                      }
                      
                      def code(x):
                      	return 1.0 - 1.0
                      
                      function code(x)
                      	return Float64(1.0 - 1.0)
                      end
                      
                      function tmp = code(x)
                      	tmp = 1.0 - 1.0;
                      end
                      
                      code[x_] := N[(1.0 - 1.0), $MachinePrecision]
                      
                      \begin{array}{l}
                      
                      \\
                      1 - 1
                      \end{array}
                      
                      Derivation
                      1. Initial program 52.6%

                        \[1 - \cos x \]
                      2. Add Preprocessing
                      3. Taylor expanded in x around 0

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

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

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

                        \[\begin{array}{l} \\ \frac{\sin x \cdot \sin x}{1 + \cos x} \end{array} \]
                        (FPCore (x) :precision binary64 (/ (* (sin x) (sin x)) (+ 1.0 (cos x))))
                        double code(double x) {
                        	return (sin(x) * sin(x)) / (1.0 + cos(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)
                        use fmin_fmax_functions
                            real(8), intent (in) :: x
                            code = (sin(x) * sin(x)) / (1.0d0 + cos(x))
                        end function
                        
                        public static double code(double x) {
                        	return (Math.sin(x) * Math.sin(x)) / (1.0 + Math.cos(x));
                        }
                        
                        def code(x):
                        	return (math.sin(x) * math.sin(x)) / (1.0 + math.cos(x))
                        
                        function code(x)
                        	return Float64(Float64(sin(x) * sin(x)) / Float64(1.0 + cos(x)))
                        end
                        
                        function tmp = code(x)
                        	tmp = (sin(x) * sin(x)) / (1.0 + cos(x));
                        end
                        
                        code[x_] := N[(N[(N[Sin[x], $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
                        
                        \begin{array}{l}
                        
                        \\
                        \frac{\sin x \cdot \sin x}{1 + \cos x}
                        \end{array}
                        

                        Reproduce

                        ?
                        herbie shell --seed 2025026 
                        (FPCore (x)
                          :name "ENA, Section 1.4, Mentioned, A"
                          :precision binary64
                          :pre (and (<= -0.01 x) (<= x 0.01))
                        
                          :alt
                          (! :herbie-platform default (/ (* (sin x) (sin x)) (+ 1 (cos x))))
                        
                          (- 1.0 (cos x)))