
(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 (- (sqrt (+ (* re re) (* im im))) re))) 0.0) (/ (* im 0.5) (sqrt re)) (sqrt (* 0.5 (- (hypot re im) re)))))
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = (im * 0.5) / sqrt(re);
} else {
tmp = sqrt((0.5 * (hypot(re, im) - re)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = (im * 0.5) / Math.sqrt(re);
} else {
tmp = Math.sqrt((0.5 * (Math.hypot(re, im) - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re))) <= 0.0: tmp = (im * 0.5) / math.sqrt(re) else: tmp = math.sqrt((0.5 * (math.hypot(re, im) - re))) return tmp
function code(re, im) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))) <= 0.0) tmp = Float64(Float64(im * 0.5) / sqrt(re)); else tmp = sqrt(Float64(0.5 * Float64(hypot(re, im) - re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) tmp = (im * 0.5) / sqrt(re); else tmp = sqrt((0.5 * (hypot(re, im) - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \leq 0:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 8.7%
Taylor expanded in re around inf 98.4%
associate-*l*98.3%
*-commutative98.3%
associate-*r*98.7%
Simplified98.7%
pow198.7%
add-log-exp11.0%
associate-*l*11.0%
exp-prod11.0%
sqrt-unprod11.0%
metadata-eval11.0%
metadata-eval11.0%
pow111.0%
add-log-exp99.4%
inv-pow99.4%
sqrt-pow199.4%
metadata-eval99.4%
Applied egg-rr99.4%
unpow199.4%
associate-*r*99.4%
*-commutative99.4%
Simplified99.4%
*-commutative99.4%
associate-*r*99.4%
rem-cube-cbrt97.6%
rem-cube-cbrt99.4%
add-sqr-sqrt99.4%
sqrt-unprod60.0%
swap-sqr49.4%
unpow249.4%
pow-prod-up49.4%
metadata-eval49.4%
inv-pow49.4%
div-inv49.4%
sqrt-div53.6%
sqrt-pow199.6%
metadata-eval99.6%
pow199.6%
associate-*r/99.6%
Applied egg-rr99.6%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 42.5%
pow142.5%
Applied egg-rr91.9%
unpow191.9%
*-commutative91.9%
associate-*r*91.9%
metadata-eval91.9%
Simplified91.9%
Final simplification92.7%
(FPCore (re im) :precision binary64 (if (<= re -3.8e+104) (sqrt (- re)) (if (<= re 4e-44) (sqrt (* 0.5 (- im re))) (* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -3.8e+104) {
tmp = sqrt(-re);
} else if (re <= 4e-44) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * 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 <= (-3.8d+104)) then
tmp = sqrt(-re)
else if (re <= 4d-44) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.8e+104) {
tmp = Math.sqrt(-re);
} else if (re <= 4e-44) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.8e+104: tmp = math.sqrt(-re) elif re <= 4e-44: tmp = math.sqrt((0.5 * (im - re))) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.8e+104) tmp = sqrt(Float64(-re)); elseif (re <= 4e-44) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.8e+104) tmp = sqrt(-re); elseif (re <= 4e-44) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.8e+104], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 4e-44], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.8 \cdot 10^{+104}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 4 \cdot 10^{-44}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -3.79999999999999969e104Initial program 26.2%
pow126.2%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.8%
neg-mul-182.8%
Simplified82.8%
if -3.79999999999999969e104 < re < 3.99999999999999981e-44Initial program 55.6%
pow155.6%
Applied egg-rr94.0%
unpow194.0%
*-commutative94.0%
associate-*r*94.0%
metadata-eval94.0%
Simplified94.0%
Taylor expanded in re around 0 77.4%
neg-mul-177.4%
sub-neg77.4%
Simplified77.4%
if 3.99999999999999981e-44 < re Initial program 11.2%
Taylor expanded in re around inf 73.4%
associate-*l*73.4%
*-commutative73.4%
associate-*r*73.5%
Simplified73.5%
pow173.5%
add-log-exp19.8%
associate-*l*19.8%
exp-prod19.8%
sqrt-unprod19.8%
metadata-eval19.8%
metadata-eval19.8%
pow119.8%
add-log-exp74.0%
inv-pow74.0%
sqrt-pow174.0%
metadata-eval74.0%
Applied egg-rr74.0%
unpow174.0%
associate-*r*74.1%
*-commutative74.1%
Simplified74.1%
(FPCore (re im) :precision binary64 (if (<= re -2.8e+103) (sqrt (- re)) (if (<= re 1.25e-43) (sqrt (* 0.5 (- im re))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -2.8e+103) {
tmp = sqrt(-re);
} else if (re <= 1.25e-43) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) / sqrt(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-2.8d+103)) then
tmp = sqrt(-re)
else if (re <= 1.25d-43) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = (im * 0.5d0) / sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.8e+103) {
tmp = Math.sqrt(-re);
} else if (re <= 1.25e-43) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.8e+103: tmp = math.sqrt(-re) elif re <= 1.25e-43: tmp = math.sqrt((0.5 * (im - re))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.8e+103) tmp = sqrt(Float64(-re)); elseif (re <= 1.25e-43) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.8e+103) tmp = sqrt(-re); elseif (re <= 1.25e-43) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.8e+103], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 1.25e-43], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.8 \cdot 10^{+103}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 1.25 \cdot 10^{-43}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.80000000000000008e103Initial program 26.2%
pow126.2%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.8%
neg-mul-182.8%
Simplified82.8%
if -2.80000000000000008e103 < re < 1.25000000000000005e-43Initial program 55.6%
pow155.6%
Applied egg-rr94.0%
unpow194.0%
*-commutative94.0%
associate-*r*94.0%
metadata-eval94.0%
Simplified94.0%
Taylor expanded in re around 0 77.4%
neg-mul-177.4%
sub-neg77.4%
Simplified77.4%
if 1.25000000000000005e-43 < re Initial program 11.2%
Taylor expanded in re around inf 73.4%
associate-*l*73.4%
*-commutative73.4%
associate-*r*73.5%
Simplified73.5%
pow173.5%
add-log-exp19.8%
associate-*l*19.8%
exp-prod19.8%
sqrt-unprod19.8%
metadata-eval19.8%
metadata-eval19.8%
pow119.8%
add-log-exp74.0%
inv-pow74.0%
sqrt-pow174.0%
metadata-eval74.0%
Applied egg-rr74.0%
unpow174.0%
associate-*r*74.1%
*-commutative74.1%
Simplified74.1%
*-commutative74.1%
associate-*r*74.0%
rem-cube-cbrt73.1%
rem-cube-cbrt74.0%
add-sqr-sqrt73.9%
sqrt-unprod47.5%
swap-sqr39.7%
unpow239.7%
pow-prod-up39.7%
metadata-eval39.7%
inv-pow39.7%
div-inv39.8%
sqrt-div48.5%
sqrt-pow174.0%
metadata-eval74.0%
pow174.0%
associate-*r/74.0%
Applied egg-rr74.0%
Final simplification77.5%
(FPCore (re im) :precision binary64 (if (<= re -2.8e+103) (sqrt (- re)) (if (<= re 5e-46) (sqrt (* 0.5 (- im re))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -2.8e+103) {
tmp = sqrt(-re);
} else if (re <= 5e-46) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = im * (0.5 / sqrt(re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-2.8d+103)) then
tmp = sqrt(-re)
else if (re <= 5d-46) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = im * (0.5d0 / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.8e+103) {
tmp = Math.sqrt(-re);
} else if (re <= 5e-46) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.8e+103: tmp = math.sqrt(-re) elif re <= 5e-46: tmp = math.sqrt((0.5 * (im - re))) else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.8e+103) tmp = sqrt(Float64(-re)); elseif (re <= 5e-46) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.8e+103) tmp = sqrt(-re); elseif (re <= 5e-46) tmp = sqrt((0.5 * (im - re))); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.8e+103], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 5e-46], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.8 \cdot 10^{+103}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 5 \cdot 10^{-46}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.80000000000000008e103Initial program 26.2%
pow126.2%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.8%
neg-mul-182.8%
Simplified82.8%
if -2.80000000000000008e103 < re < 4.99999999999999992e-46Initial program 55.6%
pow155.6%
Applied egg-rr94.0%
unpow194.0%
*-commutative94.0%
associate-*r*94.0%
metadata-eval94.0%
Simplified94.0%
Taylor expanded in re around 0 77.4%
neg-mul-177.4%
sub-neg77.4%
Simplified77.4%
if 4.99999999999999992e-46 < re Initial program 11.2%
Taylor expanded in re around inf 73.4%
associate-*l*73.4%
*-commutative73.4%
associate-*r*73.5%
Simplified73.5%
pow173.5%
add-log-exp19.8%
associate-*l*19.8%
exp-prod19.8%
sqrt-unprod19.8%
metadata-eval19.8%
metadata-eval19.8%
pow119.8%
add-log-exp74.0%
inv-pow74.0%
sqrt-pow174.0%
metadata-eval74.0%
Applied egg-rr74.0%
unpow174.0%
associate-*r*74.1%
*-commutative74.1%
Simplified74.1%
*-commutative74.1%
associate-*r*74.0%
rem-cube-cbrt73.1%
rem-cube-cbrt74.0%
add-sqr-sqrt73.9%
sqrt-unprod47.5%
swap-sqr39.7%
unpow239.7%
pow-prod-up39.7%
metadata-eval39.7%
inv-pow39.7%
div-inv39.8%
sqrt-div48.5%
sqrt-pow174.0%
metadata-eval74.0%
pow174.0%
associate-*r/74.0%
Applied egg-rr74.0%
associate-*r/74.0%
*-lft-identity74.0%
associate-*l/73.9%
associate-/r/73.1%
associate-*r/73.1%
metadata-eval73.1%
Simplified73.1%
associate-/r/73.9%
Applied egg-rr73.9%
Final simplification77.5%
(FPCore (re im) :precision binary64 (if (<= re -4e+104) (sqrt (- re)) (if (<= re 3.5e+155) (sqrt (* 0.5 (- im re))) (sqrt (* 0.5 (- re re))))))
double code(double re, double im) {
double tmp;
if (re <= -4e+104) {
tmp = sqrt(-re);
} else if (re <= 3.5e+155) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = sqrt((0.5 * (re - 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+104)) then
tmp = sqrt(-re)
else if (re <= 3.5d+155) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = sqrt((0.5d0 * (re - re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4e+104) {
tmp = Math.sqrt(-re);
} else if (re <= 3.5e+155) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = Math.sqrt((0.5 * (re - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4e+104: tmp = math.sqrt(-re) elif re <= 3.5e+155: tmp = math.sqrt((0.5 * (im - re))) else: tmp = math.sqrt((0.5 * (re - re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -4e+104) tmp = sqrt(Float64(-re)); elseif (re <= 3.5e+155) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = sqrt(Float64(0.5 * Float64(re - re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4e+104) tmp = sqrt(-re); elseif (re <= 3.5e+155) tmp = sqrt((0.5 * (im - re))); else tmp = sqrt((0.5 * (re - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4e+104], N[Sqrt[(-re)], $MachinePrecision], If[LessEqual[re, 3.5e+155], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(re - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4 \cdot 10^{+104}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{elif}\;re \leq 3.5 \cdot 10^{+155}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(re - re\right)}\\
\end{array}
\end{array}
if re < -4e104Initial program 26.2%
pow126.2%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.8%
neg-mul-182.8%
Simplified82.8%
if -4e104 < re < 3.49999999999999985e155Initial program 47.3%
pow147.3%
Applied egg-rr83.9%
unpow183.9%
*-commutative83.9%
associate-*r*83.9%
metadata-eval83.9%
Simplified83.9%
Taylor expanded in re around 0 69.6%
neg-mul-169.6%
sub-neg69.6%
Simplified69.6%
if 3.49999999999999985e155 < re Initial program 2.4%
pow12.4%
Applied egg-rr43.7%
unpow143.7%
*-commutative43.7%
associate-*r*43.7%
metadata-eval43.7%
Simplified43.7%
Taylor expanded in re around inf 36.2%
(FPCore (re im) :precision binary64 (if (<= re -5.5e+105) (sqrt (- re)) (sqrt (* 0.5 (- im re)))))
double code(double re, double im) {
double tmp;
if (re <= -5.5e+105) {
tmp = sqrt(-re);
} else {
tmp = sqrt((0.5 * (im - 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.5d+105)) then
tmp = sqrt(-re)
else
tmp = sqrt((0.5d0 * (im - re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -5.5e+105) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((0.5 * (im - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5.5e+105: tmp = math.sqrt(-re) else: tmp = math.sqrt((0.5 * (im - re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -5.5e+105) tmp = sqrt(Float64(-re)); else tmp = sqrt(Float64(0.5 * Float64(im - re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5.5e+105) tmp = sqrt(-re); else tmp = sqrt((0.5 * (im - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5.5e+105], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5.5 \cdot 10^{+105}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\end{array}
\end{array}
if re < -5.49999999999999979e105Initial program 26.2%
pow126.2%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 82.8%
neg-mul-182.8%
Simplified82.8%
if -5.49999999999999979e105 < re Initial program 41.7%
pow141.7%
Applied egg-rr78.8%
unpow178.8%
*-commutative78.8%
associate-*r*78.8%
metadata-eval78.8%
Simplified78.8%
Taylor expanded in re around 0 61.8%
neg-mul-161.8%
sub-neg61.8%
Simplified61.8%
(FPCore (re im) :precision binary64 (if (<= re -1.36e+63) (sqrt (- re)) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -1.36e+63) {
tmp = sqrt(-re);
} else {
tmp = sqrt((im * 0.5));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.36d+63)) then
tmp = sqrt(-re)
else
tmp = sqrt((im * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.36e+63) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.36e+63: tmp = math.sqrt(-re) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.36e+63) tmp = sqrt(Float64(-re)); else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.36e+63) tmp = sqrt(-re); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.36e+63], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.36 \cdot 10^{+63}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -1.36000000000000006e63Initial program 29.9%
pow129.9%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 78.6%
neg-mul-178.6%
Simplified78.6%
if -1.36000000000000006e63 < re Initial program 41.3%
pow141.3%
Applied egg-rr78.0%
unpow178.0%
*-commutative78.0%
associate-*r*78.0%
metadata-eval78.0%
Simplified78.0%
Taylor expanded in re around 0 61.6%
*-commutative61.6%
Simplified61.6%
(FPCore (re im) :precision binary64 (if (<= re -5e-310) (sqrt (- re)) (sqrt re)))
double code(double re, double im) {
double tmp;
if (re <= -5e-310) {
tmp = sqrt(-re);
} else {
tmp = 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 <= (-5d-310)) then
tmp = sqrt(-re)
else
tmp = sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -5e-310) {
tmp = Math.sqrt(-re);
} else {
tmp = Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5e-310: tmp = math.sqrt(-re) else: tmp = math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -5e-310) tmp = sqrt(Float64(-re)); else tmp = sqrt(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5e-310) tmp = sqrt(-re); else tmp = sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5e-310], N[Sqrt[(-re)], $MachinePrecision], N[Sqrt[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{-re}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{re}\\
\end{array}
\end{array}
if re < -4.999999999999985e-310Initial program 52.4%
pow152.4%
Applied egg-rr100.0%
unpow1100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around -inf 54.4%
neg-mul-154.4%
Simplified54.4%
if -4.999999999999985e-310 < re Initial program 25.2%
pow125.2%
Applied egg-rr65.6%
unpow165.6%
*-commutative65.6%
associate-*r*65.6%
metadata-eval65.6%
Simplified65.6%
Taylor expanded in re around -inf 0.0%
neg-mul-10.0%
Simplified0.0%
expm1-log1p-u0.0%
expm1-undefine0.0%
add-sqr-sqrt0.0%
sqrt-unprod3.8%
sqr-neg3.8%
sqrt-unprod4.1%
add-sqr-sqrt4.1%
Applied egg-rr4.1%
sub-neg4.1%
metadata-eval4.1%
+-commutative4.1%
log1p-undefine4.1%
rem-exp-log4.1%
associate-+r+5.6%
metadata-eval5.6%
metadata-eval5.6%
remove-double-neg5.6%
distribute-neg-in5.6%
+-lft-identity5.6%
remove-double-neg5.6%
Simplified5.6%
(FPCore (re im) :precision binary64 (sqrt re))
double code(double re, double im) {
return sqrt(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt(re)
end function
public static double code(double re, double im) {
return Math.sqrt(re);
}
def code(re, im): return math.sqrt(re)
function code(re, im) return sqrt(re) end
function tmp = code(re, im) tmp = sqrt(re); end
code[re_, im_] := N[Sqrt[re], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{re}
\end{array}
Initial program 38.8%
pow138.8%
Applied egg-rr82.8%
unpow182.8%
*-commutative82.8%
associate-*r*82.8%
metadata-eval82.8%
Simplified82.8%
Taylor expanded in re around -inf 27.2%
neg-mul-127.2%
Simplified27.2%
expm1-log1p-u25.7%
expm1-undefine18.6%
add-sqr-sqrt18.6%
sqrt-unprod10.9%
sqr-neg10.9%
sqrt-unprod2.1%
add-sqr-sqrt2.1%
Applied egg-rr2.1%
sub-neg2.1%
metadata-eval2.1%
+-commutative2.1%
log1p-undefine2.1%
rem-exp-log2.1%
associate-+r+2.8%
metadata-eval2.8%
metadata-eval2.8%
remove-double-neg2.8%
distribute-neg-in2.8%
+-lft-identity2.8%
remove-double-neg2.8%
Simplified2.8%
herbie shell --seed 2024145
(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)))))