
(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) (/ (* 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 8.7%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6449.4%
Simplified49.4%
*-commutativeN/A
sqrt-divN/A
associate-*l/N/A
sqrt-prodN/A
rem-square-sqrtN/A
metadata-evalN/A
associate-*l*N/A
metadata-evalN/A
metadata-evalN/A
sqrt-unprodN/A
associate-*l*N/A
*-commutativeN/A
/-lowering-/.f64N/A
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.5%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6491.9%
Simplified91.9%
Final simplification92.7%
(FPCore (re im)
:precision binary64
(if (<= re -3.8e+104)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 4e-44)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -3.8e+104) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4e-44) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) * pow(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 <= (-3.8d+104)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4d-44) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.8e+104) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4e-44) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.8e+104: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4e-44: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.8e+104) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4e-44) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.8e+104) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4e-44) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.8e+104], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4e-44], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.8 \cdot 10^{+104}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4 \cdot 10^{-44}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -3.79999999999999969e104Initial program 26.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6482.8%
Simplified82.8%
if -3.79999999999999969e104 < re < 3.99999999999999981e-44Initial program 55.6%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6477.4%
Simplified77.4%
if 3.99999999999999981e-44 < re Initial program 11.2%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6439.8%
Simplified39.8%
*-commutativeN/A
sqrt-divN/A
associate-*l/N/A
div-invN/A
sqrt-prodN/A
rem-square-sqrtN/A
metadata-evalN/A
sqrt-divN/A
metadata-evalN/A
associate-*l*N/A
metadata-evalN/A
metadata-evalN/A
sqrt-unprodN/A
associate-*l*N/A
*-commutativeN/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
Applied egg-rr74.1%
Final simplification77.5%
(FPCore (re im)
:precision binary64
(if (<= re -1.36e+63)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.75e-19)
(* 0.5 (sqrt (* 2.0 im)))
(* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.36e+63) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.75e-19) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = (im * 0.5) * pow(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 <= (-1.36d+63)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.75d-19) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.36e+63) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.75e-19) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.36e+63: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.75e-19: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.36e+63) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.75e-19) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.36e+63) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.75e-19) tmp = 0.5 * sqrt((2.0 * im)); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.36e+63], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.75e-19], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.36 \cdot 10^{+63}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.75 \cdot 10^{-19}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -1.36000000000000006e63Initial program 29.9%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6478.6%
Simplified78.6%
if -1.36000000000000006e63 < re < 1.75000000000000008e-19Initial program 54.2%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6474.7%
Simplified74.7%
if 1.75000000000000008e-19 < re Initial program 8.8%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6441.2%
Simplified41.2%
*-commutativeN/A
sqrt-divN/A
associate-*l/N/A
div-invN/A
sqrt-prodN/A
rem-square-sqrtN/A
metadata-evalN/A
sqrt-divN/A
metadata-evalN/A
associate-*l*N/A
metadata-evalN/A
metadata-evalN/A
sqrt-unprodN/A
associate-*l*N/A
*-commutativeN/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
Applied egg-rr77.1%
Final simplification76.1%
(FPCore (re im) :precision binary64 (if (<= re -6.2e+62) (* 0.5 (sqrt (* re -4.0))) (if (<= re 1e-14) (* 0.5 (sqrt (* 2.0 im))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -6.2e+62) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1e-14) {
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 <= (-6.2d+62)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1d-14) 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 <= -6.2e+62) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1e-14) {
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 <= -6.2e+62: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1e-14: 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 <= -6.2e+62) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1e-14) 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 <= -6.2e+62) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1e-14) 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, -6.2e+62], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1e-14], 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 -6.2 \cdot 10^{+62}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 10^{-14}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -6.20000000000000029e62Initial program 29.9%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6478.6%
Simplified78.6%
if -6.20000000000000029e62 < re < 9.99999999999999999e-15Initial program 53.6%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6474.4%
Simplified74.4%
if 9.99999999999999999e-15 < re Initial program 8.9%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6442.5%
Simplified42.5%
*-commutativeN/A
sqrt-divN/A
associate-*l/N/A
sqrt-prodN/A
rem-square-sqrtN/A
metadata-evalN/A
associate-*l*N/A
metadata-evalN/A
metadata-evalN/A
sqrt-unprodN/A
associate-*l*N/A
*-commutativeN/A
/-lowering-/.f64N/A
Applied egg-rr77.9%
Final simplification76.1%
(FPCore (re im) :precision binary64 (if (<= re -6.4e+68) (* 0.5 (sqrt (* re -4.0))) (if (<= re 2.1e-15) (* 0.5 (sqrt (* 2.0 im))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -6.4e+68) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.1e-15) {
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 <= (-6.4d+68)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.1d-15) 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 <= -6.4e+68) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.1e-15) {
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 <= -6.4e+68: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.1e-15: 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 <= -6.4e+68) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.1e-15) 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 <= -6.4e+68) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.1e-15) 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, -6.4e+68], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-15], 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 -6.4 \cdot 10^{+68}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.1 \cdot 10^{-15}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -6.39999999999999989e68Initial program 29.9%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6478.6%
Simplified78.6%
if -6.39999999999999989e68 < re < 2.09999999999999981e-15Initial program 53.6%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6474.4%
Simplified74.4%
if 2.09999999999999981e-15 < re Initial program 8.9%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6442.5%
Simplified42.5%
*-commutativeN/A
div-invN/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
un-div-invN/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f6477.8%
Applied egg-rr77.8%
Final simplification76.1%
(FPCore (re im) :precision binary64 (if (<= re -2.4e+68) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (re <= -2.4e+68) {
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 <= (-2.4d+68)) 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 <= -2.4e+68) {
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 <= -2.4e+68: 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 <= -2.4e+68) 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 <= -2.4e+68) 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, -2.4e+68], 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 -2.4 \cdot 10^{+68}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -2.40000000000000008e68Initial program 29.9%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6478.6%
Simplified78.6%
if -2.40000000000000008e68 < re Initial program 41.3%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6461.6%
Simplified61.6%
Final simplification65.3%
(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.8%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6454.1%
Simplified54.1%
Final simplification54.1%
herbie shell --seed 2024145
(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)))))