
(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 (if (<= (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))) 0.0) (* 0.5 (/ im (sqrt 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 = 0.5 * (im / sqrt(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 = 0.5 * (im / Math.sqrt(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 = 0.5 * (im / math.sqrt(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(0.5 * Float64(im / sqrt(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 = 0.5 * (im / sqrt(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[(0.5 * N[(im / N[Sqrt[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:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 2 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 9.6%
Taylor expanded in re around inf 60.2%
unpow260.2%
Simplified60.2%
expm1-log1p-u60.1%
expm1-udef14.4%
sqrt-div14.4%
sqrt-prod14.4%
add-sqr-sqrt14.4%
Applied egg-rr14.4%
expm1-def99.7%
expm1-log1p99.7%
Simplified99.7%
if 0.0 < (sqrt.f64 (*.f64 2 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 49.8%
sqr-neg49.8%
sqr-neg49.8%
hypot-def89.0%
Simplified89.0%
add-sqr-sqrt88.3%
sqrt-unprod89.0%
*-commutative89.0%
*-commutative89.0%
swap-sqr89.0%
add-sqr-sqrt89.0%
metadata-eval89.0%
Applied egg-rr89.0%
*-commutative89.0%
associate-*r*89.0%
metadata-eval89.0%
Simplified89.0%
Final simplification90.6%
(FPCore (re im)
:precision binary64
(if (<= re -2.7e+62)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re -2.5e+27)
(sqrt (* 0.5 (- im re)))
(if (<= re -3.7e-72)
(* 0.5 (sqrt (- (* re -4.0) (/ im (/ re im)))))
(if (<= re 3500.0)
(* 0.5 (sqrt (+ (* 2.0 (- im re)) (* re (/ re im)))))
(* 0.5 (/ im (sqrt re))))))))
double code(double re, double im) {
double tmp;
if (re <= -2.7e+62) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= -2.5e+27) {
tmp = sqrt((0.5 * (im - re)));
} else if (re <= -3.7e-72) {
tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im))));
} else if (re <= 3500.0) {
tmp = 0.5 * sqrt(((2.0 * (im - re)) + (re * (re / im))));
} 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 <= (-2.7d+62)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= (-2.5d+27)) then
tmp = sqrt((0.5d0 * (im - re)))
else if (re <= (-3.7d-72)) then
tmp = 0.5d0 * sqrt(((re * (-4.0d0)) - (im / (re / im))))
else if (re <= 3500.0d0) then
tmp = 0.5d0 * sqrt(((2.0d0 * (im - re)) + (re * (re / im))))
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 <= -2.7e+62) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= -2.5e+27) {
tmp = Math.sqrt((0.5 * (im - re)));
} else if (re <= -3.7e-72) {
tmp = 0.5 * Math.sqrt(((re * -4.0) - (im / (re / im))));
} else if (re <= 3500.0) {
tmp = 0.5 * Math.sqrt(((2.0 * (im - re)) + (re * (re / im))));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.7e+62: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= -2.5e+27: tmp = math.sqrt((0.5 * (im - re))) elif re <= -3.7e-72: tmp = 0.5 * math.sqrt(((re * -4.0) - (im / (re / im)))) elif re <= 3500.0: tmp = 0.5 * math.sqrt(((2.0 * (im - re)) + (re * (re / im)))) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.7e+62) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= -2.5e+27) tmp = sqrt(Float64(0.5 * Float64(im - re))); elseif (re <= -3.7e-72) tmp = Float64(0.5 * sqrt(Float64(Float64(re * -4.0) - Float64(im / Float64(re / im))))); elseif (re <= 3500.0) tmp = Float64(0.5 * sqrt(Float64(Float64(2.0 * Float64(im - re)) + Float64(re * Float64(re / im))))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.7e+62) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= -2.5e+27) tmp = sqrt((0.5 * (im - re))); elseif (re <= -3.7e-72) tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im)))); elseif (re <= 3500.0) tmp = 0.5 * sqrt(((2.0 * (im - re)) + (re * (re / im)))); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.7e+62], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -2.5e+27], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, -3.7e-72], N[(0.5 * N[Sqrt[N[(N[(re * -4.0), $MachinePrecision] - N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3500.0], N[(0.5 * N[Sqrt[N[(N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision] + N[(re * N[(re / im), $MachinePrecision]), $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 -2.7 \cdot 10^{+62}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq -2.5 \cdot 10^{+27}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq -3.7 \cdot 10^{-72}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4 - \frac{im}{\frac{re}{im}}}\\
\mathbf{elif}\;re \leq 3500:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right) + re \cdot \frac{re}{im}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.7e62Initial program 34.6%
Taylor expanded in re around -inf 82.2%
*-commutative82.2%
Simplified82.2%
if -2.7e62 < re < -2.4999999999999999e27Initial program 68.1%
sqr-neg68.1%
sqr-neg68.1%
hypot-def100.0%
Simplified100.0%
add-sqr-sqrt99.1%
sqrt-unprod100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 80.3%
neg-mul-180.3%
sub-neg80.3%
Simplified80.3%
if -2.4999999999999999e27 < re < -3.6999999999999998e-72Initial program 86.9%
Taylor expanded in re around -inf 67.0%
mul-1-neg67.0%
unsub-neg67.0%
*-commutative67.0%
unpow267.0%
associate-/l*67.1%
Simplified67.1%
if -3.6999999999999998e-72 < re < 3500Initial program 54.7%
Taylor expanded in re around 0 77.1%
associate-*r/77.1%
unpow277.1%
Simplified77.1%
expm1-log1p-u74.3%
expm1-udef43.1%
+-commutative43.1%
associate--l+43.1%
*-un-lft-identity43.1%
times-frac43.1%
metadata-eval43.1%
Applied egg-rr43.1%
expm1-def74.3%
expm1-log1p77.1%
+-commutative77.1%
distribute-lft-in77.1%
associate-*r*77.1%
metadata-eval77.1%
*-commutative77.1%
*-rgt-identity77.1%
associate-/l*77.4%
associate-/r/77.4%
*-commutative77.4%
Simplified77.4%
if 3500 < re Initial program 12.3%
Taylor expanded in re around inf 51.5%
unpow251.5%
Simplified51.5%
expm1-log1p-u51.2%
expm1-udef21.1%
sqrt-div21.1%
sqrt-prod26.8%
add-sqr-sqrt26.8%
Applied egg-rr26.8%
expm1-def79.8%
expm1-log1p80.5%
Simplified80.5%
Final simplification78.2%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (sqrt (* 0.5 (- im re)))))
(if (<= re -2.7e+62)
t_0
(if (<= re -3.4e+28)
t_1
(if (<= re -8.3e-44)
t_0
(if (or (<= re 1.95e-92) (and (not (<= re 6e-37)) (<= re 2700.0)))
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 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -2.7e+62) {
tmp = t_0;
} else if (re <= -3.4e+28) {
tmp = t_1;
} else if (re <= -8.3e-44) {
tmp = t_0;
} else if ((re <= 1.95e-92) || (!(re <= 6e-37) && (re <= 2700.0))) {
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 = sqrt((0.5d0 * (im - re)))
if (re <= (-2.7d+62)) then
tmp = t_0
else if (re <= (-3.4d+28)) then
tmp = t_1
else if (re <= (-8.3d-44)) then
tmp = t_0
else if ((re <= 1.95d-92) .or. (.not. (re <= 6d-37)) .and. (re <= 2700.0d0)) 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 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -2.7e+62) {
tmp = t_0;
} else if (re <= -3.4e+28) {
tmp = t_1;
} else if (re <= -8.3e-44) {
tmp = t_0;
} else if ((re <= 1.95e-92) || (!(re <= 6e-37) && (re <= 2700.0))) {
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 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -2.7e+62: tmp = t_0 elif re <= -3.4e+28: tmp = t_1 elif re <= -8.3e-44: tmp = t_0 elif (re <= 1.95e-92) or (not (re <= 6e-37) and (re <= 2700.0)): 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 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -2.7e+62) tmp = t_0; elseif (re <= -3.4e+28) tmp = t_1; elseif (re <= -8.3e-44) tmp = t_0; elseif ((re <= 1.95e-92) || (!(re <= 6e-37) && (re <= 2700.0))) 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 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -2.7e+62) tmp = t_0; elseif (re <= -3.4e+28) tmp = t_1; elseif (re <= -8.3e-44) tmp = t_0; elseif ((re <= 1.95e-92) || (~((re <= 6e-37)) && (re <= 2700.0))) 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[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -2.7e+62], t$95$0, If[LessEqual[re, -3.4e+28], t$95$1, If[LessEqual[re, -8.3e-44], t$95$0, If[Or[LessEqual[re, 1.95e-92], And[N[Not[LessEqual[re, 6e-37]], $MachinePrecision], LessEqual[re, 2700.0]]], 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 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -2.7 \cdot 10^{+62}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -3.4 \cdot 10^{+28}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -8.3 \cdot 10^{-44}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 1.95 \cdot 10^{-92} \lor \neg \left(re \leq 6 \cdot 10^{-37}\right) \land re \leq 2700:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.7e62 or -3.4e28 < re < -8.2999999999999999e-44Initial program 49.7%
Taylor expanded in re around -inf 78.5%
*-commutative78.5%
Simplified78.5%
if -2.7e62 < re < -3.4e28 or -8.2999999999999999e-44 < re < 1.9499999999999998e-92 or 6e-37 < re < 2700Initial program 59.4%
sqr-neg59.4%
sqr-neg59.4%
hypot-def94.1%
Simplified94.1%
add-sqr-sqrt93.4%
sqrt-unprod94.1%
*-commutative94.1%
*-commutative94.1%
swap-sqr94.1%
add-sqr-sqrt94.1%
metadata-eval94.1%
Applied egg-rr94.1%
*-commutative94.1%
associate-*r*94.1%
metadata-eval94.1%
Simplified94.1%
Taylor expanded in re around 0 82.3%
neg-mul-182.3%
sub-neg82.3%
Simplified82.3%
if 1.9499999999999998e-92 < re < 6e-37 or 2700 < re Initial program 18.2%
Taylor expanded in re around inf 48.3%
unpow248.3%
Simplified48.3%
expm1-log1p-u48.1%
expm1-udef17.8%
sqrt-div17.8%
sqrt-prod22.4%
add-sqr-sqrt22.4%
Applied egg-rr22.4%
expm1-def76.0%
expm1-log1p76.5%
Simplified76.5%
Final simplification79.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (* 0.5 (- im re)))))
(if (<= re -2.75e+62)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re -1.9e+26)
t_0
(if (<= re -3.8e-44)
(* 0.5 (sqrt (- (* re -4.0) (/ im (/ re im)))))
(if (or (<= re 1.95e-92) (and (not (<= re 1.1e-37)) (<= re 2700.0)))
t_0
(* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
double t_0 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -2.75e+62) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= -1.9e+26) {
tmp = t_0;
} else if (re <= -3.8e-44) {
tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im))));
} else if ((re <= 1.95e-92) || (!(re <= 1.1e-37) && (re <= 2700.0))) {
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 = sqrt((0.5d0 * (im - re)))
if (re <= (-2.75d+62)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= (-1.9d+26)) then
tmp = t_0
else if (re <= (-3.8d-44)) then
tmp = 0.5d0 * sqrt(((re * (-4.0d0)) - (im / (re / im))))
else if ((re <= 1.95d-92) .or. (.not. (re <= 1.1d-37)) .and. (re <= 2700.0d0)) 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 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -2.75e+62) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= -1.9e+26) {
tmp = t_0;
} else if (re <= -3.8e-44) {
tmp = 0.5 * Math.sqrt(((re * -4.0) - (im / (re / im))));
} else if ((re <= 1.95e-92) || (!(re <= 1.1e-37) && (re <= 2700.0))) {
tmp = t_0;
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -2.75e+62: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= -1.9e+26: tmp = t_0 elif re <= -3.8e-44: tmp = 0.5 * math.sqrt(((re * -4.0) - (im / (re / im)))) elif (re <= 1.95e-92) or (not (re <= 1.1e-37) and (re <= 2700.0)): tmp = t_0 else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) t_0 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -2.75e+62) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= -1.9e+26) tmp = t_0; elseif (re <= -3.8e-44) tmp = Float64(0.5 * sqrt(Float64(Float64(re * -4.0) - Float64(im / Float64(re / im))))); elseif ((re <= 1.95e-92) || (!(re <= 1.1e-37) && (re <= 2700.0))) tmp = t_0; else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -2.75e+62) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= -1.9e+26) tmp = t_0; elseif (re <= -3.8e-44) tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im)))); elseif ((re <= 1.95e-92) || (~((re <= 1.1e-37)) && (re <= 2700.0))) tmp = t_0; else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -2.75e+62], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.9e+26], t$95$0, If[LessEqual[re, -3.8e-44], N[(0.5 * N[Sqrt[N[(N[(re * -4.0), $MachinePrecision] - N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 1.95e-92], And[N[Not[LessEqual[re, 1.1e-37]], $MachinePrecision], LessEqual[re, 2700.0]]], t$95$0, N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -2.75 \cdot 10^{+62}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq -1.9 \cdot 10^{+26}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -3.8 \cdot 10^{-44}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4 - \frac{im}{\frac{re}{im}}}\\
\mathbf{elif}\;re \leq 1.95 \cdot 10^{-92} \lor \neg \left(re \leq 1.1 \cdot 10^{-37}\right) \land re \leq 2700:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.7499999999999998e62Initial program 34.6%
Taylor expanded in re around -inf 82.2%
*-commutative82.2%
Simplified82.2%
if -2.7499999999999998e62 < re < -1.9000000000000001e26 or -3.8000000000000001e-44 < re < 1.9499999999999998e-92 or 1.10000000000000001e-37 < re < 2700Initial program 59.4%
sqr-neg59.4%
sqr-neg59.4%
hypot-def94.1%
Simplified94.1%
add-sqr-sqrt93.4%
sqrt-unprod94.1%
*-commutative94.1%
*-commutative94.1%
swap-sqr94.1%
add-sqr-sqrt94.1%
metadata-eval94.1%
Applied egg-rr94.1%
*-commutative94.1%
associate-*r*94.1%
metadata-eval94.1%
Simplified94.1%
Taylor expanded in re around 0 82.3%
neg-mul-182.3%
sub-neg82.3%
Simplified82.3%
if -1.9000000000000001e26 < re < -3.8000000000000001e-44Initial program 84.0%
Taylor expanded in re around -inf 69.9%
mul-1-neg69.9%
unsub-neg69.9%
*-commutative69.9%
unpow269.9%
associate-/l*70.0%
Simplified70.0%
if 1.9499999999999998e-92 < re < 1.10000000000000001e-37 or 2700 < re Initial program 18.2%
Taylor expanded in re around inf 48.3%
unpow248.3%
Simplified48.3%
expm1-log1p-u48.1%
expm1-udef17.8%
sqrt-div17.8%
sqrt-prod22.4%
add-sqr-sqrt22.4%
Applied egg-rr22.4%
expm1-def76.0%
expm1-log1p76.5%
Simplified76.5%
Final simplification79.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))))
(if (<= re -5.8e+63)
t_0
(if (<= re -1.6e+24)
(sqrt (* 0.5 (- im re)))
(if (<= re -2.3e-67) t_0 (sqrt (* im 0.5)))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double tmp;
if (re <= -5.8e+63) {
tmp = t_0;
} else if (re <= -1.6e+24) {
tmp = sqrt((0.5 * (im - re)));
} else if (re <= -2.3e-67) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
if (re <= (-5.8d+63)) then
tmp = t_0
else if (re <= (-1.6d+24)) then
tmp = sqrt((0.5d0 * (im - re)))
else if (re <= (-2.3d-67)) then
tmp = t_0
else
tmp = sqrt((im * 0.5d0))
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 <= -5.8e+63) {
tmp = t_0;
} else if (re <= -1.6e+24) {
tmp = Math.sqrt((0.5 * (im - re)));
} else if (re <= -2.3e-67) {
tmp = t_0;
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) tmp = 0 if re <= -5.8e+63: tmp = t_0 elif re <= -1.6e+24: tmp = math.sqrt((0.5 * (im - re))) elif re <= -2.3e-67: tmp = t_0 else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) tmp = 0.0 if (re <= -5.8e+63) tmp = t_0; elseif (re <= -1.6e+24) tmp = sqrt(Float64(0.5 * Float64(im - re))); elseif (re <= -2.3e-67) tmp = t_0; else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); tmp = 0.0; if (re <= -5.8e+63) tmp = t_0; elseif (re <= -1.6e+24) tmp = sqrt((0.5 * (im - re))); elseif (re <= -2.3e-67) tmp = t_0; else tmp = sqrt((im * 0.5)); 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, -5.8e+63], t$95$0, If[LessEqual[re, -1.6e+24], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, -2.3e-67], t$95$0, N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{if}\;re \leq -5.8 \cdot 10^{+63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -1.6 \cdot 10^{+24}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq -2.3 \cdot 10^{-67}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -5.7999999999999999e63 or -1.5999999999999999e24 < re < -2.3e-67Initial program 52.9%
Taylor expanded in re around -inf 76.9%
*-commutative76.9%
Simplified76.9%
if -5.7999999999999999e63 < re < -1.5999999999999999e24Initial program 68.1%
sqr-neg68.1%
sqr-neg68.1%
hypot-def100.0%
Simplified100.0%
add-sqr-sqrt99.1%
sqrt-unprod100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 80.3%
neg-mul-180.3%
sub-neg80.3%
Simplified80.3%
if -2.3e-67 < re Initial program 39.3%
sqr-neg39.3%
sqr-neg39.3%
hypot-def67.9%
Simplified67.9%
add-sqr-sqrt67.4%
sqrt-unprod67.9%
*-commutative67.9%
*-commutative67.9%
swap-sqr67.9%
add-sqr-sqrt67.9%
metadata-eval67.9%
Applied egg-rr67.9%
*-commutative67.9%
associate-*r*67.9%
metadata-eval67.9%
Simplified67.9%
Taylor expanded in re around 0 57.1%
Final simplification62.8%
(FPCore (re im) :precision binary64 (sqrt (* 0.5 (- im re))))
double code(double re, double im) {
return sqrt((0.5 * (im - re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((0.5d0 * (im - re)))
end function
public static double code(double re, double im) {
return Math.sqrt((0.5 * (im - re)));
}
def code(re, im): return math.sqrt((0.5 * (im - re)))
function code(re, im) return sqrt(Float64(0.5 * Float64(im - re))) end
function tmp = code(re, im) tmp = sqrt((0.5 * (im - re))); end
code[re_, im_] := N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(im - re\right)}
\end{array}
Initial program 43.6%
sqr-neg43.6%
sqr-neg43.6%
hypot-def76.9%
Simplified76.9%
add-sqr-sqrt76.3%
sqrt-unprod76.9%
*-commutative76.9%
*-commutative76.9%
swap-sqr76.9%
add-sqr-sqrt76.9%
metadata-eval76.9%
Applied egg-rr76.9%
*-commutative76.9%
associate-*r*76.9%
metadata-eval76.9%
Simplified76.9%
Taylor expanded in re around 0 52.7%
neg-mul-152.7%
sub-neg52.7%
Simplified52.7%
Final simplification52.7%
(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 43.6%
sqr-neg43.6%
sqr-neg43.6%
hypot-def76.9%
Simplified76.9%
add-sqr-sqrt76.3%
sqrt-unprod76.9%
*-commutative76.9%
*-commutative76.9%
swap-sqr76.9%
add-sqr-sqrt76.9%
metadata-eval76.9%
Applied egg-rr76.9%
*-commutative76.9%
associate-*r*76.9%
metadata-eval76.9%
Simplified76.9%
Taylor expanded in re around 0 50.5%
Final simplification50.5%
herbie shell --seed 2023285
(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)))))