Trigonometry A

Percentage Accurate: 99.8% → 99.8%
Time: 10.4s
Alternatives: 10
Speedup: 1.0×

Specification

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

\\
\frac{e \cdot \sin v}{1 + e \cdot \cos v}
\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 10 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: 99.8% accurate, 1.0× speedup?

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

\\
\frac{e \cdot \sin v}{1 + e \cdot \cos v}
\end{array}

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\sin v \cdot e}{\mathsf{fma}\left(\cos v, e, 1\right)} \end{array} \]
(FPCore (e v) :precision binary64 (/ (* (sin v) e) (fma (cos v) e 1.0)))
double code(double e, double v) {
	return (sin(v) * e) / fma(cos(v), e, 1.0);
}
function code(e, v)
	return Float64(Float64(sin(v) * e) / fma(cos(v), e, 1.0))
end
code[e_, v_] := N[(N[(N[Sin[v], $MachinePrecision] * e), $MachinePrecision] / N[(N[Cos[v], $MachinePrecision] * e + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin v \cdot e}{\mathsf{fma}\left(\cos v, e, 1\right)}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-varN/A

      \[\leadsto \frac{\color{blue}{e} \cdot \sin v}{1 + e \cdot \cos v} \]
    2. lift-varN/A

      \[\leadsto \frac{\mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \sin \color{blue}{v}}{1 + e \cdot \cos v} \]
    3. lift-sin.f64N/A

      \[\leadsto \frac{\mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \color{blue}{\sin v}}{1 + e \cdot \cos v} \]
    4. lift-*.f64N/A

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

      \[\leadsto \frac{\color{blue}{\sin v \cdot e}}{1 + e \cdot \cos v} \]
    6. lift-sin.f64N/A

      \[\leadsto \frac{\color{blue}{\sin v} \cdot e}{1 + e \cdot \cos v} \]
    7. lift-varN/A

      \[\leadsto \frac{\sin \color{blue}{v} \cdot e}{1 + e \cdot \cos v} \]
    8. lift-var99.9

      \[\leadsto \frac{\sin v \cdot \color{blue}{e}}{1 + e \cdot \cos v} \]
    9. lift-literalN/A

      \[\leadsto \frac{\sin v \cdot e}{\color{blue}{1} + e \cdot \cos v} \]
    10. lift-varN/A

      \[\leadsto \frac{\sin v \cdot e}{1 + \color{blue}{e} \cdot \cos v} \]
    11. lift-varN/A

      \[\leadsto \frac{\sin v \cdot e}{1 + \mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \cos \color{blue}{v}} \]
    12. lift-cos.f64N/A

      \[\leadsto \frac{\sin v \cdot e}{1 + \mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \color{blue}{\cos v}} \]
    13. lift-*.f64N/A

      \[\leadsto \frac{\sin v \cdot e}{1 + \color{blue}{e \cdot \cos v}} \]
    14. lift-+.f64N/A

      \[\leadsto \frac{\sin v \cdot e}{\color{blue}{1 + e \cdot \cos v}} \]
    15. lower-fma.f64N/A

      \[\leadsto \frac{\sin v \cdot e}{\color{blue}{\mathsf{fma}\left(\cos v, e, 1\right)}} \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\frac{\sin v \cdot e}{\mathsf{fma}\left(\cos v, e, 1\right)}} \]
  5. Add Preprocessing

Alternative 2: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sin v \cdot \frac{e}{\mathsf{fma}\left(\cos v, e, 1\right)} \end{array} \]
(FPCore (e v) :precision binary64 (* (sin v) (/ e (fma (cos v) e 1.0))))
double code(double e, double v) {
	return sin(v) * (e / fma(cos(v), e, 1.0));
}
function code(e, v)
	return Float64(sin(v) * Float64(e / fma(cos(v), e, 1.0)))
end
code[e_, v_] := N[(N[Sin[v], $MachinePrecision] * N[(e / N[(N[Cos[v], $MachinePrecision] * e + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sin v \cdot \frac{e}{\mathsf{fma}\left(\cos v, e, 1\right)}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-varN/A

      \[\leadsto \frac{\color{blue}{e} \cdot \sin v}{1 + e \cdot \cos v} \]
    2. lift-varN/A

      \[\leadsto \frac{\mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \sin \color{blue}{v}}{1 + e \cdot \cos v} \]
    3. lift-sin.f64N/A

      \[\leadsto \frac{\mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \color{blue}{\sin v}}{1 + e \cdot \cos v} \]
    4. lift-*.f64N/A

      \[\leadsto \frac{\color{blue}{e \cdot \sin v}}{1 + e \cdot \cos v} \]
    5. lift-literalN/A

      \[\leadsto \frac{e \cdot \sin v}{\color{blue}{1} + e \cdot \cos v} \]
    6. lift-varN/A

      \[\leadsto \frac{e \cdot \sin v}{1 + \color{blue}{e} \cdot \cos v} \]
    7. lift-varN/A

      \[\leadsto \frac{e \cdot \sin v}{1 + \mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \cos \color{blue}{v}} \]
    8. lift-cos.f64N/A

      \[\leadsto \frac{e \cdot \sin v}{1 + \mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \color{blue}{\cos v}} \]
    9. lift-*.f64N/A

      \[\leadsto \frac{e \cdot \sin v}{1 + \color{blue}{e \cdot \cos v}} \]
    10. lift-+.f64N/A

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

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

      \[\leadsto \color{blue}{\sin v \cdot \frac{e}{1 + e \cdot \cos v}} \]
  4. Applied rewrites99.8%

    \[\leadsto \color{blue}{\sin v \cdot \frac{e}{\mathsf{fma}\left(\cos v, e, 1\right)}} \]
  5. Add Preprocessing

Alternative 3: 98.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sin v \cdot \mathsf{fma}\left(\left(-e\right) \cdot e, \cos v, e\right) \end{array} \]
(FPCore (e v) :precision binary64 (* (sin v) (fma (* (- e) e) (cos v) e)))
double code(double e, double v) {
	return sin(v) * fma((-e * e), cos(v), e);
}
function code(e, v)
	return Float64(sin(v) * fma(Float64(Float64(-e) * e), cos(v), e))
end
code[e_, v_] := N[(N[Sin[v], $MachinePrecision] * N[(N[((-e) * e), $MachinePrecision] * N[Cos[v], $MachinePrecision] + e), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sin v \cdot \mathsf{fma}\left(\left(-e\right) \cdot e, \cos v, e\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-varN/A

      \[\leadsto \frac{\color{blue}{e} \cdot \sin v}{1 + e \cdot \cos v} \]
    2. lift-varN/A

      \[\leadsto \frac{\mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \sin \color{blue}{v}}{1 + e \cdot \cos v} \]
    3. lift-sin.f64N/A

      \[\leadsto \frac{\mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \color{blue}{\sin v}}{1 + e \cdot \cos v} \]
    4. lift-*.f64N/A

      \[\leadsto \frac{\color{blue}{e \cdot \sin v}}{1 + e \cdot \cos v} \]
    5. lift-literalN/A

      \[\leadsto \frac{e \cdot \sin v}{\color{blue}{1} + e \cdot \cos v} \]
    6. lift-varN/A

      \[\leadsto \frac{e \cdot \sin v}{1 + \color{blue}{e} \cdot \cos v} \]
    7. lift-varN/A

      \[\leadsto \frac{e \cdot \sin v}{1 + \mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \cos \color{blue}{v}} \]
    8. lift-cos.f64N/A

      \[\leadsto \frac{e \cdot \sin v}{1 + \mathsf{Rewrite<=}\left(lift-var-spec, e\right) \cdot \color{blue}{\cos v}} \]
    9. lift-*.f64N/A

      \[\leadsto \frac{e \cdot \sin v}{1 + \color{blue}{e \cdot \cos v}} \]
    10. lift-+.f64N/A

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

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

      \[\leadsto \color{blue}{\sin v \cdot \frac{e}{1 + e \cdot \cos v}} \]
  4. Applied rewrites99.8%

    \[\leadsto \color{blue}{\sin v \cdot \frac{e}{\mathsf{fma}\left(\cos v, e, 1\right)}} \]
  5. Taylor expanded in e around 0

    \[\leadsto \sin v \cdot \color{blue}{\left(e \cdot \left(1 + -1 \cdot \left(e \cdot \cos v\right)\right)\right)} \]
  6. Step-by-step derivation
    1. Applied rewrites99.3%

      \[\leadsto \sin v \cdot \color{blue}{\mathsf{fma}\left(\left(-e\right) \cdot e, \cos v, e\right)} \]
    2. Add Preprocessing

    Alternative 4: 98.5% accurate, 1.6× speedup?

    \[\begin{array}{l} \\ \frac{\sin v}{\frac{\frac{\mathsf{fma}\left(e, e, e\right)}{e}}{e}} \end{array} \]
    (FPCore (e v) :precision binary64 (/ (sin v) (/ (/ (fma e e e) e) e)))
    double code(double e, double v) {
    	return sin(v) / ((fma(e, e, e) / e) / e);
    }
    
    function code(e, v)
    	return Float64(sin(v) / Float64(Float64(fma(e, e, e) / e) / e))
    end
    
    code[e_, v_] := N[(N[Sin[v], $MachinePrecision] / N[(N[(N[(e * e + e), $MachinePrecision] / e), $MachinePrecision] / e), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{\sin v}{\frac{\frac{\mathsf{fma}\left(e, e, e\right)}{e}}{e}}
    \end{array}
    
    Derivation
    1. Initial program 99.9%

      \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
    2. Add Preprocessing
    3. Taylor expanded in v around inf

      \[\leadsto \color{blue}{\frac{e \cdot \sin v}{1 + e \cdot \cos v}} \]
    4. Step-by-step derivation
      1. Applied rewrites69.8%

        \[\leadsto \color{blue}{\frac{\sin v}{\frac{e}{e \cdot e} + \cos v}} \]
      2. Taylor expanded in v around 0

        \[\leadsto \frac{\sin v}{1 + \color{blue}{\frac{1}{e}}} \]
      3. Step-by-step derivation
        1. Applied rewrites99.2%

          \[\leadsto \frac{\sin v}{\frac{\frac{\mathsf{fma}\left(e, e, e\right)}{e}}{\color{blue}{e}}} \]
        2. Add Preprocessing

        Alternative 5: 97.5% accurate, 2.1× speedup?

        \[\begin{array}{l} \\ \sin v \cdot e \end{array} \]
        (FPCore (e v) :precision binary64 (* (sin v) e))
        double code(double e, double v) {
        	return sin(v) * e;
        }
        
        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(e, v)
        use fmin_fmax_functions
            real(8), intent (in) :: e
            real(8), intent (in) :: v
            code = sin(v) * e
        end function
        
        public static double code(double e, double v) {
        	return Math.sin(v) * e;
        }
        
        def code(e, v):
        	return math.sin(v) * e
        
        function code(e, v)
        	return Float64(sin(v) * e)
        end
        
        function tmp = code(e, v)
        	tmp = sin(v) * e;
        end
        
        code[e_, v_] := N[(N[Sin[v], $MachinePrecision] * e), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \sin v \cdot e
        \end{array}
        
        Derivation
        1. Initial program 99.9%

          \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
        2. Add Preprocessing
        3. Taylor expanded in e around 0

          \[\leadsto \color{blue}{e \cdot \sin v} \]
        4. Step-by-step derivation
          1. Applied rewrites98.4%

            \[\leadsto \color{blue}{\sin v \cdot e} \]
          2. Add Preprocessing

          Alternative 6: 51.0% accurate, 9.8× speedup?

          \[\begin{array}{l} \\ \frac{v \cdot e}{\mathsf{fma}\left(e, 1, 1\right)} \end{array} \]
          (FPCore (e v) :precision binary64 (/ (* v e) (fma e 1.0 1.0)))
          double code(double e, double v) {
          	return (v * e) / fma(e, 1.0, 1.0);
          }
          
          function code(e, v)
          	return Float64(Float64(v * e) / fma(e, 1.0, 1.0))
          end
          
          code[e_, v_] := N[(N[(v * e), $MachinePrecision] / N[(e * 1.0 + 1.0), $MachinePrecision]), $MachinePrecision]
          
          \begin{array}{l}
          
          \\
          \frac{v \cdot e}{\mathsf{fma}\left(e, 1, 1\right)}
          \end{array}
          
          Derivation
          1. Initial program 99.9%

            \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
          2. Add Preprocessing
          3. Taylor expanded in v around 0

            \[\leadsto \color{blue}{\frac{e \cdot v}{1 + e}} \]
          4. Step-by-step derivation
            1. Applied rewrites54.4%

              \[\leadsto \color{blue}{\frac{v \cdot e}{\frac{\mathsf{fma}\left(e, e, e\right)}{e}}} \]
            2. Step-by-step derivation
              1. Applied rewrites54.4%

                \[\leadsto \frac{v \cdot e}{\mathsf{fma}\left(e, \color{blue}{1}, 1\right)} \]
              2. Add Preprocessing

              Alternative 7: 50.6% accurate, 11.3× speedup?

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

                \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
              2. Add Preprocessing
              3. Taylor expanded in v around 0

                \[\leadsto \color{blue}{\frac{e \cdot v}{1 + e}} \]
              4. Step-by-step derivation
                1. Applied rewrites54.4%

                  \[\leadsto \color{blue}{\frac{v \cdot e}{\frac{\mathsf{fma}\left(e, e, e\right)}{e}}} \]
                2. Taylor expanded in e around 0

                  \[\leadsto e \cdot \color{blue}{\left(v + e \cdot \left(e \cdot v - v\right)\right)} \]
                3. Step-by-step derivation
                  1. Applied rewrites54.1%

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

                  Alternative 8: 50.4% accurate, 16.1× speedup?

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

                    \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
                  2. Add Preprocessing
                  3. Taylor expanded in v around 0

                    \[\leadsto \color{blue}{\frac{e \cdot v}{1 + e}} \]
                  4. Step-by-step derivation
                    1. Applied rewrites54.4%

                      \[\leadsto \color{blue}{\frac{v \cdot e}{\frac{\mathsf{fma}\left(e, e, e\right)}{e}}} \]
                    2. Taylor expanded in e around 0

                      \[\leadsto e \cdot \color{blue}{\left(v + -1 \cdot \left(e \cdot v\right)\right)} \]
                    3. Step-by-step derivation
                      1. Applied rewrites54.0%

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

                      Alternative 9: 49.9% accurate, 37.5× speedup?

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

                        \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
                      2. Add Preprocessing
                      3. Taylor expanded in e around 0

                        \[\leadsto \color{blue}{e \cdot \sin v} \]
                      4. Step-by-step derivation
                        1. Applied rewrites98.4%

                          \[\leadsto \color{blue}{\sin v \cdot e} \]
                        2. Taylor expanded in v around 0

                          \[\leadsto v \cdot e \]
                        3. Step-by-step derivation
                          1. Applied rewrites53.3%

                            \[\leadsto v \cdot e \]
                          2. Add Preprocessing

                          Alternative 10: 4.5% accurate, 225.0× speedup?

                          \[\begin{array}{l} \\ v \end{array} \]
                          (FPCore (e v) :precision binary64 v)
                          double code(double e, double v) {
                          	return v;
                          }
                          
                          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(e, v)
                          use fmin_fmax_functions
                              real(8), intent (in) :: e
                              real(8), intent (in) :: v
                              code = v
                          end function
                          
                          public static double code(double e, double v) {
                          	return v;
                          }
                          
                          def code(e, v):
                          	return v
                          
                          function code(e, v)
                          	return v
                          end
                          
                          function tmp = code(e, v)
                          	tmp = v;
                          end
                          
                          code[e_, v_] := v
                          
                          \begin{array}{l}
                          
                          \\
                          v
                          \end{array}
                          
                          Derivation
                          1. Initial program 99.9%

                            \[\frac{e \cdot \sin v}{1 + e \cdot \cos v} \]
                          2. Add Preprocessing
                          3. Taylor expanded in v around 0

                            \[\leadsto \color{blue}{\frac{e \cdot v}{1 + e}} \]
                          4. Step-by-step derivation
                            1. Applied rewrites54.4%

                              \[\leadsto \color{blue}{\frac{v \cdot e}{\frac{\mathsf{fma}\left(e, e, e\right)}{e}}} \]
                            2. Taylor expanded in e around inf

                              \[\leadsto v \]
                            3. Step-by-step derivation
                              1. Applied rewrites4.7%

                                \[\leadsto v \]
                              2. Add Preprocessing

                              Reproduce

                              ?
                              herbie shell --seed 2025021 
                              (FPCore (e v)
                                :name "Trigonometry A"
                                :precision binary64
                                :pre (and (<= 0.0 e) (<= e 1.0))
                                (/ (* e (sin v)) (+ 1.0 (* e (cos v)))))