
(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 15 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) 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}
Initial program 97.7%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (PI) x)) (t_2 (* (* x (PI)) tau)))
(if (<= x 0.023000000044703484)
(*
(/ (sin t_2) t_2)
(fma (* (* -0.16666666666666666 x) x) (* (PI) (PI)) 1.0))
(/
(* (sin (fma t_1 tau (PI))) (sin t_1))
(* (* t_1 tau) (* (- (PI)) x))))))\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\\
\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(t\_1, tau, \mathsf{PI}\left(\right)\right)\right) \cdot \sin t\_1}{\left(t\_1 \cdot tau\right) \cdot \left(\left(-\mathsf{PI}\left(\right)\right) \cdot x\right)}\\
\end{array}
\end{array}
if x < 0.023Initial program 98.8%
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.5
Applied rewrites98.5%
if 0.023 < x Initial program 95.8%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3295.6
Applied rewrites95.6%
Applied rewrites93.2%
Final simplification96.6%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (PI) (PI))) (t_2 (* (* x (PI)) tau)))
(if (<= x 0.030799999833106995)
(* (/ (sin t_2) t_2) (fma (* (* -0.16666666666666666 x) x) t_1 1.0))
(/
(* (sin (fma (PI) x (PI))) (sin (* (* (PI) x) tau)))
(* (- tau) (* t_1 (* x x)))))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
t_2 := \left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\\
\mathbf{if}\;x \leq 0.030799999833106995:\\
\;\;\;\;\frac{\sin t\_2}{t\_2} \cdot \mathsf{fma}\left(\left(-0.16666666666666666 \cdot x\right) \cdot x, t\_1, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), x, \mathsf{PI}\left(\right)\right)\right) \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot x\right) \cdot tau\right)}{\left(-tau\right) \cdot \left(t\_1 \cdot \left(x \cdot x\right)\right)}\\
\end{array}
\end{array}
if x < 0.0307999998Initial program 98.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.f3298.1
Applied rewrites98.1%
if 0.0307999998 < x Initial program 95.5%
lift-*.f32N/A
lift-/.f32N/A
associate-*r/N/A
lift-*.f32N/A
*-commutativeN/A
times-fracN/A
frac-2negN/A
associate-*r/N/A
lower-/.f32N/A
Applied rewrites92.1%
Taylor expanded in tau around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f32N/A
unpow2N/A
lower-*.f3238.6
Applied rewrites38.6%
Taylor expanded in x around inf
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f32N/A
Applied rewrites92.2%
Final simplification96.2%
(FPCore (x tau) :precision binary32 (let* ((t_1 (* (PI) x)) (t_2 (* tau t_1))) (* (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 := tau \cdot t\_1\\
\sin t\_1 \cdot \frac{\frac{\sin t\_2}{t\_2}}{t\_1}
\end{array}
\end{array}
Initial program 97.7%
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
associate-*l/N/A
associate-/l*N/A
lower-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-/.f3297.6
Applied rewrites97.6%
(FPCore (x tau) :precision binary32 (let* ((t_1 (* (PI) (* x tau))) (t_2 (* (PI) x))) (/ (* (sin t_1) (sin t_2)) (* t_2 t_1))))
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{PI}\left(\right) \cdot \left(x \cdot tau\right)\\
t_2 := \mathsf{PI}\left(\right) \cdot x\\
\frac{\sin t\_1 \cdot \sin t\_2}{t\_2 \cdot t\_1}
\end{array}
\end{array}
Initial program 97.7%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3297.2
Applied rewrites97.2%
Applied rewrites97.4%
Final simplification97.4%
(FPCore (x tau) :precision binary32 (/ (* (sin (* (PI) (* x tau))) (sin (* (PI) x))) (* x (* (* tau x) (* (PI) (PI))))))
\begin{array}{l}
\\
\frac{\sin \left(\mathsf{PI}\left(\right) \cdot \left(x \cdot tau\right)\right) \cdot \sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{x \cdot \left(\left(tau \cdot x\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\right)}
\end{array}
Initial program 97.7%
lift-*.f32N/A
lift-/.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
associate-/r*N/A
lift-/.f32N/A
frac-2negN/A
frac-timesN/A
associate-*r*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lift-*.f32N/A
Applied rewrites79.2%
Applied rewrites96.8%
Final simplification96.8%
(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.f3283.7
Applied rewrites83.7%
(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.7%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3297.2
Applied rewrites97.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.f3283.3
Applied rewrites83.3%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* x (PI))))
(*
(fma (* (* tau tau) -0.16666666666666666) (* (* (* (PI) (PI)) x) x) 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(tau \cdot tau\right) \cdot -0.16666666666666666, \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot x\right) \cdot x, 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
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3277.4
Applied rewrites77.4%
(FPCore (x tau)
:precision binary32
(let* ((t_1 (* (PI) x)))
(*
(sin t_1)
(fma (* -0.16666666666666666 (* tau tau)) t_1 (/ (/ 1.0 (PI)) x)))))\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{PI}\left(\right) \cdot x\\
\sin t\_1 \cdot \mathsf{fma}\left(-0.16666666666666666 \cdot \left(tau \cdot tau\right), t\_1, \frac{\frac{1}{\mathsf{PI}\left(\right)}}{x}\right)
\end{array}
\end{array}
Initial program 97.7%
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
lift-/.f32N/A
lift-*.f32N/A
associate-/r*N/A
frac-timesN/A
lift-*.f32N/A
associate-/l*N/A
lower-*.f32N/A
Applied rewrites97.5%
Taylor expanded in tau around 0
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f32N/A
lower-/.f32N/A
lower-PI.f3276.9
Applied rewrites76.9%
(FPCore (x tau) :precision binary32 (fma (* (- (* tau tau) -1.0) (* (* (PI) (PI)) -0.16666666666666666)) (* x x) 1.0))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(tau \cdot 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.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites76.3%
Applied rewrites76.3%
(FPCore (x tau) :precision binary32 (fma (* (PI) (* (* -0.16666666666666666 (PI)) (fma tau tau 1.0))) (* x x) 1.0))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{PI}\left(\right) \cdot \left(\left(-0.16666666666666666 \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{fma}\left(tau, tau, 1\right)\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
Applied rewrites76.3%
Applied rewrites76.3%
(FPCore (x tau) :precision binary32 (fma (* (* -0.16666666666666666 (* tau tau)) (* (PI) (PI))) (* x x) 1.0))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(-0.16666666666666666 \cdot \left(tau \cdot tau\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\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
Applied rewrites76.3%
Taylor expanded in tau around inf
Applied rewrites67.8%
(FPCore (x tau) :precision binary32 (fma (* (* (PI) (PI)) -0.16666666666666666) (* x x) 1.0))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -0.16666666666666666, 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
Applied rewrites76.3%
Taylor expanded in tau around 0
Applied rewrites62.6%
(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 rewrites62.0%
herbie shell --seed 2025008
(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)))))