Average Error: 0.1 → 0.1
Time: 9.3s
Precision: binary64
Cost: 19968
\[\left(a - \frac{1}{3}\right) \cdot \left(1 + \frac{1}{\sqrt{9 \cdot \left(a - \frac{1}{3}\right)}} \cdot rand\right) \]
\[\mathsf{fma}\left({\left(\mathsf{fma}\left(9, a, -3\right)\right)}^{-0.5} \cdot \left(a + -0.3333333333333333\right), rand, a + -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
 (fma
  (* (pow (fma 9.0 a -3.0) -0.5) (+ a -0.3333333333333333))
  rand
  (+ a -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 fma((pow(fma(9.0, a, -3.0), -0.5) * (a + -0.3333333333333333)), rand, (a + -0.3333333333333333));
}
function code(a, rand)
	return Float64(Float64(a - Float64(1.0 / 3.0)) * Float64(1.0 + Float64(Float64(1.0 / sqrt(Float64(9.0 * Float64(a - Float64(1.0 / 3.0))))) * rand)))
end
function code(a, rand)
	return fma(Float64((fma(9.0, a, -3.0) ^ -0.5) * Float64(a + -0.3333333333333333)), rand, Float64(a + -0.3333333333333333))
end
code[a_, rand_] := N[(N[(a - N[(1.0 / 3.0), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(1.0 / N[Sqrt[N[(9.0 * N[(a - N[(1.0 / 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * rand), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, rand_] := N[(N[(N[Power[N[(9.0 * a + -3.0), $MachinePrecision], -0.5], $MachinePrecision] * N[(a + -0.3333333333333333), $MachinePrecision]), $MachinePrecision] * rand + N[(a + -0.3333333333333333), $MachinePrecision]), $MachinePrecision]
\left(a - \frac{1}{3}\right) \cdot \left(1 + \frac{1}{\sqrt{9 \cdot \left(a - \frac{1}{3}\right)}} \cdot rand\right)
\mathsf{fma}\left({\left(\mathsf{fma}\left(9, a, -3\right)\right)}^{-0.5} \cdot \left(a + -0.3333333333333333\right), rand, a + -0.3333333333333333\right)

Error

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. Applied egg-rr0.1

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

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

Alternatives

Alternative 1
Error0.1
Cost7360
\[a + \left(-0.3333333333333333 - \frac{rand}{3 \cdot \sqrt{a + -0.3333333333333333}} \cdot \left(0.3333333333333333 - a\right)\right) \]
Alternative 2
Error0.1
Cost7232
\[\left(a + -0.3333333333333333\right) \cdot \left(1 + \frac{\frac{rand}{3}}{\sqrt{a + -0.3333333333333333}}\right) \]
Alternative 3
Error5.2
Cost7112
\[\begin{array}{l} t_0 := rand \cdot \left(0.3333333333333333 \cdot \sqrt{a + -0.3333333333333333}\right)\\ \mathbf{if}\;rand \leq -1.0077323823976105 \cdot 10^{+90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;rand \leq 1.535103304380144 \cdot 10^{+75}:\\ \;\;\;\;a + -0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error5.2
Cost7112
\[\begin{array}{l} t_0 := rand \cdot \sqrt{\left(a + -0.3333333333333333\right) \cdot 0.1111111111111111}\\ \mathbf{if}\;rand \leq -1.0077323823976105 \cdot 10^{+90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;rand \leq 1.535103304380144 \cdot 10^{+75}:\\ \;\;\;\;a + -0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.8
Cost7104
\[\left(a + -0.3333333333333333\right) \cdot \left(1 - -0.3333333333333333 \cdot \frac{rand}{\sqrt{a}}\right) \]
Alternative 6
Error0.8
Cost7104
\[\left(a + -0.3333333333333333\right) \cdot \left(1 + \frac{rand}{\sqrt{a \cdot 9}}\right) \]
Alternative 7
Error0.2
Cost7104
\[-0.3333333333333333 + \left(a + 0.3333333333333333 \cdot \left(rand \cdot \sqrt{a + -0.3333333333333333}\right)\right) \]
Alternative 8
Error5.7
Cost6984
\[\begin{array}{l} t_0 := rand \cdot \sqrt{a \cdot 0.1111111111111111}\\ \mathbf{if}\;rand \leq -1.0077323823976105 \cdot 10^{+90}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;rand \leq 1.535103304380144 \cdot 10^{+75}:\\ \;\;\;\;a + -0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error18.8
Cost192
\[a + -0.3333333333333333 \]
Alternative 10
Error19.5
Cost64
\[a \]

Error

Reproduce

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