
(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 6 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 (- (sqrt (+ (* re re) (* im im))) re))) 0.0) (* 0.5 (* im (pow re -0.5))) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))))
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = 0.5 * (im * pow(re, -0.5));
} else {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re))) <= 0.0: tmp = 0.5 * (im * math.pow(re, -0.5)) else: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) return tmp
function code(re, im) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))) <= 0.0) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) tmp = 0.5 * (im * (re ^ -0.5)); else tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \leq 0:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\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 9.8%
add-sqr-sqrt9.8%
pow29.8%
pow1/29.8%
sqrt-pow19.8%
*-commutative9.8%
hypot-define9.8%
metadata-eval9.8%
Applied egg-rr9.8%
Taylor expanded in re around inf 99.5%
unpow1/299.5%
exp-to-pow94.2%
log-rec94.2%
distribute-lft-neg-out94.2%
distribute-rgt-neg-in94.2%
metadata-eval94.2%
exp-to-pow99.7%
Simplified99.7%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 49.0%
sub-neg49.0%
sqr-neg49.0%
sub-neg49.0%
sqr-neg49.0%
hypot-define90.2%
Simplified90.2%
Final simplification91.6%
(FPCore (re im)
:precision binary64
(if (<= re -4100000000.0)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 8.5e-53)
(* 0.5 (sqrt (* 2.0 (* im (- 1.0 (/ re im))))))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -4100000000.0) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 8.5e-53) {
tmp = 0.5 * sqrt((2.0 * (im * (1.0 - (re / im)))));
} else {
tmp = 0.5 * (im * pow(re, -0.5));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-4100000000.0d0)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 8.5d-53) then
tmp = 0.5d0 * sqrt((2.0d0 * (im * (1.0d0 - (re / im)))))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4100000000.0) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 8.5e-53) {
tmp = 0.5 * Math.sqrt((2.0 * (im * (1.0 - (re / im)))));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4100000000.0: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 8.5e-53: tmp = 0.5 * math.sqrt((2.0 * (im * (1.0 - (re / im))))) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -4100000000.0) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 8.5e-53) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im * Float64(1.0 - Float64(re / im)))))); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4100000000.0) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 8.5e-53) tmp = 0.5 * sqrt((2.0 * (im * (1.0 - (re / im))))); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4100000000.0], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.5e-53], N[(0.5 * N[Sqrt[N[(2.0 * N[(im * N[(1.0 - N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4100000000:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 8.5 \cdot 10^{-53}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot \left(1 - \frac{re}{im}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -4.1e9Initial program 50.1%
Taylor expanded in re around -inf 81.9%
*-commutative81.9%
Simplified81.9%
if -4.1e9 < re < 8.50000000000000044e-53Initial program 59.5%
Taylor expanded in im around inf 81.0%
mul-1-neg81.0%
unsub-neg81.0%
Simplified81.0%
if 8.50000000000000044e-53 < re Initial program 12.7%
add-sqr-sqrt12.6%
pow212.6%
pow1/212.6%
sqrt-pow112.6%
*-commutative12.6%
hypot-define35.7%
metadata-eval35.7%
Applied egg-rr35.7%
Taylor expanded in re around inf 78.7%
unpow1/278.7%
exp-to-pow74.3%
log-rec74.3%
distribute-lft-neg-out74.3%
distribute-rgt-neg-in74.3%
metadata-eval74.3%
exp-to-pow78.8%
Simplified78.8%
Final simplification80.6%
(FPCore (re im)
:precision binary64
(if (<= re -700000000.0)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 6.5e-50)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -700000000.0) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 6.5e-50) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * pow(re, -0.5));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-700000000.0d0)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 6.5d-50) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -700000000.0) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 6.5e-50) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -700000000.0: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 6.5e-50: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -700000000.0) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 6.5e-50) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -700000000.0) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 6.5e-50) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -700000000.0], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.5e-50], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -700000000:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 6.5 \cdot 10^{-50}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -7e8Initial program 50.1%
Taylor expanded in re around -inf 81.9%
*-commutative81.9%
Simplified81.9%
if -7e8 < re < 6.49999999999999987e-50Initial program 59.5%
Taylor expanded in re around 0 81.0%
if 6.49999999999999987e-50 < re Initial program 12.7%
add-sqr-sqrt12.6%
pow212.6%
pow1/212.6%
sqrt-pow112.6%
*-commutative12.6%
hypot-define35.7%
metadata-eval35.7%
Applied egg-rr35.7%
Taylor expanded in re around inf 78.7%
unpow1/278.7%
exp-to-pow74.3%
log-rec74.3%
distribute-lft-neg-out74.3%
distribute-rgt-neg-in74.3%
metadata-eval74.3%
exp-to-pow78.8%
Simplified78.8%
Final simplification80.6%
(FPCore (re im)
:precision binary64
(if (<= re -1.32e-52)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 9.5e-45)
(* 0.5 (sqrt (* 2.0 im)))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -1.32e-52) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 9.5e-45) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = 0.5 * (im * pow(re, -0.5));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.32d-52)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 9.5d-45) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.32e-52) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 9.5e-45) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.32e-52: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 9.5e-45: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.32e-52) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 9.5e-45) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.32e-52) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 9.5e-45) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.32e-52], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 9.5e-45], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.32 \cdot 10^{-52}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 9.5 \cdot 10^{-45}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -1.32000000000000002e-52Initial program 51.5%
Taylor expanded in re around -inf 79.1%
*-commutative79.1%
Simplified79.1%
if -1.32000000000000002e-52 < re < 9.5000000000000002e-45Initial program 58.1%
Taylor expanded in re around 0 80.1%
sqrt-unprod80.6%
pow180.6%
Applied egg-rr80.6%
unpow180.6%
Simplified80.6%
if 9.5000000000000002e-45 < re Initial program 12.9%
add-sqr-sqrt12.9%
pow212.9%
pow1/212.9%
sqrt-pow112.9%
*-commutative12.9%
hypot-define35.3%
metadata-eval35.3%
Applied egg-rr35.3%
Taylor expanded in re around inf 79.4%
unpow1/279.4%
exp-to-pow75.0%
log-rec75.0%
distribute-lft-neg-out75.0%
distribute-rgt-neg-in75.0%
metadata-eval75.0%
exp-to-pow79.5%
Simplified79.5%
Final simplification79.8%
(FPCore (re im) :precision binary64 (if (<= re 6.2e-44) (* 0.5 (sqrt (* 2.0 im))) (* 0.5 (* im (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= 6.2e-44) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = 0.5 * (im * pow(re, -0.5));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 6.2d-44) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 6.2e-44) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 6.2e-44: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= 6.2e-44) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 6.2e-44) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 6.2e-44], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 6.2 \cdot 10^{-44}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < 6.19999999999999968e-44Initial program 55.2%
Taylor expanded in re around 0 56.9%
sqrt-unprod57.2%
pow157.2%
Applied egg-rr57.2%
unpow157.2%
Simplified57.2%
if 6.19999999999999968e-44 < re Initial program 12.9%
add-sqr-sqrt12.9%
pow212.9%
pow1/212.9%
sqrt-pow112.9%
*-commutative12.9%
hypot-define35.3%
metadata-eval35.3%
Applied egg-rr35.3%
Taylor expanded in re around inf 79.4%
unpow1/279.4%
exp-to-pow75.0%
log-rec75.0%
distribute-lft-neg-out75.0%
distribute-rgt-neg-in75.0%
metadata-eval75.0%
exp-to-pow79.5%
Simplified79.5%
Final simplification63.6%
(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 43.2%
Taylor expanded in re around 0 47.8%
sqrt-unprod47.8%
pow147.8%
Applied egg-rr47.8%
unpow147.8%
Simplified47.8%
Final simplification47.8%
herbie shell --seed 2024071
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
:precision binary64
:pre (> im 0.0)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))