Beckmann Sample, near normal, slope_x

Percentage Accurate: 57.9% → 99.0%
Time: 10.5s
Alternatives: 5
Speedup: N/A×

Specification

?
\[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

Your Program's Arguments

Results

Enter valid numbers for all inputs

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.

Alternative 1: 99.0% accurate, 0.6× speedup?

\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \sqrt[3]{{\pi}^{3} \cdot {u2}^{3}}\right) \]
Derivation
  1. Initial program 60.1%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg60.1%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-def99.2%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    3. associate-*l*99.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
  3. Simplified99.2%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
  4. Step-by-step derivation
    1. add-cbrt-cube99.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\color{blue}{\sqrt[3]{\left(\pi \cdot \pi\right) \cdot \pi}} \cdot u2\right)\right) \]
    2. add-cbrt-cube99.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\sqrt[3]{\left(\pi \cdot \pi\right) \cdot \pi} \cdot \color{blue}{\sqrt[3]{\left(u2 \cdot u2\right) \cdot u2}}\right)\right) \]
    3. cbrt-unprod99.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \color{blue}{\sqrt[3]{\left(\left(\pi \cdot \pi\right) \cdot \pi\right) \cdot \left(\left(u2 \cdot u2\right) \cdot u2\right)}}\right) \]
    4. pow399.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \sqrt[3]{\color{blue}{{\pi}^{3}} \cdot \left(\left(u2 \cdot u2\right) \cdot u2\right)}\right) \]
    5. pow399.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \sqrt[3]{{\pi}^{3} \cdot \color{blue}{{u2}^{3}}}\right) \]
  5. Applied egg-rr99.2%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \color{blue}{\sqrt[3]{{\pi}^{3} \cdot {u2}^{3}}}\right) \]
  6. Final simplification99.2%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \sqrt[3]{{\pi}^{3} \cdot {u2}^{3}}\right) \]

Alternative 2: 90.0% accurate, 0.8× speedup?

\[\begin{array}{l} t_0 := \cos \left(u2 \cdot \left(2 \cdot \pi\right)\right)\\ \mathbf{if}\;t_0 \leq 0.9995999932289124:\\ \;\;\;\;t_0 \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if (cos.f32 (*.f32 (*.f32 2 (PI.f32)) u2)) < 0.999599993

    1. Initial program 57.8%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Step-by-step derivation
      1. sub-neg57.8%

        \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      2. log1p-udef97.6%

        \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      3. add-sqr-sqrt97.1%

        \[\leadsto \color{blue}{\left(\sqrt{\sqrt{-\mathsf{log1p}\left(-u1\right)}} \cdot \sqrt{\sqrt{-\mathsf{log1p}\left(-u1\right)}}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      4. pow297.1%

        \[\leadsto \color{blue}{{\left(\sqrt{\sqrt{-\mathsf{log1p}\left(-u1\right)}}\right)}^{2}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    3. Applied egg-rr73.1%

      \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{0.25}\right)}^{2}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    4. Taylor expanded in u1 around 0 75.2%

      \[\leadsto \color{blue}{\sqrt{u1}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

    if 0.999599993 < (cos.f32 (*.f32 (*.f32 2 (PI.f32)) u2))

    1. Initial program 60.8%

      \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. Step-by-step derivation
      1. sub-neg60.8%

        \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      2. log1p-def99.6%

        \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
      3. associate-*l*99.6%

        \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
    4. Step-by-step derivation
      1. add-cbrt-cube99.6%

        \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\color{blue}{\sqrt[3]{\left(\pi \cdot \pi\right) \cdot \pi}} \cdot u2\right)\right) \]
      2. add-cbrt-cube99.6%

        \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\sqrt[3]{\left(\pi \cdot \pi\right) \cdot \pi} \cdot \color{blue}{\sqrt[3]{\left(u2 \cdot u2\right) \cdot u2}}\right)\right) \]
      3. cbrt-unprod99.6%

        \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \color{blue}{\sqrt[3]{\left(\left(\pi \cdot \pi\right) \cdot \pi\right) \cdot \left(\left(u2 \cdot u2\right) \cdot u2\right)}}\right) \]
      4. pow399.6%

        \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \sqrt[3]{\color{blue}{{\pi}^{3}} \cdot \left(\left(u2 \cdot u2\right) \cdot u2\right)}\right) \]
      5. pow399.6%

        \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \sqrt[3]{{\pi}^{3} \cdot \color{blue}{{u2}^{3}}}\right) \]
    5. Applied egg-rr99.6%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \color{blue}{\sqrt[3]{{\pi}^{3} \cdot {u2}^{3}}}\right) \]
    6. Taylor expanded in u2 around 0 95.6%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification91.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right) \leq 0.9995999932289124:\\ \;\;\;\;\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \]

