?

Average Accuracy: 49.4% → 55.8%
Time: 9.0s
Precision: binary64
Cost: 3785

?

\[\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 \]
\[\begin{array}{l} t_0 := x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\ t_1 := t_0 + x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 5 \cdot 10^{+303}\right):\\ \;\;\;\;t_0 + \left(x.re \cdot x.im\right) \cdot \left(x.re - x.im\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(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
 (let* ((t_0 (* x.re (+ (* x.re x.im) (* x.re x.im))))
        (t_1 (+ t_0 (* x.im (- (* x.re x.re) (* x.im x.im))))))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 5e+303)))
     (+ t_0 (* (* x.re x.im) (- x.re x.im)))
     t_1)))
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) {
	double t_0 = x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im));
	double t_1 = t_0 + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)));
	double tmp;
	if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 5e+303)) {
		tmp = t_0 + ((x_46_re * x_46_im) * (x_46_re - x_46_im));
	} else {
		tmp = t_1;
	}
	return tmp;
}
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) {
	double t_0 = x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im));
	double t_1 = t_0 + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)));
	double tmp;
	if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 5e+303)) {
		tmp = t_0 + ((x_46_re * x_46_im) * (x_46_re - x_46_im));
	} else {
		tmp = t_1;
	}
	return tmp;
}
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):
	t_0 = x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im))
	t_1 = t_0 + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)))
	tmp = 0
	if (t_1 <= -math.inf) or not (t_1 <= 5e+303):
		tmp = t_0 + ((x_46_re * x_46_im) * (x_46_re - x_46_im))
	else:
		tmp = t_1
	return tmp
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)
	t_0 = Float64(x_46_re * Float64(Float64(x_46_re * x_46_im) + Float64(x_46_re * x_46_im)))
	t_1 = Float64(t_0 + Float64(x_46_im * Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im))))
	tmp = 0.0
	if ((t_1 <= Float64(-Inf)) || !(t_1 <= 5e+303))
		tmp = Float64(t_0 + Float64(Float64(x_46_re * x_46_im) * Float64(x_46_re - x_46_im)));
	else
		tmp = t_1;
	end
	return tmp
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_2 = code(x_46_re, x_46_im)
	t_0 = x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im));
	t_1 = t_0 + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)));
	tmp = 0.0;
	if ((t_1 <= -Inf) || ~((t_1 <= 5e+303)))
		tmp = t_0 + ((x_46_re * x_46_im) * (x_46_re - x_46_im));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
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_] := Block[{t$95$0 = N[(x$46$re * N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + N[(x$46$im * N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 5e+303]], $MachinePrecision]], N[(t$95$0 + N[(N[(x$46$re * x$46$im), $MachinePrecision] * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\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
\begin{array}{l}
t_0 := x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\
t_1 := t_0 + x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)\\
\mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 5 \cdot 10^{+303}\right):\\
\;\;\;\;t_0 + \left(x.re \cdot x.im\right) \cdot \left(x.re - x.im\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original49.4%
Target55.5%
Herbie55.8%
\[\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. Split input into 2 regimes
  2. if (+.f64 (*.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)) < -inf.0 or 4.9999999999999997e303 < (+.f64 (*.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))

    1. Initial program 0.0%

      \[\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. Applied egg-rr13.8%

      \[\leadsto \color{blue}{\left(0 + \left(x.im \cdot \left(x.re + x.im\right)\right) \cdot \left(x.re - x.im\right)\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
      Proof

      [Start]0.0

      \[ \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 \]

      add-log-exp [=>]0.0

      \[ \color{blue}{\log \left(e^{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]

      *-un-lft-identity [=>]0.0

      \[ \log \color{blue}{\left(1 \cdot e^{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]

      log-prod [=>]0.0

      \[ \color{blue}{\left(\log 1 + \log \left(e^{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}\right)\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]

      metadata-eval [=>]0.0

      \[ \left(\color{blue}{0} + \log \left(e^{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}\right)\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]

      add-log-exp [<=]0.0

      \[ \left(0 + \color{blue}{\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]

      *-commutative [=>]0.0

      \[ \left(0 + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)}\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]

      difference-of-squares [=>]0.0

      \[ \left(0 + x.im \cdot \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)}\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]

      associate-*r* [=>]13.8

      \[ \left(0 + \color{blue}{\left(x.im \cdot \left(x.re + x.im\right)\right) \cdot \left(x.re - x.im\right)}\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Taylor expanded in x.im around 0 14.3%

      \[\leadsto \left(0 + \color{blue}{\left(x.re \cdot x.im\right)} \cdot \left(x.re - x.im\right)\right) + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]

    if -inf.0 < (+.f64 (*.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)) < 4.9999999999999997e303

    1. Initial program 99.7%

      \[\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 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification59.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) + x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) \leq -\infty \lor \neg \left(x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) + x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) \leq 5 \cdot 10^{+303}\right):\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) + \left(x.re \cdot x.im\right) \cdot \left(x.re - x.im\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) + x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy55.5%
Cost7040
\[x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3} \]
Alternative 2
Accuracy55.5%
Cost7040
\[x.re \cdot \left(3 \cdot \left(x.re \cdot x.im\right)\right) - {x.im}^{3} \]
Alternative 3
Accuracy55.6%
Cost3785
\[\begin{array}{l} t_0 := x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) + x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{+303}\right):\\ \;\;\;\;x.re \cdot \left(3 \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Accuracy55.5%
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 5
Accuracy44.5%
Cost713
\[\begin{array}{l} \mathbf{if}\;x.re \leq -4.3 \cdot 10^{-76} \lor \neg \left(x.re \leq 6 \cdot 10^{-69}\right):\\ \;\;\;\;3 \cdot \left(x.im \cdot \left(x.re \cdot x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \end{array} \]
Alternative 6
Accuracy50.5%
Cost713
\[\begin{array}{l} \mathbf{if}\;x.re \leq -3.55 \cdot 10^{-81} \lor \neg \left(x.re \leq 1.8 \cdot 10^{-68}\right):\\ \;\;\;\;3 \cdot \left(x.re \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \end{array} \]
Alternative 7
Accuracy50.5%
Cost712
\[\begin{array}{l} \mathbf{if}\;x.re \leq -1.4 \cdot 10^{-75}:\\ \;\;\;\;x.re \cdot \left(3 \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{elif}\;x.re \leq 2.35 \cdot 10^{-68}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;3 \cdot \left(x.re \cdot \left(x.re \cdot x.im\right)\right)\\ \end{array} \]
Alternative 8
Accuracy50.5%
Cost712
\[\begin{array}{l} \mathbf{if}\;x.re \leq -9 \cdot 10^{-76}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{elif}\;x.re \leq 1.65 \cdot 10^{-68}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;3 \cdot \left(x.re \cdot \left(x.re \cdot x.im\right)\right)\\ \end{array} \]
Alternative 9
Accuracy32.8%
Cost649
\[\begin{array}{l} \mathbf{if}\;x.im \leq -2.3 \cdot 10^{-95} \lor \neg \left(x.im \leq 1.1 \cdot 10^{-88}\right):\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.im\right)\\ \end{array} \]
Alternative 10
Accuracy17.1%
Cost320
\[x.im \cdot \left(x.re \cdot x.re\right) \]
Alternative 11
Accuracy18.1%
Cost320
\[x.re \cdot \left(x.re \cdot x.im\right) \]
Alternative 12
Accuracy4.5%
Cost128
\[-x.im \]
Alternative 13
Accuracy2.7%
Cost64
\[-1 \]

Error

Reproduce?

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