
(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 11 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 (* (PI) x))) (/ (* (sin t_1) (sin (* t_1 tau))) (* t_2 (* tau t_2)))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
t_2 := \mathsf{PI}\left(\right) \cdot x\\
\frac{\sin t\_1 \cdot \sin \left(t\_1 \cdot tau\right)}{t\_2 \cdot \left(tau \cdot t\_2\right)}
\end{array}
\end{array}
Initial program 97.7%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites97.7%
lift-/.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l/N/A
lift-/.f32N/A
frac-timesN/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
Applied rewrites97.4%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f3297.7
lift-*.f32N/A
*-commutativeN/A
lift-*.f3297.7
lift-*.f32N/A
*-commutativeN/A
lower-*.f3297.7
lift-*.f32N/A
*-commutativeN/A
lift-*.f3297.7
Applied rewrites97.7%
(FPCore (x tau) :precision binary32 (let* ((t_1 (* x (PI))) (t_2 (* t_1 tau))) (* (sin t_2) (/ (sin t_1) (* (* t_2 x) (PI))))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
t_2 := t\_1 \cdot tau\\
\sin t\_2 \cdot \frac{\sin t\_1}{\left(t\_2 \cdot x\right) \cdot \mathsf{PI}\left(\right)}
\end{array}
\end{array}
Initial program 97.7%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites97.7%
lift-/.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l/N/A
lift-/.f32N/A
frac-timesN/A
*-commutativeN/A
Applied rewrites97.3%
(FPCore (x tau) :precision binary32 (let* ((t_1 (* x (PI))) (t_2 (* t_1 tau))) (* (sin t_1) (/ (sin t_2) (* (* t_2 x) (PI))))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \mathsf{PI}\left(\right)\\
t_2 := t\_1 \cdot tau\\
\sin t\_1 \cdot \frac{\sin t\_2}{\left(t\_2 \cdot x\right) \cdot \mathsf{PI}\left(\right)}
\end{array}
\end{array}
Initial program 97.7%
lift-*.f32N/A
lift-/.f32N/A
associate-*l/N/A
lower-/.f32N/A
Applied rewrites97.7%
lift-/.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l/N/A
lift-/.f32N/A
frac-timesN/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
Applied rewrites97.2%
(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.7%
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.f3286.6
Applied rewrites86.6%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* tau (* (PI) x))))
(*
(/ (sin t_1) t_1)
(fma (* -0.16666666666666666 (* x x)) (* (PI) (PI)) 1.0))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := tau \cdot \left(\mathsf{PI}\left(\right) \cdot x\right)\\
\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.7%
remove-double-negN/A
lift-sin.f32N/A
sin-+PI-revN/A
sin-+PI-revN/A
lower-sin.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lift-PI.f32N/A
distribute-lft1-inN/A
lift-PI.f32N/A
lower-fma.f32N/A
lower-fma.f3277.4
Applied rewrites77.4%
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.f3268.2
Applied rewrites68.2%
Applied rewrites86.6%
(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.7%
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 rewrites81.0%
Final simplification81.0%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (PI) (PI))))
(*
(*
(fma (fma (* -0.16666666666666666 tau) (* t_1 (* x x)) 0.0) tau 1.0)
(/ tau tau))
(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)\\
\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666 \cdot tau, t\_1 \cdot \left(x \cdot x\right), 0\right), tau, 1\right) \cdot \frac{tau}{tau}\right) \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \left(x \cdot x\right), t\_1, 1\right)
\end{array}
\end{array}
Initial program 97.7%
remove-double-negN/A
lift-sin.f32N/A
sin-+PI-revN/A
sin-+PI-revN/A
lower-sin.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lift-PI.f32N/A
distribute-lft1-inN/A
lift-PI.f32N/A
lower-fma.f32N/A
lower-fma.f3277.4
Applied rewrites77.4%
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.f3268.2
Applied rewrites68.2%
Taylor expanded in tau around 0
Applied rewrites81.0%
Final simplification81.0%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (PI) (PI))))
(*
(fma (fma (* -0.16666666666666666 (* tau tau)) (* t_1 x) 0.0) x 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(\mathsf{fma}\left(-0.16666666666666666 \cdot \left(tau \cdot tau\right), t\_1 \cdot x, 0\right), x, 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.7%
remove-double-negN/A
lift-sin.f32N/A
sin-+PI-revN/A
sin-+PI-revN/A
lower-sin.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lift-PI.f32N/A
distribute-lft1-inN/A
lift-PI.f32N/A
lower-fma.f32N/A
lower-fma.f3277.4
Applied rewrites77.4%
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.f3268.2
Applied rewrites68.2%
Taylor expanded in x around 0
Applied rewrites81.0%
Final simplification81.0%
(FPCore (x tau) :precision binary32 (fma (* (* (PI) (PI)) (fma (* tau tau) -0.16666666666666666 -0.16666666666666666)) (* x x) 1.0))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{fma}\left(tau \cdot tau, -0.16666666666666666, -0.16666666666666666\right), x \cdot x, 1\right)
\end{array}
Initial program 97.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f32N/A
*-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3280.4
Applied rewrites80.4%
(FPCore (x tau) :precision binary32 (* 1.0 (fma (* -0.16666666666666666 (* x x)) (* (PI) (PI)) 1.0)))
\begin{array}{l}
\\
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}
Initial program 97.7%
remove-double-negN/A
lift-sin.f32N/A
sin-+PI-revN/A
sin-+PI-revN/A
lower-sin.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lift-PI.f32N/A
distribute-lft1-inN/A
lift-PI.f32N/A
lower-fma.f32N/A
lower-fma.f3277.4
Applied rewrites77.4%
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.f3268.2
Applied rewrites68.2%
Taylor expanded in x around 0
Applied rewrites65.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.7%
Taylor expanded in x around 0
Applied rewrites65.1%
herbie shell --seed 2025017
(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)))))