
(FPCore (F l) :precision binary64 (let* ((t_0 (* (PI) l))) (- t_0 (* (/ 1.0 (* F F)) (tan t_0)))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \ell\\
t\_0 - \frac{1}{F \cdot F} \cdot \tan t\_0
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (F l) :precision binary64 (let* ((t_0 (* (PI) l))) (- t_0 (* (/ 1.0 (* F F)) (tan t_0)))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \ell\\
t\_0 - \frac{1}{F \cdot F} \cdot \tan t\_0
\end{array}
\end{array}
l\_m = (fabs.f64 l)
l\_s = (copysign.f64 #s(literal 1 binary64) l)
(FPCore (l_s F l_m)
:precision binary64
(let* ((t_0 (* (PI) l_m)))
(*
l_s
(if (<= l_m 320.0)
(- t_0 (/ (* (pow F -1.0) (sin t_0)) (* F (cos t_0))))
t_0))))\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot l\_m\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \leq 320:\\
\;\;\;\;t\_0 - \frac{{F}^{-1} \cdot \sin t\_0}{F \cdot \cos t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if l < 320Initial program 86.5%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-tan.f64N/A
quot-tanN/A
frac-timesN/A
lower-/.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6491.8
Applied rewrites91.8%
if 320 < l Initial program 67.4%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.4
Applied rewrites99.4%
l\_m = (fabs.f64 l)
l\_s = (copysign.f64 #s(literal 1 binary64) l)
(FPCore (l_s F l_m)
:precision binary64
(let* ((t_0 (* (PI) l_m)))
(*
l_s
(if (<= (- t_0 (* (/ 1.0 (* F F)) (tan t_0))) -1e-247)
(* (- l_m) (/ (PI) (* F F)))
t_0))))\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot l\_m\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 - \frac{1}{F \cdot F} \cdot \tan t\_0 \leq -1 \cdot 10^{-247}:\\
\;\;\;\;\left(-l\_m\right) \cdot \frac{\mathsf{PI}\left(\right)}{F \cdot F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if (-.f64 (*.f64 (PI.f64) l) (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 F F)) (tan.f64 (*.f64 (PI.f64) l)))) < -1e-247Initial program 80.4%
Taylor expanded in F around 0
associate-*r/N/A
times-fracN/A
quot-tanN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-tan.f6426.5
Applied rewrites26.5%
Taylor expanded in l around 0
mul-1-negN/A
associate-/l*N/A
lower-neg.f64N/A
lower-*.f64N/A
pow2N/A
lift-/.f64N/A
lift-PI.f64N/A
lift-*.f6424.9
Applied rewrites24.9%
if -1e-247 < (-.f64 (*.f64 (PI.f64) l) (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 F F)) (tan.f64 (*.f64 (PI.f64) l)))) Initial program 83.2%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6480.5
Applied rewrites80.5%
Final simplification51.8%
l\_m = (fabs.f64 l) l\_s = (copysign.f64 #s(literal 1 binary64) l) (FPCore (l_s F l_m) :precision binary64 (let* ((t_0 (* (PI) l_m))) (* l_s (if (<= l_m 320.0) (- t_0 (/ (/ (tan t_0) F) F)) t_0))))
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot l\_m\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \leq 320:\\
\;\;\;\;t\_0 - \frac{\frac{\tan t\_0}{F}}{F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if l < 320Initial program 86.5%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-tan.f64N/A
quot-tanN/A
frac-timesN/A
lower-/.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6491.8
Applied rewrites91.8%
lift-/.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
times-fracN/A
lift-pow.f64N/A
inv-powN/A
associate-/r*N/A
pow2N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites91.8%
if 320 < l Initial program 67.4%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.4
Applied rewrites99.4%
l\_m = (fabs.f64 l) l\_s = (copysign.f64 #s(literal 1 binary64) l) (FPCore (l_s F l_m) :precision binary64 (let* ((t_0 (* (PI) l_m))) (* l_s (if (<= l_m 50.0) (- t_0 (/ (* (/ (PI) F) l_m) F)) t_0))))
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot l\_m\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \leq 50:\\
\;\;\;\;t\_0 - \frac{\frac{\mathsf{PI}\left(\right)}{F} \cdot l\_m}{F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if l < 50Initial program 86.5%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-tan.f64N/A
quot-tanN/A
frac-timesN/A
lower-/.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6491.8
Applied rewrites91.8%
lift-/.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
times-fracN/A
lift-pow.f64N/A
inv-powN/A
associate-/r*N/A
pow2N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites91.8%
Taylor expanded in l around 0
associate-*r/N/A
*-commutativeN/A
lower-*.f64N/A
lift-/.f64N/A
lift-PI.f6484.9
Applied rewrites84.9%
if 50 < l Initial program 67.4%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.4
Applied rewrites99.4%
l\_m = (fabs.f64 l) l\_s = (copysign.f64 #s(literal 1 binary64) l) (FPCore (l_s F l_m) :precision binary64 (let* ((t_0 (* (PI) l_m))) (* l_s (if (<= l_m 50.0) (- t_0 (/ t_0 (* F F))) t_0))))
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot l\_m\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \leq 50:\\
\;\;\;\;t\_0 - \frac{t\_0}{F \cdot F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if l < 50Initial program 86.5%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-tan.f64N/A
quot-tanN/A
frac-timesN/A
lower-/.f64N/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
lower-sin.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6491.8
Applied rewrites91.8%
lift-/.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-cos.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
times-fracN/A
lift-pow.f64N/A
inv-powN/A
associate-/r*N/A
pow2N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
Applied rewrites91.8%
Taylor expanded in l around 0
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6484.9
Applied rewrites84.9%
lift-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
pow2N/A
lower-/.f64N/A
pow2N/A
lift-*.f6479.9
Applied rewrites79.9%
if 50 < l Initial program 67.4%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.4
Applied rewrites99.4%
l\_m = (fabs.f64 l) l\_s = (copysign.f64 #s(literal 1 binary64) l) (FPCore (l_s F l_m) :precision binary64 (* l_s (if (<= l_m 50.0) (* (- (PI) (/ (PI) (* F F))) l_m) (* (PI) l_m))))
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)
\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;l\_m \leq 50:\\
\;\;\;\;\left(\mathsf{PI}\left(\right) - \frac{\mathsf{PI}\left(\right)}{F \cdot F}\right) \cdot l\_m\\
\mathbf{else}:\\
\;\;\;\;\mathsf{PI}\left(\right) \cdot l\_m\\
\end{array}
\end{array}
if l < 50Initial program 86.5%
Taylor expanded in l around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lift-PI.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
pow2N/A
lift-*.f6479.6
Applied rewrites79.6%
if 50 < l Initial program 67.4%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.4
Applied rewrites99.4%
l\_m = (fabs.f64 l) l\_s = (copysign.f64 #s(literal 1 binary64) l) (FPCore (l_s F l_m) :precision binary64 (* l_s (* (PI) l_m)))
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)
\\
l\_s \cdot \left(\mathsf{PI}\left(\right) \cdot l\_m\right)
\end{array}
Initial program 81.7%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6475.4
Applied rewrites75.4%
l\_m = (fabs.f64 l) l\_s = (copysign.f64 #s(literal 1 binary64) l) (FPCore (l_s F l_m) :precision binary64 (* l_s 0.0))
l\_m = fabs(l);
l\_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
return l_s * 0.0;
}
l\_m = private
l\_s = private
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(l_s, f, l_m)
use fmin_fmax_functions
real(8), intent (in) :: l_s
real(8), intent (in) :: f
real(8), intent (in) :: l_m
code = l_s * 0.0d0
end function
l\_m = Math.abs(l);
l\_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
return l_s * 0.0;
}
l\_m = math.fabs(l) l\_s = math.copysign(1.0, l) def code(l_s, F, l_m): return l_s * 0.0
l\_m = abs(l) l\_s = copysign(1.0, l) function code(l_s, F, l_m) return Float64(l_s * 0.0) end
l\_m = abs(l); l\_s = sign(l) * abs(1.0); function tmp = code(l_s, F, l_m) tmp = l_s * 0.0; end
l\_m = N[Abs[l], $MachinePrecision]
l\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * 0.0), $MachinePrecision]
\begin{array}{l}
l\_m = \left|\ell\right|
\\
l\_s = \mathsf{copysign}\left(1, \ell\right)
\\
l\_s \cdot 0
\end{array}
Initial program 81.7%
lift-tan.f64N/A
tan-+PI-revN/A
tan-+PI-revN/A
lower-tan.f64N/A
lower-+.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-PI.f64N/A
lift-PI.f64N/A
lift-PI.f6459.9
Applied rewrites59.9%
Taylor expanded in l around 0
Applied rewrites2.7%
associate-/r*2.7
unpow-12.7
lift-*.f64N/A
lift-PI.f64N/A
tan-quotN/A
lift-PI.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f642.7
times-frac2.7
lift-*.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
lift-/.f64N/A
Applied rewrites3.1%
herbie shell --seed 2025037
(FPCore (F l)
:name "VandenBroeck and Keller, Equation (6)"
:precision binary64
(- (* (PI) l) (* (/ 1.0 (* F F)) (tan (* (PI) l)))))