
(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) (* (pow re -0.5) (* im 0.5)) (* 0.5 (sqrt (* 2.0 (- (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 = pow(re, -0.5) * (im * 0.5);
} else {
tmp = 0.5 * sqrt((2.0 * (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 = Math.pow(re, -0.5) * (im * 0.5);
} else {
tmp = 0.5 * Math.sqrt((2.0 * (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 = math.pow(re, -0.5) * (im * 0.5) else: tmp = 0.5 * math.sqrt((2.0 * (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((re ^ -0.5) * Float64(im * 0.5)); else tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 = (re ^ -0.5) * (im * 0.5); else tmp = 0.5 * sqrt((2.0 * (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[(N[Power[re, -0.5], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $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:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\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 8.5%
pow1/2N/A
sqr-powN/A
pow2N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
accelerator-lowering-hypot.f64N/A
metadata-eval8.5%
Applied egg-rr8.5%
Taylor expanded in re around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6499.4%
Simplified99.4%
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
pow1/2N/A
inv-powN/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f6499.6%
Applied egg-rr99.6%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 42.0%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
accelerator-lowering-hypot.f6491.5%
Simplified91.5%
(FPCore (re im)
:precision binary64
(if (<= re -2e-38)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.72e-71)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (pow re -0.5) (* im 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -2e-38) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.72e-71) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = pow(re, -0.5) * (im * 0.5);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-2d-38)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.72d-71) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = (re ** (-0.5d0)) * (im * 0.5d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2e-38) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.72e-71) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = Math.pow(re, -0.5) * (im * 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2e-38: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.72e-71: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = math.pow(re, -0.5) * (im * 0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -2e-38) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.72e-71) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64((re ^ -0.5) * Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2e-38) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.72e-71) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (re ^ -0.5) * (im * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2e-38], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.72e-71], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Power[re, -0.5], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2 \cdot 10^{-38}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.72 \cdot 10^{-71}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\end{array}
\end{array}
if re < -1.9999999999999999e-38Initial program 42.8%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6479.5%
Simplified79.5%
if -1.9999999999999999e-38 < re < 1.72e-71Initial program 53.2%
Taylor expanded in re around 0
Simplified86.2%
if 1.72e-71 < re Initial program 8.1%
pow1/2N/A
sqr-powN/A
pow2N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
accelerator-lowering-hypot.f64N/A
metadata-eval40.5%
Applied egg-rr40.5%
Taylor expanded in re around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6480.4%
Simplified80.4%
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
pow1/2N/A
inv-powN/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f6480.4%
Applied egg-rr80.4%
(FPCore (re im)
:precision binary64
(if (<= re -1.7e-54)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 3.25e-72)
(* 0.5 (sqrt (* 2.0 im)))
(* (pow re -0.5) (* im 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.7e-54) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 3.25e-72) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = pow(re, -0.5) * (im * 0.5);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.7d-54)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 3.25d-72) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = (re ** (-0.5d0)) * (im * 0.5d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.7e-54) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 3.25e-72) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = Math.pow(re, -0.5) * (im * 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.7e-54: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 3.25e-72: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = math.pow(re, -0.5) * (im * 0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.7e-54) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 3.25e-72) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64((re ^ -0.5) * Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.7e-54) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 3.25e-72) tmp = 0.5 * sqrt((2.0 * im)); else tmp = (re ^ -0.5) * (im * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.7e-54], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.25e-72], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Power[re, -0.5], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.7 \cdot 10^{-54}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 3.25 \cdot 10^{-72}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\end{array}
\end{array}
if re < -1.69999999999999994e-54Initial program 44.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6478.9%
Simplified78.9%
if -1.69999999999999994e-54 < re < 3.2499999999999998e-72Initial program 52.3%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6485.8%
Simplified85.8%
if 3.2499999999999998e-72 < re Initial program 8.1%
pow1/2N/A
sqr-powN/A
pow2N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
accelerator-lowering-hypot.f64N/A
metadata-eval40.5%
Applied egg-rr40.5%
Taylor expanded in re around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6480.4%
Simplified80.4%
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
pow1/2N/A
inv-powN/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-evalN/A
*-commutativeN/A
*-lowering-*.f6480.4%
Applied egg-rr80.4%
Final simplification82.1%
(FPCore (re im) :precision binary64 (if (<= re -1.45e-53) (* 0.5 (sqrt (* re -4.0))) (if (<= re 4e-68) (* 0.5 (sqrt (* 2.0 im))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.45e-53) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4e-68) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = (im * 0.5) / 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.45d-53)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4d-68) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = (im * 0.5d0) / sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.45e-53) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4e-68) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.45e-53: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4e-68: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.45e-53) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4e-68) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.45e-53) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4e-68) tmp = 0.5 * sqrt((2.0 * im)); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.45e-53], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4e-68], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.45 \cdot 10^{-53}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4 \cdot 10^{-68}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.4499999999999999e-53Initial program 44.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6478.9%
Simplified78.9%
if -1.4499999999999999e-53 < re < 4.00000000000000027e-68Initial program 52.3%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6485.8%
Simplified85.8%
if 4.00000000000000027e-68 < re Initial program 8.1%
pow1/2N/A
sqr-powN/A
pow2N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
accelerator-lowering-hypot.f64N/A
metadata-eval40.5%
Applied egg-rr40.5%
Taylor expanded in re around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6480.4%
Simplified80.4%
associate-*r*N/A
sqrt-divN/A
metadata-evalN/A
un-div-invN/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6480.4%
Applied egg-rr80.4%
Final simplification82.1%
(FPCore (re im) :precision binary64 (if (<= re -9.8e-54) (* 0.5 (sqrt (* re -4.0))) (if (<= re 4.5e-72) (* 0.5 (sqrt (* 2.0 im))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -9.8e-54) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4.5e-72) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = im * (0.5 / 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 <= (-9.8d-54)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4.5d-72) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = im * (0.5d0 / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -9.8e-54) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4.5e-72) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -9.8e-54: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4.5e-72: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -9.8e-54) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4.5e-72) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -9.8e-54) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4.5e-72) tmp = 0.5 * sqrt((2.0 * im)); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -9.8e-54], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.5e-72], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -9.8 \cdot 10^{-54}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4.5 \cdot 10^{-72}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -9.80000000000000042e-54Initial program 44.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6478.9%
Simplified78.9%
if -9.80000000000000042e-54 < re < 4.5e-72Initial program 52.3%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6485.8%
Simplified85.8%
if 4.5e-72 < re Initial program 8.1%
pow1/2N/A
sqr-powN/A
pow2N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
accelerator-lowering-hypot.f64N/A
metadata-eval40.5%
Applied egg-rr40.5%
Taylor expanded in re around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6480.4%
Simplified80.4%
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
*-lowering-*.f64N/A
sqrt-divN/A
metadata-evalN/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f6480.3%
Applied egg-rr80.3%
Final simplification82.1%
(FPCore (re im) :precision binary64 (if (<= re -1.7e-53) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (re <= -1.7e-53) {
tmp = 0.5 * sqrt((re * -4.0));
} else {
tmp = 0.5 * sqrt((2.0 * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.7d-53)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = 0.5d0 * sqrt((2.0d0 * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.7e-53) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.7e-53: tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.7e-53) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.7e-53) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.7e-53], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.7 \cdot 10^{-53}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -1.7e-53Initial program 44.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6478.9%
Simplified78.9%
if -1.7e-53 < re Initial program 35.3%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6462.3%
Simplified62.3%
Final simplification67.8%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 im))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * im))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * im));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * im))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * im))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * im)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot im}
\end{array}
Initial program 38.2%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6450.2%
Simplified50.2%
Final simplification50.2%
herbie shell --seed 2024191
(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)))))