Average Error: 7.6 → 0.2
Time: 6.3s
Precision: binary64
Cost: 13312
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
\[\mathsf{fma}\left(x.re \cdot x.im, x.im \cdot -3, {x.re}^{3}\right) \]
(FPCore (x.re x.im)
 :precision binary64
 (-
  (* (- (* x.re x.re) (* x.im x.im)) x.re)
  (* (+ (* x.re x.im) (* x.im x.re)) x.im)))
(FPCore (x.re x.im)
 :precision binary64
 (fma (* x.re x.im) (* x.im -3.0) (pow x.re 3.0)))
double code(double x_46_re, double x_46_im) {
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
}
double code(double x_46_re, double x_46_im) {
	return fma((x_46_re * x_46_im), (x_46_im * -3.0), pow(x_46_re, 3.0));
}
function code(x_46_re, x_46_im)
	return Float64(Float64(Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im)) * x_46_re) - Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_im))
end
function code(x_46_re, x_46_im)
	return fma(Float64(x_46_re * x_46_im), Float64(x_46_im * -3.0), (x_46_re ^ 3.0))
end
code[x$46$re_, x$46$im_] := N[(N[(N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision] * x$46$re), $MachinePrecision] - N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision]), $MachinePrecision]
code[x$46$re_, x$46$im_] := N[(N[(x$46$re * x$46$im), $MachinePrecision] * N[(x$46$im * -3.0), $MachinePrecision] + N[Power[x$46$re, 3.0], $MachinePrecision]), $MachinePrecision]
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im
\mathsf{fma}\left(x.re \cdot x.im, x.im \cdot -3, {x.re}^{3}\right)

Error

Target

Original7.6
Target0.3
Herbie0.2
\[\left(x.re \cdot x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re \cdot x.im\right) \cdot \left(x.re - 3 \cdot x.im\right) \]

Derivation

  1. Initial program 7.6

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
  2. Simplified7.6

    \[\leadsto \color{blue}{{x.re}^{3} + \left(x.re \cdot \left(x.im \cdot x.im\right)\right) \cdot -3} \]
    Proof
    (+.f64 (pow.f64 x.re 3) (*.f64 (*.f64 x.re (*.f64 x.im x.im)) -3)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite=> unpow3_binary64 (*.f64 (*.f64 x.re x.re) x.re)) (*.f64 (*.f64 x.re (*.f64 x.im x.im)) -3)): 21 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (*.f64 (*.f64 x.re (*.f64 x.im x.im)) (Rewrite<= metadata-eval (-.f64 -1 2)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (Rewrite=> associate-*l*_binary64 (*.f64 x.re (*.f64 (*.f64 x.im x.im) (-.f64 -1 2))))): 28 points increase in error, 10 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (*.f64 x.re (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 -1 (*.f64 x.im x.im)) (*.f64 2 (*.f64 x.im x.im)))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (*.f64 x.re (-.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (*.f64 x.im x.im))) (*.f64 2 (*.f64 x.im x.im))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (*.f64 x.re (-.f64 (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 x.im) x.im)) (*.f64 2 (*.f64 x.im x.im))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (*.f64 x.re (-.f64 (*.f64 (neg.f64 x.im) x.im) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 2 x.im) x.im))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (*.f64 x.re (-.f64 (*.f64 (neg.f64 x.im) x.im) (*.f64 (Rewrite<= count-2_binary64 (+.f64 x.im x.im)) x.im)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (Rewrite<= distribute-lft-out--_binary64 (-.f64 (*.f64 x.re (*.f64 (neg.f64 x.im) x.im)) (*.f64 x.re (*.f64 (+.f64 x.im x.im) x.im))))): 10 points increase in error, 28 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (-.f64 (*.f64 x.re (*.f64 (neg.f64 x.im) x.im)) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x.re (+.f64 x.im x.im)) x.im)))): 9 points increase in error, 15 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (-.f64 (*.f64 x.re (*.f64 (neg.f64 x.im) x.im)) (*.f64 (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 x.im x.re) (*.f64 x.im x.re))) x.im))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (-.f64 (*.f64 x.re (*.f64 (neg.f64 x.im) x.im)) (*.f64 (+.f64 (Rewrite=> *-commutative_binary64 (*.f64 x.re x.im)) (*.f64 x.im x.re)) x.im))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (-.f64 (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 (neg.f64 x.im) x.im) x.re)) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 (*.f64 (*.f64 x.re x.re) x.re) (*.f64 (*.f64 (neg.f64 x.im) x.im) x.re)) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im))): 1 points increase in error, 1 points decrease in error
    (-.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 x.re (+.f64 (*.f64 x.re x.re) (*.f64 (neg.f64 x.im) x.im)))) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im)): 2 points increase in error, 1 points decrease in error
    (-.f64 (*.f64 x.re (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)))) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im)): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.re)) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im)): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re \cdot x.im, x.im \cdot -3, {x.re}^{3}\right)} \]
  4. Final simplification0.2

    \[\leadsto \mathsf{fma}\left(x.re \cdot x.im, x.im \cdot -3, {x.re}^{3}\right) \]

