Average Error: 7.4 → 0.2
Time: 10.3s
Precision: binary64
Cost: 7040
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
\[x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right) - {x.im}^{3} \]
(FPCore (x.re x.im)
 :precision binary64
 (+
  (* (- (* x.re x.re) (* x.im x.im)) x.im)
  (* (+ (* x.re x.im) (* x.im x.re)) x.re)))
(FPCore (x.re x.im)
 :precision binary64
 (- (* x.re (* x.im (* x.re 3.0))) (pow x.im 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_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
double code(double x_46_re, double x_46_im) {
	return (x_46_re * (x_46_im * (x_46_re * 3.0))) - pow(x_46_im, 3.0);
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = (((x_46re * x_46re) - (x_46im * x_46im)) * x_46im) + (((x_46re * x_46im) + (x_46im * x_46re)) * x_46re)
end function
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = (x_46re * (x_46im * (x_46re * 3.0d0))) - (x_46im ** 3.0d0)
end function
public static 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_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
public static double code(double x_46_re, double x_46_im) {
	return (x_46_re * (x_46_im * (x_46_re * 3.0))) - Math.pow(x_46_im, 3.0);
}
def code(x_46_re, x_46_im):
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re)
def code(x_46_re, x_46_im):
	return (x_46_re * (x_46_im * (x_46_re * 3.0))) - math.pow(x_46_im, 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_im) + Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_re))
end
function code(x_46_re, x_46_im)
	return Float64(Float64(x_46_re * Float64(x_46_im * Float64(x_46_re * 3.0))) - (x_46_im ^ 3.0))
end
function tmp = code(x_46_re, x_46_im)
	tmp = (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
end
function tmp = code(x_46_re, x_46_im)
	tmp = (x_46_re * (x_46_im * (x_46_re * 3.0))) - (x_46_im ^ 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$im), $MachinePrecision] + N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$re), $MachinePrecision]), $MachinePrecision]
code[x$46$re_, x$46$im_] := N[(N[(x$46$re * N[(x$46$im * N[(x$46$re * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Power[x$46$im, 3.0], $MachinePrecision]), $MachinePrecision]
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right) - {x.im}^{3}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 7.4

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

    \[\leadsto \color{blue}{x.im \cdot \left(x.re \cdot \left(x.re \cdot 3\right)\right) - {x.im}^{3}} \]
    Proof
    (-.f64 (*.f64 x.im (*.f64 x.re (*.f64 x.re 3))) (pow.f64 x.im 3)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 x.im (*.f64 x.re (Rewrite<= *-commutative_binary64 (*.f64 3 x.re)))) (pow.f64 x.im 3)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 x.im (*.f64 x.re (*.f64 (Rewrite<= metadata-eval (+.f64 2 1)) x.re))) (pow.f64 x.im 3)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 x.im (*.f64 x.re (Rewrite<= distribute-lft1-in_binary64 (+.f64 (*.f64 2 x.re) x.re)))) (pow.f64 x.im 3)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 x.im (*.f64 x.re (+.f64 (Rewrite<= count-2_binary64 (+.f64 x.re x.re)) x.re))) (pow.f64 x.im 3)): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x.im x.re) (+.f64 (+.f64 x.re x.re) x.re))) (pow.f64 x.im 3)): 16 points increase in error, 33 points decrease in error
    (-.f64 (Rewrite=> *-commutative_binary64 (*.f64 (+.f64 (+.f64 x.re x.re) x.re) (*.f64 x.im x.re))) (pow.f64 x.im 3)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (+.f64 (Rewrite=> count-2_binary64 (*.f64 2 x.re)) x.re) (*.f64 x.im x.re)) (pow.f64 x.im 3)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (Rewrite=> distribute-lft1-in_binary64 (*.f64 (+.f64 2 1) x.re)) (*.f64 x.im x.re)) (pow.f64 x.im 3)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (*.f64 (Rewrite=> metadata-eval 3) x.re) (*.f64 x.im x.re)) (pow.f64 x.im 3)): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= associate-*r*_binary64 (*.f64 3 (*.f64 x.re (*.f64 x.im x.re)))) (pow.f64 x.im 3)): 28 points increase in error, 25 points decrease in error
    (-.f64 (*.f64 3 (*.f64 x.re (*.f64 x.im x.re))) (Rewrite=> unpow3_binary64 (*.f64 (*.f64 x.im x.im) x.im))): 34 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 3 (*.f64 x.re (Rewrite=> *-commutative_binary64 (*.f64 x.re x.im)))) (*.f64 (*.f64 x.im x.im) x.im)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 3 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x.re x.re) x.im))) (*.f64 (*.f64 x.im x.im) x.im)): 27 points increase in error, 10 points decrease in error
    (-.f64 (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 3 (*.f64 x.re x.re)) x.im)) (*.f64 (*.f64 x.im x.im) x.im)): 16 points increase in error, 20 points decrease in error
    (-.f64 (*.f64 (*.f64 (Rewrite<= metadata-eval (+.f64 2 1)) (*.f64 x.re x.re)) x.im) (*.f64 (*.f64 x.im x.im) x.im)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (Rewrite<= distribute-lft1-in_binary64 (+.f64 (*.f64 2 (*.f64 x.re x.re)) (*.f64 x.re x.re))) x.im) (*.f64 (*.f64 x.im x.im) x.im)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (+.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 2 x.re) x.re)) (*.f64 x.re x.re)) x.im) (*.f64 (*.f64 x.im x.im) x.im)): 0 points increase in error, 0 points decrease in error
    (-.f64 (*.f64 (+.f64 (*.f64 (Rewrite<= count-2_binary64 (+.f64 x.re x.re)) x.re) (*.f64 x.re x.re)) x.im) (*.f64 (*.f64 x.im x.im) x.im)): 0 points increase in error, 0 points decrease in error
    (Rewrite=> distribute-rgt-out--_binary64 (*.f64 x.im (-.f64 (+.f64 (*.f64 (+.f64 x.re x.re) x.re) (*.f64 x.re x.re)) (*.f64 x.im x.im)))): 0 points increase in error, 2 points decrease in error
    (*.f64 x.im (Rewrite<= associate-+r-_binary64 (+.f64 (*.f64 (+.f64 x.re x.re) x.re) (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im))))): 0 points increase in error, 0 points decrease in error
    (*.f64 x.im (Rewrite=> +-commutative_binary64 (+.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) (*.f64 (+.f64 x.re x.re) x.re)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x.im (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im))) (*.f64 x.im (*.f64 (+.f64 x.re x.re) x.re)))): 20 points increase in error, 15 points decrease in error
    (+.f64 (*.f64 x.im (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im))) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x.im (+.f64 x.re x.re)) x.re))): 5 points increase in error, 9 points decrease in error
    (+.f64 (*.f64 x.im (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im))) (*.f64 (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 x.re x.im) (*.f64 x.re x.im))) x.re)): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x.im (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im))) (*.f64 (+.f64 (*.f64 x.re x.im) (Rewrite<= *-commutative_binary64 (*.f64 x.im x.re))) x.re)): 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.im)) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.re)): 0 points increase in error, 0 points decrease in error
  3. Taylor expanded in x.im around 0 7.4

    \[\leadsto \color{blue}{3 \cdot \left({x.re}^{2} \cdot x.im\right)} - {x.im}^{3} \]
  4. Simplified0.2

    \[\leadsto \color{blue}{x.re \cdot \left(x.im \cdot \left(3 \cdot x.re\right)\right)} - {x.im}^{3} \]
    Proof
    (*.f64 x.re (*.f64 x.im (*.f64 3 x.re))): 0 points increase in error, 0 points decrease in error
    (*.f64 x.re (*.f64 x.im (Rewrite<= *-commutative_binary64 (*.f64 x.re 3)))): 0 points increase in error, 0 points decrease in error
    (*.f64 x.re (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x.im x.re) 3))): 23 points increase in error, 18 points decrease in error
    (*.f64 x.re (*.f64 (Rewrite=> *-commutative_binary64 (*.f64 x.re x.im)) 3)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x.re (*.f64 x.re x.im)) 3)): 35 points increase in error, 26 points decrease in error
    (*.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 x.re x.re) x.im)) 3): 33 points increase in error, 23 points decrease in error
    (*.f64 (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 x.re 2)) x.im) 3): 0 points increase in error, 0 points decrease in error
    (Rewrite<= *-commutative_binary64 (*.f64 3 (*.f64 (pow.f64 x.re 2) x.im))): 0 points increase in error, 0 points decrease in error
  5. Final simplification0.2

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

