Average Error: 0.1 → 0.1
Time: 7.8s
Precision: binary64
\[\left(a - \frac{1}{3}\right) \cdot \left(1 + \frac{1}{\sqrt{9 \cdot \left(a - \frac{1}{3}\right)}} \cdot rand\right) \]
\[a + \mathsf{fma}\left(rand, {\left(\mathsf{fma}\left(9, a, -3\right)\right)}^{-0.5} \cdot \left(a + -0.3333333333333333\right), -0.3333333333333333\right) \]
\left(a - \frac{1}{3}\right) \cdot \left(1 + \frac{1}{\sqrt{9 \cdot \left(a - \frac{1}{3}\right)}} \cdot rand\right)
a + \mathsf{fma}\left(rand, {\left(\mathsf{fma}\left(9, a, -3\right)\right)}^{-0.5} \cdot \left(a + -0.3333333333333333\right), -0.3333333333333333\right)
(FPCore (a rand)
 :precision binary64
 (*
  (- a (/ 1.0 3.0))
  (+ 1.0 (* (/ 1.0 (sqrt (* 9.0 (- a (/ 1.0 3.0))))) rand))))
(FPCore (a rand)
 :precision binary64
 (+
  a
  (fma
   rand
   (* (pow (fma 9.0 a -3.0) -0.5) (+ a -0.3333333333333333))
   -0.3333333333333333)))
double code(double a, double rand) {
	return (a - (1.0 / 3.0)) * (1.0 + ((1.0 / sqrt(9.0 * (a - (1.0 / 3.0)))) * rand));
}
double code(double a, double rand) {
	return a + fma(rand, (pow(fma(9.0, a, -3.0), -0.5) * (a + -0.3333333333333333)), -0.3333333333333333);
}

Error

Bits error versus a

Bits error versus rand

Derivation

  1. Initial program 0.1

    \[\left(a - \frac{1}{3}\right) \cdot \left(1 + \frac{1}{\sqrt{9 \cdot \left(a - \frac{1}{3}\right)}} \cdot rand\right) \]
  2. Simplified0.1

    \[\leadsto \color{blue}{\left(a - 0.3333333333333333\right) \cdot \left(1 + \frac{rand}{\sqrt{\mathsf{fma}\left(a, 9, -3\right)}}\right)} \]
  3. Taylor expanded in rand around 0 9.1

    \[\leadsto \color{blue}{\left(a + \left(a \cdot rand\right) \cdot \sqrt{\frac{1}{9 \cdot a - 3}}\right) - \left(0.3333333333333333 \cdot \left(rand \cdot \sqrt{\frac{1}{9 \cdot a - 3}}\right) + 0.3333333333333333\right)} \]
  4. Simplified0.1

    \[\leadsto \color{blue}{a + \mathsf{fma}\left(rand, \sqrt{\frac{1}{\mathsf{fma}\left(9, a, -3\right)}} \cdot \left(a + -0.3333333333333333\right), -0.3333333333333333\right)} \]
  5. Applied inv-pow_binary640.1

    \[\leadsto a + \mathsf{fma}\left(rand, \sqrt{\color{blue}{{\left(\mathsf{fma}\left(9, a, -3\right)\right)}^{-1}}} \cdot \left(a + -0.3333333333333333\right), -0.3333333333333333\right) \]
  6. Applied sqrt-pow1_binary640.1

    \[\leadsto a + \mathsf{fma}\left(rand, \color{blue}{{\left(\mathsf{fma}\left(9, a, -3\right)\right)}^{\left(\frac{-1}{2}\right)}} \cdot \left(a + -0.3333333333333333\right), -0.3333333333333333\right) \]
  7. Simplified0.1

    \[\leadsto a + \mathsf{fma}\left(rand, {\left(\mathsf{fma}\left(9, a, -3\right)\right)}^{\color{blue}{-0.5}} \cdot \left(a + -0.3333333333333333\right), -0.3333333333333333\right) \]
  8. Final simplification0.1

    \[\leadsto a + \mathsf{fma}\left(rand, {\left(\mathsf{fma}\left(9, a, -3\right)\right)}^{-0.5} \cdot \left(a + -0.3333333333333333\right), -0.3333333333333333\right) \]

Reproduce

herbie shell --seed 2021215 
(FPCore (a rand)
  :name "Octave 3.8, oct_fill_randg"
  :precision binary64
  (* (- a (/ 1.0 3.0)) (+ 1.0 (* (/ 1.0 (sqrt (* 9.0 (- a (/ 1.0 3.0))))) rand))))