
(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) (* (* im 0.5) (sqrt (/ 1.0 re))) (sqrt (* 0.5 (- (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 = (im * 0.5) * sqrt((1.0 / re));
} else {
tmp = sqrt((0.5 * (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 = (im * 0.5) * Math.sqrt((1.0 / re));
} else {
tmp = Math.sqrt((0.5 * (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 = (im * 0.5) * math.sqrt((1.0 / re)) else: tmp = math.sqrt((0.5 * (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(Float64(im * 0.5) * sqrt(Float64(1.0 / re))); else tmp = sqrt(Float64(0.5 * 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 = (im * 0.5) * sqrt((1.0 / re)); else tmp = sqrt((0.5 * (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[(N[(im * 0.5), $MachinePrecision] * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $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:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot \sqrt{\frac{1}{re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \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 8.1%
add-sqr-sqrt8.1%
sqrt-unprod8.1%
*-commutative8.1%
*-commutative8.1%
swap-sqr8.1%
add-sqr-sqrt8.1%
*-commutative8.1%
hypot-define8.1%
metadata-eval8.1%
Applied egg-rr8.1%
associate-*l*8.1%
metadata-eval8.1%
Simplified8.1%
Taylor expanded in re around inf 60.8%
Taylor expanded in im around 0 99.7%
associate-*r*99.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 42.9%
add-sqr-sqrt42.6%
sqrt-unprod42.9%
*-commutative42.9%
*-commutative42.9%
swap-sqr42.9%
add-sqr-sqrt42.9%
*-commutative42.9%
hypot-define88.9%
metadata-eval88.9%
Applied egg-rr88.9%
associate-*l*88.9%
metadata-eval88.9%
Simplified88.9%
Final simplification90.2%
(FPCore (re im)
:precision binary64
(if (<= re -3.5e-55)
(sqrt (* 0.5 (* re -2.0)))
(if (<= re 2.4e+50)
(sqrt (* 0.5 (- im re)))
(* (* im 0.5) (sqrt (/ 1.0 re))))))
double code(double re, double im) {
double tmp;
if (re <= -3.5e-55) {
tmp = sqrt((0.5 * (re * -2.0)));
} else if (re <= 2.4e+50) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * sqrt((1.0 / re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.5d-55)) then
tmp = sqrt((0.5d0 * (re * (-2.0d0))))
else if (re <= 2.4d+50) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = (im * 0.5d0) * sqrt((1.0d0 / re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.5e-55) {
tmp = Math.sqrt((0.5 * (re * -2.0)));
} else if (re <= 2.4e+50) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * Math.sqrt((1.0 / re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.5e-55: tmp = math.sqrt((0.5 * (re * -2.0))) elif re <= 2.4e+50: tmp = math.sqrt((0.5 * (im - re))) else: tmp = (im * 0.5) * math.sqrt((1.0 / re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.5e-55) tmp = sqrt(Float64(0.5 * Float64(re * -2.0))); elseif (re <= 2.4e+50) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(Float64(im * 0.5) * sqrt(Float64(1.0 / re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.5e-55) tmp = sqrt((0.5 * (re * -2.0))); elseif (re <= 2.4e+50) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) * sqrt((1.0 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.5e-55], N[Sqrt[N[(0.5 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, 2.4e+50], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.5 \cdot 10^{-55}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 2.4 \cdot 10^{+50}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot \sqrt{\frac{1}{re}}\\
\end{array}
\end{array}
if re < -3.50000000000000025e-55Initial program 38.4%
add-sqr-sqrt38.1%
sqrt-unprod38.4%
*-commutative38.4%
*-commutative38.4%
swap-sqr38.4%
add-sqr-sqrt38.4%
*-commutative38.4%
hypot-define100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-*l*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.5%
*-commutative75.5%
Simplified75.5%
if -3.50000000000000025e-55 < re < 2.4000000000000002e50Initial program 54.1%
add-sqr-sqrt53.8%
sqrt-unprod54.1%
*-commutative54.1%
*-commutative54.1%
swap-sqr54.1%
add-sqr-sqrt54.1%
*-commutative54.1%
hypot-define86.7%
metadata-eval86.7%
Applied egg-rr86.7%
associate-*l*86.7%
metadata-eval86.7%
Simplified86.7%
Taylor expanded in re around 0 76.3%
neg-mul-176.3%
unsub-neg76.3%
Simplified76.3%
if 2.4000000000000002e50 < re Initial program 9.4%
add-sqr-sqrt9.4%
sqrt-unprod9.4%
*-commutative9.4%
*-commutative9.4%
swap-sqr9.4%
add-sqr-sqrt9.4%
*-commutative9.4%
hypot-define41.8%
metadata-eval41.8%
Applied egg-rr41.8%
associate-*l*41.8%
metadata-eval41.8%
Simplified41.8%
Taylor expanded in re around inf 54.0%
Taylor expanded in im around 0 84.5%
associate-*r*84.5%
Simplified84.5%
Final simplification78.1%
(FPCore (re im) :precision binary64 (if (<= re -3.2e-54) (sqrt (* 0.5 (* re -2.0))) (if (<= re 7.4e+49) (sqrt (* 0.5 (- im re))) (* 0.5 (/ im (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -3.2e-54) {
tmp = sqrt((0.5 * (re * -2.0)));
} else if (re <= 7.4e+49) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = 0.5 * (im / 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 <= (-3.2d-54)) then
tmp = sqrt((0.5d0 * (re * (-2.0d0))))
else if (re <= 7.4d+49) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = 0.5d0 * (im / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.2e-54) {
tmp = Math.sqrt((0.5 * (re * -2.0)));
} else if (re <= 7.4e+49) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.2e-54: tmp = math.sqrt((0.5 * (re * -2.0))) elif re <= 7.4e+49: tmp = math.sqrt((0.5 * (im - re))) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.2e-54) tmp = sqrt(Float64(0.5 * Float64(re * -2.0))); elseif (re <= 7.4e+49) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.2e-54) tmp = sqrt((0.5 * (re * -2.0))); elseif (re <= 7.4e+49) tmp = sqrt((0.5 * (im - re))); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.2e-54], N[Sqrt[N[(0.5 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, 7.4e+49], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.2 \cdot 10^{-54}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 7.4 \cdot 10^{+49}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -3.19999999999999998e-54Initial program 38.4%
add-sqr-sqrt38.1%
sqrt-unprod38.4%
*-commutative38.4%
*-commutative38.4%
swap-sqr38.4%
add-sqr-sqrt38.4%
*-commutative38.4%
hypot-define100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-*l*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.5%
*-commutative75.5%
Simplified75.5%
if -3.19999999999999998e-54 < re < 7.40000000000000036e49Initial program 54.1%
add-sqr-sqrt53.8%
sqrt-unprod54.1%
*-commutative54.1%
*-commutative54.1%
swap-sqr54.1%
add-sqr-sqrt54.1%
*-commutative54.1%
hypot-define86.7%
metadata-eval86.7%
Applied egg-rr86.7%
associate-*l*86.7%
metadata-eval86.7%
Simplified86.7%
Taylor expanded in re around 0 76.3%
neg-mul-176.3%
unsub-neg76.3%
Simplified76.3%
if 7.40000000000000036e49 < re Initial program 9.4%
add-sqr-sqrt9.4%
sqrt-unprod9.4%
*-commutative9.4%
*-commutative9.4%
swap-sqr9.4%
add-sqr-sqrt9.4%
*-commutative9.4%
hypot-define41.8%
metadata-eval41.8%
Applied egg-rr41.8%
associate-*l*41.8%
metadata-eval41.8%
Simplified41.8%
Taylor expanded in re around inf 54.0%
sqrt-prod53.9%
sqrt-prod53.7%
sqrt-div68.5%
sqrt-pow183.9%
metadata-eval83.9%
pow183.9%
Applied egg-rr83.9%
*-commutative83.9%
associate-*r*83.6%
rem-square-sqrt84.4%
Simplified84.4%
Final simplification78.1%
(FPCore (re im) :precision binary64 (if (<= im 1.75e-83) (sqrt (* 0.5 (* re -2.0))) (sqrt (* 0.5 (- im re)))))
double code(double re, double im) {
double tmp;
if (im <= 1.75e-83) {
tmp = sqrt((0.5 * (re * -2.0)));
} else {
tmp = sqrt((0.5 * (im - re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.75d-83) then
tmp = sqrt((0.5d0 * (re * (-2.0d0))))
else
tmp = sqrt((0.5d0 * (im - re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.75e-83) {
tmp = Math.sqrt((0.5 * (re * -2.0)));
} else {
tmp = Math.sqrt((0.5 * (im - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.75e-83: tmp = math.sqrt((0.5 * (re * -2.0))) else: tmp = math.sqrt((0.5 * (im - re))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.75e-83) tmp = sqrt(Float64(0.5 * Float64(re * -2.0))); else tmp = sqrt(Float64(0.5 * Float64(im - re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.75e-83) tmp = sqrt((0.5 * (re * -2.0))); else tmp = sqrt((0.5 * (im - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.75e-83], N[Sqrt[N[(0.5 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.75 \cdot 10^{-83}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\end{array}
\end{array}
if im < 1.75000000000000015e-83Initial program 33.7%
add-sqr-sqrt33.5%
sqrt-unprod33.7%
*-commutative33.7%
*-commutative33.7%
swap-sqr33.7%
add-sqr-sqrt33.7%
*-commutative33.7%
hypot-define72.2%
metadata-eval72.2%
Applied egg-rr72.2%
associate-*l*72.2%
metadata-eval72.2%
Simplified72.2%
Taylor expanded in re around -inf 47.2%
*-commutative47.2%
Simplified47.2%
if 1.75000000000000015e-83 < im Initial program 41.9%
add-sqr-sqrt41.6%
sqrt-unprod41.9%
*-commutative41.9%
*-commutative41.9%
swap-sqr41.9%
add-sqr-sqrt41.9%
*-commutative41.9%
hypot-define83.7%
metadata-eval83.7%
Applied egg-rr83.7%
associate-*l*83.7%
metadata-eval83.7%
Simplified83.7%
Taylor expanded in re around 0 72.0%
neg-mul-172.0%
unsub-neg72.0%
Simplified72.0%
Final simplification62.1%
(FPCore (re im) :precision binary64 (if (<= re -6e-65) (sqrt (* 0.5 (* re -2.0))) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -6e-65) {
tmp = sqrt((0.5 * (re * -2.0)));
} else {
tmp = sqrt((im * 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 <= (-6d-65)) then
tmp = sqrt((0.5d0 * (re * (-2.0d0))))
else
tmp = sqrt((im * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -6e-65) {
tmp = Math.sqrt((0.5 * (re * -2.0)));
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -6e-65: tmp = math.sqrt((0.5 * (re * -2.0))) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -6e-65) tmp = sqrt(Float64(0.5 * Float64(re * -2.0))); else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -6e-65) tmp = sqrt((0.5 * (re * -2.0))); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -6e-65], N[Sqrt[N[(0.5 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -6 \cdot 10^{-65}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -5.99999999999999996e-65Initial program 38.4%
add-sqr-sqrt38.1%
sqrt-unprod38.4%
*-commutative38.4%
*-commutative38.4%
swap-sqr38.4%
add-sqr-sqrt38.4%
*-commutative38.4%
hypot-define100.0%
metadata-eval100.0%
Applied egg-rr100.0%
associate-*l*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.5%
*-commutative75.5%
Simplified75.5%
if -5.99999999999999996e-65 < re Initial program 38.7%
add-sqr-sqrt38.5%
sqrt-unprod38.7%
*-commutative38.7%
*-commutative38.7%
swap-sqr38.7%
add-sqr-sqrt38.7%
*-commutative38.7%
hypot-define71.3%
metadata-eval71.3%
Applied egg-rr71.3%
associate-*l*71.3%
metadata-eval71.3%
Simplified71.3%
Taylor expanded in re around 0 56.8%
Final simplification61.9%
(FPCore (re im) :precision binary64 (sqrt (* im 0.5)))
double code(double re, double im) {
return sqrt((im * 0.5));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((im * 0.5d0))
end function
public static double code(double re, double im) {
return Math.sqrt((im * 0.5));
}
def code(re, im): return math.sqrt((im * 0.5))
function code(re, im) return sqrt(Float64(im * 0.5)) end
function tmp = code(re, im) tmp = sqrt((im * 0.5)); end
code[re_, im_] := N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{im \cdot 0.5}
\end{array}
Initial program 38.7%
add-sqr-sqrt38.4%
sqrt-unprod38.7%
*-commutative38.7%
*-commutative38.7%
swap-sqr38.7%
add-sqr-sqrt38.7%
*-commutative38.7%
hypot-define79.1%
metadata-eval79.1%
Applied egg-rr79.1%
associate-*l*79.1%
metadata-eval79.1%
Simplified79.1%
Taylor expanded in re around 0 48.9%
herbie shell --seed 2024106
(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)))))