
(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 7 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 (* 0.5 (* (sqrt (- (hypot re im) re)) (sqrt 2.0))))
double code(double re, double im) {
return 0.5 * (sqrt((hypot(re, im) - re)) * sqrt(2.0));
}
public static double code(double re, double im) {
return 0.5 * (Math.sqrt((Math.hypot(re, im) - re)) * Math.sqrt(2.0));
}
def code(re, im): return 0.5 * (math.sqrt((math.hypot(re, im) - re)) * math.sqrt(2.0))
function code(re, im) return Float64(0.5 * Float64(sqrt(Float64(hypot(re, im) - re)) * sqrt(2.0))) end
function tmp = code(re, im) tmp = 0.5 * (sqrt((hypot(re, im) - re)) * sqrt(2.0)); end
code[re_, im_] := N[(0.5 * N[(N[Sqrt[N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(\sqrt{\mathsf{hypot}\left(re, im\right) - re} \cdot \sqrt{2}\right)
\end{array}
Initial program 55.3%
*-commutative55.3%
hypot-udef97.1%
sqrt-prod97.3%
Applied egg-rr97.3%
Final simplification97.3%
(FPCore (re im)
:precision binary64
(if (<= re -4e+39)
(* 0.5 (* (sqrt 2.0) (sqrt (* re -2.0))))
(if (<= re 4.1e+29)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* 0.5 (sqrt (* 2.0 (- re re)))))))
double code(double re, double im) {
double tmp;
if (re <= -4e+39) {
tmp = 0.5 * (sqrt(2.0) * sqrt((re * -2.0)));
} else if (re <= 4.1e+29) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * sqrt((2.0 * (re - re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-4d+39)) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt((re * (-2.0d0))))
else if (re <= 4.1d+29) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.5d0 * sqrt((2.0d0 * (re - re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4e+39) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt((re * -2.0)));
} else if (re <= 4.1e+29) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4e+39: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt((re * -2.0))) elif re <= 4.1e+29: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * math.sqrt((2.0 * (re - re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -4e+39) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(re * -2.0)))); elseif (re <= 4.1e+29) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re - re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4e+39) tmp = 0.5 * (sqrt(2.0) * sqrt((re * -2.0))); elseif (re <= 4.1e+29) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * sqrt((2.0 * (re - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4e+39], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(re * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.1e+29], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4 \cdot 10^{+39}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{re \cdot -2}\right)\\
\mathbf{elif}\;re \leq 4.1 \cdot 10^{+29}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - re\right)}\\
\end{array}
\end{array}
if re < -3.99999999999999976e39Initial program 49.5%
*-commutative49.5%
hypot-udef98.3%
sqrt-prod99.3%
Applied egg-rr99.3%
Taylor expanded in re around -inf 84.3%
*-commutative84.3%
Simplified84.3%
if -3.99999999999999976e39 < re < 4.1000000000000003e29Initial program 64.4%
Taylor expanded in re around 0 78.4%
if 4.1000000000000003e29 < re Initial program 37.5%
Taylor expanded in re around inf 68.7%
Final simplification77.6%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* (- (hypot re im) re) 2.0))))
double code(double re, double im) {
return 0.5 * sqrt(((hypot(re, im) - re) * 2.0));
}
public static double code(double re, double im) {
return 0.5 * Math.sqrt(((Math.hypot(re, im) - re) * 2.0));
}
def code(re, im): return 0.5 * math.sqrt(((math.hypot(re, im) - re) * 2.0))
function code(re, im) return Float64(0.5 * sqrt(Float64(Float64(hypot(re, im) - re) * 2.0))) end
function tmp = code(re, im) tmp = 0.5 * sqrt(((hypot(re, im) - re) * 2.0)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 2}
\end{array}
Initial program 55.3%
sub-neg55.3%
sqr-neg55.3%
sub-neg55.3%
sqr-neg55.3%
hypot-def97.1%
Simplified97.1%
Final simplification97.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))))
(if (<= re -5e+39)
t_0
(if (<= re -8.2e-40)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re -4.2e-129)
t_0
(if (<= re 1.1e+213)
(* 0.5 (sqrt (* im 2.0)))
(* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double tmp;
if (re <= -5e+39) {
tmp = t_0;
} else if (re <= -8.2e-40) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= -4.2e-129) {
tmp = t_0;
} else if (re <= 1.1e+213) {
tmp = 0.5 * sqrt((im * 2.0));
} 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) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
if (re <= (-5d+39)) then
tmp = t_0
else if (re <= (-8.2d-40)) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= (-4.2d-129)) then
tmp = t_0
else if (re <= 1.1d+213) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else
tmp = 0.5d0 * (im / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((re * -4.0));
double tmp;
if (re <= -5e+39) {
tmp = t_0;
} else if (re <= -8.2e-40) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= -4.2e-129) {
tmp = t_0;
} else if (re <= 1.1e+213) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) tmp = 0 if re <= -5e+39: tmp = t_0 elif re <= -8.2e-40: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= -4.2e-129: tmp = t_0 elif re <= 1.1e+213: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) tmp = 0.0 if (re <= -5e+39) tmp = t_0; elseif (re <= -8.2e-40) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= -4.2e-129) tmp = t_0; elseif (re <= 1.1e+213) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); tmp = 0.0; if (re <= -5e+39) tmp = t_0; elseif (re <= -8.2e-40) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= -4.2e-129) tmp = t_0; elseif (re <= 1.1e+213) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -5e+39], t$95$0, If[LessEqual[re, -8.2e-40], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -4.2e-129], t$95$0, If[LessEqual[re, 1.1e+213], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{if}\;re \leq -5 \cdot 10^{+39}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq -8.2 \cdot 10^{-40}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq -4.2 \cdot 10^{-129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 1.1 \cdot 10^{+213}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -5.00000000000000015e39 or -8.19999999999999926e-40 < re < -4.2e-129Initial program 59.9%
Taylor expanded in re around -inf 78.8%
*-commutative78.8%
Simplified78.8%
if -5.00000000000000015e39 < re < -8.19999999999999926e-40Initial program 84.1%
Taylor expanded in re around 0 80.1%
if -4.2e-129 < re < 1.0999999999999999e213Initial program 56.8%
Taylor expanded in re around 0 69.6%
*-commutative69.6%
Simplified69.6%
if 1.0999999999999999e213 < re Initial program 2.2%
Taylor expanded in im around 0 31.2%
associate-*l*31.2%
*-commutative31.2%
Simplified31.2%
expm1-log1p-u30.4%
expm1-udef63.8%
sqrt-unprod63.8%
metadata-eval63.8%
metadata-eval63.8%
*-un-lft-identity63.8%
sqrt-div63.8%
metadata-eval63.8%
un-div-inv63.8%
Applied egg-rr63.8%
expm1-def30.4%
expm1-log1p31.4%
Simplified31.4%
Final simplification70.2%
(FPCore (re im) :precision binary64 (if (or (<= re -1.4e+26) (and (not (<= re -6.5e-39)) (<= re -1.3e-129))) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* im 2.0)))))
double code(double re, double im) {
double tmp;
if ((re <= -1.4e+26) || (!(re <= -6.5e-39) && (re <= -1.3e-129))) {
tmp = 0.5 * sqrt((re * -4.0));
} else {
tmp = 0.5 * sqrt((im * 2.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-1.4d+26)) .or. (.not. (re <= (-6.5d-39))) .and. (re <= (-1.3d-129))) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = 0.5d0 * sqrt((im * 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -1.4e+26) || (!(re <= -6.5e-39) && (re <= -1.3e-129))) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = 0.5 * Math.sqrt((im * 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -1.4e+26) or (not (re <= -6.5e-39) and (re <= -1.3e-129)): tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = 0.5 * math.sqrt((im * 2.0)) return tmp
function code(re, im) tmp = 0.0 if ((re <= -1.4e+26) || (!(re <= -6.5e-39) && (re <= -1.3e-129))) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -1.4e+26) || (~((re <= -6.5e-39)) && (re <= -1.3e-129))) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((im * 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -1.4e+26], And[N[Not[LessEqual[re, -6.5e-39]], $MachinePrecision], LessEqual[re, -1.3e-129]]], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.4 \cdot 10^{+26} \lor \neg \left(re \leq -6.5 \cdot 10^{-39}\right) \land re \leq -1.3 \cdot 10^{-129}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if re < -1.4e26 or -6.50000000000000027e-39 < re < -1.3e-129Initial program 60.7%
Taylor expanded in re around -inf 77.5%
*-commutative77.5%
Simplified77.5%
if -1.4e26 < re < -6.50000000000000027e-39 or -1.3e-129 < re Initial program 53.0%
Taylor expanded in re around 0 64.7%
*-commutative64.7%
Simplified64.7%
Final simplification68.6%
(FPCore (re im)
:precision binary64
(if (<= re -4.3e+39)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 3.7e+27)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* 0.5 (sqrt (* 2.0 (- re re)))))))
double code(double re, double im) {
double tmp;
if (re <= -4.3e+39) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 3.7e+27) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * sqrt((2.0 * (re - re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-4.3d+39)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 3.7d+27) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.5d0 * sqrt((2.0d0 * (re - re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4.3e+39) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 3.7e+27) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.3e+39: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 3.7e+27: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * math.sqrt((2.0 * (re - re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.3e+39) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 3.7e+27) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re - re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.3e+39) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 3.7e+27) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * sqrt((2.0 * (re - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.3e+39], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.7e+27], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.3 \cdot 10^{+39}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 3.7 \cdot 10^{+27}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - re\right)}\\
\end{array}
\end{array}
if re < -4.3e39Initial program 49.5%
Taylor expanded in re around -inf 83.2%
*-commutative83.2%
Simplified83.2%
if -4.3e39 < re < 3.70000000000000002e27Initial program 64.4%
Taylor expanded in re around 0 78.4%
if 3.70000000000000002e27 < re Initial program 37.5%
Taylor expanded in re around inf 68.7%
Final simplification77.3%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* im 2.0))))
double code(double re, double im) {
return 0.5 * sqrt((im * 2.0));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((im * 2.0d0))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((im * 2.0));
}
def code(re, im): return 0.5 * math.sqrt((im * 2.0))
function code(re, im) return Float64(0.5 * sqrt(Float64(im * 2.0))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((im * 2.0)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{im \cdot 2}
\end{array}
Initial program 55.3%
Taylor expanded in re around 0 53.1%
*-commutative53.1%
Simplified53.1%
Final simplification53.1%
herbie shell --seed 2024031
(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)))))