(tan (* (PI) x))

Percentage Accurate: 52.8% → 91.0%
Time: 2.5s
Alternatives: 5
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \tan \left(\mathsf{PI}\left(\right) \cdot x\right) \end{array} \]
(FPCore (x) :precision binary64 (tan (* (PI) x)))
\begin{array}{l}

\\
\tan \left(\mathsf{PI}\left(\right) \cdot x\right)
\end{array}

Sampling outcomes in binary64 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 5 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: 52.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \tan \left(\mathsf{PI}\left(\right) \cdot x\right) \end{array} \]
(FPCore (x) :precision binary64 (tan (* (PI) x)))
\begin{array}{l}

\\
\tan \left(\mathsf{PI}\left(\right) \cdot x\right)
\end{array}

Alternative 1: 91.0% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{fma}\left({x}^{4}, \mathsf{fma}\left(-0.001388888888888889 \cdot {\mathsf{PI}\left(\right)}^{6}, x \cdot x, {\mathsf{PI}\left(\right)}^{4} \cdot 0.041666666666666664\right), \mathsf{fma}\left(-0.5 \cdot \left(x \cdot x\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\right)} \end{array} \]
(FPCore (x)
 :precision binary64
 (/
  (sin (* (PI) x))
  (fma
   (pow x 4.0)
   (fma
    (* -0.001388888888888889 (pow (PI) 6.0))
    (* x x)
    (* (pow (PI) 4.0) 0.041666666666666664))
   (fma (* -0.5 (* x x)) (* (PI) (PI)) 1.0))))
\begin{array}{l}

