
(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 9 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) (/ (* im 0.5) (sqrt re)) (* 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 = (im * 0.5) / sqrt(re);
} 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 = (im * 0.5) / Math.sqrt(re);
} 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 = (im * 0.5) / math.sqrt(re) 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(Float64(im * 0.5) / sqrt(re)); 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 = (im * 0.5) / sqrt(re); 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[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $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:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\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 5.1%
Taylor expanded in re around inf
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6445.5
Simplified45.5%
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6456.9
Applied egg-rr56.9%
associate-*l/N/A
sqrt-divN/A
sqrt-prodN/A
rem-square-sqrtN/A
associate-*r/N/A
*-rgt-identityN/A
/-lowering-/.f64N/A
*-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.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 44.3%
accelerator-lowering-hypot.f6491.2
Applied egg-rr91.2%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
(if (<= t_0 0.0)
(/ (* im 0.5) (sqrt re))
(if (<= t_0 4e-82)
(* 0.5 (sqrt (* re -4.0)))
(if (<= t_0 4e+75)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
(* 0.5 (sqrt (* 2.0 (- im re)))))))))
double code(double re, double im) {
double t_0 = sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
double tmp;
if (t_0 <= 0.0) {
tmp = (im * 0.5) / sqrt(re);
} else if (t_0 <= 4e-82) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (t_0 <= 4e+75) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
} else {
tmp = 0.5 * sqrt((2.0 * (im - re)));
}
return tmp;
}
function code(re, im) t_0 = sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(Float64(im * 0.5) / sqrt(re)); elseif (t_0 <= 4e-82) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (t_0 <= 4e+75) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - 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[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e-82], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 4e+75], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $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{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-82}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+75}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - 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 5.1%
Taylor expanded in re around inf
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6445.5
Simplified45.5%
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6456.9
Applied egg-rr56.9%
associate-*l/N/A
sqrt-divN/A
sqrt-prodN/A
rem-square-sqrtN/A
associate-*r/N/A
*-rgt-identityN/A
/-lowering-/.f64N/A
*-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.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))) < 4e-82Initial program 16.3%
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6416.3
Applied egg-rr16.3%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6467.0
Simplified67.0%
if 4e-82 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 3.99999999999999971e75Initial program 100.0%
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64100.0
Applied egg-rr100.0%
if 3.99999999999999971e75 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 3.6%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6465.5
Simplified65.5%
Final simplification81.7%
(FPCore (re im)
:precision binary64
(if (<= re -1.25e+107)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 2.25e+125)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (* im 0.5) (sqrt (/ 1.0 re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.25e+107) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.25e+125) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) * sqrt((1.0 / 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.25d+107)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.25d+125) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = (im * 0.5d0) * sqrt((1.0d0 / re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.25e+107) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.25e+125) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) * Math.sqrt((1.0 / re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.25e+107: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.25e+125: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (im * 0.5) * math.sqrt((1.0 / re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.25e+107) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.25e+125) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(im * 0.5) * sqrt(Float64(1.0 / re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.25e+107) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.25e+125) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (im * 0.5) * sqrt((1.0 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.25e+107], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.25e+125], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.25 \cdot 10^{+107}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.25 \cdot 10^{+125}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot \sqrt{\frac{1}{re}}\\
\end{array}
\end{array}
if re < -1.25e107Initial program 31.2%
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6431.2
Applied egg-rr31.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6485.0
Simplified85.0%
if -1.25e107 < re < 2.25e125Initial program 48.9%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6475.4
Simplified75.4%
if 2.25e125 < re Initial program 3.1%
Taylor expanded in re around inf
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6452.8
Simplified52.8%
Taylor expanded in im around 0
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6483.3
Simplified83.3%
Final simplification77.7%
(FPCore (re im)
:precision binary64
(if (<= re -1.42e+107)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 4.8e+124)
(* 0.5 (sqrt (* 2.0 (- im re))))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.42e+107) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4.8e+124) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} 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.42d+107)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4.8d+124) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
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.42e+107) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4.8e+124) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.42e+107: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4.8e+124: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.42e+107) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4.8e+124) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); 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.42e+107) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4.8e+124) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.42e+107], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.8e+124], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $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.42 \cdot 10^{+107}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4.8 \cdot 10^{+124}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.42000000000000006e107Initial program 31.2%
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6431.2
Applied egg-rr31.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6485.0
Simplified85.0%
if -1.42000000000000006e107 < re < 4.80000000000000013e124Initial program 48.9%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6475.4
Simplified75.4%
if 4.80000000000000013e124 < re Initial program 3.1%
Taylor expanded in re around inf
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6452.8
Simplified52.8%
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6468.0
Applied egg-rr68.0%
associate-*l/N/A
sqrt-divN/A
sqrt-prodN/A
rem-square-sqrtN/A
associate-*r/N/A
*-rgt-identityN/A
/-lowering-/.f64N/A
*-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6483.2
Applied egg-rr83.2%
Final simplification77.6%
(FPCore (re im)
:precision binary64
(if (<= re -4.4e+105)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 6e+124)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -4.4e+105) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6e+124) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} 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 <= (-4.4d+105)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6d+124) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
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 <= -4.4e+105) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6e+124) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.4e+105: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6e+124: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.4e+105) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6e+124) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.4e+105) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6e+124) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.4e+105], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6e+124], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.4 \cdot 10^{+105}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6 \cdot 10^{+124}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -4.40000000000000014e105Initial program 31.2%
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6431.2
Applied egg-rr31.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6485.0
Simplified85.0%
if -4.40000000000000014e105 < re < 5.9999999999999999e124Initial program 48.9%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6475.4
Simplified75.4%
if 5.9999999999999999e124 < re Initial program 3.1%
Taylor expanded in re around inf
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6452.8
Simplified52.8%
associate-*r*N/A
metadata-evalN/A
*-lft-identityN/A
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6468.0
Applied egg-rr68.0%
associate-*l/N/A
clear-numN/A
associate-/r/N/A
sqrt-prodN/A
sqrt-prodN/A
rem-square-sqrtN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-divN/A
metadata-evalN/A
associate-*l/N/A
metadata-evalN/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f6483.2
Applied egg-rr83.2%
Final simplification77.6%
(FPCore (re im) :precision binary64 (if (<= re -1.15e+106) (* 0.5 (sqrt (* re -4.0))) (if (<= re 2.1e+184) (* 0.5 (sqrt (* 2.0 (- im re)))) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -1.15e+106) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.1e+184) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.15d+106)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.1d+184) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.15e+106) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.1e+184) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.15e+106: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.1e+184: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -1.15e+106) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.1e+184) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.15e+106) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.1e+184) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.15e+106], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e+184], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.15 \cdot 10^{+106}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.1 \cdot 10^{+184}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -1.1500000000000001e106Initial program 31.2%
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6431.2
Applied egg-rr31.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6485.0
Simplified85.0%
if -1.1500000000000001e106 < re < 2.1e184Initial program 46.7%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6473.7
Simplified73.7%
if 2.1e184 < re Initial program 2.7%
Taylor expanded in re around inf
Simplified31.8%
pow1/2N/A
*-commutativeN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-eval31.8
Applied egg-rr31.8%
Final simplification71.3%
(FPCore (re im) :precision binary64 (if (<= re -3.3e-37) (* 0.5 (sqrt (* re -4.0))) (if (<= re 4.5e+192) (* 0.5 (sqrt (* 2.0 im))) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -3.3e-37) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4.5e+192) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.3d-37)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4.5d+192) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.3e-37) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4.5e+192) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.3e-37: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4.5e+192: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -3.3e-37) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4.5e+192) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.3e-37) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4.5e+192) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.3e-37], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.5e+192], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.3 \cdot 10^{-37}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4.5 \cdot 10^{+192}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -3.29999999999999982e-37Initial program 47.5%
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f6447.5
Applied egg-rr47.5%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6471.2
Simplified71.2%
if -3.29999999999999982e-37 < re < 4.5e192Initial program 43.2%
Taylor expanded in re around 0
Simplified76.2%
if 4.5e192 < re Initial program 2.6%
Taylor expanded in re around inf
Simplified33.0%
pow1/2N/A
*-commutativeN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-eval33.0
Applied egg-rr33.0%
Final simplification71.3%
(FPCore (re im) :precision binary64 (if (<= re 1.1e+193) (* 0.5 (sqrt (* 2.0 im))) 0.0))
double code(double re, double im) {
double tmp;
if (re <= 1.1e+193) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = 0.0;
}
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+193) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 1.1e+193) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.1e+193: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= 1.1e+193) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.1e+193) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.1e+193], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.1 \cdot 10^{+193}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < 1.09999999999999993e193Initial program 44.4%
Taylor expanded in re around 0
Simplified64.8%
if 1.09999999999999993e193 < re Initial program 2.6%
Taylor expanded in re around inf
Simplified33.0%
pow1/2N/A
*-commutativeN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-eval33.0
Applied egg-rr33.0%
(FPCore (re im) :precision binary64 0.0)
double code(double re, double im) {
return 0.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.0d0
end function
public static double code(double re, double im) {
return 0.0;
}
def code(re, im): return 0.0
function code(re, im) return 0.0 end
function tmp = code(re, im) tmp = 0.0; end
code[re_, im_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 40.8%
Taylor expanded in re around inf
Simplified5.7%
pow1/2N/A
*-commutativeN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-eval5.7
Applied egg-rr5.7%
herbie shell --seed 2024196
(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)))))