
(FPCore (x) :precision binary64 (- (/ (PI) 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
\begin{array}{l}
\\
\frac{\mathsf{PI}\left(\right)}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ (PI) 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))
\begin{array}{l}
\\
\frac{\mathsf{PI}\left(\right)}{2} - 2 \cdot \sin^{-1} \left(\sqrt{\frac{1 - x}{2}}\right)
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (/ (PI) 2.0))
(t_1 (pow t_0 2.0))
(t_2 (sqrt (/ (- 1.0 x) 2.0)))
(t_3 (+ t_0 (asin t_2)))
(t_4 (acos t_2))
(t_5 (fma t_4 (+ t_4 t_0) t_1)))
(/
(-
(* (- t_1 (pow (- t_0 t_4) 2.0)) t_5)
(* t_3 (- (pow t_0 3.0) (pow t_4 3.0))))
(* t_3 t_5))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{2}\\
t_1 := {t\_0}^{2}\\
t_2 := \sqrt{\frac{1 - x}{2}}\\
t_3 := t\_0 + \sin^{-1} t\_2\\
t_4 := \cos^{-1} t\_2\\
t_5 := \mathsf{fma}\left(t\_4, t\_4 + t\_0, t\_1\right)\\
\frac{\left(t\_1 - {\left(t\_0 - t\_4\right)}^{2}\right) \cdot t\_5 - t\_3 \cdot \left({t\_0}^{3} - {t\_4}^{3}\right)}{t\_3 \cdot t\_5}
\end{array}
\end{array}
Initial program 9.0%
lift-PI.f64N/A
add-sqr-sqrtN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f648.7
Applied rewrites8.7%
Applied rewrites8.9%
lift-asin.f64N/A
asin-acosN/A
lift-PI.f64N/A
lift-/.f64N/A
lift-acos.f64N/A
lower--.f6410.5
Applied rewrites10.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (/ (- 1.0 x) 2.0)))
(t_1 (asin t_0))
(t_2 (acos t_0))
(t_3 (/ (PI) 2.0))
(t_4 (pow t_3 2.0))
(t_5 (- t_4 (pow t_1 2.0))))
(/
(+ (* t_2 t_5) (- (* t_5 t_3) (* (- t_4 (pow t_2 2.0)) (+ t_1 t_3))))
(* (+ t_3 t_1) (+ t_2 t_3)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\frac{1 - x}{2}}\\
t_1 := \sin^{-1} t\_0\\
t_2 := \cos^{-1} t\_0\\
t_3 := \frac{\mathsf{PI}\left(\right)}{2}\\
t_4 := {t\_3}^{2}\\
t_5 := t\_4 - {t\_1}^{2}\\
\frac{t\_2 \cdot t\_5 + \left(t\_5 \cdot t\_3 - \left(t\_4 - {t\_2}^{2}\right) \cdot \left(t\_1 + t\_3\right)\right)}{\left(t\_3 + t\_1\right) \cdot \left(t\_2 + t\_3\right)}
\end{array}
\end{array}
Initial program 9.0%
lift-PI.f64N/A
add-sqr-sqrtN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f648.7
Applied rewrites8.7%
lift--.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-PI.f64N/A
lift-*.f64N/A
count-2-revN/A
associate--r+N/A
flip--N/A
lift-asin.f64N/A
asin-acos-revN/A
lift-acos.f64N/A
Applied rewrites10.5%
lift--.f64N/A
lift-*.f64N/A
lift-+.f64N/A
distribute-lft-inN/A
Applied rewrites10.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ (PI) 2.0))
(t_1 (pow t_0 2.0))
(t_2 (sqrt (/ (- 1.0 x) 2.0)))
(t_3 (acos t_2))
(t_4 (+ t_3 t_0))
(t_5 (asin t_2))
(t_6 (+ t_0 t_5)))
(/
(- (* (- t_1 (pow t_5 2.0)) t_4) (* t_6 (- t_1 (pow t_3 2.0))))
(* t_6 t_4))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{PI}\left(\right)}{2}\\
t_1 := {t\_0}^{2}\\
t_2 := \sqrt{\frac{1 - x}{2}}\\
t_3 := \cos^{-1} t\_2\\
t_4 := t\_3 + t\_0\\
t_5 := \sin^{-1} t\_2\\
t_6 := t\_0 + t\_5\\
\frac{\left(t\_1 - {t\_5}^{2}\right) \cdot t\_4 - t\_6 \cdot \left(t\_1 - {t\_3}^{2}\right)}{t\_6 \cdot t\_4}
\end{array}
\end{array}
Initial program 9.0%
lift-PI.f64N/A
add-sqr-sqrtN/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f648.7
Applied rewrites8.7%
lift--.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-PI.f64N/A
lift-*.f64N/A
count-2-revN/A
associate--r+N/A
flip--N/A
lift-asin.f64N/A
asin-acos-revN/A
lift-acos.f64N/A
Applied rewrites10.5%
(FPCore (x) :precision binary64 (let* ((t_0 (* 0.5 (PI)))) (fma (- t_0 (acos (sqrt (* (- 1.0 x) 0.5)))) -2.0 t_0)))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \mathsf{PI}\left(\right)\\
\mathsf{fma}\left(t\_0 - \cos^{-1} \left(\sqrt{\left(1 - x\right) \cdot 0.5}\right), -2, t\_0\right)
\end{array}
\end{array}
Initial program 9.0%
lift-asin.f64N/A
asin-acosN/A
lift-PI.f64N/A
lift-/.f64N/A
lower--.f64N/A
lower-acos.f6410.5
Applied rewrites10.5%
Taylor expanded in x around 0
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
lower-acos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower--.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f6410.4
Applied rewrites10.4%
Applied rewrites10.5%
(FPCore (x) :precision binary64 (fma (asin (sqrt (* (- 1.0 x) 0.5))) -2.0 (* 0.5 (PI))))
\begin{array}{l}
\\
\mathsf{fma}\left(\sin^{-1} \left(\sqrt{\left(1 - x\right) \cdot 0.5}\right), -2, 0.5 \cdot \mathsf{PI}\left(\right)\right)
\end{array}
Initial program 9.0%
Taylor expanded in x around 0
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
metadata-evalN/A
lower-asin.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower--.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f648.8
Applied rewrites8.8%
Applied rewrites9.0%
(FPCore (x) :precision binary64 (fma (asin (sqrt 0.5)) 2.0 (/ (PI) -2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\sin^{-1} \left(\sqrt{0.5}\right), 2, \frac{\mathsf{PI}\left(\right)}{-2}\right)
\end{array}
Initial program 9.0%
Applied rewrites3.7%
Taylor expanded in x around 0
Applied rewrites4.2%
(FPCore (x) :precision binary64 (/ 0.0 0.0))
double code(double x) {
return 0.0 / 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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 0.0d0 / 0.0d0
end function
public static double code(double x) {
return 0.0 / 0.0;
}
def code(x): return 0.0 / 0.0
function code(x) return Float64(0.0 / 0.0) end
function tmp = code(x) tmp = 0.0 / 0.0; end
code[x_] := N[(0.0 / 0.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{0}
\end{array}
Initial program 9.0%
Applied rewrites0.0%
(FPCore (x) :precision binary64 (asin x))
double code(double x) {
return asin(x);
}
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(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = asin(x)
end function
public static double code(double x) {
return Math.asin(x);
}
def code(x): return math.asin(x)
function code(x) return asin(x) end
function tmp = code(x) tmp = asin(x); end
code[x_] := N[ArcSin[x], $MachinePrecision]
\begin{array}{l}
\\
\sin^{-1} x
\end{array}
herbie shell --seed 2024358
(FPCore (x)
:name "Ian Simplification"
:precision binary64
:alt
(! :herbie-platform default (asin x))
(- (/ (PI) 2.0) (* 2.0 (asin (sqrt (/ (- 1.0 x) 2.0))))))