(cos (* -314159265359/50000000000 z0))

Percentage Accurate: 57.3% → 57.3%
Time: 1.9s
Alternatives: 6
Speedup: 0.6×

Specification

?
\[\cos \left(-6.28318530718 \cdot z0\right) \]
(FPCore (z0)
  :precision binary64
  (cos (* -6.28318530718 z0)))
double code(double z0) {
	return cos((-6.28318530718 * z0));
}
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(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = cos(((-6.28318530718d0) * z0))
end function
public static double code(double z0) {
	return Math.cos((-6.28318530718 * z0));
}
def code(z0):
	return math.cos((-6.28318530718 * z0))
function code(z0)
	return cos(Float64(-6.28318530718 * z0))
end
function tmp = code(z0)
	tmp = cos((-6.28318530718 * z0));
end
code[z0_] := N[Cos[N[(-6.28318530718 * z0), $MachinePrecision]], $MachinePrecision]
\cos \left(-6.28318530718 \cdot z0\right)

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 6 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: 57.3% accurate, 1.0× speedup?

\[\cos \left(-6.28318530718 \cdot z0\right) \]
(FPCore (z0)
  :precision binary64
  (cos (* -6.28318530718 z0)))
double code(double z0) {
	return cos((-6.28318530718 * z0));
}
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(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = cos(((-6.28318530718d0) * z0))
end function
public static double code(double z0) {
	return Math.cos((-6.28318530718 * z0));
}
def code(z0):
	return math.cos((-6.28318530718 * z0))
function code(z0)
	return cos(Float64(-6.28318530718 * z0))
end
function tmp = code(z0)
	tmp = cos((-6.28318530718 * z0));
end
code[z0_] := N[Cos[N[(-6.28318530718 * z0), $MachinePrecision]], $MachinePrecision]
\cos \left(-6.28318530718 \cdot z0\right)

Alternative 1: 57.3% accurate, 0.6× speedup?

\[\begin{array}{l} t_0 := \sqrt{\frac{1}{\left|z0\right|}}\\ \cos \left(\frac{1}{\left(-0.15915494309188485 \cdot t\_0\right) \cdot t\_0}\right) \end{array} \]
(FPCore (z0)
  :precision binary64
  (let* ((t_0 (sqrt (/ 1.0 (fabs z0)))))
  (cos (/ 1.0 (* (* -0.15915494309188485 t_0) t_0)))))
double code(double z0) {
	double t_0 = sqrt((1.0 / fabs(z0)));
	return cos((1.0 / ((-0.15915494309188485 * t_0) * t_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(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    real(8) :: t_0
    t_0 = sqrt((1.0d0 / abs(z0)))
    code = cos((1.0d0 / (((-0.15915494309188485d0) * t_0) * t_0)))
end function
public static double code(double z0) {
	double t_0 = Math.sqrt((1.0 / Math.abs(z0)));
	return Math.cos((1.0 / ((-0.15915494309188485 * t_0) * t_0)));
}
def code(z0):
	t_0 = math.sqrt((1.0 / math.fabs(z0)))
	return math.cos((1.0 / ((-0.15915494309188485 * t_0) * t_0)))
function code(z0)
	t_0 = sqrt(Float64(1.0 / abs(z0)))
	return cos(Float64(1.0 / Float64(Float64(-0.15915494309188485 * t_0) * t_0)))
end
function tmp = code(z0)
	t_0 = sqrt((1.0 / abs(z0)));
	tmp = cos((1.0 / ((-0.15915494309188485 * t_0) * t_0)));
end
code[z0_] := Block[{t$95$0 = N[Sqrt[N[(1.0 / N[Abs[z0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[Cos[N[(1.0 / N[(N[(-0.15915494309188485 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
t_0 := \sqrt{\frac{1}{\left|z0\right|}}\\
\cos \left(\frac{1}{\left(-0.15915494309188485 \cdot t\_0\right) \cdot t\_0}\right)
\end{array}
Derivation
  1. Initial program 57.3%

    \[\cos \left(-6.28318530718 \cdot z0\right) \]
  2. Step-by-step derivation
    1. *-rgt-identityN/A

      \[\leadsto \cos \color{blue}{\left(\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 1\right)} \]
    2. metadata-evalN/A

      \[\leadsto \cos \left(\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot \color{blue}{\frac{2}{2}}\right) \]
    3. associate-/l*N/A

      \[\leadsto \cos \color{blue}{\left(\frac{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}{2}\right)} \]
    4. div-flipN/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}\right)} \]
    5. lower-unsound-/.f64N/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}\right)} \]
    6. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}}\right) \]
    7. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot z0\right)} \cdot 2}}\right) \]
    8. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(z0 \cdot \frac{-314159265359}{50000000000}\right)} \cdot 2}}\right) \]
    9. associate-*l*N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{z0 \cdot \left(\frac{-314159265359}{50000000000} \cdot 2\right)}}}\right) \]
    10. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot 2\right) \cdot z0}}}\right) \]
    11. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot 2\right) \cdot z0}}}\right) \]
    12. metadata-eval57.3%

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{-12.56637061436} \cdot z0}}\right) \]
  3. Applied rewrites57.3%

    \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{-12.56637061436 \cdot z0}}\right)} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000} \cdot z0}}}\right) \]
    2. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\frac{-314159265359}{25000000000} \cdot z0}}}\right) \]
    3. associate-/r*N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{\frac{2}{\frac{-314159265359}{25000000000}}}{z0}}}\right) \]
    4. mult-flipN/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000}} \cdot \frac{1}{z0}}}\right) \]
    5. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000}} \cdot \frac{1}{z0}}}\right) \]
    6. metadata-evalN/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{-50000000000}{314159265359}} \cdot \frac{1}{z0}}\right) \]
    7. lower-/.f6457.2%

      \[\leadsto \cos \left(\frac{1}{-0.15915494309188485 \cdot \color{blue}{\frac{1}{z0}}}\right) \]
  5. Applied rewrites57.2%

    \[\leadsto \cos \left(\frac{1}{\color{blue}{-0.15915494309188485 \cdot \frac{1}{z0}}}\right) \]
  6. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\frac{1}{z0}}}\right) \]
    2. inv-powN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{{z0}^{-1}}}\right) \]
    3. sqr-powN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    4. lower-unsound-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    5. lower-unsound-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left(\color{blue}{{z0}^{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right) \]
    6. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\color{blue}{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right) \]
    7. lower-unsound-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{z0}^{\left(\frac{-1}{2}\right)}}\right)}\right) \]
    8. lower-unsound-/.f6428.3%

      \[\leadsto \cos \left(\frac{1}{-0.15915494309188485 \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\color{blue}{\left(\frac{-1}{2}\right)}}\right)}\right) \]
  7. Applied rewrites28.3%

    \[\leadsto \cos \left(\frac{1}{-0.15915494309188485 \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
  8. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    2. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    3. sqr-abs-revN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\left(\left|{z0}^{\left(\frac{-1}{2}\right)}\right| \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|\right)}}\right) \]
    4. associate-*r*N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\left(\frac{-50000000000}{314159265359} \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}}\right) \]
    5. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\left(\frac{-50000000000}{314159265359} \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}}\right) \]
    6. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\left(\frac{-50000000000}{314159265359} \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|\right)} \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    7. rem-sqrt-square-revN/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \color{blue}{\sqrt{{z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}}}\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    8. lift-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{\color{blue}{{z0}^{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}}\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    9. lift-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{{z0}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{z0}^{\left(\frac{-1}{2}\right)}}}\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    10. pow-sqrN/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{\color{blue}{{z0}^{\left(2 \cdot \frac{-1}{2}\right)}}}\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    11. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{{z0}^{\left(2 \cdot \color{blue}{\frac{-1}{2}}\right)}}\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    12. metadata-evalN/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{{z0}^{\left(2 \cdot \color{blue}{\frac{-1}{2}}\right)}}\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    13. metadata-evalN/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{{z0}^{\color{blue}{-1}}}\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    14. inv-powN/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{\color{blue}{\frac{1}{z0}}}\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    15. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{\color{blue}{\frac{1}{z0}}}\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    16. lower-sqrt.f64N/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \color{blue}{\sqrt{\frac{1}{z0}}}\right) \cdot \left|{z0}^{\left(\frac{-1}{2}\right)}\right|}\right) \]
    17. rem-sqrt-square-revN/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{\frac{1}{z0}}\right) \cdot \color{blue}{\sqrt{{z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}}}}\right) \]
    18. lift-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{\frac{1}{z0}}\right) \cdot \sqrt{\color{blue}{{z0}^{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}}}\right) \]
    19. lift-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{\frac{1}{z0}}\right) \cdot \sqrt{{z0}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{z0}^{\left(\frac{-1}{2}\right)}}}}\right) \]
    20. pow-sqrN/A

      \[\leadsto \cos \left(\frac{1}{\left(\frac{-50000000000}{314159265359} \cdot \sqrt{\frac{1}{z0}}\right) \cdot \sqrt{\color{blue}{{z0}^{\left(2 \cdot \frac{-1}{2}\right)}}}}\right) \]
  9. Applied rewrites28.3%

    \[\leadsto \cos \left(\frac{1}{\color{blue}{\left(-0.15915494309188485 \cdot \sqrt{\frac{1}{z0}}\right) \cdot \sqrt{\frac{1}{z0}}}}\right) \]
  10. Add Preprocessing

