
(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) (* 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 / sqrt(re)) * 0.5;
} else {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if ((Math.sqrt(((re * re) + (im * im))) - re) <= 0.0) {
tmp = (im / Math.sqrt(re)) * 0.5;
} else {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if (math.sqrt(((re * re) + (im * im))) - re) <= 0.0: tmp = (im / math.sqrt(re)) * 0.5 else: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) return tmp
function code(re, im) tmp = 0.0 if (Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re) <= 0.0) tmp = Float64(Float64(im / sqrt(re)) * 0.5); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((sqrt(((re * re) + (im * im))) - re) <= 0.0) tmp = (im / sqrt(re)) * 0.5; 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 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $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}{\sqrt{re}} \cdot 0.5\\
\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 4.2%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6435.9
Simplified35.9%
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-divN/A
sqrt-prodN/A
rem-square-sqrtN/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f6492.7
Applied egg-rr92.7%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 49.9%
accelerator-lowering-hypot.f6489.2
Applied egg-rr89.2%
(FPCore (re im)
:precision binary64
(if (<= re -2e+43)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 3e-29)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* 0.5 (* im (sqrt (/ 1.0 re)))))))
double code(double re, double im) {
double tmp;
if (re <= -2e+43) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 3e-29) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * 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 <= (-2d+43)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 3d-29) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.5d0 * (im * sqrt((1.0d0 / re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2e+43) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 3e-29) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2e+43: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 3e-29: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * (im * math.sqrt((1.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -2e+43) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 3e-29) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2e+43) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 3e-29) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * (im * sqrt((1.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2e+43], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3e-29], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2 \cdot 10^{+43}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 3 \cdot 10^{-29}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\end{array}
\end{array}
if re < -2.00000000000000003e43Initial program 28.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6486.7
Simplified86.7%
if -2.00000000000000003e43 < re < 3.0000000000000003e-29Initial program 60.9%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6474.1
Simplified74.1%
if 3.0000000000000003e-29 < re Initial program 16.2%
Taylor expanded in re around inf
*-lowering-*.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6476.1
Simplified76.1%
*-commutativeN/A
associate-*r*N/A
sqrt-unprodN/A
metadata-evalN/A
metadata-evalN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6476.8
Applied egg-rr76.8%
Final simplification77.3%
(FPCore (re im)
:precision binary64
(if (<= re -2.4e+43)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 2.8e-29)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (sqrt (/ 1.0 re)) (* im 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -2.4e+43) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.8e-29) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = sqrt((1.0 / re)) * (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 <= (-2.4d+43)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.8d-29) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = sqrt((1.0d0 / re)) * (im * 0.5d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.4e+43) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.8e-29) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = Math.sqrt((1.0 / re)) * (im * 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.4e+43: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.8e-29: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = math.sqrt((1.0 / re)) * (im * 0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.4e+43) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.8e-29) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(sqrt(Float64(1.0 / re)) * Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.4e+43) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.8e-29) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = sqrt((1.0 / re)) * (im * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.4e+43], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.8e-29], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.4 \cdot 10^{+43}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.8 \cdot 10^{-29}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{re}} \cdot \left(im \cdot 0.5\right)\\
\end{array}
\end{array}
if re < -2.40000000000000023e43Initial program 28.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6486.7
Simplified86.7%
if -2.40000000000000023e43 < re < 2.8000000000000002e-29Initial program 60.9%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6474.1
Simplified74.1%
if 2.8000000000000002e-29 < re Initial program 16.2%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6445.3
Simplified45.3%
Taylor expanded in im around 0
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6476.8
Simplified76.8%
Final simplification77.3%
(FPCore (re im)
:precision binary64
(if (<= re -1.8e+43)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 4.1e-29)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e+43) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4.1e-29) {
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 <= (-1.8d+43)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4.1d-29) 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 <= -1.8e+43) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4.1e-29) {
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 <= -1.8e+43: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4.1e-29: 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 <= -1.8e+43) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4.1e-29) 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 <= -1.8e+43) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4.1e-29) 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, -1.8e+43], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.1e-29], 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 -1.8 \cdot 10^{+43}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4.1 \cdot 10^{-29}:\\
\;\;\;\;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 < -1.80000000000000005e43Initial program 28.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6486.7
Simplified86.7%
if -1.80000000000000005e43 < re < 4.0999999999999998e-29Initial program 60.9%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6474.1
Simplified74.1%
if 4.0999999999999998e-29 < re Initial program 16.2%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6445.3
Simplified45.3%
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-divN/A
sqrt-prodN/A
rem-square-sqrtN/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f6476.8
Applied egg-rr76.8%
(FPCore (re im)
:precision binary64
(if (<= re -1.95e+43)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.55e-29)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.95e+43) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.55e-29) {
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.95d+43)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.55d-29) 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.95e+43) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.55e-29) {
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.95e+43: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.55e-29: 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.95e+43) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.55e-29) 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.95e+43) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.55e-29) 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.95e+43], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.55e-29], 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.95 \cdot 10^{+43}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.55 \cdot 10^{-29}:\\
\;\;\;\;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.95e43Initial program 28.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6486.7
Simplified86.7%
if -1.95e43 < re < 1.55000000000000013e-29Initial program 60.9%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f6474.1
Simplified74.1%
if 1.55000000000000013e-29 < re Initial program 16.2%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6445.3
Simplified45.3%
*-commutativeN/A
sqrt-divN/A
associate-*l/N/A
sqrt-prodN/A
rem-square-sqrtN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f6476.7
Applied egg-rr76.7%
(FPCore (re im) :precision binary64 (if (<= re -1600.0) (* 0.5 (sqrt (* re -4.0))) (if (<= re 1.2e+201) (* 0.5 (sqrt (* im 2.0))) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -1600.0) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.2e+201) {
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 <= (-1600.0d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.2d+201) 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 <= -1600.0) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.2e+201) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1600.0: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.2e+201: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -1600.0) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.2e+201) 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 <= -1600.0) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.2e+201) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1600.0], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.2e+201], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1600:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.2 \cdot 10^{+201}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -1600Initial program 35.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6479.9
Simplified79.9%
if -1600 < re < 1.19999999999999996e201Initial program 50.7%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6465.7
Simplified65.7%
if 1.19999999999999996e201 < re Initial program 2.3%
Taylor expanded in re around inf
Simplified27.2%
pow1/2N/A
*-commutativeN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-eval27.2
Applied egg-rr27.2%
(FPCore (re im) :precision binary64 (if (<= re 6e+198) (* 0.5 (sqrt (* im 2.0))) 0.0))
double code(double re, double im) {
double tmp;
if (re <= 6e+198) {
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 <= 6d+198) 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 <= 6e+198) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 6e+198: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= 6e+198) 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 <= 6e+198) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 6e+198], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 6 \cdot 10^{+198}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < 6.00000000000000037e198Initial program 46.6%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6454.7
Simplified54.7%
if 6.00000000000000037e198 < re Initial program 2.3%
Taylor expanded in re around inf
Simplified27.2%
pow1/2N/A
*-commutativeN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-eval27.2
Applied egg-rr27.2%
(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.9%
Taylor expanded in re around inf
Simplified5.3%
pow1/2N/A
*-commutativeN/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-eval5.3
Applied egg-rr5.3%
herbie shell --seed 2024194
(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)))))