
(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 8 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 (+ (* re re) (* im im))) re) 0.0) (* (/ im (sqrt re)) 0.5) (* (sqrt (* (- (hypot im re) re) 2.0)) 0.5)))
double code(double re, double im) {
double tmp;
if ((sqrt(((re * re) + (im * im))) - re) <= 0.0) {
tmp = (im / sqrt(re)) * 0.5;
} else {
tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if ((Math.sqrt(((re * re) + (im * im))) - re) <= 0.0) {
tmp = (im / Math.sqrt(re)) * 0.5;
} else {
tmp = Math.sqrt(((Math.hypot(im, re) - re) * 2.0)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if (math.sqrt(((re * re) + (im * im))) - re) <= 0.0: tmp = (im / math.sqrt(re)) * 0.5 else: tmp = math.sqrt(((math.hypot(im, re) - re) * 2.0)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re) <= 0.0) tmp = Float64(Float64(im / sqrt(re)) * 0.5); else tmp = Float64(sqrt(Float64(Float64(hypot(im, re) - re) * 2.0)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((sqrt(((re * re) + (im * im))) - re) <= 0.0) tmp = (im / sqrt(re)) * 0.5; else tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision], 0.0], N[(N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Sqrt[N[(N[(N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision] - re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{re \cdot re + im \cdot im} - re \leq 0:\\
\;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 7.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f647.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f647.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6412.8
Applied rewrites12.8%
Taylor expanded in re around 0
lower-*.f6411.8
Applied rewrites11.8%
Taylor expanded in re around inf
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6494.3
Applied rewrites94.3%
Applied rewrites95.0%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 43.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.9
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6490.6
Applied rewrites90.6%
Final simplification91.3%
(FPCore (re im)
:precision binary64
(if (<= re -2.9e-58)
(* (sqrt (* -4.0 re)) 0.5)
(if (<= re 5.3e-51)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* 0.5 (* (sqrt (pow re -1.0)) im)))))
double code(double re, double im) {
double tmp;
if (re <= -2.9e-58) {
tmp = sqrt((-4.0 * re)) * 0.5;
} else if (re <= 5.3e-51) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (sqrt(pow(re, -1.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 <= (-2.9d-58)) then
tmp = sqrt(((-4.0d0) * re)) * 0.5d0
else if (re <= 5.3d-51) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.5d0 * (sqrt((re ** (-1.0d0))) * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.9e-58) {
tmp = Math.sqrt((-4.0 * re)) * 0.5;
} else if (re <= 5.3e-51) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (Math.sqrt(Math.pow(re, -1.0)) * im);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.9e-58: tmp = math.sqrt((-4.0 * re)) * 0.5 elif re <= 5.3e-51: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * (math.sqrt(math.pow(re, -1.0)) * im) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.9e-58) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); elseif (re <= 5.3e-51) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(0.5 * Float64(sqrt((re ^ -1.0)) * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.9e-58) tmp = sqrt((-4.0 * re)) * 0.5; elseif (re <= 5.3e-51) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * (sqrt((re ^ -1.0)) * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.9e-58], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 5.3e-51], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Sqrt[N[Power[re, -1.0], $MachinePrecision]], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.9 \cdot 10^{-58}:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{elif}\;re \leq 5.3 \cdot 10^{-51}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{{re}^{-1}} \cdot im\right)\\
\end{array}
\end{array}
if re < -2.8999999999999999e-58Initial program 45.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.7
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -2.8999999999999999e-58 < re < 5.29999999999999974e-51Initial program 48.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6480.0
Applied rewrites80.0%
if 5.29999999999999974e-51 < re Initial program 15.8%
Taylor expanded in im around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-pow.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
unpow2N/A
lower-*.f6443.4
Applied rewrites43.4%
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
pow2N/A
lower-pow.f64N/A
Applied rewrites46.8%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6473.1
Applied rewrites73.1%
Final simplification77.2%
(FPCore (re im)
:precision binary64
(let* ((t_0 (- (sqrt (+ (* re re) (* im im))) re)))
(if (<= t_0 0.0)
(* (/ im (sqrt re)) 0.5)
(if (<= t_0 2e+154)
(* 0.5 (sqrt (* 2.0 t_0)))
(* 0.5 (sqrt (* 2.0 (- im re))))))))
double code(double re, double im) {
double t_0 = sqrt(((re * re) + (im * im))) - re;
double tmp;
if (t_0 <= 0.0) {
tmp = (im / sqrt(re)) * 0.5;
} else if (t_0 <= 2e+154) {
tmp = 0.5 * sqrt((2.0 * t_0));
} else {
tmp = 0.5 * sqrt((2.0 * (im - 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))) - re
if (t_0 <= 0.0d0) then
tmp = (im / sqrt(re)) * 0.5d0
else if (t_0 <= 2d+154) then
tmp = 0.5d0 * sqrt((2.0d0 * t_0))
else
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt(((re * re) + (im * im))) - re;
double tmp;
if (t_0 <= 0.0) {
tmp = (im / Math.sqrt(re)) * 0.5;
} else if (t_0 <= 2e+154) {
tmp = 0.5 * Math.sqrt((2.0 * t_0));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt(((re * re) + (im * im))) - re tmp = 0 if t_0 <= 0.0: tmp = (im / math.sqrt(re)) * 0.5 elif t_0 <= 2e+154: tmp = 0.5 * math.sqrt((2.0 * t_0)) else: tmp = 0.5 * math.sqrt((2.0 * (im - re))) return tmp
function code(re, im) t_0 = Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(Float64(im / sqrt(re)) * 0.5); elseif (t_0 <= 2e+154) tmp = Float64(0.5 * sqrt(Float64(2.0 * t_0))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt(((re * re) + (im * im))) - re; tmp = 0.0; if (t_0 <= 0.0) tmp = (im / sqrt(re)) * 0.5; elseif (t_0 <= 2e+154) tmp = 0.5 * sqrt((2.0 * t_0)); else tmp = 0.5 * sqrt((2.0 * (im - re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 2e+154], N[(0.5 * N[Sqrt[N[(2.0 * t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{re \cdot re + im \cdot im} - re\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 7.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f647.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f647.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6412.8
Applied rewrites12.8%
Taylor expanded in re around 0
lower-*.f6411.8
Applied rewrites11.8%
Taylor expanded in re around inf
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6494.3
Applied rewrites94.3%
Applied rewrites95.0%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 2.00000000000000007e154Initial program 93.0%
if 2.00000000000000007e154 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 3.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6459.0
Applied rewrites59.0%
Final simplification77.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (- (sqrt (+ (* re re) (* im im))) re)))
(if (<= t_0 0.0)
(* (/ im (sqrt re)) 0.5)
(if (<= t_0 2e+154)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(* 0.5 (sqrt (* 2.0 (- im re))))))))
double code(double re, double im) {
double t_0 = sqrt(((re * re) + (im * im))) - re;
double tmp;
if (t_0 <= 0.0) {
tmp = (im / sqrt(re)) * 0.5;
} else if (t_0 <= 2e+154) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else {
tmp = 0.5 * sqrt((2.0 * (im - re)));
}
return tmp;
}
function code(re, im) t_0 = Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(Float64(im / sqrt(re)) * 0.5); elseif (t_0 <= 2e+154) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 2e+154], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{re \cdot re + im \cdot im} - re\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 7.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f647.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f647.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6412.8
Applied rewrites12.8%
Taylor expanded in re around 0
lower-*.f6411.8
Applied rewrites11.8%
Taylor expanded in re around inf
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6494.3
Applied rewrites94.3%
Applied rewrites95.0%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 2.00000000000000007e154Initial program 93.0%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6493.0
Applied rewrites93.0%
if 2.00000000000000007e154 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 3.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6459.0
Applied rewrites59.0%
Final simplification77.5%
(FPCore (re im)
:precision binary64
(if (<= re -2.9e-58)
(* (sqrt (* -4.0 re)) 0.5)
(if (<= re 5.3e-51)
(* (sqrt (fma (- (/ re im) 2.0) re (* 2.0 im))) 0.5)
(* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -2.9e-58) {
tmp = sqrt((-4.0 * re)) * 0.5;
} else if (re <= 5.3e-51) {
tmp = sqrt(fma(((re / im) - 2.0), re, (2.0 * im))) * 0.5;
} else {
tmp = (im / sqrt(re)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -2.9e-58) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); elseif (re <= 5.3e-51) tmp = Float64(sqrt(fma(Float64(Float64(re / im) - 2.0), re, Float64(2.0 * im))) * 0.5); else tmp = Float64(Float64(im / sqrt(re)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -2.9e-58], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 5.3e-51], N[(N[Sqrt[N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + N[(2.0 * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.9 \cdot 10^{-58}:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{elif}\;re \leq 5.3 \cdot 10^{-51}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
\end{array}
\end{array}
if re < -2.8999999999999999e-58Initial program 45.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.7
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -2.8999999999999999e-58 < re < 5.29999999999999974e-51Initial program 48.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6448.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6448.8
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6489.3
Applied rewrites89.3%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6480.1
Applied rewrites80.1%
if 5.29999999999999974e-51 < re Initial program 15.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6415.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6415.8
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6440.4
Applied rewrites40.4%
Taylor expanded in re around 0
lower-*.f6430.8
Applied rewrites30.8%
Taylor expanded in re around inf
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6472.7
Applied rewrites72.7%
Applied rewrites73.2%
Final simplification77.3%
(FPCore (re im)
:precision binary64
(if (<= re -2.9e-58)
(* (sqrt (* -4.0 re)) 0.5)
(if (<= re 5.3e-51)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -2.9e-58) {
tmp = sqrt((-4.0 * re)) * 0.5;
} else if (re <= 5.3e-51) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (im / sqrt(re)) * 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 <= (-2.9d-58)) then
tmp = sqrt(((-4.0d0) * re)) * 0.5d0
else if (re <= 5.3d-51) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = (im / sqrt(re)) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.9e-58) {
tmp = Math.sqrt((-4.0 * re)) * 0.5;
} else if (re <= 5.3e-51) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (im / Math.sqrt(re)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.9e-58: tmp = math.sqrt((-4.0 * re)) * 0.5 elif re <= 5.3e-51: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (im / math.sqrt(re)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= -2.9e-58) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); elseif (re <= 5.3e-51) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(im / sqrt(re)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.9e-58) tmp = sqrt((-4.0 * re)) * 0.5; elseif (re <= 5.3e-51) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (im / sqrt(re)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.9e-58], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 5.3e-51], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.9 \cdot 10^{-58}:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{elif}\;re \leq 5.3 \cdot 10^{-51}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
\end{array}
\end{array}
if re < -2.8999999999999999e-58Initial program 45.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.7
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -2.8999999999999999e-58 < re < 5.29999999999999974e-51Initial program 48.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6480.0
Applied rewrites80.0%
if 5.29999999999999974e-51 < re Initial program 15.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6415.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6415.8
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6440.4
Applied rewrites40.4%
Taylor expanded in re around 0
lower-*.f6430.8
Applied rewrites30.8%
Taylor expanded in re around inf
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6472.7
Applied rewrites72.7%
Applied rewrites73.2%
Final simplification77.3%
(FPCore (re im) :precision binary64 (if (<= re -1.85e-58) (* (sqrt (* -4.0 re)) 0.5) (* (sqrt (* 2.0 im)) 0.5)))
double code(double re, double im) {
double tmp;
if (re <= -1.85e-58) {
tmp = sqrt((-4.0 * re)) * 0.5;
} else {
tmp = sqrt((2.0 * 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.85d-58)) then
tmp = sqrt(((-4.0d0) * re)) * 0.5d0
else
tmp = sqrt((2.0d0 * im)) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.85e-58) {
tmp = Math.sqrt((-4.0 * re)) * 0.5;
} else {
tmp = Math.sqrt((2.0 * im)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.85e-58: tmp = math.sqrt((-4.0 * re)) * 0.5 else: tmp = math.sqrt((2.0 * im)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= -1.85e-58) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); else tmp = Float64(sqrt(Float64(2.0 * im)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.85e-58) tmp = sqrt((-4.0 * re)) * 0.5; else tmp = sqrt((2.0 * im)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.85e-58], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.85 \cdot 10^{-58}:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 \cdot im} \cdot 0.5\\
\end{array}
\end{array}
if re < -1.8500000000000001e-58Initial program 45.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.7
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -1.8500000000000001e-58 < re Initial program 34.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6434.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6434.5
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6468.1
Applied rewrites68.1%
Taylor expanded in re around 0
lower-*.f6458.3
Applied rewrites58.3%
(FPCore (re im) :precision binary64 (* (sqrt (* -4.0 re)) 0.5))
double code(double re, double im) {
return sqrt((-4.0 * re)) * 0.5;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt(((-4.0d0) * re)) * 0.5d0
end function
public static double code(double re, double im) {
return Math.sqrt((-4.0 * re)) * 0.5;
}
def code(re, im): return math.sqrt((-4.0 * re)) * 0.5
function code(re, im) return Float64(sqrt(Float64(-4.0 * re)) * 0.5) end
function tmp = code(re, im) tmp = sqrt((-4.0 * re)) * 0.5; end
code[re_, im_] := N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{-4 \cdot re} \cdot 0.5
\end{array}
Initial program 38.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6438.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6438.1
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6478.4
Applied rewrites78.4%
Taylor expanded in re around -inf
lower-*.f6430.0
Applied rewrites30.0%
herbie shell --seed 2024323
(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)))))