
(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 9 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 (+ re (sqrt (+ (* re re) (* im im)))))) 0.0) (* 0.5 (sqrt (* 2.0 (* (/ im (/ re im)) -0.5)))) (* 0.5 (sqrt (* 2.0 (+ re (hypot re im)))))))
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0) {
tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else {
tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im))));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (Math.sqrt((2.0 * (re + Math.sqrt(((re * re) + (im * im)))))) <= 0.0) {
tmp = 0.5 * Math.sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + Math.hypot(re, im))));
}
return tmp;
}
def code(re, im): tmp = 0 if math.sqrt((2.0 * (re + math.sqrt(((re * re) + (im * im)))))) <= 0.0: tmp = 0.5 * math.sqrt((2.0 * ((im / (re / im)) * -0.5))) else: tmp = 0.5 * math.sqrt((2.0 * (re + math.hypot(re, im)))) return tmp
function code(re, im) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(re + sqrt(Float64(Float64(re * re) + Float64(im * im)))))) <= 0.0) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(im / Float64(re / im)) * -0.5)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + hypot(re, im))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (sqrt((2.0 * (re + sqrt(((re * re) + (im * im)))))) <= 0.0) tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5))); else tmp = 0.5 * sqrt((2.0 * (re + hypot(re, im)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(re + N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(re + \sqrt{re \cdot re + im \cdot im}\right)} \leq 0:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{im}{\frac{re}{im}} \cdot -0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 12.1%
+-commutative12.1%
hypot-def12.1%
Simplified12.1%
Taylor expanded in re around -inf 63.4%
*-commutative63.4%
unpow263.4%
associate-/l*64.8%
Simplified64.8%
if 0.0 < (sqrt.f64 (*.f64 2 (+.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 45.1%
+-commutative45.1%
hypot-def90.7%
Simplified90.7%
Final simplification87.7%
(FPCore (re im)
:precision binary64
(if (<= re -4.65e+61)
(* 0.5 (sqrt (* 2.0 (* (/ im (/ re im)) -0.5))))
(if (<= re -6.8e-256)
(* 0.5 (sqrt (+ (/ (* re re) im) (* 2.0 (+ re im)))))
(if (<= re 7.5e-79)
(* 0.5 (sqrt (* 2.0 (- re im))))
(* 0.5 (* 2.0 (sqrt re)))))))
double code(double re, double im) {
double tmp;
if (re <= -4.65e+61) {
tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else if (re <= -6.8e-256) {
tmp = 0.5 * sqrt((((re * re) / im) + (2.0 * (re + im))));
} else if (re <= 7.5e-79) {
tmp = 0.5 * sqrt((2.0 * (re - im)));
} else {
tmp = 0.5 * (2.0 * 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 <= (-4.65d+61)) then
tmp = 0.5d0 * sqrt((2.0d0 * ((im / (re / im)) * (-0.5d0))))
else if (re <= (-6.8d-256)) then
tmp = 0.5d0 * sqrt((((re * re) / im) + (2.0d0 * (re + im))))
else if (re <= 7.5d-79) then
tmp = 0.5d0 * sqrt((2.0d0 * (re - im)))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4.65e+61) {
tmp = 0.5 * Math.sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else if (re <= -6.8e-256) {
tmp = 0.5 * Math.sqrt((((re * re) / im) + (2.0 * (re + im))));
} else if (re <= 7.5e-79) {
tmp = 0.5 * Math.sqrt((2.0 * (re - im)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.65e+61: tmp = 0.5 * math.sqrt((2.0 * ((im / (re / im)) * -0.5))) elif re <= -6.8e-256: tmp = 0.5 * math.sqrt((((re * re) / im) + (2.0 * (re + im)))) elif re <= 7.5e-79: tmp = 0.5 * math.sqrt((2.0 * (re - im))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.65e+61) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(im / Float64(re / im)) * -0.5)))); elseif (re <= -6.8e-256) tmp = Float64(0.5 * sqrt(Float64(Float64(Float64(re * re) / im) + Float64(2.0 * Float64(re + im))))); elseif (re <= 7.5e-79) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re - im)))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.65e+61) tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5))); elseif (re <= -6.8e-256) tmp = 0.5 * sqrt((((re * re) / im) + (2.0 * (re + im)))); elseif (re <= 7.5e-79) tmp = 0.5 * sqrt((2.0 * (re - im))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.65e+61], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -6.8e-256], N[(0.5 * N[Sqrt[N[(N[(N[(re * re), $MachinePrecision] / im), $MachinePrecision] + N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.5e-79], N[(0.5 * N[Sqrt[N[(2.0 * N[(re - im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.65 \cdot 10^{+61}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{im}{\frac{re}{im}} \cdot -0.5\right)}\\
\mathbf{elif}\;re \leq -6.8 \cdot 10^{-256}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{re \cdot re}{im} + 2 \cdot \left(re + im\right)}\\
\mathbf{elif}\;re \leq 7.5 \cdot 10^{-79}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - im\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -4.64999999999999987e61Initial program 10.6%
+-commutative10.6%
hypot-def30.8%
Simplified30.8%
Taylor expanded in re around -inf 54.6%
*-commutative54.6%
unpow254.6%
associate-/l*59.2%
Simplified59.2%
if -4.64999999999999987e61 < re < -6.8000000000000001e-256Initial program 45.5%
+-commutative45.5%
hypot-def78.8%
Simplified78.8%
Taylor expanded in re around 0 52.6%
unpow252.6%
distribute-lft-out52.6%
Simplified52.6%
if -6.8000000000000001e-256 < re < 7.49999999999999969e-79Initial program 47.9%
+-commutative47.9%
hypot-def98.2%
Simplified98.2%
Taylor expanded in im around -inf 56.3%
mul-1-neg56.3%
sub-neg56.3%
Simplified56.3%
if 7.49999999999999969e-79 < re Initial program 49.5%
+-commutative49.5%
hypot-def99.0%
Simplified99.0%
Taylor expanded in im around 0 74.5%
unpow274.5%
rem-square-sqrt75.9%
Simplified75.9%
Final simplification62.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* 2.0 (- re im))))))
(if (<= im -1.1e+93)
t_0
(if (<= im -1.4e+65)
(* 0.5 (sqrt (/ (* im (- im)) re)))
(if (<= im -1.16e-54)
t_0
(if (<= im 1.55e-120)
(* 0.5 (* 2.0 (sqrt re)))
(* 0.5 (sqrt (* 2.0 (+ re im))))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((2.0 * (re - im)));
double tmp;
if (im <= -1.1e+93) {
tmp = t_0;
} else if (im <= -1.4e+65) {
tmp = 0.5 * sqrt(((im * -im) / re));
} else if (im <= -1.16e-54) {
tmp = t_0;
} else if (im <= 1.55e-120) {
tmp = 0.5 * (2.0 * sqrt(re));
} else {
tmp = 0.5 * sqrt((2.0 * (re + im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * sqrt((2.0d0 * (re - im)))
if (im <= (-1.1d+93)) then
tmp = t_0
else if (im <= (-1.4d+65)) then
tmp = 0.5d0 * sqrt(((im * -im) / re))
else if (im <= (-1.16d-54)) then
tmp = t_0
else if (im <= 1.55d-120) then
tmp = 0.5d0 * (2.0d0 * sqrt(re))
else
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((2.0 * (re - im)));
double tmp;
if (im <= -1.1e+93) {
tmp = t_0;
} else if (im <= -1.4e+65) {
tmp = 0.5 * Math.sqrt(((im * -im) / re));
} else if (im <= -1.16e-54) {
tmp = t_0;
} else if (im <= 1.55e-120) {
tmp = 0.5 * (2.0 * Math.sqrt(re));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((2.0 * (re - im))) tmp = 0 if im <= -1.1e+93: tmp = t_0 elif im <= -1.4e+65: tmp = 0.5 * math.sqrt(((im * -im) / re)) elif im <= -1.16e-54: tmp = t_0 elif im <= 1.55e-120: tmp = 0.5 * (2.0 * math.sqrt(re)) else: tmp = 0.5 * math.sqrt((2.0 * (re + im))) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(re - im)))) tmp = 0.0 if (im <= -1.1e+93) tmp = t_0; elseif (im <= -1.4e+65) tmp = Float64(0.5 * sqrt(Float64(Float64(im * Float64(-im)) / re))); elseif (im <= -1.16e-54) tmp = t_0; elseif (im <= 1.55e-120) tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((2.0 * (re - im))); tmp = 0.0; if (im <= -1.1e+93) tmp = t_0; elseif (im <= -1.4e+65) tmp = 0.5 * sqrt(((im * -im) / re)); elseif (im <= -1.16e-54) tmp = t_0; elseif (im <= 1.55e-120) tmp = 0.5 * (2.0 * sqrt(re)); else tmp = 0.5 * sqrt((2.0 * (re + im))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(2.0 * N[(re - im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.1e+93], t$95$0, If[LessEqual[im, -1.4e+65], N[(0.5 * N[Sqrt[N[(N[(im * (-im)), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -1.16e-54], t$95$0, If[LessEqual[im, 1.55e-120], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(re - im\right)}\\
\mathbf{if}\;im \leq -1.1 \cdot 10^{+93}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq -1.4 \cdot 10^{+65}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{im \cdot \left(-im\right)}{re}}\\
\mathbf{elif}\;im \leq -1.16 \cdot 10^{-54}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 1.55 \cdot 10^{-120}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\end{array}
\end{array}
if im < -1.10000000000000011e93 or -1.3999999999999999e65 < im < -1.16e-54Initial program 39.3%
+-commutative39.3%
hypot-def88.6%
Simplified88.6%
Taylor expanded in im around -inf 73.3%
mul-1-neg73.3%
sub-neg73.3%
Simplified73.3%
if -1.10000000000000011e93 < im < -1.3999999999999999e65Initial program 3.2%
+-commutative3.2%
hypot-def19.4%
Simplified19.4%
Taylor expanded in re around -inf 83.3%
associate-*r/83.3%
neg-mul-183.3%
unpow283.3%
distribute-rgt-neg-in83.3%
Simplified83.3%
if -1.16e-54 < im < 1.5500000000000001e-120Initial program 39.0%
+-commutative39.0%
hypot-def78.9%
Simplified78.9%
Taylor expanded in im around 0 47.9%
unpow247.9%
rem-square-sqrt48.8%
Simplified48.8%
if 1.5500000000000001e-120 < im Initial program 47.6%
+-commutative47.6%
hypot-def83.0%
Simplified83.0%
Taylor expanded in re around 0 70.6%
distribute-lft-out70.6%
+-commutative70.6%
*-commutative70.6%
+-commutative70.6%
Simplified70.6%
Final simplification63.8%
(FPCore (re im)
:precision binary64
(if (<= re -4.65e+61)
(* 0.5 (sqrt (* 2.0 (* (/ im (/ re im)) -0.5))))
(if (<= re -4e-255)
(* 0.5 (sqrt (* 2.0 im)))
(if (<= re 6.2e-78)
(* 0.5 (sqrt (* 2.0 (- re im))))
(* 0.5 (* 2.0 (sqrt re)))))))
double code(double re, double im) {
double tmp;
if (re <= -4.65e+61) {
tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else if (re <= -4e-255) {
tmp = 0.5 * sqrt((2.0 * im));
} else if (re <= 6.2e-78) {
tmp = 0.5 * sqrt((2.0 * (re - im)));
} else {
tmp = 0.5 * (2.0 * 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 <= (-4.65d+61)) then
tmp = 0.5d0 * sqrt((2.0d0 * ((im / (re / im)) * (-0.5d0))))
else if (re <= (-4d-255)) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else if (re <= 6.2d-78) then
tmp = 0.5d0 * sqrt((2.0d0 * (re - im)))
else
tmp = 0.5d0 * (2.0d0 * sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4.65e+61) {
tmp = 0.5 * Math.sqrt((2.0 * ((im / (re / im)) * -0.5)));
} else if (re <= -4e-255) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else if (re <= 6.2e-78) {
tmp = 0.5 * Math.sqrt((2.0 * (re - im)));
} else {
tmp = 0.5 * (2.0 * Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.65e+61: tmp = 0.5 * math.sqrt((2.0 * ((im / (re / im)) * -0.5))) elif re <= -4e-255: tmp = 0.5 * math.sqrt((2.0 * im)) elif re <= 6.2e-78: tmp = 0.5 * math.sqrt((2.0 * (re - im))) else: tmp = 0.5 * (2.0 * math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.65e+61) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(im / Float64(re / im)) * -0.5)))); elseif (re <= -4e-255) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); elseif (re <= 6.2e-78) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re - im)))); else tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.65e+61) tmp = 0.5 * sqrt((2.0 * ((im / (re / im)) * -0.5))); elseif (re <= -4e-255) tmp = 0.5 * sqrt((2.0 * im)); elseif (re <= 6.2e-78) tmp = 0.5 * sqrt((2.0 * (re - im))); else tmp = 0.5 * (2.0 * sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.65e+61], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -4e-255], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.2e-78], N[(0.5 * N[Sqrt[N[(2.0 * N[(re - im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.65 \cdot 10^{+61}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{im}{\frac{re}{im}} \cdot -0.5\right)}\\
\mathbf{elif}\;re \leq -4 \cdot 10^{-255}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{elif}\;re \leq 6.2 \cdot 10^{-78}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - im\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\end{array}
\end{array}
if re < -4.64999999999999987e61Initial program 10.6%
+-commutative10.6%
hypot-def30.8%
Simplified30.8%
Taylor expanded in re around -inf 54.6%
*-commutative54.6%
unpow254.6%
associate-/l*59.2%
Simplified59.2%
if -4.64999999999999987e61 < re < -4e-255Initial program 45.5%
+-commutative45.5%
hypot-def78.8%
Simplified78.8%
Taylor expanded in re around 0 52.4%
*-commutative52.4%
Simplified52.4%
if -4e-255 < re < 6.20000000000000035e-78Initial program 47.9%
+-commutative47.9%
hypot-def98.2%
Simplified98.2%
Taylor expanded in im around -inf 56.3%
mul-1-neg56.3%
sub-neg56.3%
Simplified56.3%
if 6.20000000000000035e-78 < re Initial program 49.5%
+-commutative49.5%
hypot-def99.0%
Simplified99.0%
Taylor expanded in im around 0 74.5%
unpow274.5%
rem-square-sqrt75.9%
Simplified75.9%
Final simplification62.7%
(FPCore (re im)
:precision binary64
(if (<= im -1.1e-55)
(* 0.5 (sqrt (* 2.0 (- re im))))
(if (<= im 3.6e-121)
(* 0.5 (* 2.0 (sqrt re)))
(* 0.5 (sqrt (* 2.0 (+ re im)))))))
double code(double re, double im) {
double tmp;
if (im <= -1.1e-55) {
tmp = 0.5 * sqrt((2.0 * (re - im)));
} else if (im <= 3.6e-121) {
tmp = 0.5 * (2.0 * sqrt(re));
} else {
tmp = 0.5 * sqrt((2.0 * (re + im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= (-1.1d-55)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re - im)))
else if (im <= 3.6d-121) then
tmp = 0.5d0 * (2.0d0 * sqrt(re))
else
tmp = 0.5d0 * sqrt((2.0d0 * (re + im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= -1.1e-55) {
tmp = 0.5 * Math.sqrt((2.0 * (re - im)));
} else if (im <= 3.6e-121) {
tmp = 0.5 * (2.0 * Math.sqrt(re));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re + im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= -1.1e-55: tmp = 0.5 * math.sqrt((2.0 * (re - im))) elif im <= 3.6e-121: tmp = 0.5 * (2.0 * math.sqrt(re)) else: tmp = 0.5 * math.sqrt((2.0 * (re + im))) return tmp
function code(re, im) tmp = 0.0 if (im <= -1.1e-55) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re - im)))); elseif (im <= 3.6e-121) tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re + im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= -1.1e-55) tmp = 0.5 * sqrt((2.0 * (re - im))); elseif (im <= 3.6e-121) tmp = 0.5 * (2.0 * sqrt(re)); else tmp = 0.5 * sqrt((2.0 * (re + im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, -1.1e-55], N[(0.5 * N[Sqrt[N[(2.0 * N[(re - im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 3.6e-121], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re + im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.1 \cdot 10^{-55}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - im\right)}\\
\mathbf{elif}\;im \leq 3.6 \cdot 10^{-121}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + im\right)}\\
\end{array}
\end{array}
if im < -1.1e-55Initial program 36.4%
+-commutative36.4%
hypot-def83.0%
Simplified83.0%
Taylor expanded in im around -inf 67.6%
mul-1-neg67.6%
sub-neg67.6%
Simplified67.6%
if -1.1e-55 < im < 3.59999999999999984e-121Initial program 39.0%
+-commutative39.0%
hypot-def78.9%
Simplified78.9%
Taylor expanded in im around 0 47.9%
unpow247.9%
rem-square-sqrt48.8%
Simplified48.8%
if 3.59999999999999984e-121 < im Initial program 47.6%
+-commutative47.6%
hypot-def83.0%
Simplified83.0%
Taylor expanded in re around 0 70.6%
distribute-lft-out70.6%
+-commutative70.6%
*-commutative70.6%
+-commutative70.6%
Simplified70.6%
Final simplification61.9%
(FPCore (re im) :precision binary64 (if (<= im -1.32e-55) (* 0.5 (sqrt (* im -2.0))) (if (<= im 2.8e-120) (* 0.5 (* 2.0 (sqrt re))) (* 0.5 (sqrt (* 2.0 im))))))
double code(double re, double im) {
double tmp;
if (im <= -1.32e-55) {
tmp = 0.5 * sqrt((im * -2.0));
} else if (im <= 2.8e-120) {
tmp = 0.5 * (2.0 * sqrt(re));
} 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 (im <= (-1.32d-55)) then
tmp = 0.5d0 * sqrt((im * (-2.0d0)))
else if (im <= 2.8d-120) then
tmp = 0.5d0 * (2.0d0 * sqrt(re))
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 (im <= -1.32e-55) {
tmp = 0.5 * Math.sqrt((im * -2.0));
} else if (im <= 2.8e-120) {
tmp = 0.5 * (2.0 * Math.sqrt(re));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= -1.32e-55: tmp = 0.5 * math.sqrt((im * -2.0)) elif im <= 2.8e-120: tmp = 0.5 * (2.0 * math.sqrt(re)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= -1.32e-55) tmp = Float64(0.5 * sqrt(Float64(im * -2.0))); elseif (im <= 2.8e-120) tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= -1.32e-55) tmp = 0.5 * sqrt((im * -2.0)); elseif (im <= 2.8e-120) tmp = 0.5 * (2.0 * sqrt(re)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, -1.32e-55], N[(0.5 * N[Sqrt[N[(im * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.8e-120], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.32 \cdot 10^{-55}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot -2}\\
\mathbf{elif}\;im \leq 2.8 \cdot 10^{-120}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if im < -1.31999999999999993e-55Initial program 36.4%
+-commutative36.4%
hypot-def83.0%
Simplified83.0%
Taylor expanded in im around -inf 66.6%
*-commutative66.6%
Simplified66.6%
if -1.31999999999999993e-55 < im < 2.79999999999999994e-120Initial program 39.0%
+-commutative39.0%
hypot-def78.9%
Simplified78.9%
Taylor expanded in im around 0 47.9%
unpow247.9%
rem-square-sqrt48.8%
Simplified48.8%
if 2.79999999999999994e-120 < im Initial program 47.6%
+-commutative47.6%
hypot-def83.0%
Simplified83.0%
Taylor expanded in re around 0 69.3%
*-commutative69.3%
Simplified69.3%
Final simplification61.2%
(FPCore (re im) :precision binary64 (if (<= im -8.5e-55) (* 0.5 (sqrt (* 2.0 (- re im)))) (if (<= im 4e-121) (* 0.5 (* 2.0 (sqrt re))) (* 0.5 (sqrt (* 2.0 im))))))
double code(double re, double im) {
double tmp;
if (im <= -8.5e-55) {
tmp = 0.5 * sqrt((2.0 * (re - im)));
} else if (im <= 4e-121) {
tmp = 0.5 * (2.0 * sqrt(re));
} 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 (im <= (-8.5d-55)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re - im)))
else if (im <= 4d-121) then
tmp = 0.5d0 * (2.0d0 * sqrt(re))
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 (im <= -8.5e-55) {
tmp = 0.5 * Math.sqrt((2.0 * (re - im)));
} else if (im <= 4e-121) {
tmp = 0.5 * (2.0 * Math.sqrt(re));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= -8.5e-55: tmp = 0.5 * math.sqrt((2.0 * (re - im))) elif im <= 4e-121: tmp = 0.5 * (2.0 * math.sqrt(re)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= -8.5e-55) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re - im)))); elseif (im <= 4e-121) tmp = Float64(0.5 * Float64(2.0 * sqrt(re))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= -8.5e-55) tmp = 0.5 * sqrt((2.0 * (re - im))); elseif (im <= 4e-121) tmp = 0.5 * (2.0 * sqrt(re)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, -8.5e-55], N[(0.5 * N[Sqrt[N[(2.0 * N[(re - im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 4e-121], N[(0.5 * N[(2.0 * N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -8.5 \cdot 10^{-55}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - im\right)}\\
\mathbf{elif}\;im \leq 4 \cdot 10^{-121}:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \sqrt{re}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if im < -8.49999999999999968e-55Initial program 36.4%
+-commutative36.4%
hypot-def83.0%
Simplified83.0%
Taylor expanded in im around -inf 67.6%
mul-1-neg67.6%
sub-neg67.6%
Simplified67.6%
if -8.49999999999999968e-55 < im < 3.9999999999999999e-121Initial program 39.0%
+-commutative39.0%
hypot-def78.9%
Simplified78.9%
Taylor expanded in im around 0 47.9%
unpow247.9%
rem-square-sqrt48.8%
Simplified48.8%
if 3.9999999999999999e-121 < im Initial program 47.6%
+-commutative47.6%
hypot-def83.0%
Simplified83.0%
Taylor expanded in re around 0 69.3%
*-commutative69.3%
Simplified69.3%
Final simplification61.5%
(FPCore (re im) :precision binary64 (if (<= im -4e-311) (* 0.5 (sqrt (* im -2.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (im <= -4e-311) {
tmp = 0.5 * sqrt((im * -2.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 (im <= (-4d-311)) then
tmp = 0.5d0 * sqrt((im * (-2.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 (im <= -4e-311) {
tmp = 0.5 * Math.sqrt((im * -2.0));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= -4e-311: tmp = 0.5 * math.sqrt((im * -2.0)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= -4e-311) tmp = Float64(0.5 * sqrt(Float64(im * -2.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 (im <= -4e-311) tmp = 0.5 * sqrt((im * -2.0)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, -4e-311], N[(0.5 * N[Sqrt[N[(im * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -4 \cdot 10^{-311}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if im < -3.99999999999979e-311Initial program 36.7%
+-commutative36.7%
hypot-def81.2%
Simplified81.2%
Taylor expanded in im around -inf 52.1%
*-commutative52.1%
Simplified52.1%
if -3.99999999999979e-311 < im Initial program 45.7%
+-commutative45.7%
hypot-def81.9%
Simplified81.9%
Taylor expanded in re around 0 55.4%
*-commutative55.4%
Simplified55.4%
Final simplification53.8%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* im -2.0))))
double code(double re, double im) {
return 0.5 * sqrt((im * -2.0));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((im * (-2.0d0)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((im * -2.0));
}
def code(re, im): return 0.5 * math.sqrt((im * -2.0))
function code(re, im) return Float64(0.5 * sqrt(Float64(im * -2.0))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((im * -2.0)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(im * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{im \cdot -2}
\end{array}
Initial program 41.3%
+-commutative41.3%
hypot-def81.5%
Simplified81.5%
Taylor expanded in im around -inf 25.4%
*-commutative25.4%
Simplified25.4%
Final simplification25.4%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (+ (* re re) (* im im)))))
(if (< re 0.0)
(* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- t_0 re)))))
(* 0.5 (sqrt (* 2.0 (+ t_0 re)))))))
double code(double re, double im) {
double t_0 = sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((re * re) + (im * im)))
if (re < 0.0d0) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt(((im * im) / (t_0 - re))))
else
tmp = 0.5d0 * sqrt((2.0d0 * (t_0 + re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt(((re * re) + (im * im))) tmp = 0 if re < 0.0: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt(((im * im) / (t_0 - re)))) else: tmp = 0.5 * math.sqrt((2.0 * (t_0 + re))) return tmp
function code(re, im) t_0 = sqrt(Float64(Float64(re * re) + Float64(im * im))) tmp = 0.0 if (re < 0.0) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(Float64(im * im) / Float64(t_0 - re))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(t_0 + re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt(((re * re) + (im * im))); tmp = 0.0; if (re < 0.0) tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re)))); else tmp = 0.5 * sqrt((2.0 * (t_0 + re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[re, 0.0], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(N[(im * im), $MachinePrecision] / N[(t$95$0 - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(t$95$0 + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{re \cdot re + im \cdot im}\\
\mathbf{if}\;re < 0:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{t_0 - re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(t_0 + re\right)}\\
\end{array}
\end{array}
herbie shell --seed 2023189
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:herbie-target
(if (< re 0.0) (* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))