
(FPCore (x tau) :precision binary32 (let* ((t_1 (* (* x PI) tau))) (* (/ (sin t_1) t_1) (/ (sin (* x PI)) (* x PI)))))
float code(float x, float tau) {
float t_1 = (x * ((float) M_PI)) * tau;
return (sinf(t_1) / t_1) * (sinf((x * ((float) M_PI))) / (x * ((float) M_PI)));
}
function code(x, tau) t_1 = Float32(Float32(x * Float32(pi)) * tau) return Float32(Float32(sin(t_1) / t_1) * Float32(sin(Float32(x * Float32(pi))) / Float32(x * Float32(pi)))) end
function tmp = code(x, tau) t_1 = (x * single(pi)) * tau; tmp = (sin(t_1) / t_1) * (sin((x * single(pi))) / (x * single(pi))); end
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot \pi\right) \cdot tau\\
\frac{\sin t_1}{t_1} \cdot \frac{\sin \left(x \cdot \pi\right)}{x \cdot \pi}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x tau) :precision binary32 (let* ((t_1 (* (* x PI) tau))) (* (/ (sin t_1) t_1) (/ (sin (* x PI)) (* x PI)))))
float code(float x, float tau) {
float t_1 = (x * ((float) M_PI)) * tau;
return (sinf(t_1) / t_1) * (sinf((x * ((float) M_PI))) / (x * ((float) M_PI)));
}
function code(x, tau) t_1 = Float32(Float32(x * Float32(pi)) * tau) return Float32(Float32(sin(t_1) / t_1) * Float32(sin(Float32(x * Float32(pi))) / Float32(x * Float32(pi)))) end
function tmp = code(x, tau) t_1 = (x * single(pi)) * tau; tmp = (sin(t_1) / t_1) * (sin((x * single(pi))) / (x * single(pi))); end
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(x \cdot \pi\right) \cdot tau\\
\frac{\sin t_1}{t_1} \cdot \frac{\sin \left(x \cdot \pi\right)}{x \cdot \pi}
\end{array}
\end{array}
(FPCore (x tau) :precision binary32 (let* ((t_1 (* x (* PI tau)))) (* (/ (sin t_1) t_1) (/ (sin (* x PI)) (* x PI)))))
float code(float x, float tau) {
float t_1 = x * (((float) M_PI) * tau);
return (sinf(t_1) / t_1) * (sinf((x * ((float) M_PI))) / (x * ((float) M_PI)));
}
function code(x, tau) t_1 = Float32(x * Float32(Float32(pi) * tau)) return Float32(Float32(sin(t_1) / t_1) * Float32(sin(Float32(x * Float32(pi))) / Float32(x * Float32(pi)))) end
function tmp = code(x, tau) t_1 = x * (single(pi) * tau); tmp = (sin(t_1) / t_1) * (sin((x * single(pi))) / (x * single(pi))); end
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(\pi \cdot tau\right)\\
\frac{\sin t_1}{t_1} \cdot \frac{\sin \left(x \cdot \pi\right)}{x \cdot \pi}
\end{array}
\end{array}
Initial program 98.0%
associate-*l*97.6%
associate-*l*98.1%
Simplified98.1%
Final simplification98.1%
(FPCore (x tau) :precision binary32 (* (sin (* x PI)) (/ (sin (* x (* PI tau))) (* tau (pow (* x PI) 2.0)))))
float code(float x, float tau) {
return sinf((x * ((float) M_PI))) * (sinf((x * (((float) M_PI) * tau))) / (tau * powf((x * ((float) M_PI)), 2.0f)));
}
function code(x, tau) return Float32(sin(Float32(x * Float32(pi))) * Float32(sin(Float32(x * Float32(Float32(pi) * tau))) / Float32(tau * (Float32(x * Float32(pi)) ^ Float32(2.0))))) end
function tmp = code(x, tau) tmp = sin((x * single(pi))) * (sin((x * (single(pi) * tau))) / (tau * ((x * single(pi)) ^ single(2.0)))); end
\begin{array}{l}
\\
\sin \left(x \cdot \pi\right) \cdot \frac{\sin \left(x \cdot \left(\pi \cdot tau\right)\right)}{tau \cdot {\left(x \cdot \pi\right)}^{2}}
\end{array}
Initial program 98.0%
associate-/r*97.8%
frac-times97.9%
*-commutative97.9%
associate-*l*97.4%
*-commutative97.4%
*-commutative97.4%
associate-*l*98.0%
Applied egg-rr98.0%
Taylor expanded in x around inf 96.8%
associate-/l*96.9%
associate-*r*97.2%
*-commutative97.2%
*-commutative97.2%
*-commutative97.2%
*-commutative97.2%
unpow297.2%
unpow297.2%
swap-sqr97.3%
unpow297.3%
*-commutative97.3%
*-commutative97.3%
associate-/r/97.1%
Simplified97.2%
Final simplification97.2%
(FPCore (x tau) :precision binary32 (* (sin (* x PI)) (/ (sin (* tau (* x PI))) (* tau (pow (* x PI) 2.0)))))
float code(float x, float tau) {
return sinf((x * ((float) M_PI))) * (sinf((tau * (x * ((float) M_PI)))) / (tau * powf((x * ((float) M_PI)), 2.0f)));
}
function code(x, tau) return Float32(sin(Float32(x * Float32(pi))) * Float32(sin(Float32(tau * Float32(x * Float32(pi)))) / Float32(tau * (Float32(x * Float32(pi)) ^ Float32(2.0))))) end
function tmp = code(x, tau) tmp = sin((x * single(pi))) * (sin((tau * (x * single(pi)))) / (tau * ((x * single(pi)) ^ single(2.0)))); end
\begin{array}{l}
\\
\sin \left(x \cdot \pi\right) \cdot \frac{\sin \left(tau \cdot \left(x \cdot \pi\right)\right)}{tau \cdot {\left(x \cdot \pi\right)}^{2}}
\end{array}
Initial program 98.0%
associate-/r*97.7%
div-inv97.7%
Applied egg-rr97.7%
Taylor expanded in x around inf 96.8%
*-commutative96.8%
*-commutative96.8%
associate-*r*97.1%
unpow297.1%
unpow297.1%
swap-sqr97.3%
unpow297.3%
associate-*r/97.2%
associate-*r*97.4%
Simplified97.4%
Final simplification97.4%
(FPCore (x tau) :precision binary32 (/ (sin (* tau (* x PI))) (/ (* tau (pow (* x PI) 2.0)) (sin (* x PI)))))
float code(float x, float tau) {
return sinf((tau * (x * ((float) M_PI)))) / ((tau * powf((x * ((float) M_PI)), 2.0f)) / sinf((x * ((float) M_PI))));
}
function code(x, tau) return Float32(sin(Float32(tau * Float32(x * Float32(pi)))) / Float32(Float32(tau * (Float32(x * Float32(pi)) ^ Float32(2.0))) / sin(Float32(x * Float32(pi))))) end
function tmp = code(x, tau) tmp = sin((tau * (x * single(pi)))) / ((tau * ((x * single(pi)) ^ single(2.0))) / sin((x * single(pi)))); end
\begin{array}{l}
\\
\frac{\sin \left(tau \cdot \left(x \cdot \pi\right)\right)}{\frac{tau \cdot {\left(x \cdot \pi\right)}^{2}}{\sin \left(x \cdot \pi\right)}}
\end{array}
Initial program 98.0%
frac-times97.9%
associate-/l*97.8%
*-commutative97.8%
associate-*l*97.3%
*-commutative97.3%
associate-*l*97.3%
pow297.3%
Applied egg-rr97.3%
Taylor expanded in x around inf 97.5%
Final simplification97.5%
(FPCore (x tau) :precision binary32 (fma (pow x 2.0) (* -0.16666666666666666 (* (+ (pow tau 2.0) 1.0) (pow PI 2.0))) 1.0))
float code(float x, float tau) {
return fmaf(powf(x, 2.0f), (-0.16666666666666666f * ((powf(tau, 2.0f) + 1.0f) * powf(((float) M_PI), 2.0f))), 1.0f);
}
function code(x, tau) return fma((x ^ Float32(2.0)), Float32(Float32(-0.16666666666666666) * Float32(Float32((tau ^ Float32(2.0)) + Float32(1.0)) * (Float32(pi) ^ Float32(2.0)))), Float32(1.0)) end
\begin{array}{l}
\\
\mathsf{fma}\left({x}^{2}, -0.16666666666666666 \cdot \left(\left({tau}^{2} + 1\right) \cdot {\pi}^{2}\right), 1\right)
\end{array}
Initial program 98.0%
*-commutative98.0%
associate-*l/98.0%
*-commutative98.0%
associate-*l*97.4%
*-commutative97.4%
associate-*l*98.0%
Applied egg-rr98.0%
Taylor expanded in x around 0 78.1%
+-commutative78.1%
fma-def78.1%
distribute-lft-out78.1%
distribute-lft1-in78.1%
Simplified78.1%
Final simplification78.1%
(FPCore (x tau) :precision binary32 (let* ((t_1 (* x (* PI tau)))) (/ (sin t_1) t_1)))
float code(float x, float tau) {
float t_1 = x * (((float) M_PI) * tau);
return sinf(t_1) / t_1;
}
function code(x, tau) t_1 = Float32(x * Float32(Float32(pi) * tau)) return Float32(sin(t_1) / t_1) end
function tmp = code(x, tau) t_1 = x * (single(pi) * tau); tmp = sin(t_1) / t_1; end
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot \left(\pi \cdot tau\right)\\
\frac{\sin t_1}{t_1}
\end{array}
\end{array}
Initial program 98.0%
associate-*l*97.6%
associate-*l*98.1%
Simplified98.1%
Taylor expanded in x around 0 70.8%
Final simplification70.8%
(FPCore (x tau) :precision binary32 (fma -0.16666666666666666 (pow (* x PI) 2.0) 1.0))
float code(float x, float tau) {
return fmaf(-0.16666666666666666f, powf((x * ((float) M_PI)), 2.0f), 1.0f);
}
function code(x, tau) return fma(Float32(-0.16666666666666666), (Float32(x * Float32(pi)) ^ Float32(2.0)), Float32(1.0)) end
\begin{array}{l}
\\
\mathsf{fma}\left(-0.16666666666666666, {\left(x \cdot \pi\right)}^{2}, 1\right)
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 85.4%
+-commutative85.4%
fma-def85.4%
unpow285.4%
unpow285.4%
swap-sqr85.4%
unpow285.4%
Simplified85.4%
Taylor expanded in tau around 0 64.5%
+-commutative64.5%
unpow264.5%
unpow264.5%
swap-sqr64.5%
unpow264.5%
fma-udef64.5%
Simplified64.5%
Final simplification64.5%
(FPCore (x tau) :precision binary32 (+ 1.0 (* (pow (* x PI) 2.0) -0.16666666666666666)))
float code(float x, float tau) {
return 1.0f + (powf((x * ((float) M_PI)), 2.0f) * -0.16666666666666666f);
}
function code(x, tau) return Float32(Float32(1.0) + Float32((Float32(x * Float32(pi)) ^ Float32(2.0)) * Float32(-0.16666666666666666))) end
function tmp = code(x, tau) tmp = single(1.0) + (((x * single(pi)) ^ single(2.0)) * single(-0.16666666666666666)); end
\begin{array}{l}
\\
1 + {\left(x \cdot \pi\right)}^{2} \cdot -0.16666666666666666
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 85.4%
+-commutative85.4%
fma-def85.4%
unpow285.4%
unpow285.4%
swap-sqr85.4%
unpow285.4%
Simplified85.4%
Taylor expanded in tau around 0 64.5%
+-commutative64.5%
unpow264.5%
unpow264.5%
swap-sqr64.5%
unpow264.5%
fma-udef64.5%
Simplified64.5%
fma-udef64.5%
*-commutative64.5%
Applied egg-rr64.5%
Final simplification64.5%
(FPCore (x tau) :precision binary32 1.0)
float code(float x, float tau) {
return 1.0f;
}
real(4) function code(x, tau)
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 98.0%
*-commutative98.0%
associate-*l/98.0%
*-commutative98.0%
associate-*l*97.4%
*-commutative97.4%
associate-*l*98.0%
Applied egg-rr98.0%
Taylor expanded in x around 0 63.5%
Final simplification63.5%
herbie shell --seed 2024011
(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))))