
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\end{array}
(FPCore (re im) :precision binary64 (if (<= (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im im)))))) 0.0) (* 0.5 (sqrt (* 2.0 (* -0.5 (/ im (/ re im)))))) (* 0.5 (sqrt (* 2.0 (+ re (hypot re im)))))))
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0) {
tmp = 0.5 * sqrt((2.0 * (-0.5 * (im / (re / im)))));
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (Math.sqrt((2.0 * (re + Math.sqrt(((re * re) + (im * im)))))) <= 0.0) {
tmp = 0.5 * Math.sqrt((2.0 * (-0.5 * (im / (re / im)))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if math.sqrt((2.0 * (re + math.sqrt(((re * re) + (im * im)))))) <= 0.0: tmp = 0.5 * math.sqrt((2.0 * (-0.5 * (im / (re / im))))) else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(re + sqrt(Float64(Float64(re * re) + Float64(im * im)))))) <= 0.0) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(-0.5 * Float64(im / Float64(re / im)))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0) tmp = 0.5 * sqrt((2.0 * (-0.5 * (im / (re / im))))); else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(0.5 * N[Sqrt[N[(2.0 * N[(-0.5 * N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\right)} \leq 0:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(-0.5 \cdot \frac{im}{\frac{re}{im}}\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 7.6%
sqr-neg7.6%
+-commutative7.6%
sqr-neg7.6%
+-commutative7.6%
distribute-rgt-in7.6%
cancel-sign-sub7.6%
distribute-rgt-out--7.6%
sub-neg7.6%
remove-double-neg7.6%
+-commutative7.6%
hypot-define7.6%
Simplified7.6%
Taylor expanded in re around -inf 57.5%
unpow257.5%
associate-/l*63.9%
Applied egg-rr63.9%
clear-num64.0%
un-div-inv64.0%
Applied egg-rr64.0%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 42.1%
sqr-neg42.1%
+-commutative42.1%
sqr-neg42.1%
+-commutative42.1%
distribute-rgt-in42.1%
cancel-sign-sub42.1%
distribute-rgt-out--42.1%
sub-neg42.1%
remove-double-neg42.1%
+-commutative42.1%
hypot-define89.8%
Simplified89.8%
Final simplification86.4%
(FPCore (re im)
:precision binary64
(if (<= re -2.05e+69)
(* 0.5 (sqrt (* 2.0 (* -0.5 (* im (/ im re))))))
(if (<= re 61000000000.0)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(* 0.5 (* 2.0 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -2.05e+69) {
tmp = 0.5 * sqrt((2.0 * (-0.5 * (im * (im / re)))));
} else if (re <= 61000000000.0) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-2.05d+69)) then
tmp = 0.5d0 * sqrt((2.0d0 * ((-0.5d0) * (im * (im / re)))))
else if (re <= 61000000000.0d0) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.05e+69) {
tmp = 0.5 * Math.sqrt((2.0 * (-0.5 * (im * (im / re)))));
} else if (re <= 61000000000.0) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.05e+69: tmp = 0.5 * math.sqrt((2.0 * (-0.5 * (im * (im / re))))) elif re <= 61000000000.0: tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.05e+69) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(-0.5 * Float64(im * Float64(im / re)))))); elseif (re <= 61000000000.0) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.05e+69) tmp = 0.5 * sqrt((2.0 * (-0.5 * (im * (im / re))))); elseif (re <= 61000000000.0) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.05e+69], N[(0.5 * N[Sqrt[N[(2.0 * N[(-0.5 * N[(im * N[(im / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 61000000000.0], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.05 \cdot 10^{+69}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(-0.5 \cdot \left(im \cdot \frac{im}{re}\right)\right)}\\
\mathbf{elif}\;re \leq 61000000000:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -2.05e69Initial program 5.4%
sqr-neg5.4%
+-commutative5.4%
sqr-neg5.4%
+-commutative5.4%
distribute-rgt-in5.3%
cancel-sign-sub5.3%
distribute-rgt-out--5.4%
sub-neg5.4%
remove-double-neg5.4%
+-commutative5.4%
hypot-define32.0%
Simplified32.0%
Taylor expanded in re around -inf 49.7%
unpow249.7%
associate-/l*54.4%
Applied egg-rr54.4%
if -2.05e69 < re < 6.1e10Initial program 45.9%
sqr-neg45.9%
+-commutative45.9%
sqr-neg45.9%
+-commutative45.9%
distribute-rgt-in45.9%
cancel-sign-sub45.9%
distribute-rgt-out--45.9%
sub-neg45.9%
remove-double-neg45.9%
+-commutative45.9%
hypot-define83.6%
Simplified83.6%
Taylor expanded in re around 0 39.4%
if 6.1e10 < re Initial program 42.0%
sqr-neg42.0%
+-commutative42.0%
sqr-neg42.0%
+-commutative42.0%
distribute-rgt-in42.0%
cancel-sign-sub42.0%
distribute-rgt-out--42.0%
sub-neg42.0%
remove-double-neg42.0%
+-commutative42.0%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 78.0%
*-commutative78.0%
unpow278.0%
rem-square-sqrt79.4%
Simplified79.4%
Final simplification53.2%
(FPCore (re im)
:precision binary64
(if (<= re -2.5e+67)
(* 0.5 (sqrt (* 2.0 (* -0.5 (/ im (/ re im))))))
(if (<= re 15500000000.0)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(* 0.5 (* 2.0 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -2.5e+67) {
tmp = 0.5 * sqrt((2.0 * (-0.5 * (im / (re / im)))));
} else if (re <= 15500000000.0) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-2.5d+67)) then
tmp = 0.5d0 * sqrt((2.0d0 * ((-0.5d0) * (im / (re / im)))))
else if (re <= 15500000000.0d0) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.5e+67) {
tmp = 0.5 * Math.sqrt((2.0 * (-0.5 * (im / (re / im)))));
} else if (re <= 15500000000.0) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.5e+67: tmp = 0.5 * math.sqrt((2.0 * (-0.5 * (im / (re / im))))) elif re <= 15500000000.0: tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.5e+67) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(-0.5 * Float64(im / Float64(re / im)))))); elseif (re <= 15500000000.0) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.5e+67) tmp = 0.5 * sqrt((2.0 * (-0.5 * (im / (re / im))))); elseif (re <= 15500000000.0) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.5e+67], N[(0.5 * N[Sqrt[N[(2.0 * N[(-0.5 * N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 15500000000.0], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.5 \cdot 10^{+67}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(-0.5 \cdot \frac{im}{\frac{re}{im}}\right)}\\
\mathbf{elif}\;re \leq 15500000000:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -2.49999999999999988e67Initial program 5.4%
sqr-neg5.4%
+-commutative5.4%
sqr-neg5.4%
+-commutative5.4%
distribute-rgt-in5.3%
cancel-sign-sub5.3%
distribute-rgt-out--5.4%
sub-neg5.4%
remove-double-neg5.4%
+-commutative5.4%
hypot-define32.0%
Simplified32.0%
Taylor expanded in re around -inf 49.7%
unpow249.7%
associate-/l*54.4%
Applied egg-rr54.4%
clear-num54.4%
un-div-inv54.4%
Applied egg-rr54.4%
if -2.49999999999999988e67 < re < 1.55e10Initial program 45.9%
sqr-neg45.9%
+-commutative45.9%
sqr-neg45.9%
+-commutative45.9%
distribute-rgt-in45.9%
cancel-sign-sub45.9%
distribute-rgt-out--45.9%
sub-neg45.9%
remove-double-neg45.9%
+-commutative45.9%
hypot-define83.6%
Simplified83.6%
Taylor expanded in re around 0 39.4%
if 1.55e10 < re Initial program 42.0%
sqr-neg42.0%
+-commutative42.0%
sqr-neg42.0%
+-commutative42.0%
distribute-rgt-in42.0%
cancel-sign-sub42.0%
distribute-rgt-out--42.0%
sub-neg42.0%
remove-double-neg42.0%
+-commutative42.0%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 78.0%
*-commutative78.0%
unpow278.0%
rem-square-sqrt79.4%
Simplified79.4%
Final simplification53.2%
(FPCore (re im) :precision binary64 (if (<= re 7800000000.0) (* 0.5 (sqrt (* 2.0 im))) (* 0.5 (* 2.0 (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= 7800000000.0) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = 0.5 * (2.0 * sqrt(re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 7800000000.0d0) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 7800000000.0) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 7800000000.0: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= 7800000000.0) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 7800000000.0) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 7800000000.0], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 7800000000:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < 7.8e9Initial program 35.8%
sqr-neg35.8%
+-commutative35.8%
sqr-neg35.8%
+-commutative35.8%
distribute-rgt-in35.8%
cancel-sign-sub35.8%
distribute-rgt-out--35.8%
sub-neg35.8%
remove-double-neg35.8%
+-commutative35.8%
hypot-define70.8%
Simplified70.8%
Taylor expanded in re around 0 31.9%
if 7.8e9 < re Initial program 42.0%
sqr-neg42.0%
+-commutative42.0%
sqr-neg42.0%
+-commutative42.0%
distribute-rgt-in42.0%
cancel-sign-sub42.0%
distribute-rgt-out--42.0%
sub-neg42.0%
remove-double-neg42.0%
+-commutative42.0%
hypot-define100.0%
Simplified100.0%
Taylor expanded in re around inf 78.0%
*-commutative78.0%
unpow278.0%
rem-square-sqrt79.4%
Simplified79.4%
Final simplification45.1%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 im))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * im))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * im));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * im))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * im))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * im)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot im}
\end{array}
Initial program 37.5%
sqr-neg37.5%
+-commutative37.5%
sqr-neg37.5%
+-commutative37.5%
distribute-rgt-in37.5%
cancel-sign-sub37.5%
distribute-rgt-out--37.5%
sub-neg37.5%
remove-double-neg37.5%
+-commutative37.5%
hypot-define78.9%
Simplified78.9%
Taylor expanded in re around 0 27.3%
Final simplification27.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (+ (* re re) (* im im)))))
(if (< re 0.0)
(* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- t_0 re)))))
(* 0.5 (sqrt (* 2.0 (+ t_0 re)))))))
double code(double re, double im) {
double t_0 = sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((re * re) + (im * im)))
if (re < 0.0d0) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt(((im * im) / (t_0 - re))))
else
tmp = 0.5d0 * sqrt((2.0d0 * (t_0 + re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt(((re * re) + (im * im))) tmp = 0 if re < 0.0: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt(((im * im) / (t_0 - re)))) else: tmp = 0.5 * math.sqrt((2.0 * (t_0 + re))) return tmp
function code(re, im) t_0 = sqrt(Float64(Float64(re * re) + Float64(im * im))) tmp = 0.0 if (re < 0.0) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(Float64(im * im) / Float64(t_0 - re))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(t_0 + re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt(((re * re) + (im * im))); tmp = 0.0; if (re < 0.0) tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re)))); else tmp = 0.5 * sqrt((2.0 * (t_0 + re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[re, 0.0], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(N[(im * im), $MachinePrecision] / N[(t$95$0 - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(t$95$0 + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{re \cdot re + im \cdot im}\\
\mathbf{if}\;re < 0:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{t\_0 - re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(t\_0 + re\right)}\\
\end{array}
\end{array}
herbie shell --seed 2024075
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:alt
(if (< re 0.0) (* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))