Lanczos kernel

Percentage Accurate: 97.9% → 97.9%
Time: 9.8s
Alternatives: 8
Speedup: N/A×

Specification

?
\[\left(10^{-5} \leq x \land x \leq 1\right) \land \left(1 \leq tau \land tau \leq 5\right)\]
\[\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}

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 97.9% accurate, 1.0× speedup?

\[\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}

Alternative 1: 97.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(tau \cdot x\right) \cdot \mathsf{PI}\left(\right)\\ 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} \]
(FPCore (x tau)
 :precision binary32
 (let* ((t_1 (* (* tau x) (PI))) (t_2 (* x (PI))))
   (* (/ (sin t_1) t_1) (/ (sin t_2) t_2))))
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left(tau \cdot x\right) \cdot \mathsf{PI}\left(\right)\\
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}
Derivation
  1. Initial program 97.8%

    \[\frac{\sin \left(\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right)}{\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf

    \[\leadsto \color{blue}{\frac{\sin \left(tau \cdot \left(x \cdot \mathsf{PI}\left(\right)\right)\right)}{tau \cdot \left(x \cdot \mathsf{PI}\left(\right)\right)}} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
  4. Step-by-step derivation
    1. Applied rewrites97.9%

      \[\leadsto \color{blue}{\frac{\sin \left(\left(tau \cdot x\right) \cdot \mathsf{PI}\left(\right)\right)}{\left(tau \cdot x\right) \cdot \mathsf{PI}\left(\right)}} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
    2. Add Preprocessing

    Alternative 2: 97.3% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_1 := \left(\mathsf{PI}\left(\right) \cdot tau\right) \cdot x\\ \sin t\_1 \cdot \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\left(t\_1 \cdot x\right) \cdot \mathsf{PI}\left(\right)} \end{array} \end{array} \]
    (FPCore (x tau)
     :precision binary32
     (let* ((t_1 (* (* (PI) tau) x)))
       (* (sin t_1) (/ (sin (* (PI) x)) (* (* t_1 x) (PI))))))
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_1 := \left(\mathsf{PI}\left(\right) \cdot tau\right) \cdot x\\
    \sin t\_1 \cdot \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\left(t\_1 \cdot x\right) \cdot \mathsf{PI}\left(\right)}
    \end{array}
    \end{array}
    
    Derivation
    1. Initial program 97.8%

      \[\frac{\sin \left(\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right)}{\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
    2. Add Preprocessing
    3. Applied rewrites77.7%

      \[\leadsto \color{blue}{\sin \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), x, \mathsf{PI}\left(\right)\right)\right) \cdot \frac{\sin \left(\mathsf{fma}\left(tau \cdot x, \mathsf{PI}\left(\right), \mathsf{PI}\left(\right)\right)\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot x\right) \cdot x\right) \cdot \left(tau \cdot \mathsf{PI}\left(\right)\right)}} \]
    4. Applied rewrites97.4%

      \[\leadsto \color{blue}{\sin \left(\left(\mathsf{PI}\left(\right) \cdot tau\right) \cdot x\right) \cdot \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\left(\left(\left(\mathsf{PI}\left(\right) \cdot tau\right) \cdot x\right) \cdot x\right) \cdot \mathsf{PI}\left(\right)}} \]
    5. Add Preprocessing

    Alternative 3: 97.4% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{PI}\left(\right) \cdot \left(tau \cdot x\right)\\ \sin \left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \frac{\sin t\_1}{\left(t\_1 \cdot \mathsf{PI}\left(\right)\right) \cdot x} \end{array} \end{array} \]
    (FPCore (x tau)
     :precision binary32
     (let* ((t_1 (* (PI) (* tau x))))
       (* (sin (* (PI) x)) (/ (sin t_1) (* (* t_1 (PI)) x)))))
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_1 := \mathsf{PI}\left(\right) \cdot \left(tau \cdot x\right)\\
    \sin \left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \frac{\sin t\_1}{\left(t\_1 \cdot \mathsf{PI}\left(\right)\right) \cdot x}
    \end{array}
    \end{array}
    
    Derivation
    1. Initial program 97.8%

      \[\frac{\sin \left(\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right)}{\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
    2. Add Preprocessing
    3. Applied rewrites81.6%

      \[\leadsto \color{blue}{\sin \left(\mathsf{fma}\left(tau \cdot x, \mathsf{PI}\left(\right), \mathsf{PI}\left(\right)\right)\right) \cdot \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot x\right) \cdot x\right) \cdot \left(\left(-tau\right) \cdot \mathsf{PI}\left(\right)\right)}} \]
    4. Applied rewrites97.3%

      \[\leadsto \color{blue}{\sin \left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \frac{\sin \left(\mathsf{PI}\left(\right) \cdot \left(tau \cdot x\right)\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot \left(tau \cdot x\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot x}} \]
    5. Add Preprocessing

    Alternative 4: 97.2% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{PI}\left(\right) \cdot x\\ \sin t\_1 \cdot \frac{\sin \left(tau \cdot t\_1\right)}{\left(t\_1 \cdot x\right) \cdot \left(tau \cdot \mathsf{PI}\left(\right)\right)} \end{array} \end{array} \]
    (FPCore (x tau)
     :precision binary32
     (let* ((t_1 (* (PI) x)))
       (* (sin t_1) (/ (sin (* tau t_1)) (* (* t_1 x) (* tau (PI)))))))
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_1 := \mathsf{PI}\left(\right) \cdot x\\
    \sin t\_1 \cdot \frac{\sin \left(tau \cdot t\_1\right)}{\left(t\_1 \cdot x\right) \cdot \left(tau \cdot \mathsf{PI}\left(\right)\right)}
    \end{array}
    \end{array}
    
    Derivation
    1. Initial program 97.8%

      \[\frac{\sin \left(\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right)}{\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
    2. Add Preprocessing
    3. Applied rewrites96.9%

      \[\leadsto \color{blue}{\sin \left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \frac{\sin \left(tau \cdot \left(\mathsf{PI}\left(\right) \cdot x\right)\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot x\right) \cdot x\right) \cdot \left(tau \cdot \mathsf{PI}\left(\right)\right)}} \]
    4. Add Preprocessing

    Alternative 5: 97.0% accurate, 1.0× speedup?

    \[\begin{array}{l} \\ \sin \left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \frac{\sin \left(\left(\mathsf{PI}\left(\right) \cdot tau\right) \cdot x\right)}{\left(tau \cdot \left(x \cdot x\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)} \end{array} \]
    (FPCore (x tau)
     :precision binary32
     (*
      (sin (* (PI) x))
      (/ (sin (* (* (PI) tau) x)) (* (* tau (* x x)) (* (PI) (PI))))))
    \begin{array}{l}
    
    \\
    \sin \left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \frac{\sin \left(\left(\mathsf{PI}\left(\right) \cdot tau\right) \cdot x\right)}{\left(tau \cdot \left(x \cdot x\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)}
    \end{array}
    
    Derivation
    1. Initial program 97.8%

      \[\frac{\sin \left(\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right)}{\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{\sin \left(tau \cdot \left(x \cdot \mathsf{PI}\left(\right)\right)\right)}{tau \cdot \left(x \cdot \mathsf{PI}\left(\right)\right)}} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
    4. Step-by-step derivation
      1. Applied rewrites97.9%

        \[\leadsto \color{blue}{\frac{\sin \left(\left(tau \cdot x\right) \cdot \mathsf{PI}\left(\right)\right)}{\left(tau \cdot x\right) \cdot \mathsf{PI}\left(\right)}} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
      2. Taylor expanded in x around inf

        \[\leadsto \color{blue}{\frac{\sin \left(tau \cdot \left(x \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{tau \cdot \left({x}^{2} \cdot {\mathsf{PI}\left(\right)}^{2}\right)}} \]
      3. Applied rewrites96.8%

        \[\leadsto \color{blue}{\sin \left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \frac{\sin \left(\left(\mathsf{PI}\left(\right) \cdot tau\right) \cdot x\right)}{\left(tau \cdot \left(x \cdot x\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)}} \]
      4. Final simplification96.8%

        \[\leadsto \sin \left(\mathsf{PI}\left(\right) \cdot x\right) \cdot \frac{\sin \left(\left(\mathsf{PI}\left(\right) \cdot tau\right) \cdot x\right)}{\left(tau \cdot \left(x \cdot x\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)} \]
      5. Add Preprocessing

      Alternative 6: 70.9% accurate, 1.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_1 := tau \cdot \left(\mathsf{PI}\left(\right) \cdot x\right)\\ \frac{\mathsf{PI}\left(\right) \cdot \sin t\_1}{t\_1 \cdot \mathsf{PI}\left(\right)} \end{array} \end{array} \]
      (FPCore (x tau)
       :precision binary32
       (let* ((t_1 (* tau (* (PI) x)))) (/ (* (PI) (sin t_1)) (* t_1 (PI)))))
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_1 := tau \cdot \left(\mathsf{PI}\left(\right) \cdot x\right)\\
      \frac{\mathsf{PI}\left(\right) \cdot \sin t\_1}{t\_1 \cdot \mathsf{PI}\left(\right)}
      \end{array}
      \end{array}
      
      Derivation
      1. Initial program 97.8%

        \[\frac{\sin \left(\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right)}{\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
      2. Add Preprocessing
      3. Applied rewrites97.4%

        \[\leadsto \color{blue}{\frac{\frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{x} \cdot \sin \left(tau \cdot \left(\mathsf{PI}\left(\right) \cdot x\right)\right)}{\left(tau \cdot \left(\mathsf{PI}\left(\right) \cdot x\right)\right) \cdot \mathsf{PI}\left(\right)}} \]
      4. Taylor expanded in x around 0

        \[\leadsto \frac{\color{blue}{\mathsf{PI}\left(\right)} \cdot \sin \left(tau \cdot \left(\mathsf{PI}\left(\right) \cdot x\right)\right)}{\left(tau \cdot \left(\mathsf{PI}\left(\right) \cdot x\right)\right) \cdot \mathsf{PI}\left(\right)} \]
      5. Step-by-step derivation
        1. Applied rewrites70.5%

          \[\leadsto \frac{\color{blue}{\mathsf{PI}\left(\right)} \cdot \sin \left(tau \cdot \left(\mathsf{PI}\left(\right) \cdot x\right)\right)}{\left(tau \cdot \left(\mathsf{PI}\left(\right) \cdot x\right)\right) \cdot \mathsf{PI}\left(\right)} \]
        2. Add Preprocessing

        Alternative 7: 64.3% accurate, 2.1× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{PI}\left(\right) \cdot x\\ \frac{\sin t\_1}{t\_1} \end{array} \end{array} \]
        (FPCore (x tau)
         :precision binary32
         (let* ((t_1 (* (PI) x))) (/ (sin t_1) t_1)))
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_1 := \mathsf{PI}\left(\right) \cdot x\\
        \frac{\sin t\_1}{t\_1}
        \end{array}
        \end{array}
        
        Derivation
        1. Initial program 97.8%

          \[\frac{\sin \left(\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right)}{\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
        2. Add Preprocessing
        3. Taylor expanded in tau around 0

          \[\leadsto \color{blue}{\frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)}} \]
        4. Step-by-step derivation
          1. Applied rewrites63.5%

            \[\leadsto \color{blue}{\frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{PI}\left(\right) \cdot x}} \]
          2. Final simplification63.5%

            \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{PI}\left(\right) \cdot x} \]
          3. Add Preprocessing

          Alternative 8: 63.5% accurate, 21.5× speedup?

          \[\begin{array}{l} \\ \frac{x}{x} \end{array} \]
          (FPCore (x tau) :precision binary32 (/ x x))
          float code(float x, float tau) {
          	return x / x;
          }
          
          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 = x / x
          end function
          
          function code(x, tau)
          	return Float32(x / x)
          end
          
          function tmp = code(x, tau)
          	tmp = x / x;
          end
          
          \begin{array}{l}
          
          \\
          \frac{x}{x}
          \end{array}
          
          Derivation
          1. Initial program 97.8%

            \[\frac{\sin \left(\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau\right)}{\left(x \cdot \mathsf{PI}\left(\right)\right) \cdot tau} \cdot \frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{x \cdot \mathsf{PI}\left(\right)} \]
          2. Add Preprocessing
          3. Applied rewrites81.6%

            \[\leadsto \color{blue}{\sin \left(\mathsf{fma}\left(tau \cdot x, \mathsf{PI}\left(\right), \mathsf{PI}\left(\right)\right)\right) \cdot \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\left(\left(\mathsf{PI}\left(\right) \cdot x\right) \cdot x\right) \cdot \left(\left(-tau\right) \cdot \mathsf{PI}\left(\right)\right)}} \]
          4. Taylor expanded in x around 0

            \[\leadsto \color{blue}{\frac{-1 \cdot \left(x \cdot \cos \mathsf{PI}\left(\right)\right) + -1 \cdot \frac{\sin \mathsf{PI}\left(\right)}{tau \cdot \mathsf{PI}\left(\right)}}{x}} \]
          5. Applied rewrites62.7%

            \[\leadsto \color{blue}{\frac{x}{x}} \]
          6. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2025021 
          (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)))))