?

Average Error: 34.0 → 6.0
Time: 31.0s
Precision: binary64
Cost: 39880

?

\[e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right) \]
\[\begin{array}{l} t_0 := e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)\\ \mathbf{if}\;y.re \leq -6.2 \cdot 10^{-16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.re \leq 3.2 \cdot 10^{-7}:\\ \;\;\;\;\left(\left(0 - \left(-1 - e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(-y.im\right)}\right)\right) - 1\right) \cdot 1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (*
  (exp
   (-
    (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re)
    (* (atan2 x.im x.re) y.im)))
  (cos
   (+
    (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.im)
    (* (atan2 x.im x.re) y.re)))))
(FPCore (x.re x.im y.re y.im)
 :precision binary64
 (let* ((t_0
         (*
          (exp
           (-
            (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re)
            (* (atan2 x.im x.re) y.im)))
          (cos (* y.re (atan2 x.im x.re))))))
   (if (<= y.re -6.2e-16)
     t_0
     (if (<= y.re 3.2e-7)
       (* (- (- 0.0 (- -1.0 (exp (* (atan2 x.im x.re) (- y.im))))) 1.0) 1.0)
       t_0))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return exp(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_im) + (atan2(x_46_im, x_46_re) * y_46_re)));
}
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = exp(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos((y_46_re * atan2(x_46_im, x_46_re)));
	double tmp;
	if (y_46_re <= -6.2e-16) {
		tmp = t_0;
	} else if (y_46_re <= 3.2e-7) {
		tmp = ((0.0 - (-1.0 - exp((atan2(x_46_im, x_46_re) * -y_46_im)))) - 1.0) * 1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    code = exp(((log(sqrt(((x_46re * x_46re) + (x_46im * x_46im)))) * y_46re) - (atan2(x_46im, x_46re) * y_46im))) * cos(((log(sqrt(((x_46re * x_46re) + (x_46im * x_46im)))) * y_46im) + (atan2(x_46im, x_46re) * y_46re)))
end function
real(8) function code(x_46re, x_46im, y_46re, y_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8), intent (in) :: y_46re
    real(8), intent (in) :: y_46im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = exp(((log(sqrt(((x_46re * x_46re) + (x_46im * x_46im)))) * y_46re) - (atan2(x_46im, x_46re) * y_46im))) * cos((y_46re * atan2(x_46im, x_46re)))
    if (y_46re <= (-6.2d-16)) then
        tmp = t_0
    else if (y_46re <= 3.2d-7) then
        tmp = ((0.0d0 - ((-1.0d0) - exp((atan2(x_46im, x_46re) * -y_46im)))) - 1.0d0) * 1.0d0
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	return Math.exp(((Math.log(Math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (Math.atan2(x_46_im, x_46_re) * y_46_im))) * Math.cos(((Math.log(Math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_im) + (Math.atan2(x_46_im, x_46_re) * y_46_re)));
}
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
	double t_0 = Math.exp(((Math.log(Math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (Math.atan2(x_46_im, x_46_re) * y_46_im))) * Math.cos((y_46_re * Math.atan2(x_46_im, x_46_re)));
	double tmp;
	if (y_46_re <= -6.2e-16) {
		tmp = t_0;
	} else if (y_46_re <= 3.2e-7) {
		tmp = ((0.0 - (-1.0 - Math.exp((Math.atan2(x_46_im, x_46_re) * -y_46_im)))) - 1.0) * 1.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	return math.exp(((math.log(math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (math.atan2(x_46_im, x_46_re) * y_46_im))) * math.cos(((math.log(math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_im) + (math.atan2(x_46_im, x_46_re) * y_46_re)))
def code(x_46_re, x_46_im, y_46_re, y_46_im):
	t_0 = math.exp(((math.log(math.sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (math.atan2(x_46_im, x_46_re) * y_46_im))) * math.cos((y_46_re * math.atan2(x_46_im, x_46_re)))
	tmp = 0
	if y_46_re <= -6.2e-16:
		tmp = t_0
	elif y_46_re <= 3.2e-7:
		tmp = ((0.0 - (-1.0 - math.exp((math.atan2(x_46_im, x_46_re) * -y_46_im)))) - 1.0) * 1.0
	else:
		tmp = t_0
	return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	return Float64(exp(Float64(Float64(log(sqrt(Float64(Float64(x_46_re * x_46_re) + Float64(x_46_im * x_46_im)))) * y_46_re) - Float64(atan(x_46_im, x_46_re) * y_46_im))) * cos(Float64(Float64(log(sqrt(Float64(Float64(x_46_re * x_46_re) + Float64(x_46_im * x_46_im)))) * y_46_im) + Float64(atan(x_46_im, x_46_re) * y_46_re))))
end
function code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = Float64(exp(Float64(Float64(log(sqrt(Float64(Float64(x_46_re * x_46_re) + Float64(x_46_im * x_46_im)))) * y_46_re) - Float64(atan(x_46_im, x_46_re) * y_46_im))) * cos(Float64(y_46_re * atan(x_46_im, x_46_re))))
	tmp = 0.0
	if (y_46_re <= -6.2e-16)
		tmp = t_0;
	elseif (y_46_re <= 3.2e-7)
		tmp = Float64(Float64(Float64(0.0 - Float64(-1.0 - exp(Float64(atan(x_46_im, x_46_re) * Float64(-y_46_im))))) - 1.0) * 1.0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im)
	tmp = exp(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_im) + (atan2(x_46_im, x_46_re) * y_46_re)));
end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im)
	t_0 = exp(((log(sqrt(((x_46_re * x_46_re) + (x_46_im * x_46_im)))) * y_46_re) - (atan2(x_46_im, x_46_re) * y_46_im))) * cos((y_46_re * atan2(x_46_im, x_46_re)));
	tmp = 0.0;
	if (y_46_re <= -6.2e-16)
		tmp = t_0;
	elseif (y_46_re <= 3.2e-7)
		tmp = ((0.0 - (-1.0 - exp((atan2(x_46_im, x_46_re) * -y_46_im)))) - 1.0) * 1.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[Exp[N[(N[(N[Log[N[Sqrt[N[(N[(x$46$re * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * y$46$re), $MachinePrecision] - N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(N[(N[Log[N[Sqrt[N[(N[(x$46$re * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * y$46$im), $MachinePrecision] + N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[Exp[N[(N[(N[Log[N[Sqrt[N[(N[(x$46$re * x$46$re), $MachinePrecision] + N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * y$46$re), $MachinePrecision] - N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * y$46$im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(y$46$re * N[ArcTan[x$46$im / x$46$re], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$re, -6.2e-16], t$95$0, If[LessEqual[y$46$re, 3.2e-7], N[(N[(N[(0.0 - N[(-1.0 - N[Exp[N[(N[ArcTan[x$46$im / x$46$re], $MachinePrecision] * (-y$46$im)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] * 1.0), $MachinePrecision], t$95$0]]]
e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right)
\begin{array}{l}
t_0 := e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)\\
\mathbf{if}\;y.re \leq -6.2 \cdot 10^{-16}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y.re \leq 3.2 \cdot 10^{-7}:\\
\;\;\;\;\left(\left(0 - \left(-1 - e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(-y.im\right)}\right)\right) - 1\right) \cdot 1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if y.re < -6.2000000000000002e-16 or 3.2000000000000001e-7 < y.re

    1. Initial program 32.5

      \[e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right) \]
    2. Taylor expanded in y.im around 0 5.0

      \[\leadsto e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \color{blue}{\cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)} \]

    if -6.2000000000000002e-16 < y.re < 3.2000000000000001e-7

    1. Initial program 35.0

      \[e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.im + \tan^{-1}_* \frac{x.im}{x.re} \cdot y.re\right) \]
    2. Taylor expanded in y.im around 0 30.9

      \[\leadsto e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \color{blue}{\cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)} \]
    3. Taylor expanded in y.re around 0 30.9

      \[\leadsto e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \color{blue}{1} \]
    4. Taylor expanded in y.re around 0 6.7

      \[\leadsto e^{\color{blue}{-1 \cdot \left(y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)}} \cdot 1 \]
    5. Simplified6.7

      \[\leadsto e^{\color{blue}{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(-y.im\right)}} \cdot 1 \]
      Proof

      [Start]6.7

      \[ e^{-1 \cdot \left(y.im \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)} \cdot 1 \]

      rational.json-simplify-2 [<=]6.7

      \[ e^{-1 \cdot \color{blue}{\left(\tan^{-1}_* \frac{x.im}{x.re} \cdot y.im\right)}} \cdot 1 \]

      rational.json-simplify-43 [=>]6.7

      \[ e^{\color{blue}{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(y.im \cdot -1\right)}} \cdot 1 \]

      rational.json-simplify-9 [=>]6.7

      \[ e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot \color{blue}{\left(-y.im\right)}} \cdot 1 \]
    6. Applied egg-rr6.7

      \[\leadsto \color{blue}{\left(\left(0 - \left(-1 - e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(-y.im\right)}\right)\right) - 1\right)} \cdot 1 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification6.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;y.re \leq -6.2 \cdot 10^{-16}:\\ \;\;\;\;e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)\\ \mathbf{elif}\;y.re \leq 3.2 \cdot 10^{-7}:\\ \;\;\;\;\left(\left(0 - \left(-1 - e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(-y.im\right)}\right)\right) - 1\right) \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot \cos \left(y.re \cdot \tan^{-1}_* \frac{x.im}{x.re}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error6.1
Cost26888
\[\begin{array}{l} t_0 := e^{\log \left(\sqrt{x.re \cdot x.re + x.im \cdot x.im}\right) \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot 1\\ \mathbf{if}\;y.re \leq -6.5 \cdot 10^{-16}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y.re \leq 2.25 \cdot 10^{-7}:\\ \;\;\;\;\left(\left(0 - \left(-1 - e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(-y.im\right)}\right)\right) - 1\right) \cdot 1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error9.9
Cost20036
\[\begin{array}{l} t_0 := \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im\\ \mathbf{if}\;x.im \leq -5 \cdot 10^{-310}:\\ \;\;\;\;e^{\log \left(-x.im\right) \cdot y.re - t_0} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{\log x.im \cdot y.re - t_0} \cdot 1\\ \end{array} \]
Alternative 3
Error9.0
Cost20036
\[\begin{array}{l} t_0 := \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im\\ \mathbf{if}\;x.re \leq -2.5 \cdot 10^{-303}:\\ \;\;\;\;e^{\log \left(-x.re\right) \cdot y.re - t_0} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{\log x.re \cdot y.re - t_0} \cdot 1\\ \end{array} \]
Alternative 4
Error15.3
Cost19972
\[\begin{array}{l} \mathbf{if}\;x.im \leq 1.2 \cdot 10^{-282}:\\ \;\;\;\;e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(-y.im\right)} \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{\log x.im \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot 1\\ \end{array} \]
Alternative 5
Error14.6
Cost19972
\[\begin{array}{l} \mathbf{if}\;x.re \leq 4.4 \cdot 10^{-201}:\\ \;\;\;\;\left(\left(0 - \left(-1 - e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(-y.im\right)}\right)\right) - 1\right) \cdot 1\\ \mathbf{else}:\\ \;\;\;\;e^{\log x.re \cdot y.re - \tan^{-1}_* \frac{x.im}{x.re} \cdot y.im} \cdot 1\\ \end{array} \]
Alternative 6
Error20.9
Cost13632
\[\left(\left(0 - \left(-1 - e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(-y.im\right)}\right)\right) - 1\right) \cdot 1 \]
Alternative 7
Error20.9
Cost13248
\[e^{\tan^{-1}_* \frac{x.im}{x.re} \cdot \left(-y.im\right)} \cdot 1 \]
Alternative 8
Error38.8
Cost64
\[1 \]

Error

Reproduce?

herbie shell --seed 2023077 
(FPCore (x.re x.im y.re y.im)
  :name "powComplex, real part"
  :precision binary64
  (* (exp (- (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.re) (* (atan2 x.im x.re) y.im))) (cos (+ (* (log (sqrt (+ (* x.re x.re) (* x.im x.im)))) y.im) (* (atan2 x.im x.re) y.re)))))