
(FPCore (x tau) :precision binary32 (let* ((t_1 (* x (PI))) (t_2 (* t_1 tau))) (* (/ (sin t_2) t_2) (/ (sin t_1) t_1))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
t_2 := t\_1 \cdot tau\\
\frac{\sin t\_2}{t\_2} \cdot \frac{\sin t\_1}{t\_1}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x tau) :precision binary32 (let* ((t_1 (* x (PI))) (t_2 (* t_1 tau))) (* (/ (sin t_2) t_2) (/ (sin t_1) t_1))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
t_2 := t\_1 \cdot tau\\
\frac{\sin t\_2}{t\_2} \cdot \frac{\sin t\_1}{t\_1}
\end{array}
\end{array}
(FPCore (x tau) :precision binary32 (let* ((t_1 (* x (PI))) (t_2 (* t_1 tau))) (/ (* (sin t_2) (sin t_1)) (* t_1 t_2))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
t_2 := t\_1 \cdot tau\\
\frac{\sin t\_2 \cdot \sin t\_1}{t\_1 \cdot t\_2}
\end{array}
\end{array}
Initial program 97.5%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites97.5%
Applied rewrites81.5%
Applied rewrites97.6%
Final simplification97.6%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* x (PI))) (t_2 (* t_1 tau)))
(if (<= x 0.023000000044703484)
(*
(/ (sin t_2) t_2)
(fma (* (* -0.16666666666666666 x) x) (* (PI) (PI)) 1.0))
(/
(* (sin (fma (* tau (PI)) x (PI))) (sin t_1))
(* t_1 (* (* (- x) (PI)) tau))))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
t_2 := t\_1 \cdot tau\\
\mathbf{if}\;x \leq 0.023000000044703484:\\
\;\;\;\;\frac{\sin t\_2}{t\_2} \cdot \mathsf{fma}\left(\left(-0.16666666666666666 \cdot x\right) \cdot x, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin \left(\mathsf{fma}\left(tau \cdot \mathsf{PI}\left(\right), x, \mathsf{PI}\left(\right)\right)\right) \cdot \sin t\_1}{t\_1 \cdot \left(\left(\left(-x\right) \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right)}\\
\end{array}
\end{array}
if x < 0.023Initial program 98.4%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3298.4
Applied rewrites98.4%
if 0.023 < x Initial program 96.0%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites95.9%
Applied rewrites93.3%
lift-*.f32N/A
lift-PI.f32N/A
add-log-expN/A
log-pow-revN/A
lift-fma.f32N/A
lift-*.f32N/A
pow-plus-revN/A
sum-logN/A
log-pow-revN/A
add-log-expN/A
lift-PI.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
add-log-expN/A
lift-PI.f32N/A
lower-fma.f32N/A
lower-*.f3293.9
Applied rewrites93.9%
Final simplification96.7%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* x (PI))) (t_2 (* t_1 tau)) (t_3 (sin t_2)))
(if (<= x 0.03200000151991844)
(* (/ t_3 t_2) (fma (* (* -0.16666666666666666 x) x) (* (PI) (PI)) 1.0))
(/ (* (sin (fma x (PI) (PI))) t_3) (* t_1 (* (* (- x) (PI)) tau))))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
t_2 := t\_1 \cdot tau\\
t_3 := \sin t\_2\\
\mathbf{if}\;x \leq 0.03200000151991844:\\
\;\;\;\;\frac{t\_3}{t\_2} \cdot \mathsf{fma}\left(\left(-0.16666666666666666 \cdot x\right) \cdot x, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin \left(\mathsf{fma}\left(x, \mathsf{PI}\left(\right), \mathsf{PI}\left(\right)\right)\right) \cdot t\_3}{t\_1 \cdot \left(\left(\left(-x\right) \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right)}\\
\end{array}
\end{array}
if x < 0.0320000015Initial program 98.4%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3298.1
Applied rewrites98.1%
if 0.0320000015 < x Initial program 95.8%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites95.8%
Applied rewrites94.0%
Final simplification96.6%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* x (PI))) (t_2 (* t_1 tau)))
(if (<= x 0.03099999949336052)
(*
(/ (sin t_2) t_2)
(fma (* (* -0.16666666666666666 x) x) (* (PI) (PI)) 1.0))
(/
(* (sin (* (fma x tau 1.0) (PI))) (- (sin t_1)))
(* (* t_1 (* tau (PI))) x)))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
t_2 := t\_1 \cdot tau\\
\mathbf{if}\;x \leq 0.03099999949336052:\\
\;\;\;\;\frac{\sin t\_2}{t\_2} \cdot \mathsf{fma}\left(\left(-0.16666666666666666 \cdot x\right) \cdot x, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin \left(\mathsf{fma}\left(x, tau, 1\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(-\sin t\_1\right)}{\left(t\_1 \cdot \left(tau \cdot \mathsf{PI}\left(\right)\right)\right) \cdot x}\\
\end{array}
\end{array}
if x < 0.0309999995Initial program 98.4%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3298.1
Applied rewrites98.1%
if 0.0309999995 < x Initial program 95.8%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites95.8%
Applied rewrites93.6%
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
lower-*.f3293.9
Applied rewrites93.9%
Final simplification96.6%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (PI) (PI))) (t_2 (* x (PI))) (t_3 (* t_2 tau)))
(if (<= x 0.03099999949336052)
(* (/ (sin t_3) t_3) (fma (* (* -0.16666666666666666 x) x) t_1 1.0))
(/
(* (sin (* (fma x tau 1.0) (PI))) (sin t_2))
(* (- tau) (* t_1 (* x x)))))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
t_2 := x \cdot \mathsf{PI}\left(\right)\\
t_3 := t\_2 \cdot tau\\
\mathbf{if}\;x \leq 0.03099999949336052:\\
\;\;\;\;\frac{\sin t\_3}{t\_3} \cdot \mathsf{fma}\left(\left(-0.16666666666666666 \cdot x\right) \cdot x, t\_1, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin \left(\mathsf{fma}\left(x, tau, 1\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sin t\_2}{\left(-tau\right) \cdot \left(t\_1 \cdot \left(x \cdot x\right)\right)}\\
\end{array}
\end{array}
if x < 0.0309999995Initial program 98.4%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3298.1
Applied rewrites98.1%
if 0.0309999995 < x Initial program 95.8%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites95.8%
Applied rewrites93.6%
Taylor expanded in x around 0
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f32N/A
lower-neg.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f32N/A
unpow2N/A
lower-*.f3293.8
Applied rewrites93.8%
(FPCore (x tau) :precision binary32 (let* ((t_1 (* x (PI)))) (/ (* (sin (* (* tau (PI)) x)) (sin t_1)) (* t_1 (* t_1 tau)))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
\frac{\sin \left(\left(tau \cdot \mathsf{PI}\left(\right)\right) \cdot x\right) \cdot \sin t\_1}{t\_1 \cdot \left(t\_1 \cdot tau\right)}
\end{array}
\end{array}
Initial program 97.5%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites97.5%
Applied rewrites81.5%
Applied rewrites97.6%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f3297.0
Applied rewrites97.0%
Final simplification97.0%
(FPCore (x tau) :precision binary32 (/ (* (sin (* (* tau x) (PI))) (sin (* (PI) x))) (* tau (* (* (PI) (PI)) (* x x)))))
\begin{array}{l}
\\
\frac{\sin \left(\left(tau \cdot x\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{tau \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(x \cdot x\right)\right)}
\end{array}
Initial program 97.5%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites97.5%
Applied rewrites81.5%
Applied rewrites97.6%
Taylor expanded in x around inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f32N/A
Applied rewrites96.9%
Final simplification96.9%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (* x (PI)) tau)))
(*
(/ (sin t_1) t_1)
(fma (* (* -0.16666666666666666 x) x) (* (PI) (PI)) 1.0))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\\
\frac{\sin t\_1}{t\_1} \cdot \mathsf{fma}\left(\left(-0.16666666666666666 \cdot x\right) \cdot x, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)
\end{array}
\end{array}
Initial program 97.5%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3280.9
Applied rewrites80.9%
(FPCore (x tau) :precision binary32 (* (/ (sin (* (* tau x) (PI))) (* (* x (PI)) tau)) (fma (* -0.16666666666666666 (* x x)) (* (PI) (PI)) 1.0)))
\begin{array}{l}
\\
\frac{\sin \left(\left(tau \cdot x\right) \cdot \mathsf{PI}\left(\right)\right)}{\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau} \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \left(x \cdot x\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)
\end{array}
Initial program 97.5%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3297.1
Applied rewrites97.1%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3280.4
Applied rewrites80.4%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* x (PI))))
(*
(fma (* (* -0.16666666666666666 x) x) (* (* (* (PI) (PI)) tau) tau) 1.0)
(/ (sin t_1) t_1))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
\mathsf{fma}\left(\left(-0.16666666666666666 \cdot x\right) \cdot x, \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right) \cdot tau, 1\right) \cdot \frac{\sin t\_1}{t\_1}
\end{array}
\end{array}
Initial program 97.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites75.1%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (PI) (PI))))
(*
(fma (* (* -0.16666666666666666 x) x) (* (* t_1 tau) tau) 1.0)
(fma (* -0.16666666666666666 (* x x)) t_1 1.0))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathsf{fma}\left(\left(-0.16666666666666666 \cdot x\right) \cdot x, \left(t\_1 \cdot tau\right) \cdot tau, 1\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \left(x \cdot x\right), t\_1, 1\right)
\end{array}
\end{array}
Initial program 97.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites75.1%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3274.9
Applied rewrites74.9%
(FPCore (x tau) :precision binary32 (fma (* (fma tau tau 1.0) (* (* (PI) (PI)) -0.16666666666666666)) (* x x) 1.0))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(tau, tau, 1\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -0.16666666666666666\right), x \cdot x, 1\right)
\end{array}
Initial program 97.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites73.9%
Final simplification73.9%
(FPCore (x tau) :precision binary32 1.0)
float code(float x, float tau) {
return 1.0f;
}
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(4) function code(x, tau)
use fmin_fmax_functions
real(4), intent (in) :: x
real(4), intent (in) :: tau
code = 1.0e0
end function
function code(x, tau) return Float32(1.0) end
function tmp = code(x, tau) tmp = single(1.0); end
\begin{array}{l}
\\
1
\end{array}
Initial program 97.5%
Taylor expanded in x around 0
Applied rewrites59.8%
Final simplification59.8%
herbie shell --seed 2024364
(FPCore (x tau)
:name "Lanczos kernel"
:precision binary32
:pre (and (and (<= 1e-5 x) (<= x 1.0)) (and (<= 1.0 tau) (<= tau 5.0)))
(* (/ (sin (* (* x (PI)) tau)) (* (* x (PI)) tau)) (/ (sin (* x (PI))) (* x (PI)))))