
(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 (<= re 3.6e+49) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re)))) (* 0.5 (/ im (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= 3.6e+49) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else {
tmp = 0.5 * (im / sqrt(re));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 3.6e+49) {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 3.6e+49: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= 3.6e+49) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, 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.6e+49) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 3.6e+49], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $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.6 \cdot 10^{+49}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 3.59999999999999996e49Initial program 48.4%
hypot-def93.5%
Simplified93.5%
if 3.59999999999999996e49 < re Initial program 3.8%
Taylor expanded in re around inf 51.3%
unpow251.3%
Simplified51.3%
Taylor expanded in im around 0 85.6%
unpow-185.6%
metadata-eval85.6%
pow-sqr85.6%
rem-sqrt-square85.6%
rem-square-sqrt85.3%
fabs-sqr85.3%
rem-square-sqrt85.6%
exp-to-pow80.5%
metadata-eval80.5%
distribute-rgt-neg-in80.5%
exp-neg80.5%
exp-to-pow85.5%
unpow1/285.5%
associate-*l/85.7%
*-lft-identity85.7%
Simplified85.7%
Final simplification91.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* 2.0 (- im re))))))
(if (<= re -3e+77)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re -8.6e-133)
t_0
(if (<= re -6.8e-164)
(* 0.5 (sqrt (- (* re -4.0) (/ im (/ re im)))))
(if (<= re 4.1e+48) t_0 (* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((2.0 * (im - re)));
double tmp;
if (re <= -3e+77) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= -8.6e-133) {
tmp = t_0;
} else if (re <= -6.8e-164) {
tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im))));
} else if (re <= 4.1e+48) {
tmp = t_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((2.0d0 * (im - re)))
if (re <= (-3d+77)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= (-8.6d-133)) then
tmp = t_0
else if (re <= (-6.8d-164)) then
tmp = 0.5d0 * sqrt(((re * (-4.0d0)) - (im / (re / im))))
else if (re <= 4.1d+48) then
tmp = t_0
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((2.0 * (im - re)));
double tmp;
if (re <= -3e+77) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= -8.6e-133) {
tmp = t_0;
} else if (re <= -6.8e-164) {
tmp = 0.5 * Math.sqrt(((re * -4.0) - (im / (re / im))));
} else if (re <= 4.1e+48) {
tmp = t_0;
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((2.0 * (im - re))) tmp = 0 if re <= -3e+77: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= -8.6e-133: tmp = t_0 elif re <= -6.8e-164: tmp = 0.5 * math.sqrt(((re * -4.0) - (im / (re / im)))) elif re <= 4.1e+48: tmp = t_0 else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))) tmp = 0.0 if (re <= -3e+77) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= -8.6e-133) tmp = t_0; elseif (re <= -6.8e-164) tmp = Float64(0.5 * sqrt(Float64(Float64(re * -4.0) - Float64(im / Float64(re / im))))); elseif (re <= 4.1e+48) tmp = t_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((2.0 * (im - re))); tmp = 0.0; if (re <= -3e+77) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= -8.6e-133) tmp = t_0; elseif (re <= -6.8e-164) tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im)))); elseif (re <= 4.1e+48) tmp = t_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[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -3e+77], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -8.6e-133], t$95$0, If[LessEqual[re, -6.8e-164], N[(0.5 * N[Sqrt[N[(N[(re * -4.0), $MachinePrecision] - N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.1e+48], t$95$0, N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -3 \cdot 10^{+77}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq -8.6 \cdot 10^{-133}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -6.8 \cdot 10^{-164}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4 - \frac{im}{\frac{re}{im}}}\\
\mathbf{elif}\;re \leq 4.1 \cdot 10^{+48}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.9999999999999998e77Initial program 27.2%
Taylor expanded in re around -inf 80.2%
*-commutative80.2%
Simplified80.2%
if -2.9999999999999998e77 < re < -8.60000000000000032e-133 or -6.8e-164 < re < 4.1000000000000003e48Initial program 53.1%
Taylor expanded in re around 0 78.8%
if -8.60000000000000032e-133 < re < -6.8e-164Initial program 83.7%
Taylor expanded in re around -inf 88.3%
+-commutative88.3%
mul-1-neg88.3%
unsub-neg88.3%
*-commutative88.3%
unpow288.3%
associate-/l*88.3%
Simplified88.3%
if 4.1000000000000003e48 < re Initial program 3.8%
Taylor expanded in re around inf 51.3%
unpow251.3%
Simplified51.3%
Taylor expanded in im around 0 85.6%
unpow-185.6%
metadata-eval85.6%
pow-sqr85.6%
rem-sqrt-square85.6%
rem-square-sqrt85.3%
fabs-sqr85.3%
rem-square-sqrt85.6%
exp-to-pow80.5%
metadata-eval80.5%
distribute-rgt-neg-in80.5%
exp-neg80.5%
exp-to-pow85.5%
unpow1/285.5%
associate-*l/85.7%
*-lft-identity85.7%
Simplified85.7%
Final simplification80.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0))))
(t_1 (* 0.5 (sqrt (* 2.0 (- im re))))))
(if (<= re -9.2e+77)
t_0
(if (<= re -8.6e-133)
t_1
(if (<= re -6.8e-164)
t_0
(if (<= re 7e+48) t_1 (* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double t_1 = 0.5 * sqrt((2.0 * (im - re)));
double tmp;
if (re <= -9.2e+77) {
tmp = t_0;
} else if (re <= -8.6e-133) {
tmp = t_1;
} else if (re <= -6.8e-164) {
tmp = t_0;
} else if (re <= 7e+48) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
t_1 = 0.5d0 * sqrt((2.0d0 * (im - re)))
if (re <= (-9.2d+77)) then
tmp = t_0
else if (re <= (-8.6d-133)) then
tmp = t_1
else if (re <= (-6.8d-164)) then
tmp = t_0
else if (re <= 7d+48) then
tmp = t_1
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 t_1 = 0.5 * Math.sqrt((2.0 * (im - re)));
double tmp;
if (re <= -9.2e+77) {
tmp = t_0;
} else if (re <= -8.6e-133) {
tmp = t_1;
} else if (re <= -6.8e-164) {
tmp = t_0;
} else if (re <= 7e+48) {
tmp = t_1;
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) t_1 = 0.5 * math.sqrt((2.0 * (im - re))) tmp = 0 if re <= -9.2e+77: tmp = t_0 elif re <= -8.6e-133: tmp = t_1 elif re <= -6.8e-164: tmp = t_0 elif re <= 7e+48: tmp = t_1 else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) t_1 = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))) tmp = 0.0 if (re <= -9.2e+77) tmp = t_0; elseif (re <= -8.6e-133) tmp = t_1; elseif (re <= -6.8e-164) tmp = t_0; elseif (re <= 7e+48) tmp = t_1; 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)); t_1 = 0.5 * sqrt((2.0 * (im - re))); tmp = 0.0; if (re <= -9.2e+77) tmp = t_0; elseif (re <= -8.6e-133) tmp = t_1; elseif (re <= -6.8e-164) tmp = t_0; elseif (re <= 7e+48) tmp = t_1; 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]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -9.2e+77], t$95$0, If[LessEqual[re, -8.6e-133], t$95$1, If[LessEqual[re, -6.8e-164], t$95$0, If[LessEqual[re, 7e+48], t$95$1, 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}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -9.2 \cdot 10^{+77}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -8.6 \cdot 10^{-133}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -6.8 \cdot 10^{-164}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 7 \cdot 10^{+48}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -9.19999999999999979e77 or -8.60000000000000032e-133 < re < -6.8e-164Initial program 35.5%
Taylor expanded in re around -inf 81.4%
*-commutative81.4%
Simplified81.4%
if -9.19999999999999979e77 < re < -8.60000000000000032e-133 or -6.8e-164 < re < 6.9999999999999995e48Initial program 53.1%
Taylor expanded in re around 0 78.8%
if 6.9999999999999995e48 < re Initial program 3.8%
Taylor expanded in re around inf 51.3%
unpow251.3%
Simplified51.3%
Taylor expanded in im around 0 85.6%
unpow-185.6%
metadata-eval85.6%
pow-sqr85.6%
rem-sqrt-square85.6%
rem-square-sqrt85.3%
fabs-sqr85.3%
rem-square-sqrt85.6%
exp-to-pow80.5%
metadata-eval80.5%
distribute-rgt-neg-in80.5%
exp-neg80.5%
exp-to-pow85.5%
unpow1/285.5%
associate-*l/85.7%
*-lft-identity85.7%
Simplified85.7%
Final simplification80.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (* 0.5 (sqrt (* 2.0 im)))))
(if (<= re -1.75e+77)
t_0
(if (<= re -4.3e-132)
t_1
(if (<= re -6.8e-164)
t_0
(if (<= re 2.3e+49) t_1 (* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double t_1 = 0.5 * sqrt((2.0 * im));
double tmp;
if (re <= -1.75e+77) {
tmp = t_0;
} else if (re <= -4.3e-132) {
tmp = t_1;
} else if (re <= -6.8e-164) {
tmp = t_0;
} else if (re <= 2.3e+49) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
t_1 = 0.5d0 * sqrt((2.0d0 * im))
if (re <= (-1.75d+77)) then
tmp = t_0
else if (re <= (-4.3d-132)) then
tmp = t_1
else if (re <= (-6.8d-164)) then
tmp = t_0
else if (re <= 2.3d+49) then
tmp = t_1
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 t_1 = 0.5 * Math.sqrt((2.0 * im));
double tmp;
if (re <= -1.75e+77) {
tmp = t_0;
} else if (re <= -4.3e-132) {
tmp = t_1;
} else if (re <= -6.8e-164) {
tmp = t_0;
} else if (re <= 2.3e+49) {
tmp = t_1;
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) t_1 = 0.5 * math.sqrt((2.0 * im)) tmp = 0 if re <= -1.75e+77: tmp = t_0 elif re <= -4.3e-132: tmp = t_1 elif re <= -6.8e-164: tmp = t_0 elif re <= 2.3e+49: tmp = t_1 else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) t_1 = Float64(0.5 * sqrt(Float64(2.0 * im))) tmp = 0.0 if (re <= -1.75e+77) tmp = t_0; elseif (re <= -4.3e-132) tmp = t_1; elseif (re <= -6.8e-164) tmp = t_0; elseif (re <= 2.3e+49) tmp = t_1; 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)); t_1 = 0.5 * sqrt((2.0 * im)); tmp = 0.0; if (re <= -1.75e+77) tmp = t_0; elseif (re <= -4.3e-132) tmp = t_1; elseif (re <= -6.8e-164) tmp = t_0; elseif (re <= 2.3e+49) tmp = t_1; 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]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.75e+77], t$95$0, If[LessEqual[re, -4.3e-132], t$95$1, If[LessEqual[re, -6.8e-164], t$95$0, If[LessEqual[re, 2.3e+49], t$95$1, 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}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{if}\;re \leq -1.75 \cdot 10^{+77}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -4.3 \cdot 10^{-132}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -6.8 \cdot 10^{-164}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 2.3 \cdot 10^{+49}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.7500000000000001e77 or -4.2999999999999997e-132 < re < -6.8e-164Initial program 35.5%
Taylor expanded in re around -inf 81.4%
*-commutative81.4%
Simplified81.4%
if -1.7500000000000001e77 < re < -4.2999999999999997e-132 or -6.8e-164 < re < 2.30000000000000002e49Initial program 53.1%
Taylor expanded in re around 0 77.1%
*-commutative77.1%
Simplified77.1%
if 2.30000000000000002e49 < re Initial program 3.8%
Taylor expanded in re around inf 51.3%
unpow251.3%
Simplified51.3%
Taylor expanded in im around 0 85.6%
unpow-185.6%
metadata-eval85.6%
pow-sqr85.6%
rem-sqrt-square85.6%
rem-square-sqrt85.3%
fabs-sqr85.3%
rem-square-sqrt85.6%
exp-to-pow80.5%
metadata-eval80.5%
distribute-rgt-neg-in80.5%
exp-neg80.5%
exp-to-pow85.5%
unpow1/285.5%
associate-*l/85.7%
*-lft-identity85.7%
Simplified85.7%
Final simplification79.8%
(FPCore (re im) :precision binary64 (if (<= im 3.8e-170) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (im <= 3.8e-170) {
tmp = 0.5 * sqrt((re * -4.0));
} else {
tmp = 0.5 * sqrt((2.0 * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 3.8d-170) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = 0.5d0 * sqrt((2.0d0 * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3.8e-170) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3.8e-170: tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 3.8e-170) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3.8e-170) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3.8e-170], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.8 \cdot 10^{-170}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if im < 3.7999999999999998e-170Initial program 39.6%
Taylor expanded in re around -inf 57.4%
*-commutative57.4%
Simplified57.4%
if 3.7999999999999998e-170 < im Initial program 38.5%
Taylor expanded in re around 0 65.1%
*-commutative65.1%
Simplified65.1%
Final simplification63.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 38.8%
Taylor expanded in re around 0 53.4%
*-commutative53.4%
Simplified53.4%
Final simplification53.4%
herbie shell --seed 2023213
(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)))))