
(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 11 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 (* (PI) (* n 2.0)))) (/ (sqrt t_0) (* (pow t_0 (/ k 2.0)) (sqrt k)))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \left(n \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
(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 5e+273)
(* (sqrt (* 2.0 n)) (sqrt (/ (PI) k)))
(/ (pow 0.0 (* -0.125 k)) (sqrt k))))))\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 5 \cdot 10^{+273}:\\
\;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{k}}\\
\mathbf{else}:\\
\;\;\;\;\frac{{0}^{\left(-0.125 \cdot k\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%
Applied rewrites1.6%
lift-pow.f64N/A
lift-*.f64N/A
mul0-lftN/A
pow-base-0100.0
Applied rewrites100.0%
Taylor expanded in k around 0
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)))) < 4.99999999999999961e273Initial program 99.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.f6469.6
Applied rewrites69.6%
Applied rewrites69.7%
Applied rewrites97.1%
if 4.99999999999999961e273 < (*.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%
Applied rewrites100.0%
Taylor expanded in k around inf
lower-*.f64100.0
Applied rewrites100.0%
Final simplification98.5%
(FPCore (k n)
:precision binary64
(let* ((t_0 (* (PI) n))
(t_1
(* (pow (sqrt k) -1.0) (pow (* (* 2.0 (PI)) n) (/ (- 1.0 k) 2.0)))))
(if (<= t_1 0.0)
0.0
(if (<= t_1 4e+272)
(* (sqrt (* 2.0 n)) (sqrt (/ (PI) k)))
(/
(* (* (sqrt (sqrt t_0)) (sqrt (sqrt (* k (* t_0 k))))) (sqrt 2.0))
k)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot n\\
t_1 := {\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\_1 \leq 0:\\
\;\;\;\;0\\
\mathbf{elif}\;t\_1 \leq 4 \cdot 10^{+272}:\\
\;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{k}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\sqrt{\sqrt{t\_0}} \cdot \sqrt{\sqrt{k \cdot \left(t\_0 \cdot k\right)}}\right) \cdot \sqrt{2}}{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%
Applied rewrites1.6%
lift-pow.f64N/A
lift-*.f64N/A
mul0-lftN/A
pow-base-0100.0
Applied rewrites100.0%
Taylor expanded in k around 0
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)))) < 4.0000000000000003e272Initial program 99.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.f6470.0
Applied rewrites70.0%
Applied rewrites70.2%
Applied rewrites97.0%
if 4.0000000000000003e272 < (*.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 0
lower-/.f64N/A
Applied rewrites72.2%
Taylor expanded in k around 0
Applied rewrites3.7%
Applied rewrites31.7%
Final simplification81.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 4e+136)
(sqrt (* (* 2.0 n) (/ (PI) k)))
(/ (sqrt (* (* (* (PI) n) k) 2.0)) k)))))\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 4 \cdot 10^{+136}:\\
\;\;\;\;\sqrt{\left(2 \cdot n\right) \cdot \frac{\mathsf{PI}\left(\right)}{k}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\left(\left(\mathsf{PI}\left(\right) \cdot n\right) \cdot k\right) \cdot 2}}{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%
Applied rewrites1.6%
lift-pow.f64N/A
lift-*.f64N/A
mul0-lftN/A
pow-base-0100.0
Applied rewrites100.0%
Taylor expanded in k around 0
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)))) < 4.00000000000000023e136Initial program 98.9%
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.f6495.8
Applied rewrites95.8%
Applied rewrites96.0%
Applied rewrites96.1%
if 4.00000000000000023e136 < (*.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.6%
Taylor expanded in k around 0
lower-/.f64N/A
Applied rewrites82.9%
Taylor expanded in k around 0
Applied rewrites41.4%
Applied rewrites41.5%
Final simplification74.9%
(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 n)) (sqrt (/ (PI) 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}:\\
\;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{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%
Applied rewrites1.6%
lift-pow.f64N/A
lift-*.f64N/A
mul0-lftN/A
pow-base-0100.0
Applied rewrites100.0%
Taylor expanded in k around 0
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.3%
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.f6447.8
Applied rewrites47.8%
Applied rewrites47.9%
Applied rewrites66.4%
Final simplification74.8%
(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) (sqrt (/ (* (PI) 2.0) 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}:\\
\;\;\;\;\sqrt{n} \cdot \sqrt{\frac{\mathsf{PI}\left(\right) \cdot 2}{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%
Applied rewrites1.6%
lift-pow.f64N/A
lift-*.f64N/A
mul0-lftN/A
pow-base-0100.0
Applied rewrites100.0%
Taylor expanded in k around 0
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.3%
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.f6447.8
Applied rewrites47.8%
Applied rewrites47.9%
Applied rewrites66.4%
Final simplification74.8%
(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 n) (/ (PI) 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}:\\
\;\;\;\;\sqrt{\left(2 \cdot n\right) \cdot \frac{\mathsf{PI}\left(\right)}{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%
Applied rewrites1.6%
lift-pow.f64N/A
lift-*.f64N/A
mul0-lftN/A
pow-base-0100.0
Applied rewrites100.0%
Taylor expanded in k around 0
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.3%
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.f6447.8
Applied rewrites47.8%
Applied rewrites47.9%
Applied rewrites47.9%
Final simplification60.9%
(FPCore (k n) :precision binary64 (* (sqrt (pow (* (* n (PI)) 2.0) (- 1.0 k))) (sqrt (pow k -1.0))))
\begin{array}{l}
\\
\sqrt{{\left(\left(n \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}^{\left(1 - k\right)}} \cdot \sqrt{{k}^{-1}}
\end{array}
Initial program 99.5%
Taylor expanded in k around inf
Applied rewrites99.5%
Taylor expanded in k around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
exp-prodN/A
unpow1/2N/A
lower-sqrt.f64N/A
exp-to-powN/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower--.f64N/A
lower-sqrt.f64N/A
lower-/.f6499.5
Applied rewrites99.5%
Final simplification99.5%
(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.5%
Final simplification99.5%
(FPCore (k n) :precision binary64 (if (<= k 1.25e-21) (* (sqrt (* 2.0 n)) (sqrt (/ (PI) k))) (sqrt (/ (pow (* (* n (PI)) 2.0) (- 1.0 k)) k))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;k \leq 1.25 \cdot 10^{-21}:\\
\;\;\;\;\sqrt{2 \cdot n} \cdot \sqrt{\frac{\mathsf{PI}\left(\right)}{k}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{{\left(\left(n \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}^{\left(1 - k\right)}}{k}}\\
\end{array}
\end{array}
if k < 1.24999999999999993e-21Initial program 99.2%
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.f6470.0
Applied rewrites70.0%
Applied rewrites70.2%
Applied rewrites99.5%
if 1.24999999999999993e-21 < k Initial program 99.7%
Taylor expanded in k around inf
Applied rewrites99.7%
Taylor expanded in k around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
exp-prodN/A
unpow1/2N/A
lower-sqrt.f64N/A
exp-to-powN/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f64N/A
lower--.f64N/A
lower-sqrt.f64N/A
lower-/.f6499.7
Applied rewrites99.7%
Taylor expanded in k around inf
Applied rewrites99.7%
(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%
Applied rewrites26.0%
lift-pow.f64N/A
lift-*.f64N/A
mul0-lftN/A
pow-base-026.7
Applied rewrites26.7%
Taylor expanded in k around 0
Applied rewrites26.7%
herbie shell --seed 2024363
(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))))