Alternative 3: 99.0% accurate, 1.0× speedup?

\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \]
Derivation
  1. Initial program 60.1%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg60.1%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-def99.2%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    3. associate-*l*99.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
  3. Simplified99.2%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
  4. Final simplification99.2%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \]

Alternative 4: 79.9% accurate, 2.0× speedup?

\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \]
Derivation
  1. Initial program 60.1%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Step-by-step derivation
    1. sub-neg60.1%

      \[\leadsto \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    2. log1p-def99.2%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    3. associate-*l*99.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
  3. Simplified99.2%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
  4. Step-by-step derivation
    1. add-cbrt-cube99.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\color{blue}{\sqrt[3]{\left(\pi \cdot \pi\right) \cdot \pi}} \cdot u2\right)\right) \]
    2. add-cbrt-cube99.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\sqrt[3]{\left(\pi \cdot \pi\right) \cdot \pi} \cdot \color{blue}{\sqrt[3]{\left(u2 \cdot u2\right) \cdot u2}}\right)\right) \]
    3. cbrt-unprod99.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \color{blue}{\sqrt[3]{\left(\left(\pi \cdot \pi\right) \cdot \pi\right) \cdot \left(\left(u2 \cdot u2\right) \cdot u2\right)}}\right) \]
    4. pow399.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \sqrt[3]{\color{blue}{{\pi}^{3}} \cdot \left(\left(u2 \cdot u2\right) \cdot u2\right)}\right) \]
    5. pow399.2%

      \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \sqrt[3]{{\pi}^{3} \cdot \color{blue}{{u2}^{3}}}\right) \]
  5. Applied egg-rr99.2%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \color{blue}{\sqrt[3]{{\pi}^{3} \cdot {u2}^{3}}}\right) \]
  6. Taylor expanded in u2 around 0 81.7%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{1} \]
  7. Final simplification81.7%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \]

Alternative 5: 64.8% accurate, 4.0× speedup?

\[\sqrt{u1} \]
Derivation
  1. Initial program 60.1%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Taylor expanded in u2 around 0 52.5%

    \[\leadsto \sqrt{-\log \left(1 - u1\right)} \cdot \color{blue}{1} \]
  3. Step-by-step derivation
    1. add-cbrt-cube52.5%

      \[\leadsto \color{blue}{\sqrt[3]{\left(\sqrt{-\log \left(1 - u1\right)} \cdot \sqrt{-\log \left(1 - u1\right)}\right) \cdot \sqrt{-\log \left(1 - u1\right)}}} \cdot 1 \]
    2. pow1/352.5%

      \[\leadsto \color{blue}{{\left(\left(\sqrt{-\log \left(1 - u1\right)} \cdot \sqrt{-\log \left(1 - u1\right)}\right) \cdot \sqrt{-\log \left(1 - u1\right)}\right)}^{0.3333333333333333}} \cdot 1 \]
  4. Applied egg-rr62.0%

    \[\leadsto \color{blue}{{\left({\left(\mathsf{log1p}\left(u1\right)\right)}^{1.5}\right)}^{0.3333333333333333}} \cdot 1 \]
  5. Taylor expanded in u1 around 0 64.8%

    \[\leadsto \color{blue}{\sqrt{u1}} \cdot 1 \]
  6. Final simplification64.8%

    \[\leadsto \sqrt{u1} \]

Reproduce

?
herbie shell --seed 2023167 
(FPCore (cosTheta_i u1 u2)
  :name "Beckmann Sample, near normal, slope_x"
  :precision binary32
  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
  (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))