Alternative 2: 57.3% accurate, 0.8× speedup?

\[\cos \left(\frac{1}{-0.15915494309188485 \cdot \frac{1}{z0}}\right) \]
(FPCore (z0)
  :precision binary64
  (cos (/ 1.0 (* -0.15915494309188485 (/ 1.0 z0)))))
double code(double z0) {
	return cos((1.0 / (-0.15915494309188485 * (1.0 / z0))));
}
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(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = cos((1.0d0 / ((-0.15915494309188485d0) * (1.0d0 / z0))))
end function
public static double code(double z0) {
	return Math.cos((1.0 / (-0.15915494309188485 * (1.0 / z0))));
}
def code(z0):
	return math.cos((1.0 / (-0.15915494309188485 * (1.0 / z0))))
function code(z0)
	return cos(Float64(1.0 / Float64(-0.15915494309188485 * Float64(1.0 / z0))))
end
function tmp = code(z0)
	tmp = cos((1.0 / (-0.15915494309188485 * (1.0 / z0))));
end
code[z0_] := N[Cos[N[(1.0 / N[(-0.15915494309188485 * N[(1.0 / z0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\cos \left(\frac{1}{-0.15915494309188485 \cdot \frac{1}{z0}}\right)
Derivation
  1. Initial program 57.3%

    \[\cos \left(-6.28318530718 \cdot z0\right) \]
  2. Step-by-step derivation
    1. *-rgt-identityN/A

      \[\leadsto \cos \color{blue}{\left(\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 1\right)} \]
    2. metadata-evalN/A

      \[\leadsto \cos \left(\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot \color{blue}{\frac{2}{2}}\right) \]
    3. associate-/l*N/A

      \[\leadsto \cos \color{blue}{\left(\frac{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}{2}\right)} \]
    4. div-flipN/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}\right)} \]
    5. lower-unsound-/.f64N/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}\right)} \]
    6. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}}\right) \]
    7. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot z0\right)} \cdot 2}}\right) \]
    8. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(z0 \cdot \frac{-314159265359}{50000000000}\right)} \cdot 2}}\right) \]
    9. associate-*l*N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{z0 \cdot \left(\frac{-314159265359}{50000000000} \cdot 2\right)}}}\right) \]
    10. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot 2\right) \cdot z0}}}\right) \]
    11. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot 2\right) \cdot z0}}}\right) \]
    12. metadata-eval57.3%

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{-12.56637061436} \cdot z0}}\right) \]
  3. Applied rewrites57.3%

    \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{-12.56637061436 \cdot z0}}\right)} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000} \cdot z0}}}\right) \]
    2. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\frac{-314159265359}{25000000000} \cdot z0}}}\right) \]
    3. associate-/r*N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{\frac{2}{\frac{-314159265359}{25000000000}}}{z0}}}\right) \]
    4. mult-flipN/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000}} \cdot \frac{1}{z0}}}\right) \]
    5. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000}} \cdot \frac{1}{z0}}}\right) \]
    6. metadata-evalN/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{-50000000000}{314159265359}} \cdot \frac{1}{z0}}\right) \]
    7. lower-/.f6457.2%

      \[\leadsto \cos \left(\frac{1}{-0.15915494309188485 \cdot \color{blue}{\frac{1}{z0}}}\right) \]
  5. Applied rewrites57.2%

    \[\leadsto \cos \left(\frac{1}{\color{blue}{-0.15915494309188485 \cdot \frac{1}{z0}}}\right) \]
  6. Add Preprocessing

