
(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 15 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 -2e-240) (* (sqrt (* im (/ (* im -2.0) (- re (hypot re im))))) 0.5) (* 0.5 (sqrt (* 2.0 (+ re (hypot re im)))))))
double code(double re, double im) {
double tmp;
if (re <= -2e-240) {
tmp = sqrt((im * ((im * -2.0) / (re - hypot(re, im))))) * 0.5;
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= -2e-240) {
tmp = Math.sqrt((im * ((im * -2.0) / (re - Math.hypot(re, im))))) * 0.5;
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2e-240: tmp = math.sqrt((im * ((im * -2.0) / (re - math.hypot(re, im))))) * 0.5 else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (re <= -2e-240) tmp = Float64(sqrt(Float64(im * Float64(Float64(im * -2.0) / Float64(re - hypot(re, im))))) * 0.5); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2e-240) tmp = sqrt((im * ((im * -2.0) / (re - hypot(re, im))))) * 0.5; else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2e-240], N[(N[Sqrt[N[(im * N[(N[(im * -2.0), $MachinePrecision] / N[(re - N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2 \cdot 10^{-240}:\\
\;\;\;\;\sqrt{im \cdot \frac{im \cdot -2}{re - \mathsf{hypot}\left(re, im\right)}} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if re < -1.9999999999999999e-240Initial program 24.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6424.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f6424.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6424.0
Applied rewrites24.0%
Applied rewrites45.4%
Applied rewrites45.0%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lower-hypot.f6482.6
Applied rewrites82.6%
if -1.9999999999999999e-240 < re Initial program 57.5%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Final simplification92.5%
(FPCore (re im) :precision binary64 (if (<= (sqrt (* 2.0 (+ re (sqrt (+ (* re re) (* im im)))))) 0.0) (* (/ 0.5 (sqrt (- (sqrt (fma re re (* im im))) re))) (* im (sqrt 2.0))) (* 0.5 (sqrt (* 2.0 (+ re (hypot re im)))))))
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0) {
tmp = (0.5 / sqrt((sqrt(fma(re, re, (im * im))) - re))) * (im * sqrt(2.0));
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im))));
}
return tmp;
}
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(0.5 / sqrt(Float64(sqrt(fma(re, re, Float64(im * im))) - re))) * Float64(im * sqrt(2.0))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im))))); end return tmp end
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[(0.5 / N[Sqrt[N[(N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(im * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\right)} \leq 0:\\
\;\;\;\;\frac{0.5}{\sqrt{\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re}} \cdot \left(im \cdot \sqrt{2}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 5.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f645.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f645.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f645.0
Applied rewrites5.0%
Applied rewrites68.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites55.4%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 46.9%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6488.6
Applied rewrites88.6%
Final simplification85.5%
(FPCore (re im)
:precision binary64
(if (<= re -1.1e+150)
(* 0.5 (* (sqrt (* -2.0 (- (* im im)))) (sqrt (/ -1.0 (- re (- re))))))
(if (<= re -1.3e+119)
(* 0.5 (sqrt (fma 2.0 (+ re im) (/ (* re re) im))))
(if (<= re -3.9e-100)
(*
0.5
(*
(* (sqrt (* -2.0 (- im))) (sqrt im))
(sqrt (/ -1.0 (- re (sqrt (fma re re (* im im))))))))
(if (<= re 2.65e-21)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(if (<= re 2.6e+123)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (fma im im (* re re)))))))
(sqrt re)))))))
double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * (sqrt((-2.0 * -(im * im))) * sqrt((-1.0 / (re - -re))));
} else if (re <= -1.3e+119) {
tmp = 0.5 * sqrt(fma(2.0, (re + im), ((re * re) / im)));
} else if (re <= -3.9e-100) {
tmp = 0.5 * ((sqrt((-2.0 * -im)) * sqrt(im)) * sqrt((-1.0 / (re - sqrt(fma(re, re, (im * im)))))));
} else if (re <= 2.65e-21) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else if (re <= 2.6e+123) {
tmp = 0.5 * sqrt((2.0 * (re + sqrt(fma(im, im, (re * re))))));
} else {
tmp = sqrt(re);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.1e+150) tmp = Float64(0.5 * Float64(sqrt(Float64(-2.0 * Float64(-Float64(im * im)))) * sqrt(Float64(-1.0 / Float64(re - Float64(-re)))))); elseif (re <= -1.3e+119) tmp = Float64(0.5 * sqrt(fma(2.0, Float64(re + im), Float64(Float64(re * re) / im)))); elseif (re <= -3.9e-100) tmp = Float64(0.5 * Float64(Float64(sqrt(Float64(-2.0 * Float64(-im))) * sqrt(im)) * sqrt(Float64(-1.0 / Float64(re - sqrt(fma(re, re, Float64(im * im)))))))); elseif (re <= 2.65e-21) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); elseif (re <= 2.6e+123) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + sqrt(fma(im, im, Float64(re * re))))))); else tmp = sqrt(re); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.1e+150], N[(0.5 * N[(N[Sqrt[N[(-2.0 * (-N[(im * im), $MachinePrecision])), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(-1.0 / N[(re - (-re)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.3e+119], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision] + N[(N[(re * re), $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -3.9e-100], N[(0.5 * N[(N[(N[Sqrt[N[(-2.0 * (-im)), $MachinePrecision]], $MachinePrecision] * N[Sqrt[im], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(-1.0 / N[(re - N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.65e-21], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.6e+123], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{+150}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{-2 \cdot \left(-im \cdot im\right)} \cdot \sqrt{\frac{-1}{re - \left(-re\right)}}\right)\\
\mathbf{elif}\;re \leq -1.3 \cdot 10^{+119}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(2, re + im, \frac{re \cdot re}{im}\right)}\\
\mathbf{elif}\;re \leq -3.9 \cdot 10^{-100}:\\
\;\;\;\;0.5 \cdot \left(\left(\sqrt{-2 \cdot \left(-im\right)} \cdot \sqrt{im}\right) \cdot \sqrt{\frac{-1}{re - \sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)}}}\right)\\
\mathbf{elif}\;re \leq 2.65 \cdot 10^{-21}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{elif}\;re \leq 2.6 \cdot 10^{+123}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.1e150Initial program 2.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f642.5
lift-+.f64N/A
+-commutativeN/A
lower-+.f642.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f642.5
Applied rewrites2.5%
Applied rewrites26.1%
Taylor expanded in re around -inf
mul-1-negN/A
lower-neg.f6475.5
Applied rewrites75.5%
if -1.1e150 < re < -1.3e119Initial program 13.9%
Taylor expanded in re around 0
distribute-rgt-inN/A
associate-+r+N/A
associate-*l/N/A
unpow2N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6460.2
Applied rewrites60.2%
if -1.3e119 < re < -3.89999999999999977e-100Initial program 30.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6430.4
lift-+.f64N/A
+-commutativeN/A
lower-+.f6430.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6430.4
Applied rewrites30.4%
Applied rewrites62.1%
lift-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-neg.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
associate-*r*N/A
sqrt-prodN/A
unpow1/2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-neg.f6436.6
lift-exp.f64N/A
lift-*.f64N/A
lift-log.f64N/A
exp-to-powN/A
unpow1/2N/A
lower-sqrt.f6438.6
Applied rewrites38.6%
if -3.89999999999999977e-100 < re < 2.65e-21Initial program 59.2%
Taylor expanded in re around 0
lower-+.f6445.8
Applied rewrites45.8%
if 2.65e-21 < re < 2.59999999999999985e123Initial program 87.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6487.4
lift-+.f64N/A
+-commutativeN/A
lower-+.f6487.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.4
Applied rewrites87.4%
if 2.59999999999999985e123 < re Initial program 10.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.4
Applied rewrites85.4%
Final simplification60.1%
(FPCore (re im)
:precision binary64
(if (<= re -1.1e+150)
(* 0.5 (* (sqrt (* -2.0 (- (* im im)))) (sqrt (/ -1.0 (- re (- re))))))
(if (<= re -4.2e+119)
(* 0.5 (sqrt (fma 2.0 (+ re im) (/ (* re re) im))))
(if (<= re -1.5e-145)
(* (/ 0.5 (sqrt (- (sqrt (fma re re (* im im))) re))) (* im (sqrt 2.0)))
(if (<= re 2.65e-21)
(* 0.5 (sqrt (* 2.0 (+ re im))))
(if (<= re 2.6e+123)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (fma im im (* re re)))))))
(sqrt re)))))))
double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * (sqrt((-2.0 * -(im * im))) * sqrt((-1.0 / (re - -re))));
} else if (re <= -4.2e+119) {
tmp = 0.5 * sqrt(fma(2.0, (re + im), ((re * re) / im)));
} else if (re <= -1.5e-145) {
tmp = (0.5 / sqrt((sqrt(fma(re, re, (im * im))) - re))) * (im * sqrt(2.0));
} else if (re <= 2.65e-21) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else if (re <= 2.6e+123) {
tmp = 0.5 * sqrt((2.0 * (re + sqrt(fma(im, im, (re * re))))));
} else {
tmp = sqrt(re);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.1e+150) tmp = Float64(0.5 * Float64(sqrt(Float64(-2.0 * Float64(-Float64(im * im)))) * sqrt(Float64(-1.0 / Float64(re - Float64(-re)))))); elseif (re <= -4.2e+119) tmp = Float64(0.5 * sqrt(fma(2.0, Float64(re + im), Float64(Float64(re * re) / im)))); elseif (re <= -1.5e-145) tmp = Float64(Float64(0.5 / sqrt(Float64(sqrt(fma(re, re, Float64(im * im))) - re))) * Float64(im * sqrt(2.0))); elseif (re <= 2.65e-21) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); elseif (re <= 2.6e+123) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + sqrt(fma(im, im, Float64(re * re))))))); else tmp = sqrt(re); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.1e+150], N[(0.5 * N[(N[Sqrt[N[(-2.0 * (-N[(im * im), $MachinePrecision])), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(-1.0 / N[(re - (-re)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -4.2e+119], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision] + N[(N[(re * re), $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.5e-145], N[(N[(0.5 / N[Sqrt[N[(N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(im * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.65e-21], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.6e+123], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{+150}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{-2 \cdot \left(-im \cdot im\right)} \cdot \sqrt{\frac{-1}{re - \left(-re\right)}}\right)\\
\mathbf{elif}\;re \leq -4.2 \cdot 10^{+119}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(2, re + im, \frac{re \cdot re}{im}\right)}\\
\mathbf{elif}\;re \leq -1.5 \cdot 10^{-145}:\\
\;\;\;\;\frac{0.5}{\sqrt{\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re}} \cdot \left(im \cdot \sqrt{2}\right)\\
\mathbf{elif}\;re \leq 2.65 \cdot 10^{-21}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{elif}\;re \leq 2.6 \cdot 10^{+123}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.1e150Initial program 2.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f642.5
lift-+.f64N/A
+-commutativeN/A
lower-+.f642.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f642.5
Applied rewrites2.5%
Applied rewrites26.1%
Taylor expanded in re around -inf
mul-1-negN/A
lower-neg.f6475.5
Applied rewrites75.5%
if -1.1e150 < re < -4.19999999999999966e119Initial program 13.9%
Taylor expanded in re around 0
distribute-rgt-inN/A
associate-+r+N/A
associate-*l/N/A
unpow2N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6460.2
Applied rewrites60.2%
if -4.19999999999999966e119 < re < -1.49999999999999996e-145Initial program 32.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6432.2
lift-+.f64N/A
+-commutativeN/A
lower-+.f6432.2
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6432.2
Applied rewrites32.2%
Applied rewrites61.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites38.6%
if -1.49999999999999996e-145 < re < 2.65e-21Initial program 59.5%
Taylor expanded in re around 0
lower-+.f6446.6
Applied rewrites46.6%
if 2.65e-21 < re < 2.59999999999999985e123Initial program 87.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6487.4
lift-+.f64N/A
+-commutativeN/A
lower-+.f6487.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.4
Applied rewrites87.4%
if 2.59999999999999985e123 < re Initial program 10.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.4
Applied rewrites85.4%
Final simplification60.4%
(FPCore (re im)
:precision binary64
(if (<= re -1.1e+150)
(* 0.5 (* (sqrt (* -2.0 (- (* im im)))) (sqrt (/ -1.0 (- re (- re))))))
(if (<= re -1.3e+119)
(* 0.5 (sqrt (fma 2.0 (+ re im) (/ (* re re) im))))
(if (<= re -0.01)
(*
0.5
(sqrt (* im (/ (* im -2.0) (- re (sqrt (fma re re (* im im))))))))
(if (<= re 2.65e-21)
(* 0.5 (* (sqrt 2.0) (sqrt (+ re im))))
(if (<= re 2.6e+123)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (fma im im (* re re)))))))
(sqrt re)))))))
double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * (sqrt((-2.0 * -(im * im))) * sqrt((-1.0 / (re - -re))));
} else if (re <= -1.3e+119) {
tmp = 0.5 * sqrt(fma(2.0, (re + im), ((re * re) / im)));
} else if (re <= -0.01) {
tmp = 0.5 * sqrt((im * ((im * -2.0) / (re - sqrt(fma(re, re, (im * im)))))));
} else if (re <= 2.65e-21) {
tmp = 0.5 * (sqrt(2.0) * sqrt((re + im)));
} else if (re <= 2.6e+123) {
tmp = 0.5 * sqrt((2.0 * (re + sqrt(fma(im, im, (re * re))))));
} else {
tmp = sqrt(re);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.1e+150) tmp = Float64(0.5 * Float64(sqrt(Float64(-2.0 * Float64(-Float64(im * im)))) * sqrt(Float64(-1.0 / Float64(re - Float64(-re)))))); elseif (re <= -1.3e+119) tmp = Float64(0.5 * sqrt(fma(2.0, Float64(re + im), Float64(Float64(re * re) / im)))); elseif (re <= -0.01) tmp = Float64(0.5 * sqrt(Float64(im * Float64(Float64(im * -2.0) / Float64(re - sqrt(fma(re, re, Float64(im * im)))))))); elseif (re <= 2.65e-21) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(re + im)))); elseif (re <= 2.6e+123) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + sqrt(fma(im, im, Float64(re * re))))))); else tmp = sqrt(re); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.1e+150], N[(0.5 * N[(N[Sqrt[N[(-2.0 * (-N[(im * im), $MachinePrecision])), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(-1.0 / N[(re - (-re)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.3e+119], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision] + N[(N[(re * re), $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -0.01], N[(0.5 * N[Sqrt[N[(im * N[(N[(im * -2.0), $MachinePrecision] / N[(re - N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.65e-21], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(re + im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.6e+123], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{+150}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{-2 \cdot \left(-im \cdot im\right)} \cdot \sqrt{\frac{-1}{re - \left(-re\right)}}\right)\\
\mathbf{elif}\;re \leq -1.3 \cdot 10^{+119}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(2, re + im, \frac{re \cdot re}{im}\right)}\\
\mathbf{elif}\;re \leq -0.01:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{im \cdot -2}{re - \sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)}}}\\
\mathbf{elif}\;re \leq 2.65 \cdot 10^{-21}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{re + im}\right)\\
\mathbf{elif}\;re \leq 2.6 \cdot 10^{+123}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.1e150Initial program 2.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f642.5
lift-+.f64N/A
+-commutativeN/A
lower-+.f642.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f642.5
Applied rewrites2.5%
Applied rewrites26.1%
Taylor expanded in re around -inf
mul-1-negN/A
lower-neg.f6475.5
Applied rewrites75.5%
if -1.1e150 < re < -1.3e119Initial program 13.9%
Taylor expanded in re around 0
distribute-rgt-inN/A
associate-+r+N/A
associate-*l/N/A
unpow2N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6460.2
Applied rewrites60.2%
if -1.3e119 < re < -0.0100000000000000002Initial program 31.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6431.1
lift-+.f64N/A
+-commutativeN/A
lower-+.f6431.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6431.1
Applied rewrites31.1%
Applied rewrites77.8%
Applied rewrites75.2%
if -0.0100000000000000002 < re < 2.65e-21Initial program 54.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6454.8
lift-+.f64N/A
+-commutativeN/A
lower-+.f6454.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6454.8
Applied rewrites54.8%
Taylor expanded in re around 0
lower-+.f6442.4
Applied rewrites42.4%
lift-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
sqrt-prodN/A
pow1/2N/A
lift-sqrt.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6442.1
Applied rewrites42.1%
if 2.65e-21 < re < 2.59999999999999985e123Initial program 87.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6487.4
lift-+.f64N/A
+-commutativeN/A
lower-+.f6487.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.4
Applied rewrites87.4%
if 2.59999999999999985e123 < re Initial program 10.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.4
Applied rewrites85.4%
Final simplification62.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (fma im im (* re re)))))
(if (<= re -1.1e+150)
(* 0.5 (* (sqrt (* -2.0 (- (* im im)))) (sqrt (/ -1.0 (- re (- re))))))
(if (<= re -6e+118)
(* 0.5 (sqrt (fma 2.0 (+ re im) (/ (* re re) im))))
(if (<= re -0.01)
(* 0.5 (sqrt (/ (* -2.0 (* im im)) (- re t_0))))
(if (<= re 2.65e-21)
(* 0.5 (* (sqrt 2.0) (sqrt (+ re im))))
(if (<= re 2.6e+123)
(* 0.5 (sqrt (* 2.0 (+ re t_0))))
(sqrt re))))))))
double code(double re, double im) {
double t_0 = sqrt(fma(im, im, (re * re)));
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * (sqrt((-2.0 * -(im * im))) * sqrt((-1.0 / (re - -re))));
} else if (re <= -6e+118) {
tmp = 0.5 * sqrt(fma(2.0, (re + im), ((re * re) / im)));
} else if (re <= -0.01) {
tmp = 0.5 * sqrt(((-2.0 * (im * im)) / (re - t_0)));
} else if (re <= 2.65e-21) {
tmp = 0.5 * (sqrt(2.0) * sqrt((re + im)));
} else if (re <= 2.6e+123) {
tmp = 0.5 * sqrt((2.0 * (re + t_0)));
} else {
tmp = sqrt(re);
}
return tmp;
}
function code(re, im) t_0 = sqrt(fma(im, im, Float64(re * re))) tmp = 0.0 if (re <= -1.1e+150) tmp = Float64(0.5 * Float64(sqrt(Float64(-2.0 * Float64(-Float64(im * im)))) * sqrt(Float64(-1.0 / Float64(re - Float64(-re)))))); elseif (re <= -6e+118) tmp = Float64(0.5 * sqrt(fma(2.0, Float64(re + im), Float64(Float64(re * re) / im)))); elseif (re <= -0.01) tmp = Float64(0.5 * sqrt(Float64(Float64(-2.0 * Float64(im * im)) / Float64(re - t_0)))); elseif (re <= 2.65e-21) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(re + im)))); elseif (re <= 2.6e+123) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + t_0)))); else tmp = sqrt(re); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -1.1e+150], N[(0.5 * N[(N[Sqrt[N[(-2.0 * (-N[(im * im), $MachinePrecision])), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(-1.0 / N[(re - (-re)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -6e+118], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision] + N[(N[(re * re), $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -0.01], N[(0.5 * N[Sqrt[N[(N[(-2.0 * N[(im * im), $MachinePrecision]), $MachinePrecision] / N[(re - t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.65e-21], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(re + im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.6e+123], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)}\\
\mathbf{if}\;re \leq -1.1 \cdot 10^{+150}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{-2 \cdot \left(-im \cdot im\right)} \cdot \sqrt{\frac{-1}{re - \left(-re\right)}}\right)\\
\mathbf{elif}\;re \leq -6 \cdot 10^{+118}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(2, re + im, \frac{re \cdot re}{im}\right)}\\
\mathbf{elif}\;re \leq -0.01:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{-2 \cdot \left(im \cdot im\right)}{re - t\_0}}\\
\mathbf{elif}\;re \leq 2.65 \cdot 10^{-21}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{re + im}\right)\\
\mathbf{elif}\;re \leq 2.6 \cdot 10^{+123}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.1e150Initial program 2.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f642.5
lift-+.f64N/A
+-commutativeN/A
lower-+.f642.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f642.5
Applied rewrites2.5%
Applied rewrites26.1%
Taylor expanded in re around -inf
mul-1-negN/A
lower-neg.f6475.5
Applied rewrites75.5%
if -1.1e150 < re < -6e118Initial program 13.9%
Taylor expanded in re around 0
distribute-rgt-inN/A
associate-+r+N/A
associate-*l/N/A
unpow2N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6460.2
Applied rewrites60.2%
if -6e118 < re < -0.0100000000000000002Initial program 31.1%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
flip-+N/A
associate-*l/N/A
lower-/.f64N/A
Applied rewrites30.4%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6474.7
Applied rewrites74.7%
if -0.0100000000000000002 < re < 2.65e-21Initial program 54.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6454.8
lift-+.f64N/A
+-commutativeN/A
lower-+.f6454.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6454.8
Applied rewrites54.8%
Taylor expanded in re around 0
lower-+.f6442.4
Applied rewrites42.4%
lift-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
sqrt-prodN/A
pow1/2N/A
lift-sqrt.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6442.1
Applied rewrites42.1%
if 2.65e-21 < re < 2.59999999999999985e123Initial program 87.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6487.4
lift-+.f64N/A
+-commutativeN/A
lower-+.f6487.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.4
Applied rewrites87.4%
if 2.59999999999999985e123 < re Initial program 10.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.4
Applied rewrites85.4%
Final simplification62.8%
(FPCore (re im)
:precision binary64
(if (<= re -1.1e+150)
(* 0.5 (* (sqrt (* -2.0 (- (* im im)))) (sqrt (/ -1.0 (- re (- re))))))
(if (<= re 2.65e-21)
(* 0.5 (sqrt (fma 2.0 (+ re im) (/ (* re re) im))))
(if (<= re 2.6e+123)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (fma im im (* re re)))))))
(sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * (sqrt((-2.0 * -(im * im))) * sqrt((-1.0 / (re - -re))));
} else if (re <= 2.65e-21) {
tmp = 0.5 * sqrt(fma(2.0, (re + im), ((re * re) / im)));
} else if (re <= 2.6e+123) {
tmp = 0.5 * sqrt((2.0 * (re + sqrt(fma(im, im, (re * re))))));
} else {
tmp = sqrt(re);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.1e+150) tmp = Float64(0.5 * Float64(sqrt(Float64(-2.0 * Float64(-Float64(im * im)))) * sqrt(Float64(-1.0 / Float64(re - Float64(-re)))))); elseif (re <= 2.65e-21) tmp = Float64(0.5 * sqrt(fma(2.0, Float64(re + im), Float64(Float64(re * re) / im)))); elseif (re <= 2.6e+123) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + sqrt(fma(im, im, Float64(re * re))))))); else tmp = sqrt(re); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.1e+150], N[(0.5 * N[(N[Sqrt[N[(-2.0 * (-N[(im * im), $MachinePrecision])), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(-1.0 / N[(re - (-re)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.65e-21], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision] + N[(N[(re * re), $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.6e+123], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{+150}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{-2 \cdot \left(-im \cdot im\right)} \cdot \sqrt{\frac{-1}{re - \left(-re\right)}}\right)\\
\mathbf{elif}\;re \leq 2.65 \cdot 10^{-21}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(2, re + im, \frac{re \cdot re}{im}\right)}\\
\mathbf{elif}\;re \leq 2.6 \cdot 10^{+123}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.1e150Initial program 2.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f642.5
lift-+.f64N/A
+-commutativeN/A
lower-+.f642.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f642.5
Applied rewrites2.5%
Applied rewrites26.1%
Taylor expanded in re around -inf
mul-1-negN/A
lower-neg.f6475.5
Applied rewrites75.5%
if -1.1e150 < re < 2.65e-21Initial program 47.9%
Taylor expanded in re around 0
distribute-rgt-inN/A
associate-+r+N/A
associate-*l/N/A
unpow2N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6438.8
Applied rewrites38.8%
if 2.65e-21 < re < 2.59999999999999985e123Initial program 87.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6487.4
lift-+.f64N/A
+-commutativeN/A
lower-+.f6487.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.4
Applied rewrites87.4%
if 2.59999999999999985e123 < re Initial program 10.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.4
Applied rewrites85.4%
Final simplification56.6%
(FPCore (re im)
:precision binary64
(if (<= re -1.1e+150)
(* 0.5 (sqrt (* im (/ im (- re)))))
(if (<= re 2.65e-21)
(* 0.5 (sqrt (fma 2.0 (+ re im) (/ (* re re) im))))
(if (<= re 2.6e+123)
(* 0.5 (sqrt (* 2.0 (+ re (sqrt (fma im im (* re re)))))))
(sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * sqrt((im * (im / -re)));
} else if (re <= 2.65e-21) {
tmp = 0.5 * sqrt(fma(2.0, (re + im), ((re * re) / im)));
} else if (re <= 2.6e+123) {
tmp = 0.5 * sqrt((2.0 * (re + sqrt(fma(im, im, (re * re))))));
} else {
tmp = sqrt(re);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.1e+150) tmp = Float64(0.5 * sqrt(Float64(im * Float64(im / Float64(-re))))); elseif (re <= 2.65e-21) tmp = Float64(0.5 * sqrt(fma(2.0, Float64(re + im), Float64(Float64(re * re) / im)))); elseif (re <= 2.6e+123) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + sqrt(fma(im, im, Float64(re * re))))))); else tmp = sqrt(re); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.1e+150], N[(0.5 * N[Sqrt[N[(im * N[(im / (-re)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.65e-21], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision] + N[(N[(re * re), $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.6e+123], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{+150}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{im}{-re}}\\
\mathbf{elif}\;re \leq 2.65 \cdot 10^{-21}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(2, re + im, \frac{re \cdot re}{im}\right)}\\
\mathbf{elif}\;re \leq 2.6 \cdot 10^{+123}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.1e150Initial program 2.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f642.5
lift-+.f64N/A
+-commutativeN/A
lower-+.f642.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f642.5
Applied rewrites2.5%
Applied rewrites26.1%
Applied rewrites26.5%
Taylor expanded in re around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6470.3
Applied rewrites70.3%
if -1.1e150 < re < 2.65e-21Initial program 47.9%
Taylor expanded in re around 0
distribute-rgt-inN/A
associate-+r+N/A
associate-*l/N/A
unpow2N/A
distribute-lft-outN/A
lower-fma.f64N/A
lower-+.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6438.8
Applied rewrites38.8%
if 2.65e-21 < re < 2.59999999999999985e123Initial program 87.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6487.4
lift-+.f64N/A
+-commutativeN/A
lower-+.f6487.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6487.4
Applied rewrites87.4%
if 2.59999999999999985e123 < re Initial program 10.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.4
Applied rewrites85.4%
Final simplification55.9%
(FPCore (re im) :precision binary64 (if (<= re -1.1e+150) (* 0.5 (sqrt (* im (/ im (- re))))) (if (<= re 1.12e+52) (* 0.5 (* (sqrt 2.0) (sqrt (+ re im)))) (sqrt re))))
double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * sqrt((im * (im / -re)));
} else if (re <= 1.12e+52) {
tmp = 0.5 * (sqrt(2.0) * sqrt((re + im)));
} else {
tmp = 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 <= (-1.1d+150)) then
tmp = 0.5d0 * sqrt((im * (im / -re)))
else if (re <= 1.12d+52) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt((re + im)))
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * Math.sqrt((im * (im / -re)));
} else if (re <= 1.12e+52) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt((re + im)));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.1e+150: tmp = 0.5 * math.sqrt((im * (im / -re))) elif re <= 1.12e+52: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt((re + im))) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.1e+150) tmp = Float64(0.5 * sqrt(Float64(im * Float64(im / Float64(-re))))); elseif (re <= 1.12e+52) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(re + im)))); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.1e+150) tmp = 0.5 * sqrt((im * (im / -re))); elseif (re <= 1.12e+52) tmp = 0.5 * (sqrt(2.0) * sqrt((re + im))); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.1e+150], N[(0.5 * N[Sqrt[N[(im * N[(im / (-re)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.12e+52], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(re + im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{+150}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{im}{-re}}\\
\mathbf{elif}\;re \leq 1.12 \cdot 10^{+52}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{re + im}\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.1e150Initial program 2.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f642.5
lift-+.f64N/A
+-commutativeN/A
lower-+.f642.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f642.5
Applied rewrites2.5%
Applied rewrites26.1%
Applied rewrites26.5%
Taylor expanded in re around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6470.3
Applied rewrites70.3%
if -1.1e150 < re < 1.12000000000000002e52Initial program 51.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6451.7
lift-+.f64N/A
+-commutativeN/A
lower-+.f6451.7
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6451.7
Applied rewrites51.7%
Taylor expanded in re around 0
lower-+.f6439.4
Applied rewrites39.4%
lift-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
sqrt-prodN/A
pow1/2N/A
lift-sqrt.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6439.2
Applied rewrites39.2%
if 1.12000000000000002e52 < re Initial program 41.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.2
Applied rewrites85.2%
Final simplification52.2%
(FPCore (re im) :precision binary64 (if (<= re -1.1e+150) (* 0.5 (sqrt (* im (/ im (- re))))) (if (<= re 1.12e+52) (* 0.5 (sqrt (* 2.0 (+ re im)))) (sqrt re))))
double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * sqrt((im * (im / -re)));
} else if (re <= 1.12e+52) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else {
tmp = 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 <= (-1.1d+150)) then
tmp = 0.5d0 * sqrt((im * (im / -re)))
else if (re <= 1.12d+52) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * Math.sqrt((im * (im / -re)));
} else if (re <= 1.12e+52) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.1e+150: tmp = 0.5 * math.sqrt((im * (im / -re))) elif re <= 1.12e+52: tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.1e+150) tmp = Float64(0.5 * sqrt(Float64(im * Float64(im / Float64(-re))))); elseif (re <= 1.12e+52) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.1e+150) tmp = 0.5 * sqrt((im * (im / -re))); elseif (re <= 1.12e+52) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.1e+150], N[(0.5 * N[Sqrt[N[(im * N[(im / (-re)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.12e+52], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{+150}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot \frac{im}{-re}}\\
\mathbf{elif}\;re \leq 1.12 \cdot 10^{+52}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.1e150Initial program 2.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f642.5
lift-+.f64N/A
+-commutativeN/A
lower-+.f642.5
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f642.5
Applied rewrites2.5%
Applied rewrites26.1%
Applied rewrites26.5%
Taylor expanded in re around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6470.3
Applied rewrites70.3%
if -1.1e150 < re < 1.12000000000000002e52Initial program 51.7%
Taylor expanded in re around 0
lower-+.f6439.4
Applied rewrites39.4%
if 1.12000000000000002e52 < re Initial program 41.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.2
Applied rewrites85.2%
Final simplification52.4%
(FPCore (re im) :precision binary64 (if (<= re -1.1e+150) (* 0.5 (sqrt (/ (* im im) (- re)))) (if (<= re 1.12e+52) (* 0.5 (sqrt (* 2.0 (+ re im)))) (sqrt re))))
double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * sqrt(((im * im) / -re));
} else if (re <= 1.12e+52) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else {
tmp = 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 <= (-1.1d+150)) then
tmp = 0.5d0 * sqrt(((im * im) / -re))
else if (re <= 1.12d+52) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.1e+150) {
tmp = 0.5 * Math.sqrt(((im * im) / -re));
} else if (re <= 1.12e+52) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.1e+150: tmp = 0.5 * math.sqrt(((im * im) / -re)) elif re <= 1.12e+52: tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.1e+150) tmp = Float64(0.5 * sqrt(Float64(Float64(im * im) / Float64(-re)))); elseif (re <= 1.12e+52) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.1e+150) tmp = 0.5 * sqrt(((im * im) / -re)); elseif (re <= 1.12e+52) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.1e+150], N[(0.5 * N[Sqrt[N[(N[(im * im), $MachinePrecision] / (-re)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.12e+52], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{+150}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{im \cdot im}{-re}}\\
\mathbf{elif}\;re \leq 1.12 \cdot 10^{+52}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.1e150Initial program 2.5%
Taylor expanded in re around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6462.5
Applied rewrites62.5%
if -1.1e150 < re < 1.12000000000000002e52Initial program 51.7%
Taylor expanded in re around 0
lower-+.f6439.4
Applied rewrites39.4%
if 1.12000000000000002e52 < re Initial program 41.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.2
Applied rewrites85.2%
Final simplification51.3%
(FPCore (re im) :precision binary64 (if (<= re -1.55e+179) (* 0.5 (sqrt (* 2.0 (+ re (- re))))) (if (<= re 1.12e+52) (* 0.5 (sqrt (* 2.0 (+ re im)))) (sqrt re))))
double code(double re, double im) {
double tmp;
if (re <= -1.55e+179) {
tmp = 0.5 * sqrt((2.0 * (re + -re)));
} else if (re <= 1.12e+52) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else {
tmp = 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 <= (-1.55d+179)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + -re)))
else if (re <= 1.12d+52) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.55e+179) {
tmp = 0.5 * Math.sqrt((2.0 * (re + -re)));
} else if (re <= 1.12e+52) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.55e+179: tmp = 0.5 * math.sqrt((2.0 * (re + -re))) elif re <= 1.12e+52: tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.55e+179) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + Float64(-re))))); elseif (re <= 1.12e+52) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.55e+179) tmp = 0.5 * sqrt((2.0 * (re + -re))); elseif (re <= 1.12e+52) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.55e+179], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + (-re)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.12e+52], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.55 \cdot 10^{+179}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \left(-re\right)\right)}\\
\mathbf{elif}\;re \leq 1.12 \cdot 10^{+52}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -1.55e179Initial program 2.5%
Taylor expanded in re around -inf
mul-1-negN/A
lower-neg.f6430.9
Applied rewrites30.9%
if -1.55e179 < re < 1.12000000000000002e52Initial program 50.1%
Taylor expanded in re around 0
lower-+.f6438.1
Applied rewrites38.1%
if 1.12000000000000002e52 < re Initial program 41.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.2
Applied rewrites85.2%
Final simplification46.3%
(FPCore (re im) :precision binary64 (if (<= re 1.12e+52) (* 0.5 (sqrt (* 2.0 (+ re im)))) (sqrt re)))
double code(double re, double im) {
double tmp;
if (re <= 1.12e+52) {
tmp = 0.5 * sqrt((2.0 * (re + im)));
} else {
tmp = 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 <= 1.12d+52) then
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 1.12e+52) {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.12e+52: tmp = 0.5 * math.sqrt((2.0 * (re + im))) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.12e+52) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.12e+52) tmp = 0.5 * sqrt((2.0 * (re + im))); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.12e+52], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.12 \cdot 10^{+52}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < 1.12000000000000002e52Initial program 43.4%
Taylor expanded in re around 0
lower-+.f6432.8
Applied rewrites32.8%
if 1.12000000000000002e52 < re Initial program 41.4%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6485.2
Applied rewrites85.2%
Final simplification42.8%
(FPCore (re im) :precision binary64 (if (<= re 7e+38) (* 0.5 (sqrt (* im 2.0))) (sqrt re)))
double code(double re, double im) {
double tmp;
if (re <= 7e+38) {
tmp = 0.5 * sqrt((im * 2.0));
} else {
tmp = 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 <= 7d+38) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 7e+38) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 7e+38: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= 7e+38) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 7e+38) tmp = 0.5 * sqrt((im * 2.0)); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 7e+38], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 7 \cdot 10^{+38}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < 7.00000000000000003e38Initial program 42.3%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f6431.6
Applied rewrites31.6%
if 7.00000000000000003e38 < re Initial program 45.8%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6482.9
Applied rewrites82.9%
(FPCore (re im) :precision binary64 (sqrt re))
double code(double re, double im) {
return sqrt(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt(re)
end function
public static double code(double re, double im) {
return Math.sqrt(re);
}
def code(re, im): return math.sqrt(re)
function code(re, im) return sqrt(re) end
function tmp = code(re, im) tmp = sqrt(re); end
code[re_, im_] := N[Sqrt[re], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{re}
\end{array}
Initial program 43.0%
Taylor expanded in re around inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
lower-sqrt.f6426.9
Applied rewrites26.9%
(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 2024233
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:alt
(! :herbie-platform default (if (< re 0) (* 1/2 (* (sqrt 2) (sqrt (/ (* im im) (- (modulus re im) re))))) (* 1/2 (sqrt (* 2 (+ (modulus re im) re))))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))