Average Error: 0.1 → 0.1
Time: 10.3s
Precision: binary64
Cost: 13504
\[\left(a - \frac{1}{3}\right) \cdot \left(1 + \frac{1}{\sqrt{9 \cdot \left(a - \frac{1}{3}\right)}} \cdot rand\right) \]
\[\left(a - 0.3333333333333333\right) \cdot \left(1 + \frac{rand}{\sqrt{\mathsf{fma}\left(a, 9, -3\right)}}\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 0.3333333333333333) (+ 1.0 (/ rand (sqrt (fma a 9.0 -3.0))))))
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 - 0.3333333333333333) * (1.0 + (rand / sqrt(fma(a, 9.0, -3.0))));
}
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 Float64(Float64(a - 0.3333333333333333) * Float64(1.0 + Float64(rand / sqrt(fma(a, 9.0, -3.0)))))
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[(a - 0.3333333333333333), $MachinePrecision] * N[(1.0 + N[(rand / N[Sqrt[N[(a * 9.0 + -3.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $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)
\left(a - 0.3333333333333333\right) \cdot \left(1 + \frac{rand}{\sqrt{\mathsf{fma}\left(a, 9, -3\right)}}\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. Simplified0.1

    \[\leadsto \color{blue}{\left(a - 0.3333333333333333\right) \cdot \left(1 + \frac{rand}{\sqrt{\mathsf{fma}\left(a, 9, -3\right)}}\right)} \]
    Proof
    (*.f64 (-.f64 a 1/3) (+.f64 1 (/.f64 rand (sqrt.f64 (fma.f64 a 9 -3))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (Rewrite<= metadata-eval (/.f64 1 3))) (+.f64 1 (/.f64 rand (sqrt.f64 (fma.f64 a 9 -3))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (/.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 rand)) (sqrt.f64 (fma.f64 a 9 -3))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (/.f64 (*.f64 1 rand) (sqrt.f64 (fma.f64 a 9 (Rewrite<= metadata-eval (*.f64 -1/3 9))))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (/.f64 (*.f64 1 rand) (sqrt.f64 (fma.f64 a 9 (*.f64 (Rewrite<= metadata-eval (neg.f64 1/3)) 9)))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (/.f64 (*.f64 1 rand) (sqrt.f64 (fma.f64 a 9 (*.f64 (neg.f64 (Rewrite<= metadata-eval (/.f64 1 3))) 9)))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (/.f64 (*.f64 1 rand) (sqrt.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 a 9) (*.f64 (neg.f64 (/.f64 1 3)) 9))))))): 1 points increase in error, 1 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (/.f64 (*.f64 1 rand) (sqrt.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 9 (+.f64 a (neg.f64 (/.f64 1 3))))))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (/.f64 (*.f64 1 rand) (sqrt.f64 (*.f64 9 (Rewrite<= sub-neg_binary64 (-.f64 a (/.f64 1 3)))))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 9 (-.f64 a (/.f64 1 3))))) rand)))): 11 points increase in error, 7 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 9 (-.f64 a (/.f64 1 3))))) rand)))))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (Rewrite<= sub-neg_binary64 (-.f64 1 (neg.f64 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 9 (-.f64 a (/.f64 1 3))))) rand))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 1 (-.f64 a (/.f64 1 3))) (*.f64 (neg.f64 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 9 (-.f64 a (/.f64 1 3))))) rand)) (-.f64 a (/.f64 1 3))))): 0 points increase in error, 1 points decrease in error
    (-.f64 (Rewrite=> *-lft-identity_binary64 (-.f64 a (/.f64 1 3))) (*.f64 (neg.f64 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 9 (-.f64 a (/.f64 1 3))))) rand)) (-.f64 a (/.f64 1 3)))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> cancel-sign-sub_binary64 (+.f64 (-.f64 a (/.f64 1 3)) (*.f64 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 9 (-.f64 a (/.f64 1 3))))) rand) (-.f64 a (/.f64 1 3))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (-.f64 a (/.f64 1 3)))) (*.f64 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 9 (-.f64 a (/.f64 1 3))))) rand) (-.f64 a (/.f64 1 3)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-rgt-in_binary64 (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 9 (-.f64 a (/.f64 1 3))))) rand)))): 1 points increase in error, 0 points decrease in error
  3. Final simplification0.1

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

Alternatives

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

Error

Reproduce

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