Average Error: 0.1 → 0.1
Time: 9.0s
Precision: binary64
Cost: 13632
\[\left(a - \frac{1}{3}\right) \cdot \left(1 + \frac{1}{\sqrt{9 \cdot \left(a - \frac{1}{3}\right)}} \cdot rand\right) \]
\[\frac{rand}{\frac{\sqrt{\mathsf{fma}\left(a, 9, -3\right)}}{-0.3333333333333333 + a}} + \left(-0.3333333333333333 + a\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
 (+
  (/ rand (/ (sqrt (fma a 9.0 -3.0)) (+ -0.3333333333333333 a)))
  (+ -0.3333333333333333 a)))
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 (rand / (sqrt(fma(a, 9.0, -3.0)) / (-0.3333333333333333 + a))) + (-0.3333333333333333 + a);
}
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(rand / Float64(sqrt(fma(a, 9.0, -3.0)) / Float64(-0.3333333333333333 + a))) + Float64(-0.3333333333333333 + a))
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[(rand / N[(N[Sqrt[N[(a * 9.0 + -3.0), $MachinePrecision]], $MachinePrecision] / N[(-0.3333333333333333 + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.3333333333333333 + a), $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)
\frac{rand}{\frac{\sqrt{\mathsf{fma}\left(a, 9, -3\right)}}{-0.3333333333333333 + a}} + \left(-0.3333333333333333 + a\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{1}{\sqrt{\left(a + -0.3333333333333333\right) \cdot 9}} \cdot rand\right)} \]
    Proof
    (*.f64 (+.f64 a -1/3) (+.f64 1 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 (+.f64 a -1/3) 9))) rand))): 0 points increase in error, 0 points decrease in error
    (*.f64 (+.f64 a (Rewrite<= metadata-eval (neg.f64 1/3))) (+.f64 1 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 (+.f64 a -1/3) 9))) rand))): 0 points increase in error, 0 points decrease in error
    (*.f64 (+.f64 a (neg.f64 (Rewrite<= metadata-eval (/.f64 1 3)))) (+.f64 1 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 (+.f64 a -1/3) 9))) rand))): 0 points increase in error, 0 points decrease in error
    (*.f64 (Rewrite<= sub-neg_binary64 (-.f64 a (/.f64 1 3))) (+.f64 1 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 (+.f64 a -1/3) 9))) rand))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 (+.f64 a (Rewrite<= metadata-eval (neg.f64 1/3))) 9))) rand))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 (+.f64 a (neg.f64 (Rewrite<= metadata-eval (/.f64 1 3)))) 9))) rand))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (*.f64 (/.f64 1 (sqrt.f64 (*.f64 (Rewrite<= sub-neg_binary64 (-.f64 a (/.f64 1 3))) 9))) rand))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 a (/.f64 1 3)) (+.f64 1 (*.f64 (/.f64 1 (sqrt.f64 (Rewrite<= *-commutative_binary64 (*.f64 9 (-.f64 a (/.f64 1 3)))))) rand))): 0 points increase in error, 0 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))))): 2 points increase in error, 4 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)))): 4 points increase in error, 2 points decrease in error
  3. Applied egg-rr9.0

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

    \[\leadsto \color{blue}{\left(-0.3333333333333333 + a\right) + \frac{rand}{\frac{\sqrt{\mathsf{fma}\left(a, 9, -3\right)}}{-0.3333333333333333 + a}}} \]
    Proof
    (+.f64 (+.f64 -1/3 a) (/.f64 rand (/.f64 (sqrt.f64 (fma.f64 a 9 -3)) (+.f64 -1/3 a)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 a -1/3)) (/.f64 rand (/.f64 (sqrt.f64 (fma.f64 a 9 -3)) (+.f64 -1/3 a)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 a -1/3) (/.f64 rand (/.f64 (sqrt.f64 (fma.f64 a 9 -3)) (Rewrite<= +-commutative_binary64 (+.f64 a -1/3))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 a -1/3) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 rand (+.f64 a -1/3)) (sqrt.f64 (fma.f64 a 9 -3))))): 41 points increase in error, 4 points decrease in error
    (Rewrite=> associate-+l+_binary64 (+.f64 a (+.f64 -1/3 (/.f64 (*.f64 rand (+.f64 a -1/3)) (sqrt.f64 (fma.f64 a 9 -3)))))): 0 points increase in error, 0 points decrease in error
  5. Final simplification0.1

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

Alternatives

Alternative 1
Error0.1
Cost13504
\[\left(-0.3333333333333333 + a\right) \cdot \left(1 + \frac{rand}{\sqrt{\mathsf{fma}\left(a, 9, -3\right)}}\right) \]
Alternative 2
Error5.6
Cost7240
\[\begin{array}{l} t_0 := \sqrt{-0.3333333333333333 + a}\\ \mathbf{if}\;rand \leq -1.1 \cdot 10^{+64}:\\ \;\;\;\;0.3333333333333333 \cdot \left(rand \cdot t_0\right)\\ \mathbf{elif}\;rand \leq 1.32 \cdot 10^{+100}:\\ \;\;\;\;-0.3333333333333333 + a\\ \mathbf{else}:\\ \;\;\;\;-0.3333333333333333 + t_0 \cdot \left(rand \cdot 0.3333333333333333\right)\\ \end{array} \]
Alternative 3
Error5.6
Cost7240
\[\begin{array}{l} t_0 := \sqrt{-0.3333333333333333 + a}\\ \mathbf{if}\;rand \leq -3.2 \cdot 10^{+63}:\\ \;\;\;\;-0.3333333333333333 + rand \cdot \left(0.3333333333333333 \cdot t_0\right)\\ \mathbf{elif}\;rand \leq 1.32 \cdot 10^{+100}:\\ \;\;\;\;-0.3333333333333333 + a\\ \mathbf{else}:\\ \;\;\;\;-0.3333333333333333 + t_0 \cdot \left(rand \cdot 0.3333333333333333\right)\\ \end{array} \]
Alternative 4
Error0.1
Cost7232
\[\left(-0.3333333333333333 + a\right) \cdot \left(1 + \frac{rand}{\sqrt{-3 + a \cdot 9}}\right) \]
Alternative 5
Error5.6
Cost7112
\[\begin{array}{l} t_0 := 0.3333333333333333 \cdot \left(rand \cdot \sqrt{-0.3333333333333333 + a}\right)\\ \mathbf{if}\;rand \leq -1.6 \cdot 10^{+66}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;rand \leq 1.32 \cdot 10^{+100}:\\ \;\;\;\;-0.3333333333333333 + a\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.9
Cost7104
\[\left(-0.3333333333333333 + a\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{-0.3333333333333333 + a}\right)\right) \]
Alternative 8
Error6.2
Cost6984
\[\begin{array}{l} t_0 := 0.3333333333333333 \cdot \left(rand \cdot \sqrt{a}\right)\\ \mathbf{if}\;rand \leq -2.7 \cdot 10^{+63}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;rand \leq 1.32 \cdot 10^{+100}:\\ \;\;\;\;-0.3333333333333333 + a\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error18.4
Cost192
\[-0.3333333333333333 + a \]
Alternative 10
Error63.0
Cost64
\[-0.3333333333333333 \]
Alternative 11
Error19.3
Cost64
\[a \]

Error

Reproduce

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