\\
\frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{fma}\left({x}^{4}, \mathsf{fma}\left(-0.001388888888888889 \cdot {\mathsf{PI}\left(\right)}^{6}, x \cdot x, {\mathsf{PI}\left(\right)}^{4} \cdot 0.041666666666666664\right), \mathsf{fma}\left(-0.5 \cdot \left(x \cdot x\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\right)}
\end{array}
Derivation
  1. Initial program 51.2%

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

    \[\leadsto \color{blue}{\frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)}} \]
  4. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)}} \]
    2. lower-sin.f64N/A

      \[\leadsto \frac{\color{blue}{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
    3. *-commutativeN/A

      \[\leadsto \frac{\sin \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
    4. lower-*.f64N/A

      \[\leadsto \frac{\sin \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
    5. lower-PI.f64N/A

      \[\leadsto \frac{\sin \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot x\right)}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
    6. lower-cos.f64N/A

      \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\color{blue}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)}} \]
    7. *-commutativeN/A

      \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}} \]
    8. lower-*.f64N/A

      \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}} \]
    9. lower-PI.f6451.2

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

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

    \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{1 + \color{blue}{{x}^{2} \cdot \left(\frac{-1}{2} \cdot {\mathsf{PI}\left(\right)}^{2} + {x}^{2} \cdot \left(\frac{-1}{720} \cdot \left({x}^{2} \cdot {\mathsf{PI}\left(\right)}^{6}\right) + \frac{1}{24} \cdot {\mathsf{PI}\left(\right)}^{4}\right)\right)}} \]
  7. Step-by-step derivation
    1. Applied rewrites90.4%

      \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{fma}\left({x}^{4}, \color{blue}{\mathsf{fma}\left(-0.001388888888888889 \cdot {\mathsf{PI}\left(\right)}^{6}, x \cdot x, {\mathsf{PI}\left(\right)}^{4} \cdot 0.041666666666666664\right)}, \mathsf{fma}\left(-0.5 \cdot \left(x \cdot x\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\right)} \]
    2. Add Preprocessing

    Alternative 2: 87.1% accurate, 0.4× speedup?

    \[\begin{array}{l} \\ \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\left({\mathsf{PI}\left(\right)}^{4} \cdot 0.041666666666666664\right) \cdot x, x, \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -0.5\right), x \cdot x, 1\right)} \end{array} \]
    (FPCore (x)
     :precision binary64
     (/
      (sin (* (PI) x))
      (fma
       (fma (* (* (pow (PI) 4.0) 0.041666666666666664) x) x (* (* (PI) (PI)) -0.5))
       (* x x)
       1.0)))
    \begin{array}{l}
    
    \\
    \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\left({\mathsf{PI}\left(\right)}^{4} \cdot 0.041666666666666664\right) \cdot x, x, \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -0.5\right), x \cdot x, 1\right)}
    \end{array}
    
    Derivation
    1. Initial program 51.2%

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

      \[\leadsto \color{blue}{\frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)}} \]
    4. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)}} \]
      2. lower-sin.f64N/A

        \[\leadsto \frac{\color{blue}{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
      3. *-commutativeN/A

        \[\leadsto \frac{\sin \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
      4. lower-*.f64N/A

        \[\leadsto \frac{\sin \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
      5. lower-PI.f64N/A

        \[\leadsto \frac{\sin \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot x\right)}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
      6. lower-cos.f64N/A

        \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\color{blue}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)}} \]
      7. *-commutativeN/A

        \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}} \]
      8. lower-*.f64N/A

        \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}} \]
      9. lower-PI.f6451.2

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

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

      \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{1 + \color{blue}{{x}^{2} \cdot \left(\frac{-1}{2} \cdot {\mathsf{PI}\left(\right)}^{2} + \frac{1}{24} \cdot \left({x}^{2} \cdot {\mathsf{PI}\left(\right)}^{4}\right)\right)}} \]
    7. Step-by-step derivation
      1. Applied rewrites86.3%

        \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\left({\mathsf{PI}\left(\right)}^{4} \cdot 0.041666666666666664\right) \cdot x, x, \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -0.5\right), \color{blue}{x \cdot x}, 1\right)} \]
      2. Add Preprocessing

      Alternative 3: 75.6% accurate, 0.8× speedup?

      \[\begin{array}{l} \\ \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{fma}\left(-0.5 \cdot \left(x \cdot x\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)} \end{array} \]
      (FPCore (x)
       :precision binary64
       (/ (sin (* (PI) x)) (fma (* -0.5 (* x x)) (* (PI) (PI)) 1.0)))
      \begin{array}{l}
      
      \\
      \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{fma}\left(-0.5 \cdot \left(x \cdot x\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)}
      \end{array}
      
      Derivation
      1. Initial program 51.2%

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

        \[\leadsto \color{blue}{\frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)}} \]
      4. Step-by-step derivation
        1. lower-/.f64N/A

          \[\leadsto \color{blue}{\frac{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)}} \]
        2. lower-sin.f64N/A

          \[\leadsto \frac{\color{blue}{\sin \left(x \cdot \mathsf{PI}\left(\right)\right)}}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
        3. *-commutativeN/A

          \[\leadsto \frac{\sin \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
        4. lower-*.f64N/A

          \[\leadsto \frac{\sin \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
        5. lower-PI.f64N/A

          \[\leadsto \frac{\sin \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot x\right)}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)} \]
        6. lower-cos.f64N/A

          \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\color{blue}{\cos \left(x \cdot \mathsf{PI}\left(\right)\right)}} \]
        7. *-commutativeN/A

          \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}} \]
        8. lower-*.f64N/A

          \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\cos \color{blue}{\left(\mathsf{PI}\left(\right) \cdot x\right)}} \]
        9. lower-PI.f6451.2

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

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

        \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{1 + \color{blue}{\frac{-1}{2} \cdot \left({x}^{2} \cdot {\mathsf{PI}\left(\right)}^{2}\right)}} \]
      7. Step-by-step derivation
        1. Applied rewrites71.9%

          \[\leadsto \frac{\sin \left(\mathsf{PI}\left(\right) \cdot x\right)}{\mathsf{fma}\left(-0.5 \cdot \left(x \cdot x\right), \color{blue}{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}, 1\right)} \]
        2. Add Preprocessing

        Alternative 4: 52.8% accurate, 1.0× speedup?

        \[\begin{array}{l} \\ \tan \left(\mathsf{PI}\left(\right) \cdot x\right) \end{array} \]
        (FPCore (x) :precision binary64 (tan (* (PI) x)))
        \begin{array}{l}
        
        \\
        \tan \left(\mathsf{PI}\left(\right) \cdot x\right)
        \end{array}
        
        Derivation
        1. Initial program 51.2%

          \[\tan \left(\mathsf{PI}\left(\right) \cdot x\right) \]
        2. Add Preprocessing
        3. Add Preprocessing

        Alternative 5: 50.6% accurate, 17.7× speedup?

        \[\begin{array}{l} \\ \mathsf{PI}\left(\right) \cdot x \end{array} \]
        (FPCore (x) :precision binary64 (* (PI) x))
        \begin{array}{l}
        
        \\
        \mathsf{PI}\left(\right) \cdot x
        \end{array}
        
        Derivation
        1. Initial program 51.2%

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

          \[\leadsto \color{blue}{x \cdot \mathsf{PI}\left(\right)} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{\mathsf{PI}\left(\right) \cdot x} \]
          2. lower-*.f64N/A

            \[\leadsto \color{blue}{\mathsf{PI}\left(\right) \cdot x} \]
          3. lower-PI.f6449.6

            \[\leadsto \color{blue}{\mathsf{PI}\left(\right)} \cdot x \]
        5. Applied rewrites49.6%

          \[\leadsto \color{blue}{\mathsf{PI}\left(\right) \cdot x} \]
        6. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 1 
        (FPCore (x)
          :name "(tan (* (PI) x))"
          :precision binary64
          (tan (* (PI) x)))