
(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}
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (<= (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im im)))))) 0.0) (/ (* im 0.5) (sqrt (- re))) (sqrt (* 0.5 (+ re (hypot re im))))))
im = abs(im);
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0) {
tmp = (im * 0.5) / sqrt(-re);
} else {
tmp = sqrt((0.5 * (re + hypot(re, im))));
}
return tmp;
}
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (Math.sqrt((2.0 * (re + Math.sqrt(((re * re) + (im * im)))))) <= 0.0) {
tmp = (im * 0.5) / Math.sqrt(-re);
} else {
tmp = Math.sqrt((0.5 * (re + Math.hypot(re, im))));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if math.sqrt((2.0 * (re + math.sqrt(((re * re) + (im * im)))))) <= 0.0: tmp = (im * 0.5) / math.sqrt(-re) else: tmp = math.sqrt((0.5 * (re + math.hypot(re, im)))) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(re + sqrt(Float64(Float64(re * re) + Float64(im * im)))))) <= 0.0) tmp = Float64(Float64(im * 0.5) / sqrt(Float64(-re))); else tmp = sqrt(Float64(0.5 * Float64(re + hypot(re, im)))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0) tmp = (im * 0.5) / sqrt(-re); else tmp = sqrt((0.5 * (re + hypot(re, im)))); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\right)} \leq 0:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 8.0%
+-commutative8.0%
hypot-def8.0%
Simplified8.0%
Taylor expanded in re around -inf 65.5%
associate-*r/65.5%
neg-mul-165.5%
unpow265.5%
distribute-rgt-neg-in65.5%
Simplified65.5%
frac-2neg65.5%
sqrt-div66.4%
distribute-rgt-neg-out66.4%
remove-double-neg66.4%
sqrt-unprod55.5%
add-sqr-sqrt60.4%
Applied egg-rr60.4%
associate-*r/60.4%
Applied egg-rr60.4%
if 0.0 < (sqrt.f64 (*.f64 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 50.2%
+-commutative50.2%
hypot-def88.6%
Simplified88.6%
add-sqr-sqrt88.0%
sqrt-unprod88.6%
*-commutative88.6%
*-commutative88.6%
swap-sqr88.6%
add-sqr-sqrt88.6%
*-commutative88.6%
metadata-eval88.6%
Applied egg-rr88.6%
associate-*l*88.6%
metadata-eval88.6%
Simplified88.6%
Final simplification85.9%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 2.0 (+ re im))) (t_1 (sqrt (- re))))
(if (<= re -5.8e+142)
(* 0.5 (/ im t_1))
(if (<= re -2.9e+124)
(* 0.5 (sqrt (+ (* re (/ re im)) t_0)))
(if (<= re -2.35e+26)
(/ (* im 0.5) t_1)
(if (<= re 6.6e-187)
(* 0.5 (sqrt (* 2.0 im)))
(if (<= re 1.1e-125)
(sqrt re)
(if (or (<= re 1.4e-76) (and (not (<= re 1.76e-6)) (<= re 9e+47)))
(* 0.5 (sqrt t_0))
(sqrt re)))))))))im = abs(im);
double code(double re, double im) {
double t_0 = 2.0 * (re + im);
double t_1 = sqrt(-re);
double tmp;
if (re <= -5.8e+142) {
tmp = 0.5 * (im / t_1);
} else if (re <= -2.9e+124) {
tmp = 0.5 * sqrt(((re * (re / im)) + t_0));
} else if (re <= -2.35e+26) {
tmp = (im * 0.5) / t_1;
} else if (re <= 6.6e-187) {
tmp = 0.5 * sqrt((2.0 * im));
} else if (re <= 1.1e-125) {
tmp = sqrt(re);
} else if ((re <= 1.4e-76) || (!(re <= 1.76e-6) && (re <= 9e+47))) {
tmp = 0.5 * sqrt(t_0);
} else {
tmp = sqrt(re);
}
return tmp;
}
NOTE: im should be positive before calling this function
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 = 2.0d0 * (re + im)
t_1 = sqrt(-re)
if (re <= (-5.8d+142)) then
tmp = 0.5d0 * (im / t_1)
else if (re <= (-2.9d+124)) then
tmp = 0.5d0 * sqrt(((re * (re / im)) + t_0))
else if (re <= (-2.35d+26)) then
tmp = (im * 0.5d0) / t_1
else if (re <= 6.6d-187) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else if (re <= 1.1d-125) then
tmp = sqrt(re)
else if ((re <= 1.4d-76) .or. (.not. (re <= 1.76d-6)) .and. (re <= 9d+47)) then
tmp = 0.5d0 * sqrt(t_0)
else
tmp = sqrt(re)
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double t_0 = 2.0 * (re + im);
double t_1 = Math.sqrt(-re);
double tmp;
if (re <= -5.8e+142) {
tmp = 0.5 * (im / t_1);
} else if (re <= -2.9e+124) {
tmp = 0.5 * Math.sqrt(((re * (re / im)) + t_0));
} else if (re <= -2.35e+26) {
tmp = (im * 0.5) / t_1;
} else if (re <= 6.6e-187) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else if (re <= 1.1e-125) {
tmp = Math.sqrt(re);
} else if ((re <= 1.4e-76) || (!(re <= 1.76e-6) && (re <= 9e+47))) {
tmp = 0.5 * Math.sqrt(t_0);
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im = abs(im) def code(re, im): t_0 = 2.0 * (re + im) t_1 = math.sqrt(-re) tmp = 0 if re <= -5.8e+142: tmp = 0.5 * (im / t_1) elif re <= -2.9e+124: tmp = 0.5 * math.sqrt(((re * (re / im)) + t_0)) elif re <= -2.35e+26: tmp = (im * 0.5) / t_1 elif re <= 6.6e-187: tmp = 0.5 * math.sqrt((2.0 * im)) elif re <= 1.1e-125: tmp = math.sqrt(re) elif (re <= 1.4e-76) or (not (re <= 1.76e-6) and (re <= 9e+47)): tmp = 0.5 * math.sqrt(t_0) else: tmp = math.sqrt(re) return tmp
im = abs(im) function code(re, im) t_0 = Float64(2.0 * Float64(re + im)) t_1 = sqrt(Float64(-re)) tmp = 0.0 if (re <= -5.8e+142) tmp = Float64(0.5 * Float64(im / t_1)); elseif (re <= -2.9e+124) tmp = Float64(0.5 * sqrt(Float64(Float64(re * Float64(re / im)) + t_0))); elseif (re <= -2.35e+26) tmp = Float64(Float64(im * 0.5) / t_1); elseif (re <= 6.6e-187) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); elseif (re <= 1.1e-125) tmp = sqrt(re); elseif ((re <= 1.4e-76) || (!(re <= 1.76e-6) && (re <= 9e+47))) tmp = Float64(0.5 * sqrt(t_0)); else tmp = sqrt(re); end return tmp end
im = abs(im) function tmp_2 = code(re, im) t_0 = 2.0 * (re + im); t_1 = sqrt(-re); tmp = 0.0; if (re <= -5.8e+142) tmp = 0.5 * (im / t_1); elseif (re <= -2.9e+124) tmp = 0.5 * sqrt(((re * (re / im)) + t_0)); elseif (re <= -2.35e+26) tmp = (im * 0.5) / t_1; elseif (re <= 6.6e-187) tmp = 0.5 * sqrt((2.0 * im)); elseif (re <= 1.1e-125) tmp = sqrt(re); elseif ((re <= 1.4e-76) || (~((re <= 1.76e-6)) && (re <= 9e+47))) tmp = 0.5 * sqrt(t_0); else tmp = sqrt(re); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function
code[re_, im_] := Block[{t$95$0 = N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[(-re)], $MachinePrecision]}, If[LessEqual[re, -5.8e+142], N[(0.5 * N[(im / t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -2.9e+124], N[(0.5 * N[Sqrt[N[(N[(re * N[(re / im), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -2.35e+26], N[(N[(im * 0.5), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[re, 6.6e-187], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.1e-125], N[Sqrt[re], $MachinePrecision], If[Or[LessEqual[re, 1.4e-76], And[N[Not[LessEqual[re, 1.76e-6]], $MachinePrecision], LessEqual[re, 9e+47]]], N[(0.5 * N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]]]]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
t_0 := 2 \cdot \left(re + im\right)\\
t_1 := \sqrt{-re}\\
\mathbf{if}\;re \leq -5.8 \cdot 10^{+142}:\\
\;\;\;\;0.5 \cdot \frac{im}{t_1}\\
\mathbf{elif}\;re \leq -2.9 \cdot 10^{+124}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot \frac{re}{im} + t_0}\\
\mathbf{elif}\;re \leq -2.35 \cdot 10^{+26}:\\
\;\;\;\;\frac{im \cdot 0.5}{t_1}\\
\mathbf{elif}\;re \leq 6.6 \cdot 10^{-187}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{elif}\;re \leq 1.1 \cdot 10^{-125}:\\
\;\;\;\;\sqrt{re}\\
\mathbf{elif}\;re \leq 1.4 \cdot 10^{-76} \lor \neg \left(re \leq 1.76 \cdot 10^{-6}\right) \land re \leq 9 \cdot 10^{+47}:\\
\;\;\;\;0.5 \cdot \sqrt{t_0}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -5.80000000000000027e142Initial program 2.8%
+-commutative2.8%
hypot-def35.7%
Simplified35.7%
Taylor expanded in re around -inf 59.9%
associate-*r/59.9%
neg-mul-159.9%
unpow259.9%
distribute-rgt-neg-in59.9%
Simplified59.9%
frac-2neg59.9%
sqrt-div69.6%
distribute-rgt-neg-out69.6%
remove-double-neg69.6%
sqrt-unprod46.4%
add-sqr-sqrt60.5%
Applied egg-rr60.5%
if -5.80000000000000027e142 < re < -2.90000000000000021e124Initial program 35.5%
+-commutative35.5%
hypot-def99.7%
Simplified99.7%
Taylor expanded in re around 0 80.4%
unpow280.4%
distribute-lft-out80.4%
Simplified80.4%
associate-/l*80.4%
associate-/r/80.4%
Applied egg-rr80.4%
if -2.90000000000000021e124 < re < -2.3499999999999999e26Initial program 7.6%
+-commutative7.6%
hypot-def21.3%
Simplified21.3%
Taylor expanded in re around -inf 62.3%
associate-*r/62.3%
neg-mul-162.3%
unpow262.3%
distribute-rgt-neg-in62.3%
Simplified62.3%
frac-2neg62.3%
sqrt-div63.9%
distribute-rgt-neg-out63.9%
remove-double-neg63.9%
sqrt-unprod50.0%
add-sqr-sqrt54.4%
Applied egg-rr54.4%
associate-*r/54.4%
Applied egg-rr54.4%
if -2.3499999999999999e26 < re < 6.6e-187Initial program 52.3%
+-commutative52.3%
hypot-def83.9%
Simplified83.9%
Taylor expanded in re around 0 46.4%
*-commutative46.4%
Simplified46.4%
if 6.6e-187 < re < 1.09999999999999997e-125 or 1.40000000000000005e-76 < re < 1.7600000000000001e-6 or 8.99999999999999958e47 < re Initial program 61.4%
+-commutative61.4%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 77.4%
associate-*r*77.4%
unpow277.4%
rem-square-sqrt78.9%
metadata-eval78.9%
*-lft-identity78.9%
Simplified78.9%
if 1.09999999999999997e-125 < re < 1.40000000000000005e-76 or 1.7600000000000001e-6 < re < 8.99999999999999958e47Initial program 61.7%
+-commutative61.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around 0 39.2%
distribute-lft-out39.2%
+-commutative39.2%
*-commutative39.2%
+-commutative39.2%
Simplified39.2%
Final simplification60.1%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= re -4.8e+25)
(/ (* im 0.5) (sqrt (- re)))
(if (<= re 6.6e-187)
(* 0.5 (sqrt (* 2.0 im)))
(if (<= re 1.1e-125)
(sqrt re)
(if (or (<= re 1.6e-77) (and (not (<= re 4.2e-5)) (<= re 5.2e+47)))
(* 0.5 (sqrt (* 2.0 (+ re im))))
(sqrt re))))))im = abs(im);
double code(double re, double im) {
double tmp;
if (re <= -4.8e+25) {
tmp = (im * 0.5) / sqrt(-re);
} else if (re <= 6.6e-187) {
tmp = 0.5 * sqrt((2.0 * im));
} else if (re <= 1.1e-125) {
tmp = sqrt(re);
} else if ((re <= 1.6e-77) || (!(re <= 4.2e-5) && (re <= 5.2e+47))) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else {
tmp = sqrt(re);
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-4.8d+25)) then
tmp = (im * 0.5d0) / sqrt(-re)
else if (re <= 6.6d-187) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else if (re <= 1.1d-125) then
tmp = sqrt(re)
else if ((re <= 1.6d-77) .or. (.not. (re <= 4.2d-5)) .and. (re <= 5.2d+47)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
else
tmp = sqrt(re)
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (re <= -4.8e+25) {
tmp = (im * 0.5) / Math.sqrt(-re);
} else if (re <= 6.6e-187) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else if (re <= 1.1e-125) {
tmp = Math.sqrt(re);
} else if ((re <= 1.6e-77) || (!(re <= 4.2e-5) && (re <= 5.2e+47))) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if re <= -4.8e+25: tmp = (im * 0.5) / math.sqrt(-re) elif re <= 6.6e-187: tmp = 0.5 * math.sqrt((2.0 * im)) elif re <= 1.1e-125: tmp = math.sqrt(re) elif (re <= 1.6e-77) or (not (re <= 4.2e-5) and (re <= 5.2e+47)): tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = math.sqrt(re) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (re <= -4.8e+25) tmp = Float64(Float64(im * 0.5) / sqrt(Float64(-re))); elseif (re <= 6.6e-187) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); elseif (re <= 1.1e-125) tmp = sqrt(re); elseif ((re <= 1.6e-77) || (!(re <= 4.2e-5) && (re <= 5.2e+47))) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); else tmp = sqrt(re); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.8e+25) tmp = (im * 0.5) / sqrt(-re); elseif (re <= 6.6e-187) tmp = 0.5 * sqrt((2.0 * im)); elseif (re <= 1.1e-125) tmp = sqrt(re); elseif ((re <= 1.6e-77) || (~((re <= 4.2e-5)) && (re <= 5.2e+47))) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = sqrt(re); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[re, -4.8e+25], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.6e-187], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.1e-125], N[Sqrt[re], $MachinePrecision], If[Or[LessEqual[re, 1.6e-77], And[N[Not[LessEqual[re, 4.2e-5]], $MachinePrecision], LessEqual[re, 5.2e+47]]], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.8 \cdot 10^{+25}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\
\mathbf{elif}\;re \leq 6.6 \cdot 10^{-187}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{elif}\;re \leq 1.1 \cdot 10^{-125}:\\
\;\;\;\;\sqrt{re}\\
\mathbf{elif}\;re \leq 1.6 \cdot 10^{-77} \lor \neg \left(re \leq 4.2 \cdot 10^{-5}\right) \land re \leq 5.2 \cdot 10^{+47}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -4.79999999999999992e25Initial program 7.3%
+-commutative7.3%
hypot-def38.8%
Simplified38.8%
Taylor expanded in re around -inf 55.2%
associate-*r/55.2%
neg-mul-155.2%
unpow255.2%
distribute-rgt-neg-in55.2%
Simplified55.2%
frac-2neg55.2%
sqrt-div62.0%
distribute-rgt-neg-out62.0%
remove-double-neg62.0%
sqrt-unprod43.7%
add-sqr-sqrt54.0%
Applied egg-rr54.0%
associate-*r/54.0%
Applied egg-rr54.0%
if -4.79999999999999992e25 < re < 6.6e-187Initial program 52.3%
+-commutative52.3%
hypot-def83.9%
Simplified83.9%
Taylor expanded in re around 0 46.4%
*-commutative46.4%
Simplified46.4%
if 6.6e-187 < re < 1.09999999999999997e-125 or 1.6e-77 < re < 4.19999999999999977e-5 or 5.20000000000000007e47 < re Initial program 61.4%
+-commutative61.4%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 77.4%
associate-*r*77.4%
unpow277.4%
rem-square-sqrt78.9%
metadata-eval78.9%
*-lft-identity78.9%
Simplified78.9%
if 1.09999999999999997e-125 < re < 1.6e-77 or 4.19999999999999977e-5 < re < 5.20000000000000007e47Initial program 61.7%
+-commutative61.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around 0 39.2%
distribute-lft-out39.2%
+-commutative39.2%
*-commutative39.2%
+-commutative39.2%
Simplified39.2%
Final simplification58.5%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= re -3.3e+28)
(* 0.5 (/ im (sqrt (- re))))
(if (or (<= re 6.6e-187)
(and (not (<= re 1.1e-125))
(or (<= re 1.95e-78)
(and (not (<= re 0.0031)) (<= re 1.8e+53)))))
(* 0.5 (sqrt (* 2.0 im)))
(sqrt re))))im = abs(im);
double code(double re, double im) {
double tmp;
if (re <= -3.3e+28) {
tmp = 0.5 * (im / sqrt(-re));
} else if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.95e-78) || (!(re <= 0.0031) && (re <= 1.8e+53))))) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = sqrt(re);
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.3d+28)) then
tmp = 0.5d0 * (im / sqrt(-re))
else if ((re <= 6.6d-187) .or. (.not. (re <= 1.1d-125)) .and. (re <= 1.95d-78) .or. (.not. (re <= 0.0031d0)) .and. (re <= 1.8d+53)) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = sqrt(re)
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (re <= -3.3e+28) {
tmp = 0.5 * (im / Math.sqrt(-re));
} else if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.95e-78) || (!(re <= 0.0031) && (re <= 1.8e+53))))) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if re <= -3.3e+28: tmp = 0.5 * (im / math.sqrt(-re)) elif (re <= 6.6e-187) or (not (re <= 1.1e-125) and ((re <= 1.95e-78) or (not (re <= 0.0031) and (re <= 1.8e+53)))): tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = math.sqrt(re) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (re <= -3.3e+28) tmp = Float64(0.5 * Float64(im / sqrt(Float64(-re)))); elseif ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.95e-78) || (!(re <= 0.0031) && (re <= 1.8e+53))))) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = sqrt(re); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.3e+28) tmp = 0.5 * (im / sqrt(-re)); elseif ((re <= 6.6e-187) || (~((re <= 1.1e-125)) && ((re <= 1.95e-78) || (~((re <= 0.0031)) && (re <= 1.8e+53))))) tmp = 0.5 * sqrt((2.0 * im)); else tmp = sqrt(re); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[re, -3.3e+28], N[(0.5 * N[(im / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 6.6e-187], And[N[Not[LessEqual[re, 1.1e-125]], $MachinePrecision], Or[LessEqual[re, 1.95e-78], And[N[Not[LessEqual[re, 0.0031]], $MachinePrecision], LessEqual[re, 1.8e+53]]]]], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.3 \cdot 10^{+28}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{-re}}\\
\mathbf{elif}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.95 \cdot 10^{-78} \lor \neg \left(re \leq 0.0031\right) \land re \leq 1.8 \cdot 10^{+53}\right):\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -3.3e28Initial program 7.3%
+-commutative7.3%
hypot-def38.8%
Simplified38.8%
Taylor expanded in re around -inf 55.2%
associate-*r/55.2%
neg-mul-155.2%
unpow255.2%
distribute-rgt-neg-in55.2%
Simplified55.2%
frac-2neg55.2%
sqrt-div62.0%
distribute-rgt-neg-out62.0%
remove-double-neg62.0%
sqrt-unprod43.7%
add-sqr-sqrt54.0%
Applied egg-rr54.0%
if -3.3e28 < re < 6.6e-187 or 1.09999999999999997e-125 < re < 1.9500000000000001e-78 or 0.00309999999999999989 < re < 1.8e53Initial program 54.4%
+-commutative54.4%
hypot-def87.5%
Simplified87.5%
Taylor expanded in re around 0 44.2%
*-commutative44.2%
Simplified44.2%
if 6.6e-187 < re < 1.09999999999999997e-125 or 1.9500000000000001e-78 < re < 0.00309999999999999989 or 1.8e53 < re Initial program 61.4%
+-commutative61.4%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 77.4%
associate-*r*77.4%
unpow277.4%
rem-square-sqrt78.9%
metadata-eval78.9%
*-lft-identity78.9%
Simplified78.9%
Final simplification58.2%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= re -1.5e+25)
(/ (* im 0.5) (sqrt (- re)))
(if (or (<= re 6.6e-187)
(and (not (<= re 1.1e-125))
(or (<= re 1.25e-76)
(and (not (<= re 8.5e-5)) (<= re 3.5e+45)))))
(* 0.5 (sqrt (* 2.0 im)))
(sqrt re))))im = abs(im);
double code(double re, double im) {
double tmp;
if (re <= -1.5e+25) {
tmp = (im * 0.5) / sqrt(-re);
} else if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.25e-76) || (!(re <= 8.5e-5) && (re <= 3.5e+45))))) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = sqrt(re);
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.5d+25)) then
tmp = (im * 0.5d0) / sqrt(-re)
else if ((re <= 6.6d-187) .or. (.not. (re <= 1.1d-125)) .and. (re <= 1.25d-76) .or. (.not. (re <= 8.5d-5)) .and. (re <= 3.5d+45)) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = sqrt(re)
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (re <= -1.5e+25) {
tmp = (im * 0.5) / Math.sqrt(-re);
} else if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.25e-76) || (!(re <= 8.5e-5) && (re <= 3.5e+45))))) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if re <= -1.5e+25: tmp = (im * 0.5) / math.sqrt(-re) elif (re <= 6.6e-187) or (not (re <= 1.1e-125) and ((re <= 1.25e-76) or (not (re <= 8.5e-5) and (re <= 3.5e+45)))): tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = math.sqrt(re) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (re <= -1.5e+25) tmp = Float64(Float64(im * 0.5) / sqrt(Float64(-re))); elseif ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.25e-76) || (!(re <= 8.5e-5) && (re <= 3.5e+45))))) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = sqrt(re); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.5e+25) tmp = (im * 0.5) / sqrt(-re); elseif ((re <= 6.6e-187) || (~((re <= 1.1e-125)) && ((re <= 1.25e-76) || (~((re <= 8.5e-5)) && (re <= 3.5e+45))))) tmp = 0.5 * sqrt((2.0 * im)); else tmp = sqrt(re); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[re, -1.5e+25], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[(-re)], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 6.6e-187], And[N[Not[LessEqual[re, 1.1e-125]], $MachinePrecision], Or[LessEqual[re, 1.25e-76], And[N[Not[LessEqual[re, 8.5e-5]], $MachinePrecision], LessEqual[re, 3.5e+45]]]]], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.5 \cdot 10^{+25}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{-re}}\\
\mathbf{elif}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.25 \cdot 10^{-76} \lor \neg \left(re \leq 8.5 \cdot 10^{-5}\right) \land re \leq 3.5 \cdot 10^{+45}\right):\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.50000000000000003e25Initial program 7.3%
+-commutative7.3%
hypot-def38.8%
Simplified38.8%
Taylor expanded in re around -inf 55.2%
associate-*r/55.2%
neg-mul-155.2%
unpow255.2%
distribute-rgt-neg-in55.2%
Simplified55.2%
frac-2neg55.2%
sqrt-div62.0%
distribute-rgt-neg-out62.0%
remove-double-neg62.0%
sqrt-unprod43.7%
add-sqr-sqrt54.0%
Applied egg-rr54.0%
associate-*r/54.0%
Applied egg-rr54.0%
if -1.50000000000000003e25 < re < 6.6e-187 or 1.09999999999999997e-125 < re < 1.2499999999999999e-76 or 8.500000000000001e-5 < re < 3.50000000000000023e45Initial program 54.4%
+-commutative54.4%
hypot-def87.5%
Simplified87.5%
Taylor expanded in re around 0 44.2%
*-commutative44.2%
Simplified44.2%
if 6.6e-187 < re < 1.09999999999999997e-125 or 1.2499999999999999e-76 < re < 8.500000000000001e-5 or 3.50000000000000023e45 < re Initial program 61.4%
+-commutative61.4%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 77.4%
associate-*r*77.4%
unpow277.4%
rem-square-sqrt78.9%
metadata-eval78.9%
*-lft-identity78.9%
Simplified78.9%
Final simplification58.2%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (or (<= re 6.6e-187)
(and (not (<= re 1.1e-125))
(or (<= re 1.85e-78)
(and (not (<= re 2.85e-6)) (<= re 8.8e+46)))))
(* 0.5 (sqrt (* 2.0 im)))
(sqrt re)))im = abs(im);
double code(double re, double im) {
double tmp;
if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.85e-78) || (!(re <= 2.85e-6) && (re <= 8.8e+46))))) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = sqrt(re);
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= 6.6d-187) .or. (.not. (re <= 1.1d-125)) .and. (re <= 1.85d-78) .or. (.not. (re <= 2.85d-6)) .and. (re <= 8.8d+46)) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = sqrt(re)
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.85e-78) || (!(re <= 2.85e-6) && (re <= 8.8e+46))))) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if (re <= 6.6e-187) or (not (re <= 1.1e-125) and ((re <= 1.85e-78) or (not (re <= 2.85e-6) and (re <= 8.8e+46)))): tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = math.sqrt(re) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if ((re <= 6.6e-187) || (!(re <= 1.1e-125) && ((re <= 1.85e-78) || (!(re <= 2.85e-6) && (re <= 8.8e+46))))) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = sqrt(re); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if ((re <= 6.6e-187) || (~((re <= 1.1e-125)) && ((re <= 1.85e-78) || (~((re <= 2.85e-6)) && (re <= 8.8e+46))))) tmp = 0.5 * sqrt((2.0 * im)); else tmp = sqrt(re); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[Or[LessEqual[re, 6.6e-187], And[N[Not[LessEqual[re, 1.1e-125]], $MachinePrecision], Or[LessEqual[re, 1.85e-78], And[N[Not[LessEqual[re, 2.85e-6]], $MachinePrecision], LessEqual[re, 8.8e+46]]]]], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq 6.6 \cdot 10^{-187} \lor \neg \left(re \leq 1.1 \cdot 10^{-125}\right) \land \left(re \leq 1.85 \cdot 10^{-78} \lor \neg \left(re \leq 2.85 \cdot 10^{-6}\right) \land re \leq 8.8 \cdot 10^{+46}\right):\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < 6.6e-187 or 1.09999999999999997e-125 < re < 1.85000000000000003e-78 or 2.8499999999999998e-6 < re < 8.8000000000000001e46Initial program 38.2%
+-commutative38.2%
hypot-def70.8%
Simplified70.8%
Taylor expanded in re around 0 33.8%
*-commutative33.8%
Simplified33.8%
if 6.6e-187 < re < 1.09999999999999997e-125 or 1.85000000000000003e-78 < re < 2.8499999999999998e-6 or 8.8000000000000001e46 < re Initial program 61.4%
+-commutative61.4%
hypot-def100.0%
Simplified100.0%
Taylor expanded in im around 0 77.4%
associate-*r*77.4%
unpow277.4%
rem-square-sqrt78.9%
metadata-eval78.9%
*-lft-identity78.9%
Simplified78.9%
Final simplification49.1%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (sqrt re))
im = abs(im);
double code(double re, double im) {
return sqrt(re);
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt(re)
end function
im = Math.abs(im);
public static double code(double re, double im) {
return Math.sqrt(re);
}
im = abs(im) def code(re, im): return math.sqrt(re)
im = abs(im) function code(re, im) return sqrt(re) end
im = abs(im) function tmp = code(re, im) tmp = sqrt(re); end
NOTE: im should be positive before calling this function code[re_, im_] := N[Sqrt[re], $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
\sqrt{re}
\end{array}
Initial program 46.1%
+-commutative46.1%
hypot-def80.7%
Simplified80.7%
Taylor expanded in im around 0 29.3%
associate-*r*29.3%
unpow229.3%
rem-square-sqrt29.8%
metadata-eval29.8%
*-lft-identity29.8%
Simplified29.8%
Final simplification29.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (+ (* re re) (* im im)))))
(if (< re 0.0)
(* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- t_0 re)))))
(* 0.5 (sqrt (* 2.0 (+ t_0 re)))))))
double code(double re, double im) {
double t_0 = sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * sqrt((2.0 * (t_0 + 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(((re * re) + (im * im)))
if (re < 0.0d0) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt(((im * im) / (t_0 - re))))
else
tmp = 0.5d0 * sqrt((2.0d0 * (t_0 + re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt(((re * re) + (im * im))) tmp = 0 if re < 0.0: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt(((im * im) / (t_0 - re)))) else: tmp = 0.5 * math.sqrt((2.0 * (t_0 + re))) return tmp
function code(re, im) t_0 = sqrt(Float64(Float64(re * re) + Float64(im * im))) tmp = 0.0 if (re < 0.0) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(Float64(im * im) / Float64(t_0 - re))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(t_0 + re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt(((re * re) + (im * im))); tmp = 0.0; if (re < 0.0) tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re)))); else tmp = 0.5 * sqrt((2.0 * (t_0 + re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[re, 0.0], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(N[(im * im), $MachinePrecision] / N[(t$95$0 - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(t$95$0 + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{re \cdot re + im \cdot im}\\
\mathbf{if}\;re < 0:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{t_0 - re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(t_0 + re\right)}\\
\end{array}
\end{array}
herbie shell --seed 2023258
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:herbie-target
(if (< re 0.0) (* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))