Alternative 3: 57.3% accurate, 0.9× speedup?

\[\cos \left(\frac{6.28318530718}{\frac{-1}{z0}}\right) \]
(FPCore (z0)
  :precision binary64
  (cos (/ 6.28318530718 (/ -1.0 z0))))
double code(double z0) {
	return cos((6.28318530718 / (-1.0 / z0)));
}
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(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = cos((6.28318530718d0 / ((-1.0d0) / z0)))
end function
public static double code(double z0) {
	return Math.cos((6.28318530718 / (-1.0 / z0)));
}
def code(z0):
	return math.cos((6.28318530718 / (-1.0 / z0)))
function code(z0)
	return cos(Float64(6.28318530718 / Float64(-1.0 / z0)))
end
function tmp = code(z0)
	tmp = cos((6.28318530718 / (-1.0 / z0)));
end
code[z0_] := N[Cos[N[(6.28318530718 / N[(-1.0 / z0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\cos \left(\frac{6.28318530718}{\frac{-1}{z0}}\right)
Derivation
  1. Initial program 57.3%

    \[\cos \left(-6.28318530718 \cdot z0\right) \]
  2. Step-by-step derivation
    1. *-rgt-identityN/A

      \[\leadsto \cos \color{blue}{\left(\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 1\right)} \]
    2. metadata-evalN/A

      \[\leadsto \cos \left(\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot \color{blue}{\frac{2}{2}}\right) \]
    3. associate-/l*N/A

      \[\leadsto \cos \color{blue}{\left(\frac{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}{2}\right)} \]
    4. div-flipN/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}\right)} \]
    5. lower-unsound-/.f64N/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}\right)} \]
    6. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}}\right) \]
    7. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot z0\right)} \cdot 2}}\right) \]
    8. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(z0 \cdot \frac{-314159265359}{50000000000}\right)} \cdot 2}}\right) \]
    9. associate-*l*N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{z0 \cdot \left(\frac{-314159265359}{50000000000} \cdot 2\right)}}}\right) \]
    10. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot 2\right) \cdot z0}}}\right) \]
    11. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot 2\right) \cdot z0}}}\right) \]
    12. metadata-eval57.3%

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{-12.56637061436} \cdot z0}}\right) \]
  3. Applied rewrites57.3%

    \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{-12.56637061436 \cdot z0}}\right)} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000} \cdot z0}}}\right) \]
    2. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\frac{-314159265359}{25000000000} \cdot z0}}}\right) \]
    3. associate-/r*N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{\frac{2}{\frac{-314159265359}{25000000000}}}{z0}}}\right) \]
    4. mult-flipN/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000}} \cdot \frac{1}{z0}}}\right) \]
    5. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000}} \cdot \frac{1}{z0}}}\right) \]
    6. metadata-evalN/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{-50000000000}{314159265359}} \cdot \frac{1}{z0}}\right) \]
    7. lower-/.f6457.2%

      \[\leadsto \cos \left(\frac{1}{-0.15915494309188485 \cdot \color{blue}{\frac{1}{z0}}}\right) \]
  5. Applied rewrites57.2%

    \[\leadsto \cos \left(\frac{1}{\color{blue}{-0.15915494309188485 \cdot \frac{1}{z0}}}\right) \]
  6. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\frac{1}{z0}}}\right) \]
    2. inv-powN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{{z0}^{-1}}}\right) \]
    3. sqr-powN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    4. lower-unsound-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    5. lower-unsound-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left(\color{blue}{{z0}^{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right) \]
    6. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\color{blue}{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right) \]
    7. lower-unsound-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{z0}^{\left(\frac{-1}{2}\right)}}\right)}\right) \]
    8. lower-unsound-/.f6428.3%

      \[\leadsto \cos \left(\frac{1}{-0.15915494309188485 \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\color{blue}{\left(\frac{-1}{2}\right)}}\right)}\right) \]
  7. Applied rewrites28.3%

    \[\leadsto \cos \left(\frac{1}{-0.15915494309188485 \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
  8. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    3. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\color{blue}{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right) \]
    4. lower-unsound-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left(\color{blue}{{z0}^{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right) \]
    5. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\color{blue}{\left(\frac{-1}{2}\right)}}\right)}\right) \]
    6. lower-unsound-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{z0}^{\left(\frac{-1}{2}\right)}}\right)}\right) \]
    7. lower-unsound-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    8. sqr-powN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{{z0}^{-1}}}\right) \]
    9. inv-powN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\frac{1}{z0}}}\right) \]
    10. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\frac{1}{z0}}}\right) \]
    11. associate-/r*N/A

      \[\leadsto \cos \color{blue}{\left(\frac{\frac{1}{\frac{-50000000000}{314159265359}}}{\frac{1}{z0}}\right)} \]
    12. metadata-evalN/A

      \[\leadsto \cos \left(\frac{\color{blue}{\frac{-314159265359}{50000000000}}}{\frac{1}{z0}}\right) \]
    13. frac-2negN/A

      \[\leadsto \cos \color{blue}{\left(\frac{\mathsf{neg}\left(\frac{-314159265359}{50000000000}\right)}{\mathsf{neg}\left(\frac{1}{z0}\right)}\right)} \]
    14. metadata-evalN/A

      \[\leadsto \cos \left(\frac{\color{blue}{\frac{314159265359}{50000000000}}}{\mathsf{neg}\left(\frac{1}{z0}\right)}\right) \]
    15. lower-/.f64N/A

      \[\leadsto \cos \color{blue}{\left(\frac{\frac{314159265359}{50000000000}}{\mathsf{neg}\left(\frac{1}{z0}\right)}\right)} \]
    16. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{\frac{314159265359}{50000000000}}{\mathsf{neg}\left(\color{blue}{\frac{1}{z0}}\right)}\right) \]
    17. distribute-neg-fracN/A

      \[\leadsto \cos \left(\frac{\frac{314159265359}{50000000000}}{\color{blue}{\frac{\mathsf{neg}\left(1\right)}{z0}}}\right) \]
    18. metadata-evalN/A

      \[\leadsto \cos \left(\frac{\frac{314159265359}{50000000000}}{\frac{\color{blue}{-1}}{z0}}\right) \]
    19. lower-/.f6457.3%

      \[\leadsto \cos \left(\frac{6.28318530718}{\color{blue}{\frac{-1}{z0}}}\right) \]
  9. Applied rewrites57.3%

    \[\leadsto \cos \color{blue}{\left(\frac{6.28318530718}{\frac{-1}{z0}}\right)} \]
  10. Add Preprocessing

