
(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 (/ (- (pow im 2.0)) re))) (* 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((-pow(im, 2.0) / re));
} 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((-Math.pow(im, 2.0) / re));
} 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((-math.pow(im, 2.0) / re)) 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(Float64(-(im ^ 2.0)) / re))); 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((-(im ^ 2.0) / re)); 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[((-N[Power[im, 2.0], $MachinePrecision]) / re), $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{\frac{-{im}^{2}}{re}}\\
\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 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 16.0%
sqr-neg16.0%
+-commutative16.0%
sqr-neg16.0%
+-commutative16.0%
distribute-rgt-in16.0%
cancel-sign-sub16.0%
distribute-rgt-out--16.0%
sub-neg16.0%
remove-double-neg16.0%
+-commutative16.0%
hypot-def16.0%
Simplified16.0%
Taylor expanded in re around -inf 60.5%
mul-1-neg60.5%
distribute-neg-frac60.5%
Simplified60.5%
if 0.0 < (sqrt.f64 (*.f64 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 42.4%
sqr-neg42.4%
+-commutative42.4%
sqr-neg42.4%
+-commutative42.4%
distribute-rgt-in42.4%
cancel-sign-sub42.4%
distribute-rgt-out--42.4%
sub-neg42.4%
remove-double-neg42.4%
+-commutative42.4%
hypot-def90.3%
Simplified90.3%
Final simplification86.7%
(FPCore (re im)
:precision binary64
(if (<= re -1.85e+53)
(* 0.5 (sqrt (/ (- (pow im 2.0)) re)))
(if (<= re 6.6e+72)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(* 0.5 (* 2.0 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.85e+53) {
tmp = 0.5 * sqrt((-pow(im, 2.0) / re));
} else if (re <= 6.6e+72) {
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 <= (-1.85d+53)) then
tmp = 0.5d0 * sqrt((-(im ** 2.0d0) / re))
else if (re <= 6.6d+72) 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 <= -1.85e+53) {
tmp = 0.5 * Math.sqrt((-Math.pow(im, 2.0) / re));
} else if (re <= 6.6e+72) {
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 <= -1.85e+53: tmp = 0.5 * math.sqrt((-math.pow(im, 2.0) / re)) elif re <= 6.6e+72: 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 <= -1.85e+53) tmp = Float64(0.5 * sqrt(Float64(Float64(-(im ^ 2.0)) / re))); elseif (re <= 6.6e+72) 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 <= -1.85e+53) tmp = 0.5 * sqrt((-(im ^ 2.0) / re)); elseif (re <= 6.6e+72) 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, -1.85e+53], N[(0.5 * N[Sqrt[N[((-N[Power[im, 2.0], $MachinePrecision]) / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.6e+72], 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 -1.85 \cdot 10^{+53}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{-{im}^{2}}{re}}\\
\mathbf{elif}\;re \leq 6.6 \cdot 10^{+72}:\\
\;\;\;\;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 < -1.85e53Initial program 10.8%
sqr-neg10.8%
+-commutative10.8%
sqr-neg10.8%
+-commutative10.8%
distribute-rgt-in10.8%
cancel-sign-sub10.8%
distribute-rgt-out--10.8%
sub-neg10.8%
remove-double-neg10.8%
+-commutative10.8%
hypot-def38.7%
Simplified38.7%
Taylor expanded in re around -inf 55.2%
mul-1-neg55.2%
distribute-neg-frac55.2%
Simplified55.2%
if -1.85e53 < re < 6.6e72Initial program 50.3%
sqr-neg50.3%
+-commutative50.3%
sqr-neg50.3%
+-commutative50.3%
distribute-rgt-in50.3%
cancel-sign-sub50.3%
distribute-rgt-out--50.3%
sub-neg50.3%
remove-double-neg50.3%
+-commutative50.3%
hypot-def88.2%
Simplified88.2%
Taylor expanded in re around 0 37.1%
distribute-lft-out37.1%
*-commutative37.1%
Simplified37.1%
if 6.6e72 < re Initial program 30.1%
sqr-neg30.1%
+-commutative30.1%
sqr-neg30.1%
+-commutative30.1%
distribute-rgt-in30.1%
cancel-sign-sub30.1%
distribute-rgt-out--30.1%
sub-neg30.1%
remove-double-neg30.1%
+-commutative30.1%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 86.1%
*-commutative86.1%
unpow286.1%
rem-square-sqrt87.7%
Simplified87.7%
Final simplification49.9%
(FPCore (re im)
:precision binary64
(if (<= re -2.35e+148)
(* 0.5 (sqrt (* 2.0 (- re re))))
(if (<= re 9.8e+72)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(* 0.5 (* 2.0 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -2.35e+148) {
tmp = 0.5 * sqrt((2.0 * (re - re)));
} else if (re <= 9.8e+72) {
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.35d+148)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re - re)))
else if (re <= 9.8d+72) 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.35e+148) {
tmp = 0.5 * Math.sqrt((2.0 * (re - re)));
} else if (re <= 9.8e+72) {
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.35e+148: tmp = 0.5 * math.sqrt((2.0 * (re - re))) elif re <= 9.8e+72: 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.35e+148) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re - re)))); elseif (re <= 9.8e+72) 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.35e+148) tmp = 0.5 * sqrt((2.0 * (re - re))); elseif (re <= 9.8e+72) 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.35e+148], N[(0.5 * N[Sqrt[N[(2.0 * N[(re - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 9.8e+72], 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.35 \cdot 10^{+148}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - re\right)}\\
\mathbf{elif}\;re \leq 9.8 \cdot 10^{+72}:\\
\;\;\;\;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.3499999999999999e148Initial program 6.0%
Taylor expanded in re around -inf 28.8%
mul-1-neg28.8%
Simplified28.8%
if -2.3499999999999999e148 < re < 9.80000000000000012e72Initial program 46.8%
sqr-neg46.8%
+-commutative46.8%
sqr-neg46.8%
+-commutative46.8%
distribute-rgt-in46.8%
cancel-sign-sub46.8%
distribute-rgt-out--46.8%
sub-neg46.8%
remove-double-neg46.8%
+-commutative46.8%
hypot-def83.9%
Simplified83.9%
Taylor expanded in re around 0 34.3%
distribute-lft-out34.3%
*-commutative34.3%
Simplified34.3%
if 9.80000000000000012e72 < re Initial program 30.1%
sqr-neg30.1%
+-commutative30.1%
sqr-neg30.1%
+-commutative30.1%
distribute-rgt-in30.1%
cancel-sign-sub30.1%
distribute-rgt-out--30.1%
sub-neg30.1%
remove-double-neg30.1%
+-commutative30.1%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 86.1%
*-commutative86.1%
unpow286.1%
rem-square-sqrt87.7%
Simplified87.7%
Final simplification43.7%
(FPCore (re im) :precision binary64 (if (<= re 0.0132) (* 0.5 (sqrt (* 2.0 im))) (* 0.5 (* 2.0 (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= 0.0132) {
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 <= 0.0132d0) 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 <= 0.0132) {
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 <= 0.0132: 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 <= 0.0132) 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 <= 0.0132) 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, 0.0132], 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 0.0132:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < 0.0132Initial program 39.8%
sqr-neg39.8%
+-commutative39.8%
sqr-neg39.8%
+-commutative39.8%
distribute-rgt-in39.8%
cancel-sign-sub39.8%
distribute-rgt-out--39.8%
sub-neg39.8%
remove-double-neg39.8%
+-commutative39.8%
hypot-def75.8%
Simplified75.8%
Taylor expanded in re around 0 29.3%
*-commutative29.3%
Simplified29.3%
if 0.0132 < re Initial program 37.2%
sqr-neg37.2%
+-commutative37.2%
sqr-neg37.2%
+-commutative37.2%
distribute-rgt-in37.2%
cancel-sign-sub37.2%
distribute-rgt-out--37.2%
sub-neg37.2%
remove-double-neg37.2%
+-commutative37.2%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 80.3%
*-commutative80.3%
unpow280.3%
rem-square-sqrt81.9%
Simplified81.9%
Final simplification41.2%
(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 39.2%
sqr-neg39.2%
+-commutative39.2%
sqr-neg39.2%
+-commutative39.2%
distribute-rgt-in39.2%
cancel-sign-sub39.2%
distribute-rgt-out--39.2%
sub-neg39.2%
remove-double-neg39.2%
+-commutative39.2%
hypot-def81.3%
Simplified81.3%
Taylor expanded in re around 0 24.7%
*-commutative24.7%
Simplified24.7%
Final simplification24.7%
(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 2023321
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:herbie-target
(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)))))