
(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 8 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) (* (sqrt (/ 1.0 re)) (* im 0.5)) (* 0.5 (sqrt (* 2.0 (- (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 = sqrt((1.0 / re)) * (im * 0.5);
} else {
tmp = 0.5 * sqrt((2.0 * (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 = Math.sqrt((1.0 / re)) * (im * 0.5);
} else {
tmp = 0.5 * Math.sqrt((2.0 * (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 = math.sqrt((1.0 / re)) * (im * 0.5) else: tmp = 0.5 * math.sqrt((2.0 * (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(sqrt(Float64(1.0 / re)) * Float64(im * 0.5)); else tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 = sqrt((1.0 / re)) * (im * 0.5); else tmp = 0.5 * sqrt((2.0 * (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[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $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:\\
\;\;\;\;\sqrt{\frac{1}{re}} \cdot \left(im \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \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 5.5%
Taylor expanded in re around inf
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6498.9
Applied rewrites98.9%
lift-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
associate-*l*N/A
lower-*.f64N/A
lift-/.f64N/A
inv-powN/A
pow-powN/A
lower-pow.f64N/A
metadata-evalN/A
metadata-evalN/A
lift-*.f64N/A
associate-*r*N/A
Applied rewrites99.2%
Taylor expanded in im around 0
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6499.7
Applied rewrites99.7%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 43.7%
lower-hypot.f6491.6
Applied rewrites91.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
(if (<= t_0 0.0)
(* (sqrt (/ 1.0 re)) (* im 0.5))
(if (<= t_0 1e+77)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(* (* 0.5 (sqrt (- im re))) (sqrt 2.0))))))
double code(double re, double im) {
double t_0 = sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
double tmp;
if (t_0 <= 0.0) {
tmp = sqrt((1.0 / re)) * (im * 0.5);
} else if (t_0 <= 1e+77) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else {
tmp = (0.5 * sqrt((im - re))) * sqrt(2.0);
}
return tmp;
}
function code(re, im) t_0 = sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(sqrt(Float64(1.0 / re)) * Float64(im * 0.5)); elseif (t_0 <= 1e+77) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); else tmp = Float64(Float64(0.5 * sqrt(Float64(im - re))) * sqrt(2.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+77], 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], N[(N[(0.5 * N[Sqrt[N[(im - re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\sqrt{\frac{1}{re}} \cdot \left(im \cdot 0.5\right)\\
\mathbf{elif}\;t\_0 \leq 10^{+77}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sqrt{im - re}\right) \cdot \sqrt{2}\\
\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 5.5%
Taylor expanded in re around inf
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6498.9
Applied rewrites98.9%
lift-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
associate-*l*N/A
lower-*.f64N/A
lift-/.f64N/A
inv-powN/A
pow-powN/A
lower-pow.f64N/A
metadata-evalN/A
metadata-evalN/A
lift-*.f64N/A
associate-*r*N/A
Applied rewrites99.2%
Taylor expanded in im around 0
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6499.7
Applied rewrites99.7%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 9.99999999999999983e76Initial program 91.3%
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sqrt.f64N/A
*-commutativeN/A
lower-*.f6491.3
Applied rewrites91.3%
if 9.99999999999999983e76 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 3.6%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6461.9
Applied rewrites61.9%
lift--.f64N/A
*-commutativeN/A
sqrt-prodN/A
pow1/2N/A
lift-sqrt.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6462.2
Applied rewrites62.2%
Final simplification79.5%
(FPCore (re im)
:precision binary64
(if (<= re -1.8e+112)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 7.2e-24)
(* (* 0.5 (sqrt (- im re))) (sqrt 2.0))
(* (sqrt (/ 1.0 re)) (* im 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 7.2e-24) {
tmp = (0.5 * sqrt((im - re))) * sqrt(2.0);
} else {
tmp = sqrt((1.0 / re)) * (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.8d+112)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 7.2d-24) then
tmp = (0.5d0 * sqrt((im - re))) * sqrt(2.0d0)
else
tmp = sqrt((1.0d0 / re)) * (im * 0.5d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 7.2e-24) {
tmp = (0.5 * Math.sqrt((im - re))) * Math.sqrt(2.0);
} else {
tmp = Math.sqrt((1.0 / re)) * (im * 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e+112: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 7.2e-24: tmp = (0.5 * math.sqrt((im - re))) * math.sqrt(2.0) else: tmp = math.sqrt((1.0 / re)) * (im * 0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.8e+112) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 7.2e-24) tmp = Float64(Float64(0.5 * sqrt(Float64(im - re))) * sqrt(2.0)); else tmp = Float64(sqrt(Float64(1.0 / re)) * Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.8e+112) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 7.2e-24) tmp = (0.5 * sqrt((im - re))) * sqrt(2.0); else tmp = sqrt((1.0 / re)) * (im * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e+112], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.2e-24], N[(N[(0.5 * N[Sqrt[N[(im - re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.8 \cdot 10^{+112}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 7.2 \cdot 10^{-24}:\\
\;\;\;\;\left(0.5 \cdot \sqrt{im - re}\right) \cdot \sqrt{2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{re}} \cdot \left(im \cdot 0.5\right)\\
\end{array}
\end{array}
if re < -1.8e112Initial program 21.5%
Taylor expanded in re around -inf
*-commutativeN/A
lower-*.f6481.9
Applied rewrites81.9%
if -1.8e112 < re < 7.2000000000000002e-24Initial program 53.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6477.8
Applied rewrites77.8%
lift--.f64N/A
*-commutativeN/A
sqrt-prodN/A
pow1/2N/A
lift-sqrt.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6477.9
Applied rewrites77.9%
if 7.2000000000000002e-24 < re Initial program 9.7%
Taylor expanded in re around inf
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6479.4
Applied rewrites79.4%
lift-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
associate-*l*N/A
lower-*.f64N/A
lift-/.f64N/A
inv-powN/A
pow-powN/A
lower-pow.f64N/A
metadata-evalN/A
metadata-evalN/A
lift-*.f64N/A
associate-*r*N/A
Applied rewrites79.6%
Taylor expanded in im around 0
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6480.0
Applied rewrites80.0%
(FPCore (re im)
:precision binary64
(if (<= re -1.8e+112)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 6.4e-24)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (sqrt (/ 1.0 re)) (* im 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6.4e-24) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = sqrt((1.0 / re)) * (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.8d+112)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6.4d-24) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = sqrt((1.0d0 / re)) * (im * 0.5d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6.4e-24) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = Math.sqrt((1.0 / re)) * (im * 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e+112: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6.4e-24: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = math.sqrt((1.0 / re)) * (im * 0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.8e+112) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6.4e-24) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(sqrt(Float64(1.0 / re)) * Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.8e+112) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6.4e-24) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = sqrt((1.0 / re)) * (im * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e+112], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.4e-24], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.8 \cdot 10^{+112}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6.4 \cdot 10^{-24}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{re}} \cdot \left(im \cdot 0.5\right)\\
\end{array}
\end{array}
if re < -1.8e112Initial program 21.5%
Taylor expanded in re around -inf
*-commutativeN/A
lower-*.f6481.9
Applied rewrites81.9%
if -1.8e112 < re < 6.40000000000000025e-24Initial program 53.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6477.8
Applied rewrites77.8%
if 6.40000000000000025e-24 < re Initial program 9.7%
Taylor expanded in re around inf
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6479.4
Applied rewrites79.4%
lift-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-sqrt.f64N/A
pow1/2N/A
sqr-powN/A
associate-*l*N/A
lower-*.f64N/A
lift-/.f64N/A
inv-powN/A
pow-powN/A
lower-pow.f64N/A
metadata-evalN/A
metadata-evalN/A
lift-*.f64N/A
associate-*r*N/A
Applied rewrites79.6%
Taylor expanded in im around 0
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6480.0
Applied rewrites80.0%
(FPCore (re im)
:precision binary64
(if (<= re -1.8e+112)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 6.4e-24)
(* 0.5 (sqrt (* 2.0 (- im re))))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6.4e-24) {
tmp = 0.5 * sqrt((2.0 * (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 <= (-1.8d+112)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6.4d-24) then
tmp = 0.5d0 * sqrt((2.0d0 * (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 <= -1.8e+112) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6.4e-24) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e+112: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6.4e-24: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.8e+112) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6.4e-24) tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 <= -1.8e+112) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6.4e-24) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e+112], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.4e-24], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.8 \cdot 10^{+112}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6.4 \cdot 10^{-24}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.8e112Initial program 21.5%
Taylor expanded in re around -inf
*-commutativeN/A
lower-*.f6481.9
Applied rewrites81.9%
if -1.8e112 < re < 6.40000000000000025e-24Initial program 53.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6477.8
Applied rewrites77.8%
if 6.40000000000000025e-24 < re Initial program 9.7%
Taylor expanded in re around inf
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6479.4
Applied rewrites79.4%
lift-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-divN/A
metadata-evalN/A
un-div-invN/A
Applied rewrites79.9%
(FPCore (re im)
:precision binary64
(if (<= re -1.8e+112)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 6.4e-24)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6.4e-24) {
tmp = 0.5 * sqrt((2.0 * (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 <= (-1.8d+112)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6.4d-24) then
tmp = 0.5d0 * sqrt((2.0d0 * (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 <= -1.8e+112) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6.4e-24) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e+112: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6.4e-24: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.8e+112) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6.4e-24) tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 <= -1.8e+112) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6.4e-24) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e+112], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.4e-24], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.8 \cdot 10^{+112}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6.4 \cdot 10^{-24}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.8e112Initial program 21.5%
Taylor expanded in re around -inf
*-commutativeN/A
lower-*.f6481.9
Applied rewrites81.9%
if -1.8e112 < re < 6.40000000000000025e-24Initial program 53.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6477.8
Applied rewrites77.8%
if 6.40000000000000025e-24 < re Initial program 9.7%
Taylor expanded in re around inf
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-sqrt.f6479.4
Applied rewrites79.4%
lift-/.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
Applied rewrites79.8%
Final simplification79.0%
(FPCore (re im) :precision binary64 (if (<= re -3.5e+78) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (re <= -3.5e+78) {
tmp = 0.5 * sqrt((re * -4.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 (re <= (-3.5d+78)) then
tmp = 0.5d0 * sqrt((re * (-4.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 (re <= -3.5e+78) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.5e+78: tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.5e+78) tmp = Float64(0.5 * sqrt(Float64(re * -4.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 (re <= -3.5e+78) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.5e+78], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.5 \cdot 10^{+78}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -3.5000000000000001e78Initial program 24.3%
Taylor expanded in re around -inf
*-commutativeN/A
lower-*.f6479.2
Applied rewrites79.2%
if -3.5000000000000001e78 < re Initial program 40.1%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f6460.6
Applied rewrites60.6%
Final simplification63.7%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 im))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * im))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * im));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * im))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * im))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * im)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot im}
\end{array}
Initial program 37.5%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f6454.3
Applied rewrites54.3%
Final simplification54.3%
herbie shell --seed 2024219
(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)))))