(FPCore (x) :precision binary64 (let* ((t_0 (/ (- x 0.5) 0.5))) (* 0.5 (+ (+ 1.0 t_0) (* (/ 1.0 (PI)) (sin (* t_0 (PI))))))))
\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x - 0.5}{0.5}\\ 0.5 \cdot \left(\left(1 + t\_0\right) + \frac{1}{\mathsf{PI}\left(\right)} \cdot \sin \left(t\_0 \cdot \mathsf{PI}\left(\right)\right)\right) \end{array} \end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (let* ((t_0 (/ (- x 0.5) 0.5))) (* 0.5 (+ (+ 1.0 t_0) (* (/ 1.0 (PI)) (sin (* t_0 (PI))))))))
\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x - 0.5}{0.5}\\ 0.5 \cdot \left(\left(1 + t\_0\right) + \frac{1}{\mathsf{PI}\left(\right)} \cdot \sin \left(t\_0 \cdot \mathsf{PI}\left(\right)\right)\right) \end{array} \end{array}
(FPCore (x) :precision binary64 (let* ((t_0 (* (* (PI) 2.0) x))) (fma (fma (sin t_0) (cos (PI)) (* (cos t_0) (- (sin (PI))))) (/ 0.5 (PI)) (fma (fma x 2.0 -1.0) 0.5 0.5))))
\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot x\\ \mathsf{fma}\left(\mathsf{fma}\left(\sin t\_0, \cos \mathsf{PI}\left(\right), \cos t\_0 \cdot \left(-\sin \mathsf{PI}\left(\right)\right)\right), \frac{0.5}{\mathsf{PI}\left(\right)}, \mathsf{fma}\left(\mathsf{fma}\left(x, 2, -1\right), 0.5, 0.5\right)\right) \end{array} \end{array}
Initial program 85.0%
lift-*.f64
N/A
lift-+.f64
N/A
distribute-rgt-in
N/A
+-commutative
N/A
lift-*.f64
N/A
lift-/.f64
N/A
associate-*l/
N/A
associate-*l/
N/A
*-lft-identity
N/A
times-frac
N/A
Applied rewrites85.0%
lift-/.f64
N/A
/-rgt-identity
85.0
lift-sin.f64
N/A
lift-*.f64
N/A
lift-fma.f64
N/A
distribute-lft-in
N/A
sin-sum
N/A
*-commutative
N/A
lower-fma.f64
N/A
Applied rewrites85.1%
(FPCore (x) :precision binary64 (fma (pow (pow (sin (* (PI) (fma 2.0 x -1.0))) -1.0) -1.0) (/ 0.5 (PI)) (fma (fma x 2.0 -1.0) 0.5 0.5)))
\begin{array}{l} \\ \mathsf{fma}\left({\left({\sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, x, -1\right)\right)}^{-1}\right)}^{-1}, \frac{0.5}{\mathsf{PI}\left(\right)}, \mathsf{fma}\left(\mathsf{fma}\left(x, 2, -1\right), 0.5, 0.5\right)\right) \end{array}
Initial program 85.0%
lift-*.f64
N/A
lift-+.f64
N/A
distribute-rgt-in
N/A
+-commutative
N/A
lift-*.f64
N/A
lift-/.f64
N/A
associate-*l/
N/A
associate-*l/
N/A
*-lft-identity
N/A
times-frac
N/A
Applied rewrites85.0%
lift-/.f64
N/A
clear-num
N/A
lower-/.f64
N/A
inv-pow
N/A
lower-pow.f64
85.0
lift-fma.f64
N/A
*-commutative
N/A
lower-fma.f64
85.0
Applied rewrites85.0%
Final simplification85.0%
(FPCore (x) :precision binary64 (* 0.5 (+ (+ 1.0 (/ (- x 0.5) 0.5)) (* (pow (PI) -1.0) (* (* (PI) (fma (* (* (* (PI) x) (PI)) x) 1.3333333333333333 -2.0)) x)))))
\begin{array}{l} \\ 0.5 \cdot \left(\left(1 + \frac{x - 0.5}{0.5}\right) + {\mathsf{PI}\left(\right)}^{-1} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \mathsf{PI}\left(\right)\right) \cdot x, 1.3333333333333333, -2\right)\right) \cdot x\right)\right) \end{array}
Initial program 85.0%
Taylor expanded in x around 0
Applied rewrites31.9%
Final simplification31.9%
(FPCore (x) :precision binary64 (fma (sin (* (PI) (fma 2.0 x -1.0))) (/ 0.5 (PI)) (fma (fma x 2.0 -1.0) 0.5 0.5)))
\begin{array}{l} \\ \mathsf{fma}\left(\sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(2, x, -1\right)\right), \frac{0.5}{\mathsf{PI}\left(\right)}, \mathsf{fma}\left(\mathsf{fma}\left(x, 2, -1\right), 0.5, 0.5\right)\right) \end{array}
Initial program 85.0%
lift-*.f64
N/A
lift-+.f64
N/A
distribute-rgt-in
N/A
+-commutative
N/A
lift-*.f64
N/A
lift-/.f64
N/A
associate-*l/
N/A
associate-*l/
N/A
*-lft-identity
N/A
times-frac
N/A
Applied rewrites85.0%
lift-/.f64
N/A
/-rgt-identity
85.0
lift-fma.f64
N/A
*-commutative
N/A
lower-fma.f64
85.0
Applied rewrites85.0%
(FPCore (x) :precision binary64 (* 0.5 (fma 2.0 x (/ (sin (* (fma 2.0 x -1.0) (PI))) (PI)))))
\begin{array}{l} \\ 0.5 \cdot \mathsf{fma}\left(2, x, \frac{\sin \left(\mathsf{fma}\left(2, x, -1\right) \cdot \mathsf{PI}\left(\right)\right)}{\mathsf{PI}\left(\right)}\right) \end{array}
Initial program 85.0%
Taylor expanded in x around inf
Applied rewrites84.9%
(FPCore (x) :precision binary64 (fma (/ 0.5 (PI)) (sin (* (fma 2.0 x -1.0) (PI))) x))
\begin{array}{l} \\ \mathsf{fma}\left(\frac{0.5}{\mathsf{PI}\left(\right)}, \sin \left(\mathsf{fma}\left(2, x, -1\right) \cdot \mathsf{PI}\left(\right)\right), x\right) \end{array}
Initial program 85.0%
Taylor expanded in x around inf
Applied rewrites84.9%
(FPCore (x) :precision binary64 (* 0.5 (+ (+ 1.0 (/ (- x 0.5) 0.5)) (* (fma (* (* (* (PI) x) (PI)) x) 1.3333333333333333 -2.0) x))))
\begin{array}{l} \\ 0.5 \cdot \left(\left(1 + \frac{x - 0.5}{0.5}\right) + \mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \mathsf{PI}\left(\right)\right) \cdot x, 1.3333333333333333, -2\right) \cdot x\right) \end{array}
Initial program 85.0%
Taylor expanded in x around 0
Applied rewrites31.9%
(FPCore (x) :precision binary64 (fma (* x x) (fma (* (* (PI) x) (PI)) 0.6666666666666666 0.0) 0.0))
\begin{array}{l} \\ \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \mathsf{PI}\left(\right), 0.6666666666666666, 0\right), 0\right) \end{array}
Initial program 85.0%
lift-*.f64
N/A
lift-+.f64
N/A
distribute-rgt-in
N/A
+-commutative
N/A
lift-*.f64
N/A
lift-/.f64
N/A
associate-*l/
N/A
associate-*l/
N/A
*-lft-identity
N/A
times-frac
N/A
Applied rewrites85.0%
Taylor expanded in x around 0
Applied rewrites31.9%
Final simplification31.9%
(FPCore (x) :precision binary64 (* (* x x) (* (* (* x 0.6666666666666666) (PI)) (PI))))
\begin{array}{l} \\ \left(x \cdot x\right) \cdot \left(\left(\left(x \cdot 0.6666666666666666\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \end{array}
Initial program 85.0%
Taylor expanded in x around 0
Applied rewrites31.9%
(FPCore (x) :precision binary64 0.0)
double code(double x) { return 0.0; }
real(8) function code(x) real(8), intent (in) :: x code = 0.0d0 end function
public static double code(double x) { return 0.0; }
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l} \\ 0 \end{array}
Initial program 85.0%
Taylor expanded in x around 0
associate-*r/
N/A
*-commutative
N/A
associate-/l*
N/A
mul-1-neg
N/A
sin-neg
N/A
sin-PI
N/A
metadata-eval
N/A
mul0-lft
3.2
Applied rewrites3.2%
herbie shell --seed 1
(FPCore (x)
:name "0.5 * (1 + (x - 0.5) / 0.5 + (1 / PI) * sin((x - 0.5) / 0.5 * PI))"
:precision binary64
:pre (and (<= 0.001 x) (<= x 1.0))
(* 0.5 (+ (+ 1.0 (/ (- x 0.5) 0.5)) (* (/ 1.0 (PI)) (sin (* (/ (- x 0.5) 0.5) (PI)))))))