
(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 (<= re 1.12e+35) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re)))) (* (/ im (sqrt re)) 0.5)))
double code(double re, double im) {
double tmp;
if (re <= 1.12e+35) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else {
tmp = (im / sqrt(re)) * 0.5;
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 1.12e+35) {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
} else {
tmp = (im / Math.sqrt(re)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.12e+35: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) else: tmp = (im / math.sqrt(re)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= 1.12e+35) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, 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.12e+35) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); else tmp = (im / sqrt(re)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.12e+35], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - 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.12 \cdot 10^{+35}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
\end{array}
\end{array}
if re < 1.12000000000000003e35Initial program 48.4%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6491.7
Applied rewrites91.7%
if 1.12000000000000003e35 < re Initial program 9.6%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6432.8
Applied rewrites32.8%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6482.0
Applied rewrites82.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.0
Applied rewrites82.8%
(FPCore (re im)
:precision binary64
(if (<= re -6.8e+89)
(* (* 0.5 (sqrt 2.0)) (sqrt (* -2.0 re)))
(if (<= re -3.2e-58)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(if (<= re 8.9e+33)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (/ im (sqrt re)) 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -6.8e+89) {
tmp = (0.5 * sqrt(2.0)) * sqrt((-2.0 * re));
} else if (re <= -3.2e-58) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else if (re <= 8.9e+33) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (im / sqrt(re)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -6.8e+89) tmp = Float64(Float64(0.5 * sqrt(2.0)) * sqrt(Float64(-2.0 * re))); elseif (re <= -3.2e-58) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); elseif (re <= 8.9e+33) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(im / sqrt(re)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -6.8e+89], N[(N[(0.5 * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(-2.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -3.2e-58], 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], If[LessEqual[re, 8.9e+33], 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 -6.8 \cdot 10^{+89}:\\
\;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{-2 \cdot re}\\
\mathbf{elif}\;re \leq -3.2 \cdot 10^{-58}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{elif}\;re \leq 8.9 \cdot 10^{+33}:\\
\;\;\;\;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 < -6.8000000000000004e89Initial program 24.4%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6498.3
Applied rewrites98.3%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
sqrt-prodN/A
lift-sqrt.f64N/A
pow1/2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6424.2
Applied rewrites99.0%
Taylor expanded in re around -inf
lower-*.f6480.5
Applied rewrites80.5%
if -6.8000000000000004e89 < re < -3.2000000000000001e-58Initial program 86.3%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6486.3
Applied rewrites86.3%
if -3.2000000000000001e-58 < re < 8.9000000000000005e33Initial program 51.2%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6478.5
Applied rewrites78.5%
if 8.9000000000000005e33 < re Initial program 9.6%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6432.8
Applied rewrites32.8%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6482.0
Applied rewrites82.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.0
Applied rewrites82.8%
Final simplification80.9%
(FPCore (re im)
:precision binary64
(if (<= re -1.5e+32)
(* (* 0.5 (sqrt 2.0)) (sqrt (* -2.0 re)))
(if (<= re 8.9e+33)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -1.5e+32) {
tmp = (0.5 * sqrt(2.0)) * sqrt((-2.0 * re));
} else if (re <= 8.9e+33) {
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.5d+32)) then
tmp = (0.5d0 * sqrt(2.0d0)) * sqrt(((-2.0d0) * re))
else if (re <= 8.9d+33) 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.5e+32) {
tmp = (0.5 * Math.sqrt(2.0)) * Math.sqrt((-2.0 * re));
} else if (re <= 8.9e+33) {
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.5e+32: tmp = (0.5 * math.sqrt(2.0)) * math.sqrt((-2.0 * re)) elif re <= 8.9e+33: 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.5e+32) tmp = Float64(Float64(0.5 * sqrt(2.0)) * sqrt(Float64(-2.0 * re))); elseif (re <= 8.9e+33) 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.5e+32) tmp = (0.5 * sqrt(2.0)) * sqrt((-2.0 * re)); elseif (re <= 8.9e+33) 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.5e+32], N[(N[(0.5 * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(-2.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.9e+33], 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.5 \cdot 10^{+32}:\\
\;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{-2 \cdot re}\\
\mathbf{elif}\;re \leq 8.9 \cdot 10^{+33}:\\
\;\;\;\;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.5e32Initial program 35.7%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6498.6
Applied rewrites98.6%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
sqrt-prodN/A
lift-sqrt.f64N/A
pow1/2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6435.5
Applied rewrites99.1%
Taylor expanded in re around -inf
lower-*.f6477.1
Applied rewrites77.1%
if -1.5e32 < re < 8.9000000000000005e33Initial program 55.6%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6476.6
Applied rewrites76.6%
if 8.9000000000000005e33 < re Initial program 9.6%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6432.8
Applied rewrites32.8%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6482.0
Applied rewrites82.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.0
Applied rewrites82.8%
Final simplification78.3%
(FPCore (re im)
:precision binary64
(if (<= re -1.5e+32)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re 8.9e+33)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -1.5e+32) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= 8.9e+33) {
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.5d+32)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else if (re <= 8.9d+33) 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.5e+32) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else if (re <= 8.9e+33) {
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.5e+32: tmp = 0.5 * math.sqrt((-4.0 * re)) elif re <= 8.9e+33: 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.5e+32) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= 8.9e+33) 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.5e+32) tmp = 0.5 * sqrt((-4.0 * re)); elseif (re <= 8.9e+33) 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.5e+32], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.9e+33], 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.5 \cdot 10^{+32}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq 8.9 \cdot 10^{+33}:\\
\;\;\;\;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.5e32Initial program 35.7%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6498.6
Applied rewrites98.6%
Taylor expanded in re around -inf
lower-*.f6476.4
Applied rewrites76.4%
if -1.5e32 < re < 8.9000000000000005e33Initial program 55.6%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6476.6
Applied rewrites76.6%
if 8.9000000000000005e33 < re Initial program 9.6%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6432.8
Applied rewrites32.8%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6482.0
Applied rewrites82.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.0
Applied rewrites82.8%
(FPCore (re im) :precision binary64 (if (<= re -2.4e+14) (* 0.5 (sqrt (* -4.0 re))) (* (sqrt (+ im im)) 0.5)))
double code(double re, double im) {
double tmp;
if (re <= -2.4e+14) {
tmp = 0.5 * sqrt((-4.0 * re));
} else {
tmp = sqrt((im + 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+14)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else
tmp = sqrt((im + im)) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.4e+14) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else {
tmp = Math.sqrt((im + im)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.4e+14: tmp = 0.5 * math.sqrt((-4.0 * re)) else: tmp = math.sqrt((im + im)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= -2.4e+14) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); else tmp = Float64(sqrt(Float64(im + im)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.4e+14) tmp = 0.5 * sqrt((-4.0 * re)); else tmp = sqrt((im + im)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.4e+14], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.4 \cdot 10^{+14}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im + im} \cdot 0.5\\
\end{array}
\end{array}
if re < -2.4e14Initial program 37.5%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6498.7
Applied rewrites98.7%
Taylor expanded in re around -inf
lower-*.f6475.7
Applied rewrites75.7%
if -2.4e14 < re Initial program 39.3%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6457.3
Applied rewrites57.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6457.3
Applied rewrites57.6%
Applied rewrites57.6%
(FPCore (re im) :precision binary64 (if (<= im 1.8e-223) 0.0 (* (sqrt (+ im im)) 0.5)))
double code(double re, double im) {
double tmp;
if (im <= 1.8e-223) {
tmp = 0.0;
} else {
tmp = sqrt((im + 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 (im <= 1.8d-223) then
tmp = 0.0d0
else
tmp = sqrt((im + im)) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.8e-223) {
tmp = 0.0;
} else {
tmp = Math.sqrt((im + im)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.8e-223: tmp = 0.0 else: tmp = math.sqrt((im + im)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (im <= 1.8e-223) tmp = 0.0; else tmp = Float64(sqrt(Float64(im + im)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.8e-223) tmp = 0.0; else tmp = sqrt((im + im)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.8e-223], 0.0, N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.8 \cdot 10^{-223}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im + im} \cdot 0.5\\
\end{array}
\end{array}
if im < 1.8000000000000002e-223Initial program 33.6%
Applied rewrites19.6%
if 1.8000000000000002e-223 < im Initial program 39.7%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6455.8
Applied rewrites55.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.8
Applied rewrites56.2%
Applied rewrites56.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 38.8%
Applied rewrites5.9%
herbie shell --seed 2024305
(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)))))