
(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 10 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 7.8e+46) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re)))) (* (* im (pow re -0.5)) 0.5)))
double code(double re, double im) {
double tmp;
if (re <= 7.8e+46) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else {
tmp = (im * pow(re, -0.5)) * 0.5;
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 7.8e+46) {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
} else {
tmp = (im * Math.pow(re, -0.5)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 7.8e+46: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) else: tmp = (im * math.pow(re, -0.5)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= 7.8e+46) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); else tmp = Float64(Float64(im * (re ^ -0.5)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 7.8e+46) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); else tmp = (im * (re ^ -0.5)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 7.8e+46], 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[Power[re, -0.5], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 7.8 \cdot 10^{+46}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot {re}^{-0.5}\right) \cdot 0.5\\
\end{array}
\end{array}
if re < 7.7999999999999999e46Initial program 56.6%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6494.1
Applied rewrites94.1%
if 7.7999999999999999e46 < re Initial program 10.0%
Taylor expanded in re around inf
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6482.3
Applied rewrites82.3%
Applied rewrites82.9%
(FPCore (re im)
:precision binary64
(if (<= re -1.55e+127)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re -9e-157)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(if (<= re 7.8e+46)
(* 0.5 (sqrt (fma (- (/ re im) 2.0) re (* 2.0 im))))
(* (* im (pow re -0.5)) 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.55e+127) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= -9e-157) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else if (re <= 7.8e+46) {
tmp = 0.5 * sqrt(fma(((re / im) - 2.0), re, (2.0 * im)));
} else {
tmp = (im * pow(re, -0.5)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.55e+127) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= -9e-157) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); elseif (re <= 7.8e+46) tmp = Float64(0.5 * sqrt(fma(Float64(Float64(re / im) - 2.0), re, Float64(2.0 * im)))); else tmp = Float64(Float64(im * (re ^ -0.5)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.55e+127], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -9e-157], 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, 7.8e+46], N[(0.5 * N[Sqrt[N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + N[(2.0 * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.55 \cdot 10^{+127}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq -9 \cdot 10^{-157}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot {re}^{-0.5}\right) \cdot 0.5\\
\end{array}
\end{array}
if re < -1.5500000000000001e127Initial program 4.2%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6485.5
Applied rewrites85.5%
if -1.5500000000000001e127 < re < -8.99999999999999997e-157Initial program 80.5%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6480.5
Applied rewrites80.5%
if -8.99999999999999997e-157 < re < 7.7999999999999999e46Initial program 58.0%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6488.7
Applied rewrites88.7%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6486.6
Applied rewrites86.6%
if 7.7999999999999999e46 < re Initial program 10.0%
Taylor expanded in re around inf
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6482.3
Applied rewrites82.3%
Applied rewrites82.9%
(FPCore (re im)
:precision binary64
(if (<= re -1.55e+127)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re -9e-157)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(if (<= re 7.8e+46)
(* 0.5 (sqrt (fma (- (/ re im) 2.0) re (* 2.0 im))))
(* (/ im (sqrt re)) 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.55e+127) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= -9e-157) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else if (re <= 7.8e+46) {
tmp = 0.5 * sqrt(fma(((re / im) - 2.0), re, (2.0 * im)));
} else {
tmp = (im / sqrt(re)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.55e+127) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= -9e-157) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); elseif (re <= 7.8e+46) tmp = Float64(0.5 * sqrt(fma(Float64(Float64(re / im) - 2.0), re, Float64(2.0 * im)))); else tmp = Float64(Float64(im / sqrt(re)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.55e+127], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -9e-157], 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, 7.8e+46], N[(0.5 * N[Sqrt[N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + N[(2.0 * im), $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.55 \cdot 10^{+127}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq -9 \cdot 10^{-157}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
\end{array}
\end{array}
if re < -1.5500000000000001e127Initial program 4.2%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6485.5
Applied rewrites85.5%
if -1.5500000000000001e127 < re < -8.99999999999999997e-157Initial program 80.5%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6480.5
Applied rewrites80.5%
if -8.99999999999999997e-157 < re < 7.7999999999999999e46Initial program 58.0%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6488.7
Applied rewrites88.7%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6486.6
Applied rewrites86.6%
if 7.7999999999999999e46 < re Initial program 10.0%
Taylor expanded in re around inf
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6482.3
Applied rewrites82.3%
Applied rewrites82.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.7
Applied rewrites82.7%
(FPCore (re im)
:precision binary64
(if (<= re -3.8e+26)
(* 0.5 (sqrt (fma -4.0 re (* (/ (- im) re) im))))
(if (<= re 7.8e+46)
(* 0.5 (sqrt (fma (- (/ re im) 2.0) re (* 2.0 im))))
(* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -3.8e+26) {
tmp = 0.5 * sqrt(fma(-4.0, re, ((-im / re) * im)));
} else if (re <= 7.8e+46) {
tmp = 0.5 * sqrt(fma(((re / im) - 2.0), re, (2.0 * im)));
} else {
tmp = (im / sqrt(re)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -3.8e+26) tmp = Float64(0.5 * sqrt(fma(-4.0, re, Float64(Float64(Float64(-im) / re) * im)))); elseif (re <= 7.8e+46) tmp = Float64(0.5 * sqrt(fma(Float64(Float64(re / im) - 2.0), re, Float64(2.0 * im)))); else tmp = Float64(Float64(im / sqrt(re)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -3.8e+26], N[(0.5 * N[Sqrt[N[(-4.0 * re + N[(N[((-im) / re), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.8e+46], N[(0.5 * N[Sqrt[N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + N[(2.0 * im), $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 -3.8 \cdot 10^{+26}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(-4, re, \frac{-im}{re} \cdot im\right)}\\
\mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, 2 \cdot im\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
\end{array}
\end{array}
if re < -3.8000000000000002e26Initial program 40.1%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
unpow2N/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6482.9
Applied rewrites82.9%
Taylor expanded in im around 0
Applied rewrites76.0%
Applied rewrites82.9%
if -3.8000000000000002e26 < re < 7.7999999999999999e46Initial program 62.9%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6491.8
Applied rewrites91.8%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6481.0
Applied rewrites81.0%
if 7.7999999999999999e46 < re Initial program 10.0%
Taylor expanded in re around inf
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6482.3
Applied rewrites82.3%
Applied rewrites82.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.7
Applied rewrites82.7%
Final simplification81.8%
(FPCore (re im)
:precision binary64
(if (<= re -4.2e+26)
(* 0.5 (sqrt (fma -4.0 re (* (/ (- im) re) im))))
(if (<= re 7.8e+46)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -4.2e+26) {
tmp = 0.5 * sqrt(fma(-4.0, re, ((-im / re) * im)));
} else if (re <= 7.8e+46) {
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 <= -4.2e+26) tmp = Float64(0.5 * sqrt(fma(-4.0, re, Float64(Float64(Float64(-im) / re) * im)))); elseif (re <= 7.8e+46) 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, -4.2e+26], N[(0.5 * N[Sqrt[N[(-4.0 * re + N[(N[((-im) / re), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.8e+46], 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 -4.2 \cdot 10^{+26}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(-4, re, \frac{-im}{re} \cdot im\right)}\\
\mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\
\;\;\;\;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 < -4.2000000000000002e26Initial program 40.1%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
unpow2N/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f6482.9
Applied rewrites82.9%
Taylor expanded in im around 0
Applied rewrites76.0%
Applied rewrites82.9%
if -4.2000000000000002e26 < re < 7.7999999999999999e46Initial program 62.9%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6480.9
Applied rewrites80.9%
if 7.7999999999999999e46 < re Initial program 10.0%
Taylor expanded in re around inf
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6482.3
Applied rewrites82.3%
Applied rewrites82.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.7
Applied rewrites82.7%
Final simplification81.7%
(FPCore (re im)
:precision binary64
(if (<= re -4.2e+26)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re 7.8e+46)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -4.2e+26) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= 7.8e+46) {
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 <= (-4.2d+26)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else if (re <= 7.8d+46) 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 <= -4.2e+26) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else if (re <= 7.8e+46) {
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 <= -4.2e+26: tmp = 0.5 * math.sqrt((-4.0 * re)) elif re <= 7.8e+46: 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 <= -4.2e+26) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= 7.8e+46) 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 <= -4.2e+26) tmp = 0.5 * sqrt((-4.0 * re)); elseif (re <= 7.8e+46) 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, -4.2e+26], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.8e+46], 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 -4.2 \cdot 10^{+26}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq 7.8 \cdot 10^{+46}:\\
\;\;\;\;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 < -4.2000000000000002e26Initial program 40.1%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6482.7
Applied rewrites82.7%
if -4.2000000000000002e26 < re < 7.7999999999999999e46Initial program 62.9%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6480.9
Applied rewrites80.9%
if 7.7999999999999999e46 < re Initial program 10.0%
Taylor expanded in re around inf
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6482.3
Applied rewrites82.3%
Applied rewrites82.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6482.7
Applied rewrites82.7%
(FPCore (re im) :precision binary64 (if (<= re -4.2e+26) (* 0.5 (sqrt (* -4.0 re))) (if (<= re 5.1e+113) (* 0.5 (sqrt (* 2.0 (- im re)))) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -4.2e+26) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= 5.1e+113) {
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 <= (-4.2d+26)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else if (re <= 5.1d+113) 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 <= -4.2e+26) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else if (re <= 5.1e+113) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.2e+26: tmp = 0.5 * math.sqrt((-4.0 * re)) elif re <= 5.1e+113: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -4.2e+26) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= 5.1e+113) 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 <= -4.2e+26) tmp = 0.5 * sqrt((-4.0 * re)); elseif (re <= 5.1e+113) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.2e+26], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.1e+113], 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 -4.2 \cdot 10^{+26}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq 5.1 \cdot 10^{+113}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -4.2000000000000002e26Initial program 40.1%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6482.7
Applied rewrites82.7%
if -4.2000000000000002e26 < re < 5.09999999999999994e113Initial program 57.7%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6476.8
Applied rewrites76.8%
if 5.09999999999999994e113 < re Initial program 7.1%
Applied rewrites24.2%
(FPCore (re im) :precision binary64 (if (<= re -3.8e+26) (* 0.5 (sqrt (* -4.0 re))) (if (<= re 5.1e+113) (* (sqrt (+ im im)) 0.5) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -3.8e+26) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= 5.1e+113) {
tmp = sqrt((im + im)) * 0.5;
} 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.8d+26)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else if (re <= 5.1d+113) then
tmp = sqrt((im + im)) * 0.5d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.8e+26) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else if (re <= 5.1e+113) {
tmp = Math.sqrt((im + im)) * 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.8e+26: tmp = 0.5 * math.sqrt((-4.0 * re)) elif re <= 5.1e+113: tmp = math.sqrt((im + im)) * 0.5 else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -3.8e+26) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= 5.1e+113) tmp = Float64(sqrt(Float64(im + im)) * 0.5); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.8e+26) tmp = 0.5 * sqrt((-4.0 * re)); elseif (re <= 5.1e+113) tmp = sqrt((im + im)) * 0.5; else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.8e+26], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.1e+113], N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.8 \cdot 10^{+26}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq 5.1 \cdot 10^{+113}:\\
\;\;\;\;\sqrt{im + im} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -3.8000000000000002e26Initial program 40.1%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6482.7
Applied rewrites82.7%
if -3.8000000000000002e26 < re < 5.09999999999999994e113Initial program 57.7%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6475.4
Applied rewrites75.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6475.4
Applied rewrites76.0%
Applied rewrites76.0%
if 5.09999999999999994e113 < re Initial program 7.1%
Applied rewrites24.2%
(FPCore (re im) :precision binary64 (if (<= im 7e-211) 0.0 (* (sqrt (+ im im)) 0.5)))
double code(double re, double im) {
double tmp;
if (im <= 7e-211) {
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 <= 7d-211) 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 <= 7e-211) {
tmp = 0.0;
} else {
tmp = Math.sqrt((im + im)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 7e-211: tmp = 0.0 else: tmp = math.sqrt((im + im)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (im <= 7e-211) 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 <= 7e-211) tmp = 0.0; else tmp = sqrt((im + im)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 7e-211], 0.0, N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 7 \cdot 10^{-211}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im + im} \cdot 0.5\\
\end{array}
\end{array}
if im < 7e-211Initial program 37.0%
Applied rewrites26.7%
if 7e-211 < im Initial program 47.9%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6460.8
Applied rewrites60.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6460.8
Applied rewrites61.3%
Applied rewrites61.3%
(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 46.6%
Applied rewrites6.3%
herbie shell --seed 2024327
(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)))))