Alternatives

Alternative 1
Error0.2
Cost1088
\[\left(x.re \cdot \left(x.re + x.im\right)\right) \cdot \left(x.re - x.im\right) + \left(x.im \cdot \left(x.re \cdot x.im\right)\right) \cdot -2 \]
Alternative 2
Error0.6
Cost968
\[\begin{array}{l} \mathbf{if}\;x.im \leq -4 \cdot 10^{+104}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(x.re \cdot -3\right)\right)\\ \mathbf{elif}\;x.im \leq 4.7 \cdot 10^{+54}:\\ \;\;\;\;x.re \cdot \left(-3 \cdot \left(x.im \cdot x.im\right) + x.re \cdot x.re\right)\\ \mathbf{else}:\\ \;\;\;\;-3 \cdot \left(x.im \cdot \left(x.re \cdot x.im\right)\right)\\ \end{array} \]
Alternative 3
Error5.2
Cost712
\[\begin{array}{l} t_0 := -3 \cdot \left(x.im \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{if}\;x.im \leq -1 \cdot 10^{-44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.im \leq 5.2 \cdot 10^{-58}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error5.2
Cost712
\[\begin{array}{l} t_0 := x.im \cdot \left(\left(x.re \cdot x.im\right) \cdot -3\right)\\ \mathbf{if}\;x.im \leq -1.5 \cdot 10^{-44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.im \leq 3.4 \cdot 10^{-58}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error5.2
Cost712
\[\begin{array}{l} \mathbf{if}\;x.im \leq -1.15 \cdot 10^{-44}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(x.re \cdot -3\right)\right)\\ \mathbf{elif}\;x.im \leq 8.5 \cdot 10^{-58}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.re \cdot x.im\right) \cdot -3\right)\\ \end{array} \]
Alternative 6
Error5.2
Cost712
\[\begin{array}{l} \mathbf{if}\;x.im \leq -1.25 \cdot 10^{-44}:\\ \;\;\;\;x.im \cdot \left(x.re \cdot \left(x.im \cdot -3\right)\right)\\ \mathbf{elif}\;x.im \leq 8 \cdot 10^{-58}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.re \cdot x.im\right) \cdot -3\right)\\ \end{array} \]
Alternative 7
Error28.6
Cost320
\[x.re \cdot \left(x.re \cdot x.re\right) \]

Error

Reproduce

herbie shell --seed 2022325 
(FPCore (x.re x.im)
  :name "math.cube on complex, real part"
  :precision binary64

  :herbie-target
  (+ (* (* x.re x.re) (- x.re x.im)) (* (* x.re x.im) (- x.re (* 3.0 x.im))))

  (- (* (- (* x.re x.re) (* x.im x.im)) x.re) (* (+ (* x.re x.im) (* x.im x.re)) x.im)))