
(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 11 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 (* 0.5 (* (sqrt (- (hypot re im) re)) (sqrt 2.0))))
double code(double re, double im) {
return 0.5 * (sqrt((hypot(re, im) - re)) * sqrt(2.0));
}
public static double code(double re, double im) {
return 0.5 * (Math.sqrt((Math.hypot(re, im) - re)) * Math.sqrt(2.0));
}
def code(re, im): return 0.5 * (math.sqrt((math.hypot(re, im) - re)) * math.sqrt(2.0))
function code(re, im) return Float64(0.5 * Float64(sqrt(Float64(hypot(re, im) - re)) * sqrt(2.0))) end
function tmp = code(re, im) tmp = 0.5 * (sqrt((hypot(re, im) - re)) * sqrt(2.0)); end
code[re_, im_] := N[(0.5 * N[(N[Sqrt[N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(\sqrt{\mathsf{hypot}\left(re, im\right) - re} \cdot \sqrt{2}\right)
\end{array}
Initial program 53.5%
*-commutative53.5%
hypot-udef92.2%
sqrt-prod92.4%
Applied egg-rr92.4%
Final simplification92.4%
(FPCore (re im)
:precision binary64
(if (<= re -5.2e+39)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 2.15e+32)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 2.1e+206)
(* 0.5 (sqrt (/ (pow im 2.0) re)))
(* 0.5 (* im (sqrt (/ 1.0 re))))))))
double code(double re, double im) {
double tmp;
if (re <= -5.2e+39) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.15e+32) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 2.1e+206) {
tmp = 0.5 * sqrt((pow(im, 2.0) / 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 <= (-5.2d+39)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.15d+32) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 2.1d+206) then
tmp = 0.5d0 * sqrt(((im ** 2.0d0) / 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 <= -5.2e+39) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.15e+32) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 2.1e+206) {
tmp = 0.5 * Math.sqrt((Math.pow(im, 2.0) / re));
} else {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5.2e+39: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.15e+32: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 2.1e+206: tmp = 0.5 * math.sqrt((math.pow(im, 2.0) / re)) else: tmp = 0.5 * (im * math.sqrt((1.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -5.2e+39) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.15e+32) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 2.1e+206) tmp = Float64(0.5 * sqrt(Float64((im ^ 2.0) / 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 <= -5.2e+39) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.15e+32) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 2.1e+206) tmp = 0.5 * sqrt(((im ^ 2.0) / re)); else tmp = 0.5 * (im * sqrt((1.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5.2e+39], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.15e+32], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e+206], N[(0.5 * N[Sqrt[N[(N[Power[im, 2.0], $MachinePrecision] / re), $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 -5.2 \cdot 10^{+39}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.15 \cdot 10^{+32}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 2.1 \cdot 10^{+206}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{{im}^{2}}{re}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\end{array}
\end{array}
if re < -5.2e39Initial program 49.5%
Taylor expanded in re around -inf 83.2%
*-commutative83.2%
Simplified83.2%
if -5.2e39 < re < 2.1499999999999999e32Initial program 62.4%
Taylor expanded in re around 0 78.4%
if 2.1499999999999999e32 < re < 2.09999999999999987e206Initial program 49.1%
Taylor expanded in re around inf 62.2%
if 2.09999999999999987e206 < re Initial program 3.0%
Taylor expanded in im around 0 61.8%
associate-*l*61.7%
associate-*l*61.9%
Simplified61.9%
associate-*r*61.7%
sqrt-unprod62.5%
metadata-eval62.5%
sqrt-prod62.5%
*-un-lft-identity62.5%
Applied egg-rr62.5%
Final simplification75.9%
(FPCore (re im)
:precision binary64
(if (<= re -4e+39)
(* 0.5 (* (sqrt 2.0) (sqrt (* re -2.0))))
(if (<= re 6.4e+32)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 8e+209)
(* 0.5 (sqrt (/ (pow im 2.0) re)))
(* 0.5 (* im (sqrt (/ 1.0 re))))))))
double code(double re, double im) {
double tmp;
if (re <= -4e+39) {
tmp = 0.5 * (sqrt(2.0) * sqrt((re * -2.0)));
} else if (re <= 6.4e+32) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 8e+209) {
tmp = 0.5 * sqrt((pow(im, 2.0) / 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 <= (-4d+39)) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt((re * (-2.0d0))))
else if (re <= 6.4d+32) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 8d+209) then
tmp = 0.5d0 * sqrt(((im ** 2.0d0) / 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 <= -4e+39) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt((re * -2.0)));
} else if (re <= 6.4e+32) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 8e+209) {
tmp = 0.5 * Math.sqrt((Math.pow(im, 2.0) / re));
} else {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4e+39: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt((re * -2.0))) elif re <= 6.4e+32: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 8e+209: tmp = 0.5 * math.sqrt((math.pow(im, 2.0) / re)) else: tmp = 0.5 * (im * math.sqrt((1.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -4e+39) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(re * -2.0)))); elseif (re <= 6.4e+32) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 8e+209) tmp = Float64(0.5 * sqrt(Float64((im ^ 2.0) / 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 <= -4e+39) tmp = 0.5 * (sqrt(2.0) * sqrt((re * -2.0))); elseif (re <= 6.4e+32) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 8e+209) tmp = 0.5 * sqrt(((im ^ 2.0) / re)); else tmp = 0.5 * (im * sqrt((1.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4e+39], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(re * -2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.4e+32], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8e+209], N[(0.5 * N[Sqrt[N[(N[Power[im, 2.0], $MachinePrecision] / re), $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 -4 \cdot 10^{+39}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{re \cdot -2}\right)\\
\mathbf{elif}\;re \leq 6.4 \cdot 10^{+32}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 8 \cdot 10^{+209}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{{im}^{2}}{re}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\end{array}
\end{array}
if re < -3.99999999999999976e39Initial program 49.5%
*-commutative49.5%
hypot-udef98.3%
sqrt-prod99.3%
Applied egg-rr99.3%
Taylor expanded in re around -inf 84.3%
*-commutative84.3%
Simplified84.3%
if -3.99999999999999976e39 < re < 6.3999999999999998e32Initial program 62.4%
Taylor expanded in re around 0 78.4%
if 6.3999999999999998e32 < re < 8.0000000000000006e209Initial program 49.1%
Taylor expanded in re around inf 62.2%
if 8.0000000000000006e209 < re Initial program 3.0%
Taylor expanded in im around 0 61.8%
associate-*l*61.7%
associate-*l*61.9%
Simplified61.9%
associate-*r*61.7%
sqrt-unprod62.5%
metadata-eval62.5%
sqrt-prod62.5%
*-un-lft-identity62.5%
Applied egg-rr62.5%
Final simplification76.2%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* (- (hypot re im) re) 2.0))))
double code(double re, double im) {
return 0.5 * sqrt(((hypot(re, im) - re) * 2.0));
}
public static double code(double re, double im) {
return 0.5 * Math.sqrt(((Math.hypot(re, im) - re) * 2.0));
}
def code(re, im): return 0.5 * math.sqrt(((math.hypot(re, im) - re) * 2.0))
function code(re, im) return Float64(0.5 * sqrt(Float64(Float64(hypot(re, im) - re) * 2.0))) end
function tmp = code(re, im) tmp = 0.5 * sqrt(((hypot(re, im) - re) * 2.0)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{\left(\mathsf{hypot}\left(re, im\right) - re\right) \cdot 2}
\end{array}
Initial program 53.5%
sub-neg53.5%
sqr-neg53.5%
sub-neg53.5%
sqr-neg53.5%
hypot-def92.2%
Simplified92.2%
Final simplification92.2%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (* 0.5 (sqrt (* im 2.0)))))
(if (<= re -1.3e+31)
t_0
(if (<= re -1.75e-39)
t_1
(if (<= re -4.2e-129)
t_0
(if (<= re 1.16e+33)
t_1
(if (<= re 1.2e+167)
(* 0.5 (+ (+ im 1.0) -1.0))
(* 0.5 (* im (pow re -0.5))))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double t_1 = 0.5 * sqrt((im * 2.0));
double tmp;
if (re <= -1.3e+31) {
tmp = t_0;
} else if (re <= -1.75e-39) {
tmp = t_1;
} else if (re <= -4.2e-129) {
tmp = t_0;
} else if (re <= 1.16e+33) {
tmp = t_1;
} else if (re <= 1.2e+167) {
tmp = 0.5 * ((im + 1.0) + -1.0);
} else {
tmp = 0.5 * (im * pow(re, -0.5));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
t_1 = 0.5d0 * sqrt((im * 2.0d0))
if (re <= (-1.3d+31)) then
tmp = t_0
else if (re <= (-1.75d-39)) then
tmp = t_1
else if (re <= (-4.2d-129)) then
tmp = t_0
else if (re <= 1.16d+33) then
tmp = t_1
else if (re <= 1.2d+167) then
tmp = 0.5d0 * ((im + 1.0d0) + (-1.0d0))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((re * -4.0));
double t_1 = 0.5 * Math.sqrt((im * 2.0));
double tmp;
if (re <= -1.3e+31) {
tmp = t_0;
} else if (re <= -1.75e-39) {
tmp = t_1;
} else if (re <= -4.2e-129) {
tmp = t_0;
} else if (re <= 1.16e+33) {
tmp = t_1;
} else if (re <= 1.2e+167) {
tmp = 0.5 * ((im + 1.0) + -1.0);
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) t_1 = 0.5 * math.sqrt((im * 2.0)) tmp = 0 if re <= -1.3e+31: tmp = t_0 elif re <= -1.75e-39: tmp = t_1 elif re <= -4.2e-129: tmp = t_0 elif re <= 1.16e+33: tmp = t_1 elif re <= 1.2e+167: tmp = 0.5 * ((im + 1.0) + -1.0) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) t_1 = Float64(0.5 * sqrt(Float64(im * 2.0))) tmp = 0.0 if (re <= -1.3e+31) tmp = t_0; elseif (re <= -1.75e-39) tmp = t_1; elseif (re <= -4.2e-129) tmp = t_0; elseif (re <= 1.16e+33) tmp = t_1; elseif (re <= 1.2e+167) tmp = Float64(0.5 * Float64(Float64(im + 1.0) + -1.0)); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); t_1 = 0.5 * sqrt((im * 2.0)); tmp = 0.0; if (re <= -1.3e+31) tmp = t_0; elseif (re <= -1.75e-39) tmp = t_1; elseif (re <= -4.2e-129) tmp = t_0; elseif (re <= 1.16e+33) tmp = t_1; elseif (re <= 1.2e+167) tmp = 0.5 * ((im + 1.0) + -1.0); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.3e+31], t$95$0, If[LessEqual[re, -1.75e-39], t$95$1, If[LessEqual[re, -4.2e-129], t$95$0, If[LessEqual[re, 1.16e+33], t$95$1, If[LessEqual[re, 1.2e+167], N[(0.5 * N[(N[(im + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
t_1 := 0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{if}\;re \leq -1.3 \cdot 10^{+31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq -1.75 \cdot 10^{-39}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;re \leq -4.2 \cdot 10^{-129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 1.16 \cdot 10^{+33}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;re \leq 1.2 \cdot 10^{+167}:\\
\;\;\;\;0.5 \cdot \left(\left(im + 1\right) + -1\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -1.3e31 or -1.75e-39 < re < -4.2e-129Initial program 60.7%
Taylor expanded in re around -inf 77.5%
*-commutative77.5%
Simplified77.5%
if -1.3e31 < re < -1.75e-39 or -4.2e-129 < re < 1.16000000000000001e33Initial program 57.7%
Taylor expanded in re around 0 83.8%
*-commutative83.8%
Simplified83.8%
if 1.16000000000000001e33 < re < 1.19999999999999999e167Initial program 57.7%
Taylor expanded in im around 0 25.2%
associate-*l*25.3%
associate-*l*25.4%
Simplified25.4%
add-cbrt-cube70.6%
pow370.6%
associate-*r*70.6%
sqrt-unprod70.6%
metadata-eval70.6%
sqrt-prod70.6%
*-un-lft-identity70.6%
inv-pow70.6%
sqrt-pow170.6%
metadata-eval70.6%
Applied egg-rr70.6%
Applied egg-rr64.9%
if 1.19999999999999999e167 < re Initial program 3.1%
Taylor expanded in im around 0 56.0%
associate-*l*56.0%
associate-*l*56.1%
Simplified56.1%
associate-*r*56.0%
sqrt-unprod56.7%
metadata-eval56.7%
metadata-eval56.7%
expm1-log1p-u56.7%
*-un-lft-identity56.7%
expm1-udef35.1%
inv-pow35.1%
sqrt-pow135.1%
metadata-eval35.1%
Applied egg-rr35.1%
expm1-def56.7%
expm1-log1p56.7%
Simplified56.7%
Final simplification77.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (* 0.5 (sqrt (* im 2.0)))))
(if (<= re -2.5e+23)
t_0
(if (<= re -5.1e-39)
t_1
(if (<= re -4.2e-129)
t_0
(if (<= re 4.2e+26) t_1 (* 0.5 (+ (+ im 1.0) -1.0))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double t_1 = 0.5 * sqrt((im * 2.0));
double tmp;
if (re <= -2.5e+23) {
tmp = t_0;
} else if (re <= -5.1e-39) {
tmp = t_1;
} else if (re <= -4.2e-129) {
tmp = t_0;
} else if (re <= 4.2e+26) {
tmp = t_1;
} else {
tmp = 0.5 * ((im + 1.0) + -1.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
t_1 = 0.5d0 * sqrt((im * 2.0d0))
if (re <= (-2.5d+23)) then
tmp = t_0
else if (re <= (-5.1d-39)) then
tmp = t_1
else if (re <= (-4.2d-129)) then
tmp = t_0
else if (re <= 4.2d+26) then
tmp = t_1
else
tmp = 0.5d0 * ((im + 1.0d0) + (-1.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((re * -4.0));
double t_1 = 0.5 * Math.sqrt((im * 2.0));
double tmp;
if (re <= -2.5e+23) {
tmp = t_0;
} else if (re <= -5.1e-39) {
tmp = t_1;
} else if (re <= -4.2e-129) {
tmp = t_0;
} else if (re <= 4.2e+26) {
tmp = t_1;
} else {
tmp = 0.5 * ((im + 1.0) + -1.0);
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) t_1 = 0.5 * math.sqrt((im * 2.0)) tmp = 0 if re <= -2.5e+23: tmp = t_0 elif re <= -5.1e-39: tmp = t_1 elif re <= -4.2e-129: tmp = t_0 elif re <= 4.2e+26: tmp = t_1 else: tmp = 0.5 * ((im + 1.0) + -1.0) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) t_1 = Float64(0.5 * sqrt(Float64(im * 2.0))) tmp = 0.0 if (re <= -2.5e+23) tmp = t_0; elseif (re <= -5.1e-39) tmp = t_1; elseif (re <= -4.2e-129) tmp = t_0; elseif (re <= 4.2e+26) tmp = t_1; else tmp = Float64(0.5 * Float64(Float64(im + 1.0) + -1.0)); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); t_1 = 0.5 * sqrt((im * 2.0)); tmp = 0.0; if (re <= -2.5e+23) tmp = t_0; elseif (re <= -5.1e-39) tmp = t_1; elseif (re <= -4.2e-129) tmp = t_0; elseif (re <= 4.2e+26) tmp = t_1; else tmp = 0.5 * ((im + 1.0) + -1.0); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -2.5e+23], t$95$0, If[LessEqual[re, -5.1e-39], t$95$1, If[LessEqual[re, -4.2e-129], t$95$0, If[LessEqual[re, 4.2e+26], t$95$1, N[(0.5 * N[(N[(im + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
t_1 := 0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{if}\;re \leq -2.5 \cdot 10^{+23}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq -5.1 \cdot 10^{-39}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;re \leq -4.2 \cdot 10^{-129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 4.2 \cdot 10^{+26}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(im + 1\right) + -1\right)\\
\end{array}
\end{array}
if re < -2.5e23 or -5.09999999999999988e-39 < re < -4.2e-129Initial program 60.7%
Taylor expanded in re around -inf 77.5%
*-commutative77.5%
Simplified77.5%
if -2.5e23 < re < -5.09999999999999988e-39 or -4.2e-129 < re < 4.2000000000000002e26Initial program 57.7%
Taylor expanded in re around 0 83.8%
*-commutative83.8%
Simplified83.8%
if 4.2000000000000002e26 < re Initial program 34.3%
Taylor expanded in im around 0 38.4%
associate-*l*38.4%
associate-*l*38.5%
Simplified38.5%
add-cbrt-cube67.7%
pow367.8%
associate-*r*67.7%
sqrt-unprod67.8%
metadata-eval67.8%
sqrt-prod67.8%
*-un-lft-identity67.8%
inv-pow67.8%
sqrt-pow167.8%
metadata-eval67.8%
Applied egg-rr67.8%
Applied egg-rr49.4%
Final simplification74.4%
(FPCore (re im)
:precision binary64
(if (<= re -4.7e+39)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 8e+31)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 8.1e+170)
(* 0.5 (+ (+ im 1.0) -1.0))
(* 0.5 (* im (sqrt (/ 1.0 re))))))))
double code(double re, double im) {
double tmp;
if (re <= -4.7e+39) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 8e+31) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 8.1e+170) {
tmp = 0.5 * ((im + 1.0) + -1.0);
} 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 <= (-4.7d+39)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 8d+31) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 8.1d+170) then
tmp = 0.5d0 * ((im + 1.0d0) + (-1.0d0))
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 <= -4.7e+39) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 8e+31) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 8.1e+170) {
tmp = 0.5 * ((im + 1.0) + -1.0);
} else {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.7e+39: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 8e+31: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 8.1e+170: tmp = 0.5 * ((im + 1.0) + -1.0) else: tmp = 0.5 * (im * math.sqrt((1.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.7e+39) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 8e+31) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 8.1e+170) tmp = Float64(0.5 * Float64(Float64(im + 1.0) + -1.0)); 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 <= -4.7e+39) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 8e+31) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 8.1e+170) tmp = 0.5 * ((im + 1.0) + -1.0); else tmp = 0.5 * (im * sqrt((1.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.7e+39], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8e+31], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.1e+170], N[(0.5 * N[(N[(im + 1.0), $MachinePrecision] + -1.0), $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 -4.7 \cdot 10^{+39}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 8 \cdot 10^{+31}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 8.1 \cdot 10^{+170}:\\
\;\;\;\;0.5 \cdot \left(\left(im + 1\right) + -1\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\end{array}
\end{array}
if re < -4.6999999999999999e39Initial program 49.5%
Taylor expanded in re around -inf 83.2%
*-commutative83.2%
Simplified83.2%
if -4.6999999999999999e39 < re < 7.9999999999999997e31Initial program 62.4%
Taylor expanded in re around 0 78.4%
if 7.9999999999999997e31 < re < 8.09999999999999965e170Initial program 57.7%
Taylor expanded in im around 0 25.2%
associate-*l*25.3%
associate-*l*25.4%
Simplified25.4%
add-cbrt-cube70.6%
pow370.6%
associate-*r*70.6%
sqrt-unprod70.6%
metadata-eval70.6%
sqrt-prod70.6%
*-un-lft-identity70.6%
inv-pow70.6%
sqrt-pow170.6%
metadata-eval70.6%
Applied egg-rr70.6%
Applied egg-rr64.9%
if 8.09999999999999965e170 < re Initial program 3.1%
Taylor expanded in im around 0 56.0%
associate-*l*56.0%
associate-*l*56.1%
Simplified56.1%
associate-*r*56.0%
sqrt-unprod56.7%
metadata-eval56.7%
sqrt-prod56.7%
*-un-lft-identity56.7%
Applied egg-rr56.7%
Final simplification75.7%
(FPCore (re im)
:precision binary64
(if (<= re -4.6e+39)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 4.2e+29)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 2.7e+170)
(* 0.5 (+ (+ im 1.0) -1.0))
(* 0.5 (* im (pow re -0.5)))))))
double code(double re, double im) {
double tmp;
if (re <= -4.6e+39) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4.2e+29) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 2.7e+170) {
tmp = 0.5 * ((im + 1.0) + -1.0);
} else {
tmp = 0.5 * (im * pow(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.6d+39)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4.2d+29) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 2.7d+170) then
tmp = 0.5d0 * ((im + 1.0d0) + (-1.0d0))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4.6e+39) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4.2e+29) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 2.7e+170) {
tmp = 0.5 * ((im + 1.0) + -1.0);
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.6e+39: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4.2e+29: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 2.7e+170: tmp = 0.5 * ((im + 1.0) + -1.0) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.6e+39) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4.2e+29) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 2.7e+170) tmp = Float64(0.5 * Float64(Float64(im + 1.0) + -1.0)); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.6e+39) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4.2e+29) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 2.7e+170) tmp = 0.5 * ((im + 1.0) + -1.0); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.6e+39], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.2e+29], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.7e+170], N[(0.5 * N[(N[(im + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.6 \cdot 10^{+39}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4.2 \cdot 10^{+29}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 2.7 \cdot 10^{+170}:\\
\;\;\;\;0.5 \cdot \left(\left(im + 1\right) + -1\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -4.60000000000000024e39Initial program 49.5%
Taylor expanded in re around -inf 83.2%
*-commutative83.2%
Simplified83.2%
if -4.60000000000000024e39 < re < 4.2000000000000003e29Initial program 62.4%
Taylor expanded in re around 0 78.4%
if 4.2000000000000003e29 < re < 2.7000000000000002e170Initial program 57.7%
Taylor expanded in im around 0 25.2%
associate-*l*25.3%
associate-*l*25.4%
Simplified25.4%
add-cbrt-cube70.6%
pow370.6%
associate-*r*70.6%
sqrt-unprod70.6%
metadata-eval70.6%
sqrt-prod70.6%
*-un-lft-identity70.6%
inv-pow70.6%
sqrt-pow170.6%
metadata-eval70.6%
Applied egg-rr70.6%
Applied egg-rr64.9%
if 2.7000000000000002e170 < re Initial program 3.1%
Taylor expanded in im around 0 56.0%
associate-*l*56.0%
associate-*l*56.1%
Simplified56.1%
associate-*r*56.0%
sqrt-unprod56.7%
metadata-eval56.7%
metadata-eval56.7%
expm1-log1p-u56.7%
*-un-lft-identity56.7%
expm1-udef35.1%
inv-pow35.1%
sqrt-pow135.1%
metadata-eval35.1%
Applied egg-rr35.1%
expm1-def56.7%
expm1-log1p56.7%
Simplified56.7%
Final simplification75.7%
(FPCore (re im) :precision binary64 (if (<= im 1.5e-92) (* 0.5 (+ (+ im 1.0) -1.0)) (* 0.5 (sqrt (* im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 1.5e-92) {
tmp = 0.5 * ((im + 1.0) + -1.0);
} else {
tmp = 0.5 * sqrt((im * 2.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.5d-92) then
tmp = 0.5d0 * ((im + 1.0d0) + (-1.0d0))
else
tmp = 0.5d0 * sqrt((im * 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.5e-92) {
tmp = 0.5 * ((im + 1.0) + -1.0);
} else {
tmp = 0.5 * Math.sqrt((im * 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.5e-92: tmp = 0.5 * ((im + 1.0) + -1.0) else: tmp = 0.5 * math.sqrt((im * 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.5e-92) tmp = Float64(0.5 * Float64(Float64(im + 1.0) + -1.0)); else tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.5e-92) tmp = 0.5 * ((im + 1.0) + -1.0); else tmp = 0.5 * sqrt((im * 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.5e-92], N[(0.5 * N[(N[(im + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.5 \cdot 10^{-92}:\\
\;\;\;\;0.5 \cdot \left(\left(im + 1\right) + -1\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if im < 1.50000000000000007e-92Initial program 70.2%
Taylor expanded in im around 0 7.6%
associate-*l*7.6%
associate-*l*7.6%
Simplified7.6%
add-cbrt-cube37.4%
pow337.4%
associate-*r*37.4%
sqrt-unprod37.4%
metadata-eval37.4%
sqrt-prod37.4%
*-un-lft-identity37.4%
inv-pow37.4%
sqrt-pow137.4%
metadata-eval37.4%
Applied egg-rr37.4%
Applied egg-rr38.9%
if 1.50000000000000007e-92 < im Initial program 44.9%
Taylor expanded in re around 0 70.9%
*-commutative70.9%
Simplified70.9%
Final simplification60.0%
(FPCore (re im) :precision binary64 (* 0.5 (+ (+ im 1.0) -1.0)))
double code(double re, double im) {
return 0.5 * ((im + 1.0) + -1.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * ((im + 1.0d0) + (-1.0d0))
end function
public static double code(double re, double im) {
return 0.5 * ((im + 1.0) + -1.0);
}
def code(re, im): return 0.5 * ((im + 1.0) + -1.0)
function code(re, im) return Float64(0.5 * Float64(Float64(im + 1.0) + -1.0)) end
function tmp = code(re, im) tmp = 0.5 * ((im + 1.0) + -1.0); end
code[re_, im_] := N[(0.5 * N[(N[(im + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(\left(im + 1\right) + -1\right)
\end{array}
Initial program 53.5%
Taylor expanded in im around 0 11.2%
associate-*l*11.2%
associate-*l*11.3%
Simplified11.3%
add-cbrt-cube20.9%
pow320.9%
associate-*r*20.9%
sqrt-unprod20.9%
metadata-eval20.9%
sqrt-prod20.9%
*-un-lft-identity20.9%
inv-pow20.9%
sqrt-pow120.9%
metadata-eval20.9%
Applied egg-rr20.9%
Applied egg-rr18.7%
Final simplification18.7%
(FPCore (re im) :precision binary64 (* 0.5 im))
double code(double re, double im) {
return 0.5 * im;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * im
end function
public static double code(double re, double im) {
return 0.5 * im;
}
def code(re, im): return 0.5 * im
function code(re, im) return Float64(0.5 * im) end
function tmp = code(re, im) tmp = 0.5 * im; end
code[re_, im_] := N[(0.5 * im), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot im
\end{array}
Initial program 53.5%
Taylor expanded in im around 0 11.2%
associate-*l*11.2%
associate-*l*11.3%
Simplified11.3%
add-cbrt-cube20.9%
pow320.9%
associate-*r*20.9%
sqrt-unprod20.9%
metadata-eval20.9%
sqrt-prod20.9%
*-un-lft-identity20.9%
inv-pow20.9%
sqrt-pow120.9%
metadata-eval20.9%
Applied egg-rr20.9%
Applied egg-rr6.3%
+-lft-identity6.3%
Simplified6.3%
Final simplification6.3%
herbie shell --seed 2024031
(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)))))