Alternative 4: 57.2% accurate, 0.9× speedup?

\[\cos \left(\frac{z0}{-0.15915494309188485}\right) \]
(FPCore (z0)
  :precision binary64
  (cos (/ z0 -0.15915494309188485)))
double code(double z0) {
	return cos((z0 / -0.15915494309188485));
}
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(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = cos((z0 / (-0.15915494309188485d0)))
end function
public static double code(double z0) {
	return Math.cos((z0 / -0.15915494309188485));
}
def code(z0):
	return math.cos((z0 / -0.15915494309188485))
function code(z0)
	return cos(Float64(z0 / -0.15915494309188485))
end
function tmp = code(z0)
	tmp = cos((z0 / -0.15915494309188485));
end
code[z0_] := N[Cos[N[(z0 / -0.15915494309188485), $MachinePrecision]], $MachinePrecision]
\cos \left(\frac{z0}{-0.15915494309188485}\right)
Derivation
  1. Initial program 57.3%

    \[\cos \left(-6.28318530718 \cdot z0\right) \]
  2. Step-by-step derivation
    1. *-rgt-identityN/A

      \[\leadsto \cos \color{blue}{\left(\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 1\right)} \]
    2. metadata-evalN/A

      \[\leadsto \cos \left(\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot \color{blue}{\frac{2}{2}}\right) \]
    3. associate-/l*N/A

      \[\leadsto \cos \color{blue}{\left(\frac{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}{2}\right)} \]
    4. div-flipN/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}\right)} \]
    5. lower-unsound-/.f64N/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}\right)} \]
    6. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\left(\frac{-314159265359}{50000000000} \cdot z0\right) \cdot 2}}}\right) \]
    7. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot z0\right)} \cdot 2}}\right) \]
    8. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(z0 \cdot \frac{-314159265359}{50000000000}\right)} \cdot 2}}\right) \]
    9. associate-*l*N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{z0 \cdot \left(\frac{-314159265359}{50000000000} \cdot 2\right)}}}\right) \]
    10. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot 2\right) \cdot z0}}}\right) \]
    11. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\left(\frac{-314159265359}{50000000000} \cdot 2\right) \cdot z0}}}\right) \]
    12. metadata-eval57.3%

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{-12.56637061436} \cdot z0}}\right) \]
  3. Applied rewrites57.3%

    \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{2}{-12.56637061436 \cdot z0}}\right)} \]
  4. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000} \cdot z0}}}\right) \]
    2. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{2}{\color{blue}{\frac{-314159265359}{25000000000} \cdot z0}}}\right) \]
    3. associate-/r*N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{\frac{2}{\frac{-314159265359}{25000000000}}}{z0}}}\right) \]
    4. mult-flipN/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000}} \cdot \frac{1}{z0}}}\right) \]
    5. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{2}{\frac{-314159265359}{25000000000}} \cdot \frac{1}{z0}}}\right) \]
    6. metadata-evalN/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{-50000000000}{314159265359}} \cdot \frac{1}{z0}}\right) \]
    7. lower-/.f6457.2%

      \[\leadsto \cos \left(\frac{1}{-0.15915494309188485 \cdot \color{blue}{\frac{1}{z0}}}\right) \]
  5. Applied rewrites57.2%

    \[\leadsto \cos \left(\frac{1}{\color{blue}{-0.15915494309188485 \cdot \frac{1}{z0}}}\right) \]
  6. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\frac{1}{z0}}}\right) \]
    2. inv-powN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{{z0}^{-1}}}\right) \]
    3. sqr-powN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    4. lower-unsound-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    5. lower-unsound-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left(\color{blue}{{z0}^{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right) \]
    6. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\color{blue}{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right) \]
    7. lower-unsound-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{z0}^{\left(\frac{-1}{2}\right)}}\right)}\right) \]
    8. lower-unsound-/.f6428.3%

      \[\leadsto \cos \left(\frac{1}{-0.15915494309188485 \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\color{blue}{\left(\frac{-1}{2}\right)}}\right)}\right) \]
  7. Applied rewrites28.3%

    \[\leadsto \cos \left(\frac{1}{-0.15915494309188485 \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
  8. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    3. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\color{blue}{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right) \]
    4. lower-unsound-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left(\color{blue}{{z0}^{\left(\frac{-1}{2}\right)}} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}\right) \]
    5. lower-unsound-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\color{blue}{\left(\frac{-1}{2}\right)}}\right)}\right) \]
    6. lower-unsound-pow.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \left({z0}^{\left(\frac{-1}{2}\right)} \cdot \color{blue}{{z0}^{\left(\frac{-1}{2}\right)}}\right)}\right) \]
    7. lower-unsound-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\left({z0}^{\left(\frac{-1}{2}\right)} \cdot {z0}^{\left(\frac{-1}{2}\right)}\right)}}\right) \]
    8. sqr-powN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{{z0}^{-1}}}\right) \]
    9. inv-powN/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\frac{1}{z0}}}\right) \]
    10. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\frac{-50000000000}{314159265359} \cdot \color{blue}{\frac{1}{z0}}}\right) \]
    11. metadata-evalN/A

      \[\leadsto \cos \left(\frac{\color{blue}{1 \cdot 1}}{\frac{-50000000000}{314159265359} \cdot \frac{1}{z0}}\right) \]
    12. *-commutativeN/A

      \[\leadsto \cos \left(\frac{1 \cdot 1}{\color{blue}{\frac{1}{z0} \cdot \frac{-50000000000}{314159265359}}}\right) \]
    13. frac-timesN/A

      \[\leadsto \cos \color{blue}{\left(\frac{1}{\frac{1}{z0}} \cdot \frac{1}{\frac{-50000000000}{314159265359}}\right)} \]
    14. lift-/.f64N/A

      \[\leadsto \cos \left(\frac{1}{\color{blue}{\frac{1}{z0}}} \cdot \frac{1}{\frac{-50000000000}{314159265359}}\right) \]
    15. remove-double-divN/A

      \[\leadsto \cos \left(\color{blue}{z0} \cdot \frac{1}{\frac{-50000000000}{314159265359}}\right) \]
    16. metadata-evalN/A

      \[\leadsto \cos \left(z0 \cdot \color{blue}{\frac{-314159265359}{50000000000}}\right) \]
    17. metadata-evalN/A

      \[\leadsto \cos \left(z0 \cdot \color{blue}{\frac{1}{\frac{-50000000000}{314159265359}}}\right) \]
    18. mult-flip-revN/A

      \[\leadsto \cos \color{blue}{\left(\frac{z0}{\frac{-50000000000}{314159265359}}\right)} \]
    19. lower-/.f6457.3%

      \[\leadsto \cos \color{blue}{\left(\frac{z0}{-0.15915494309188485}\right)} \]
  9. Applied rewrites57.3%

    \[\leadsto \cos \color{blue}{\left(\frac{z0}{-0.15915494309188485}\right)} \]
  10. Add Preprocessing

Alternative 5: 55.8% accurate, 106.0× speedup?

\[1 \]
(FPCore (z0)
  :precision binary64
  1.0)
double code(double z0) {
	return 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(z0)
use fmin_fmax_functions
    real(8), intent (in) :: z0
    code = 1.0d0
end function
public static double code(double z0) {
	return 1.0;
}
def code(z0):
	return 1.0
function code(z0)
	return 1.0
end
function tmp = code(z0)
	tmp = 1.0;
end
code[z0_] := 1.0
1
Derivation
  1. Initial program 57.3%

    \[\cos \left(-6.28318530718 \cdot z0\right) \]
  2. Taylor expanded in z0 around 0

    \[\leadsto \color{blue}{1} \]
  3. Step-by-step derivation
    1. Applied rewrites55.8%

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

    Reproduce

    ?
    herbie shell --seed 2025250 
    (FPCore (z0)
      :name "(cos (* -314159265359/50000000000 z0))"
      :precision binary64
      (cos (* -6.28318530718 z0)))