
(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 12 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)) (t_3 (* (PI) (PI))))
(if (<= (* (/ (sin t_2) t_2) (/ (sin t_1) t_1)) 0.9850000143051147)
(/
(* (sin (fma (* x tau) (PI) (PI))) (sin (* (PI) x)))
(* (* (- x) x) (* t_3 tau)))
(fma
(fma
(fma tau tau 1.0)
(* t_3 -0.16666666666666666)
(*
(*
(pow (PI) 4.0)
(fma
(* 0.027777777777777776 tau)
tau
(fma
(* tau tau)
(* (* tau tau) 0.008333333333333333)
0.008333333333333333)))
(* x x)))
(* x x)
1.0))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
t_2 := t\_1 \cdot tau\\
t_3 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;\frac{\sin t\_2}{t\_2} \cdot \frac{\sin t\_1}{t\_1} \leq 0.9850000143051147:\\
\;\;\;\;\frac{\sin \left(\mathsf{fma}\left(x \cdot tau, \mathsf{PI}\left(\right), \mathsf{PI}\left(\right)\right)\right) \cdot \sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\left(\left(-x\right) \cdot x\right) \cdot \left(t\_3 \cdot tau\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(tau, tau, 1\right), t\_3 \cdot -0.16666666666666666, \left({\mathsf{PI}\left(\right)}^{4} \cdot \mathsf{fma}\left(0.027777777777777776 \cdot tau, tau, \mathsf{fma}\left(tau \cdot tau, \left(tau \cdot tau\right) \cdot 0.008333333333333333, 0.008333333333333333\right)\right)\right) \cdot \left(x \cdot x\right)\right), x \cdot x, 1\right)\\
\end{array}
\end{array}
if (*.f32 (/.f32 (sin.f32 (*.f32 (*.f32 x (PI.f32)) tau)) (*.f32 (*.f32 x (PI.f32)) tau)) (/.f32 (sin.f32 (*.f32 x (PI.f32))) (*.f32 x (PI.f32)))) < 0.985000014Initial program 96.2%
Taylor expanded in x around inf
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
times-fracN/A
lower-*.f32N/A
Applied rewrites95.8%
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
frac-2negN/A
lift-/.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
frac-timesN/A
lower-/.f32N/A
Applied rewrites94.6%
if 0.985000014 < (*.f32 (/.f32 (sin.f32 (*.f32 (*.f32 x (PI.f32)) tau)) (*.f32 (*.f32 x (PI.f32)) tau)) (/.f32 (sin.f32 (*.f32 x (PI.f32))) (*.f32 x (PI.f32)))) Initial program 98.7%
Taylor expanded in x around 0
Applied rewrites99.9%
lift-fma.f32N/A
lift-pow.f32N/A
metadata-evalN/A
pow-powN/A
pow2N/A
pow2N/A
associate-*l*N/A
lower-fma.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lower-*.f3299.9
Applied rewrites99.9%
(FPCore (x tau) :precision binary32 (let* ((t_1 (* (* (PI) tau) x)) (t_2 (* x (PI)))) (* (/ (sin t_1) t_1) (/ (sin t_2) t_2))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(\mathsf{PI}\left(\right) \cdot tau\right) \cdot x\\
t_2 := x \cdot \mathsf{PI}\left(\right)\\
\frac{\sin t\_1}{t\_1} \cdot \frac{\sin t\_2}{t\_2}
\end{array}
\end{array}
Initial program 97.9%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f3297.3
Applied rewrites97.3%
Taylor expanded in x around inf
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-/.f32N/A
lower-sin.f32N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-*.f32N/A
Applied rewrites98.0%
Final simplification98.0%
(FPCore (x tau) :precision binary32 (let* ((t_1 (* (PI) x)) (t_2 (* (* x (PI)) tau))) (/ (* (sin t_1) (sin t_2)) (* t_2 t_1))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{PI}\left(\right) \cdot x\\
t_2 := \left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\\
\frac{\sin t\_1 \cdot \sin t\_2}{t\_2 \cdot t\_1}
\end{array}
\end{array}
Initial program 97.9%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites97.7%
Applied rewrites97.6%
Final simplification97.6%
(FPCore (x tau) :precision binary32 (let* ((t_1 (* x (PI)))) (/ (* (sin (* (PI) x)) (sin (* t_1 tau))) (* x (* (* tau (PI)) t_1)))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
\frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \sin \left(t\_1 \cdot tau\right)}{x \cdot \left(\left(tau \cdot \mathsf{PI}\left(\right)\right) \cdot t\_1\right)}
\end{array}
\end{array}
Initial program 97.9%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites97.7%
Applied rewrites97.1%
Final simplification97.1%
(FPCore (x tau) :precision binary32 (/ (* (sin (* (* x tau) (PI))) (sin (* x (PI)))) (* (* (* (PI) (PI)) tau) (* x x))))
\begin{array}{l}
\\
\frac{\sin \left(\left(x \cdot tau\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right) \cdot \left(x \cdot x\right)}
\end{array}
Initial program 97.9%
Taylor expanded in x around inf
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
times-fracN/A
lower-*.f32N/A
Applied rewrites96.8%
Applied rewrites96.7%
Final simplification96.7%
(FPCore (x tau) :precision binary32 (/ (* (sin (* (* (PI) x) tau)) (sin (* x (PI)))) (* (* (* (PI) (PI)) tau) (* x x))))
\begin{array}{l}
\\
\frac{\sin \left(\left(\mathsf{PI}\left(\right) \cdot x\right) \cdot tau\right) \cdot \sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right) \cdot \left(x \cdot x\right)}
\end{array}
Initial program 97.9%
Taylor expanded in x around inf
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
times-fracN/A
lower-*.f32N/A
Applied rewrites96.8%
Applied rewrites96.7%
Taylor expanded in x around inf
lower-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3296.7
Applied rewrites96.7%
Final simplification96.7%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (* x (PI)) tau)))
(*
(/ (sin t_1) t_1)
(fma (* (* (PI) (PI)) -0.16666666666666666) (* x x) 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(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -0.16666666666666666, x \cdot x, 1\right)
\end{array}
\end{array}
Initial program 97.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f32N/A
unpow2N/A
lower-*.f3282.8
Applied rewrites82.8%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (* (PI) tau) x)))
(*
(/ (sin t_1) t_1)
(fma (* -0.16666666666666666 (* x x)) (* (PI) (PI)) 1.0))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(\mathsf{PI}\left(\right) \cdot tau\right) \cdot x\\
\frac{\sin t\_1}{t\_1} \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}
\end{array}
Initial program 97.9%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f3297.3
Applied rewrites97.3%
Taylor expanded in x around inf
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-/.f32N/A
lower-sin.f32N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-*.f32N/A
Applied rewrites98.0%
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.f3282.8
Applied rewrites82.8%
Final simplification82.8%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (PI) (PI))))
(*
(fma (* (* (* tau tau) x) x) (* t_1 -0.16666666666666666) 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(\left(tau \cdot tau\right) \cdot x\right) \cdot x, t\_1 \cdot -0.16666666666666666, 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.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites78.2%
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.f3277.6
Applied rewrites77.6%
(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.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites77.3%
(FPCore (x tau) :precision binary32 (fma (* -0.16666666666666666 (* x x)) (* (fma tau tau 1.0) (* (PI) (PI))) 1.0))
\begin{array}{l}
\\
\mathsf{fma}\left(-0.16666666666666666 \cdot \left(x \cdot x\right), \mathsf{fma}\left(tau, tau, 1\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), 1\right)
\end{array}
Initial program 97.9%
Taylor expanded in x around 0
Applied rewrites82.1%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
Applied rewrites77.3%
(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.9%
Taylor expanded in x around 0
Applied rewrites63.8%
herbie shell --seed 2025026
(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)))))