
(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 9 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 1.55e+15) (+ t_0 (* (/ -1.0 F) (/ (tan t_0) 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 1.55 \cdot 10^{+15}:\\
\;\;\;\;t\_0 + \frac{-1}{F} \cdot \frac{\tan t\_0}{F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if l < 1.55e15Initial program 78.6%
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-/.f64N/A
lift-tan.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
associate-*l/N/A
pow2N/A
sqr-neg-revN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-tan.f64N/A
lower-neg.f6490.0
Applied rewrites90.0%
if 1.55e15 < l Initial program 57.5%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.7
Applied rewrites99.7%
Final simplification92.6%
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)) (t_1 (- t_0 (* (/ 1.0 (* F F)) (tan t_0)))))
(*
l_s
(if (or (<= t_1 -2e+234) (not (<= t_1 -5e-255)))
t_0
(* (- l_m) (/ (PI) (* F F)))))))\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\\
t_1 := t\_0 - \frac{1}{F \cdot F} \cdot \tan t\_0\\
l\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+234} \lor \neg \left(t\_1 \leq -5 \cdot 10^{-255}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(-l\_m\right) \cdot \frac{\mathsf{PI}\left(\right)}{F \cdot F}\\
\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)))) < -2.00000000000000004e234 or -4.9999999999999996e-255 < (-.f64 (*.f64 (PI.f64) l) (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 F F)) (tan.f64 (*.f64 (PI.f64) l)))) Initial program 64.5%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6468.6
Applied rewrites68.6%
if -2.00000000000000004e234 < (-.f64 (*.f64 (PI.f64) l) (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 F F)) (tan.f64 (*.f64 (PI.f64) l)))) < -4.9999999999999996e-255Initial program 94.8%
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.f6421.1
Applied rewrites21.1%
Taylor expanded in l around 0
mul-1-negN/A
lower-neg.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
pow2N/A
lift-*.f6418.8
Applied rewrites18.8%
Final simplification54.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 1.55e+15) (- t_0 (/ (* (/ 1.0 F) (tan t_0)) 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 1.55 \cdot 10^{+15}:\\
\;\;\;\;t\_0 - \frac{\frac{1}{F} \cdot \tan t\_0}{F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if l < 1.55e15Initial program 78.6%
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-/.f64N/A
lift-tan.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
associate-*l/N/A
pow2N/A
sqr-neg-revN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-tan.f64N/A
lower-neg.f6490.0
Applied rewrites90.0%
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
lift-tan.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
metadata-evalN/A
frac-2negN/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-tan.f64N/A
lift-neg.f6490.0
Applied rewrites90.0%
if 1.55e15 < l Initial program 57.5%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.7
Applied rewrites99.7%
Final simplification92.6%
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 52000.0) (fma (PI) l_m (* (/ -1.0 F) (/ t_0 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 52000:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{PI}\left(\right), l\_m, \frac{-1}{F} \cdot \frac{t\_0}{F}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if l < 52000Initial program 78.4%
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-/.f64N/A
lift-tan.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
associate-*l/N/A
pow2N/A
sqr-neg-revN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-tan.f64N/A
lower-neg.f6490.0
Applied rewrites90.0%
Taylor expanded in l around 0
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6483.4
Applied rewrites83.4%
lift--.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
metadata-evalN/A
frac-2negN/A
fp-cancel-sub-sign-invN/A
lift-PI.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-PI.f64N/A
lower-*.f64N/A
Applied rewrites83.4%
lift-neg.f64N/A
lift-/.f64N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6483.4
Applied rewrites83.4%
if 52000 < l Initial program 58.1%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.7
Applied rewrites99.7%
Final simplification87.9%
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 52000.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 52000:\\
\;\;\;\;t\_0 - \frac{\frac{t\_0}{F}}{F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if l < 52000Initial program 78.4%
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-/.f64N/A
lift-tan.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
associate-*l/N/A
pow2N/A
sqr-neg-revN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-tan.f64N/A
lower-neg.f6490.0
Applied rewrites90.0%
Taylor expanded in l around 0
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6483.4
Applied rewrites83.4%
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
metadata-evalN/A
frac-2negN/A
*-commutativeN/A
lift-neg.f64N/A
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
frac-timesN/A
sqr-neg-revN/A
pow2N/A
lower-/.f64N/A
Applied rewrites73.2%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites83.4%
if 52000 < l Initial program 58.1%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.7
Applied rewrites99.7%
Final simplification87.9%
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 52000.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 52000:\\
\;\;\;\;t\_0 - \frac{t\_0}{F \cdot F}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
\end{array}
if l < 52000Initial program 78.4%
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-/.f64N/A
lift-tan.f64N/A
lift-PI.f64N/A
lift-*.f64N/A
associate-*l/N/A
pow2N/A
sqr-neg-revN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
lift-tan.f64N/A
lower-neg.f6490.0
Applied rewrites90.0%
Taylor expanded in l around 0
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6483.4
Applied rewrites83.4%
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
metadata-evalN/A
frac-2negN/A
*-commutativeN/A
lift-neg.f64N/A
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
frac-timesN/A
sqr-neg-revN/A
pow2N/A
lower-/.f64N/A
Applied rewrites73.2%
Applied rewrites73.2%
if 52000 < l Initial program 58.1%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.7
Applied rewrites99.7%
Final simplification80.5%
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 52000.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 52000:\\
\;\;\;\;\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 < 52000Initial program 78.4%
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-*.f6471.9
Applied rewrites71.9%
if 52000 < l Initial program 58.1%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6499.7
Applied rewrites99.7%
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 72.9%
Taylor expanded in F around inf
*-commutativeN/A
lift-*.f64N/A
lift-PI.f6472.0
Applied rewrites72.0%
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 72.9%
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.f6421.2
Applied rewrites21.2%
lift-tan.f64N/A
tan-+PI-revN/A
lift-PI.f64N/A
lift-*.f64N/A
tan-+PIN/A
tan-+PI-revN/A
lower-tan.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
associate-+l+N/A
lift-PI.f64N/A
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
+-commutativeN/A
distribute-rgt-outN/A
lower-fma.f64N/A
lift-PI.f64N/A
lower-+.f64N/A
lift-PI.f649.0
Applied rewrites9.0%
Taylor expanded in l around 0
associate-/r*N/A
+-commutativeN/A
cos-+PIN/A
count-2-revN/A
cos-+PIN/A
cos-PIN/A
metadata-evalN/A
metadata-evalN/A
Applied rewrites3.1%
Final simplification3.1%
herbie shell --seed 2025045
(FPCore (F l)
:name "VandenBroeck and Keller, Equation (6)"
:precision binary64
(- (* (PI) l) (* (/ 1.0 (* F F)) (tan (* (PI) l)))))