(FPCore (x) :precision binary64 (let* ((t_0 (/ (- x 0.5) 0.5))) (* (/ 1.0 2.0) (+ (+ 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}\\ \frac{1}{2} \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 3 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (let* ((t_0 (/ (- x 0.5) 0.5))) (* (/ 1.0 2.0) (+ (+ 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}\\ \frac{1}{2} \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 (* (* (* (* 1.3333333333333333 (* (* (PI) (PI)) x)) x) x) 0.5))
\begin{array}{l} \\ \left(\left(\left(1.3333333333333333 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot x\right)\right) \cdot x\right) \cdot x\right) \cdot 0.5 \end{array}
Initial program 4.2%
lift-*.f64
N/A
lift-/.f64
N/A
metadata-eval
N/A
*-commutative
N/A
lower-*.f64
4.2
Applied rewrites4.2%
Taylor expanded in x around 0
Applied rewrites98.4%
(FPCore (x) :precision binary64 (* (* x x) (* 0.6666666666666666 (* x (* (PI) (PI))))))
\begin{array}{l} \\ \left(x \cdot x\right) \cdot \left(0.6666666666666666 \cdot \left(x \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right)\right) \end{array}
Initial program 4.2%
Taylor expanded in x around 0
Applied rewrites98.3%
Applied rewrites98.4%
(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 4.2%
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
66.0
Applied rewrites66.0%
herbie shell --seed 1
(FPCore (x)
:name "(1 / 2) * (1 + (x - 0.5) / 0.5 + (1 / PI) * sin((x - 0.5) / 0.5 * PI))"
:precision binary64
:pre (and (<= 0.0 x) (<= x 1.0))
(* (/ 1.0 2.0) (+ (+ 1.0 (/ (- x 0.5) 0.5)) (* (/ 1.0 (PI)) (sin (* (/ (- x 0.5) 0.5) (PI)))))))