Alternatives

Alternative 1
Error0.4
Cost1480
\[\begin{array}{l} \mathbf{if}\;x.re \leq -4.397228096644896 \cdot 10^{+71}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{elif}\;x.re \leq 4.396866311121434 \cdot 10^{+69}:\\ \;\;\;\;x.im \cdot \left(x.re \cdot \left(x.re \cdot 3\right) - x.im \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) + \frac{1}{\frac{1}{x.re \cdot \left(x.re \cdot x.im\right)}}\\ \end{array} \]
Alternative 2
Error0.2
Cost1216
\[\left(x.im \cdot \left(x.re + x.im\right)\right) \cdot \left(x.re - x.im\right) + x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) \]
Alternative 3
Error0.6
Cost1096
\[\begin{array}{l} \mathbf{if}\;x.re \leq -4.397228096644896 \cdot 10^{+71}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{elif}\;x.re \leq 10^{+160}:\\ \;\;\;\;x.im \cdot \left(x.re \cdot \left(x.re \cdot 3\right) - x.im \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.im\right) + x.re \cdot \left(\left(x.re \cdot x.im\right) \cdot 2\right)\\ \end{array} \]
Alternative 4
Error0.5
Cost968
\[\begin{array}{l} t_0 := x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{if}\;x.re \leq -4.397228096644896 \cdot 10^{+71}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.re \leq 4.394743958625503 \cdot 10^{+65}:\\ \;\;\;\;x.im \cdot \left(x.re \cdot \left(x.re \cdot 3\right) - x.im \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error12.7
Cost712
\[\begin{array}{l} t_0 := x.im \cdot \left(x.re \cdot \left(x.re \cdot 3\right)\right)\\ \mathbf{if}\;x.re \leq -4.204622830237812 \cdot 10^{-27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.re \leq 6.639645126105348 \cdot 10^{-48}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error12.7
Cost712
\[\begin{array}{l} \mathbf{if}\;x.re \leq -4.204622830237812 \cdot 10^{-27}:\\ \;\;\;\;x.im \cdot \left(x.re \cdot \left(x.re \cdot 3\right)\right)\\ \mathbf{elif}\;x.re \leq 6.639645126105348 \cdot 10^{-48}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(3 \cdot \left(x.re \cdot x.re\right)\right)\\ \end{array} \]
Alternative 7
Error5.5
Cost712
\[\begin{array}{l} t_0 := x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{if}\;x.re \leq -4.204622830237812 \cdot 10^{-27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.re \leq 6.639645126105348 \cdot 10^{-48}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error28.8
Cost384
\[x.im \cdot \left(x.im \cdot \left(-x.im\right)\right) \]

Error

Reproduce

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

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

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