
(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 (+ (* 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(((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(((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(((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 (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(((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[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $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{re \cdot re + im \cdot im} - re \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 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 10.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-*.f6410.3
Applied egg-rr10.3%
Taylor expanded in im around 0
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6450.4
Simplified50.4%
sqrt-divN/A
sqrt-prodN/A
rem-square-sqrtN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6491.3
Applied egg-rr91.3%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 48.6%
accelerator-lowering-hypot.f6492.6
Applied egg-rr92.6%
(FPCore (re im)
:precision binary64
(if (<= re -2.05e+124)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re -5.2e-45)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
(if (<= re 0.000235)
(* 0.5 (sqrt (* 2.0 (- im re))))
(/ (* im 0.5) (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -2.05e+124) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= -5.2e-45) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
} else if (re <= 0.000235) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) / sqrt(re);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -2.05e+124) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= -5.2e-45) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re)))); elseif (re <= 0.000235) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
code[re_, im_] := If[LessEqual[re, -2.05e+124], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -5.2e-45], 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], If[LessEqual[re, 0.000235], 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 -2.05 \cdot 10^{+124}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq -5.2 \cdot 10^{-45}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
\mathbf{elif}\;re \leq 0.000235:\\
\;\;\;\;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 < -2.05000000000000001e124Initial program 15.9%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6486.7
Simplified86.7%
if -2.05000000000000001e124 < re < -5.19999999999999973e-45Initial program 89.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-*.f6489.3
Applied egg-rr89.3%
if -5.19999999999999973e-45 < re < 2.34999999999999993e-4Initial program 51.3%
Taylor expanded in re around 0
Simplified79.8%
if 2.34999999999999993e-4 < re Initial program 15.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-*.f6415.5
Applied egg-rr15.5%
Taylor expanded in im around 0
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6455.1
Simplified55.1%
sqrt-divN/A
sqrt-prodN/A
rem-square-sqrtN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6479.7
Applied egg-rr79.7%
Final simplification82.2%
(FPCore (re im)
:precision binary64
(if (<= re -3e+16)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 0.000118)
(* 0.5 (sqrt (* 2.0 (- im re))))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -3e+16) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 0.000118) {
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 <= (-3d+16)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 0.000118d0) 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 <= -3e+16) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 0.000118) {
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 <= -3e+16: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 0.000118: 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 <= -3e+16) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 0.000118) 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 <= -3e+16) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 0.000118) 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, -3e+16], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 0.000118], 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 -3 \cdot 10^{+16}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 0.000118:\\
\;\;\;\;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 < -3e16Initial program 42.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6480.3
Simplified80.3%
if -3e16 < re < 1.18e-4Initial program 55.1%
Taylor expanded in re around 0
Simplified77.6%
if 1.18e-4 < re Initial program 15.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-*.f6415.5
Applied egg-rr15.5%
Taylor expanded in im around 0
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6455.1
Simplified55.1%
sqrt-divN/A
sqrt-prodN/A
rem-square-sqrtN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6479.7
Applied egg-rr79.7%
(FPCore (re im)
:precision binary64
(if (<= re -1.12e+15)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 0.00013)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.12e+15) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 0.00013) {
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.12d+15)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 0.00013d0) 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.12e+15) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 0.00013) {
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.12e+15: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 0.00013: 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.12e+15) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 0.00013) 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 <= -1.12e+15) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 0.00013) 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.12e+15], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 0.00013], 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 -1.12 \cdot 10^{+15}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 0.00013:\\
\;\;\;\;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 < -1.12e15Initial program 42.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6480.3
Simplified80.3%
if -1.12e15 < re < 1.29999999999999989e-4Initial program 55.1%
Taylor expanded in re around 0
Simplified77.6%
if 1.29999999999999989e-4 < re Initial program 15.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-*.f6415.5
Applied egg-rr15.5%
Taylor expanded in im around 0
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6455.1
Simplified55.1%
div-invN/A
sqrt-prodN/A
sqrt-prodN/A
rem-square-sqrtN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
sqrt-unprodN/A
associate-*r*N/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
Applied egg-rr79.6%
Final simplification78.8%
(FPCore (re im) :precision binary64 (if (<= re -5.2e-44) (* 0.5 (sqrt (* re -4.0))) (if (<= re 1.95e+151) (* 0.5 (sqrt (* im 2.0))) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -5.2e-44) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.95e+151) {
tmp = 0.5 * sqrt((im * 2.0));
} 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 <= (-5.2d-44)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.95d+151) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -5.2e-44) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.95e+151) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5.2e-44: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.95e+151: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -5.2e-44) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.95e+151) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5.2e-44) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.95e+151) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5.2e-44], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.95e+151], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5.2 \cdot 10^{-44}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.95 \cdot 10^{+151}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -5.1999999999999996e-44Initial program 50.2%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6475.4
Simplified75.4%
if -5.1999999999999996e-44 < re < 1.94999999999999988e151Initial program 44.8%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6469.8
Simplified69.8%
if 1.94999999999999988e151 < re Initial program 5.9%
Taylor expanded in re around inf
Simplified36.2%
pow1/2N/A
*-commutativeN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-eval36.2
Applied egg-rr36.2%
(FPCore (re im) :precision binary64 (if (<= im 1.25e-240) 0.0 (* 0.5 (sqrt (* im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 1.25e-240) {
tmp = 0.0;
} else {
tmp = 0.5 * sqrt((im * 2.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.25d-240) then
tmp = 0.0d0
else
tmp = 0.5d0 * sqrt((im * 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.25e-240) {
tmp = 0.0;
} else {
tmp = 0.5 * Math.sqrt((im * 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.25e-240: tmp = 0.0 else: tmp = 0.5 * math.sqrt((im * 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.25e-240) tmp = 0.0; else tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.25e-240) tmp = 0.0; else tmp = 0.5 * sqrt((im * 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.25e-240], 0.0, N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.25 \cdot 10^{-240}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if im < 1.2500000000000001e-240Initial program 43.1%
Taylor expanded in re around inf
Simplified29.6%
pow1/2N/A
*-commutativeN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-eval29.6
Applied egg-rr29.6%
if 1.2500000000000001e-240 < im Initial program 41.9%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6457.4
Simplified57.4%
(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 42.0%
Taylor expanded in re around inf
Simplified7.6%
pow1/2N/A
*-commutativeN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-eval7.6
Applied egg-rr7.6%
herbie shell --seed 2024204
(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)))))