
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0))))
\begin{array}{l}
\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (k n) :precision binary64 (* (/ 1.0 (sqrt k)) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0))))
\begin{array}{l}
\\
\frac{1}{\sqrt{k}} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}
\end{array}
(FPCore (k n) :precision binary64 (let* ((t_0 (* n (* (PI) 2.0)))) (* (* (pow (pow t_0 -0.5) k) (sqrt t_0)) (sqrt (pow k -1.0)))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := n \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\\
\left({\left({t\_0}^{-0.5}\right)}^{k} \cdot \sqrt{t\_0}\right) \cdot \sqrt{{k}^{-1}}
\end{array}
\end{array}
Initial program 99.5%
Taylor expanded in k around inf
Applied rewrites99.6%
Applied rewrites99.7%
Final simplification99.7%
(FPCore (k n)
:precision binary64
(let* ((t_0
(* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))))
(if (<= t_0 0.0)
0.0
(if (<= t_0 2e+284)
(* (* 1.0 (sqrt (* n (* (PI) 2.0)))) (sqrt (pow k -1.0)))
(pow 0.0 (fma -0.5 k 0.5))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;0\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+284}:\\
\;\;\;\;\left(1 \cdot \sqrt{n \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)}\right) \cdot \sqrt{{k}^{-1}}\\
\mathbf{else}:\\
\;\;\;\;{0}^{\left(\mathsf{fma}\left(-0.5, k, 0.5\right)\right)}\\
\end{array}
\end{array}
if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0Initial program 100.0%
Taylor expanded in k around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f643.2
Applied rewrites3.2%
Applied rewrites3.2%
Applied rewrites100.0%
if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 2.00000000000000016e284Initial program 99.0%
Taylor expanded in k around inf
Applied rewrites99.2%
Applied rewrites99.5%
Taylor expanded in k around 0
Applied rewrites97.1%
if 2.00000000000000016e284 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) Initial program 100.0%
Taylor expanded in k around inf
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
Final simplification98.6%
(FPCore (k n)
:precision binary64
(if (<=
(* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))
0.0)
0.0
(* (* 1.0 (sqrt (* n (* (PI) 2.0)))) (sqrt (pow k -1.0)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\left(1 \cdot \sqrt{n \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)}\right) \cdot \sqrt{{k}^{-1}}\\
\end{array}
\end{array}
if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0Initial program 100.0%
Taylor expanded in k around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f643.2
Applied rewrites3.2%
Applied rewrites3.2%
Applied rewrites100.0%
if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) Initial program 99.4%
Taylor expanded in k around inf
Applied rewrites99.5%
Applied rewrites99.7%
Taylor expanded in k around 0
Applied rewrites62.2%
Final simplification71.5%
(FPCore (k n)
:precision binary64
(if (<=
(* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))
0.0)
0.0
(/ (sqrt (* n (* (PI) 2.0))) (sqrt k))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{n \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)}}{\sqrt{k}}\\
\end{array}
\end{array}
if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0Initial program 100.0%
Taylor expanded in k around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f643.2
Applied rewrites3.2%
Applied rewrites3.2%
Applied rewrites100.0%
if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) Initial program 99.4%
Taylor expanded in k around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6445.6
Applied rewrites45.6%
Applied rewrites62.1%
Final simplification71.5%
(FPCore (k n)
:precision binary64
(if (<=
(* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))
0.0)
0.0
(sqrt (* (* (/ n k) (PI)) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\frac{n}{k} \cdot \mathsf{PI}\left(\right)\right) \cdot 2}\\
\end{array}
\end{array}
if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0Initial program 100.0%
Taylor expanded in k around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f643.2
Applied rewrites3.2%
Applied rewrites3.2%
Applied rewrites100.0%
if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) Initial program 99.4%
Taylor expanded in k around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6445.6
Applied rewrites45.6%
Applied rewrites45.8%
Applied rewrites45.8%
Final simplification59.1%
(FPCore (k n)
:precision binary64
(if (<=
(* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))
0.0)
0.0
(sqrt (* (/ 2.0 k) (PI)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{\left(\sqrt{k}\right)}^{-1} \cdot {\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\frac{1 - k}{2}\right)} \leq 0:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{2}{k} \cdot \mathsf{PI}\left(\right)}\\
\end{array}
\end{array}
if (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) < 0.0Initial program 100.0%
Taylor expanded in k around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f643.2
Applied rewrites3.2%
Applied rewrites3.2%
Applied rewrites100.0%
if 0.0 < (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 k)) (pow.f64 (*.f64 (*.f64 #s(literal 2 binary64) (PI.f64)) n) (/.f64 (-.f64 #s(literal 1 binary64) k) #s(literal 2 binary64)))) Initial program 99.4%
Taylor expanded in k around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6445.6
Applied rewrites45.6%
Applied rewrites45.8%
Applied rewrites5.2%
Applied rewrites5.2%
Final simplification28.6%
(FPCore (k n) :precision binary64 (* (pow (sqrt (* n (* (PI) 2.0))) (* 2.0 (fma -0.5 k 0.5))) (sqrt (pow k -1.0))))
\begin{array}{l}
\\
{\left(\sqrt{n \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)}\right)}^{\left(2 \cdot \mathsf{fma}\left(-0.5, k, 0.5\right)\right)} \cdot \sqrt{{k}^{-1}}
\end{array}
Initial program 99.5%
Taylor expanded in k around inf
Applied rewrites99.6%
Applied rewrites99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (* (pow (* (* 2.0 n) (PI)) (fma -0.5 k 0.5)) (sqrt (pow k -1.0))))
\begin{array}{l}
\\
{\left(\left(2 \cdot n\right) \cdot \mathsf{PI}\left(\right)\right)}^{\left(\mathsf{fma}\left(-0.5, k, 0.5\right)\right)} \cdot \sqrt{{k}^{-1}}
\end{array}
Initial program 99.5%
Taylor expanded in k around inf
Applied rewrites99.6%
Final simplification99.6%
(FPCore (k n) :precision binary64 (* (/ (sqrt (* (PI) n)) (sqrt (pow (* (* 2.0 (PI)) n) k))) (sqrt (/ 2.0 k))))
\begin{array}{l}
\\
\frac{\sqrt{\mathsf{PI}\left(\right) \cdot n}}{\sqrt{{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{k}}} \cdot \sqrt{\frac{2}{k}}
\end{array}
Initial program 99.5%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6499.4
Applied rewrites99.4%
Applied rewrites99.7%
lift-/.f64N/A
lift-*.f64N/A
*-rgt-identityN/A
lift-sqrt.f64N/A
pow1/2N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
unpow-prod-downN/A
lift-*.f64N/A
times-fracN/A
pow1/2N/A
lift-sqrt.f64N/A
sqrt-divN/A
lift-/.f64N/A
pow1/2N/A
lower-*.f64N/A
Applied rewrites99.7%
(FPCore (k n) :precision binary64 (let* ((t_0 (* n (* (PI) 2.0)))) (/ (sqrt t_0) (* (pow t_0 (/ k 2.0)) (sqrt k)))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := n \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\\
\frac{\sqrt{t\_0}}{{t\_0}^{\left(\frac{k}{2}\right)} \cdot \sqrt{k}}
\end{array}
\end{array}
Initial program 99.5%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f6499.4
Applied rewrites99.4%
Applied rewrites99.7%
Final simplification99.7%
(FPCore (k n) :precision binary64 (/ (pow (* (* 2.0 (PI)) n) (fma -0.5 k 0.5)) (sqrt k)))
\begin{array}{l}
\\
\frac{{\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot n\right)}^{\left(\mathsf{fma}\left(-0.5, k, 0.5\right)\right)}}{\sqrt{k}}
\end{array}
Initial program 99.5%
Taylor expanded in k around inf
sinh-+-cosh-revN/A
+-commutativeN/A
distribute-rgt-out--N/A
fp-cancel-sub-signN/A
mul-1-negN/A
distribute-rgt-inN/A
distribute-rgt-out--N/A
fp-cancel-sub-signN/A
Applied rewrites99.5%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
*-lft-identityN/A
lower-/.f6499.6
Applied rewrites99.6%
(FPCore (k n) :precision binary64 0.0)
double code(double k, double n) {
return 0.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(k, n)
use fmin_fmax_functions
real(8), intent (in) :: k
real(8), intent (in) :: n
code = 0.0d0
end function
public static double code(double k, double n) {
return 0.0;
}
def code(k, n): return 0.0
function code(k, n) return 0.0 end
function tmp = code(k, n) tmp = 0.0; end
code[k_, n_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 99.5%
Taylor expanded in k around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6435.2
Applied rewrites35.2%
Applied rewrites35.3%
Applied rewrites26.3%
herbie shell --seed 2024360
(FPCore (k n)
:name "Migdal et al, Equation (51)"
:precision binary64
(* (/ 1.0 (sqrt k)) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0))))