
(FPCore (p r q) :precision binary64 (* (/ 1.0 2.0) (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
return (1.0 / 2.0) * ((fabs(p) + fabs(r)) - sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
real(8) function code(p, r, q)
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q): return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q) return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0)))))) end
function tmp = code(p, r, q) tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0))))); end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (p r q) :precision binary64 (* (/ 1.0 2.0) (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
return (1.0 / 2.0) * ((fabs(p) + fabs(r)) - sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
real(8) function code(p, r, q)
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q): return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q) return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0)))))) end
function tmp = code(p, r, q) tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0))))); end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
\end{array}
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(let* ((t_0 (hypot (* 2.0 q_m) p)) (t_1 (pow t_0 0.5)) (t_2 (/ p t_1)))
(if (<= r 1.15e-291)
(*
(fma (/ r t_1) t_2 (+ (- (fabs p) (hypot p (* q_m 2.0))) (fabs r)))
0.5)
(if (<= r 1.15e+38)
(*
(fma
(/
r
(fma
(* 0.0625 (pow 4.0 0.25))
(* (sqrt (pow (pow q_m 3.0) -1.0)) (* p p))
(* (sqrt q_m) (pow 4.0 0.25))))
t_2
(- (+ (fabs p) (fabs r)) t_0))
0.5)
(fma
(fma
(-
(fma
p
(/ (+ (/ p (* r r)) (pow r -1.0)) (* r r))
(pow (* r r) -1.0)))
p
(/ -1.0 r))
(* q_m q_m)
(* 0.5 (+ (+ p (- (fabs r) r)) (fabs p))))))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double t_0 = hypot((2.0 * q_m), p);
double t_1 = pow(t_0, 0.5);
double t_2 = p / t_1;
double tmp;
if (r <= 1.15e-291) {
tmp = fma((r / t_1), t_2, ((fabs(p) - hypot(p, (q_m * 2.0))) + fabs(r))) * 0.5;
} else if (r <= 1.15e+38) {
tmp = fma((r / fma((0.0625 * pow(4.0, 0.25)), (sqrt(pow(pow(q_m, 3.0), -1.0)) * (p * p)), (sqrt(q_m) * pow(4.0, 0.25)))), t_2, ((fabs(p) + fabs(r)) - t_0)) * 0.5;
} else {
tmp = fma(fma(-fma(p, (((p / (r * r)) + pow(r, -1.0)) / (r * r)), pow((r * r), -1.0)), p, (-1.0 / r)), (q_m * q_m), (0.5 * ((p + (fabs(r) - r)) + fabs(p))));
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) t_0 = hypot(Float64(2.0 * q_m), p) t_1 = t_0 ^ 0.5 t_2 = Float64(p / t_1) tmp = 0.0 if (r <= 1.15e-291) tmp = Float64(fma(Float64(r / t_1), t_2, Float64(Float64(abs(p) - hypot(p, Float64(q_m * 2.0))) + abs(r))) * 0.5); elseif (r <= 1.15e+38) tmp = Float64(fma(Float64(r / fma(Float64(0.0625 * (4.0 ^ 0.25)), Float64(sqrt(((q_m ^ 3.0) ^ -1.0)) * Float64(p * p)), Float64(sqrt(q_m) * (4.0 ^ 0.25)))), t_2, Float64(Float64(abs(p) + abs(r)) - t_0)) * 0.5); else tmp = fma(fma(Float64(-fma(p, Float64(Float64(Float64(p / Float64(r * r)) + (r ^ -1.0)) / Float64(r * r)), (Float64(r * r) ^ -1.0))), p, Float64(-1.0 / r)), Float64(q_m * q_m), Float64(0.5 * Float64(Float64(p + Float64(abs(r) - r)) + abs(p)))); end return tmp end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := Block[{t$95$0 = N[Sqrt[N[(2.0 * q$95$m), $MachinePrecision] ^ 2 + p ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 0.5], $MachinePrecision]}, Block[{t$95$2 = N[(p / t$95$1), $MachinePrecision]}, If[LessEqual[r, 1.15e-291], N[(N[(N[(r / t$95$1), $MachinePrecision] * t$95$2 + N[(N[(N[Abs[p], $MachinePrecision] - N[Sqrt[p ^ 2 + N[(q$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[r, 1.15e+38], N[(N[(N[(r / N[(N[(0.0625 * N[Power[4.0, 0.25], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[Power[N[Power[q$95$m, 3.0], $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision] * N[(p * p), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[q$95$m], $MachinePrecision] * N[Power[4.0, 0.25], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2 + N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[((-N[(p * N[(N[(N[(p / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[r, -1.0], $MachinePrecision]), $MachinePrecision] / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[N[(r * r), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]) * p + N[(-1.0 / r), $MachinePrecision]), $MachinePrecision] * N[(q$95$m * q$95$m), $MachinePrecision] + N[(0.5 * N[(N[(p + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(2 \cdot q\_m, p\right)\\
t_1 := {t\_0}^{0.5}\\
t_2 := \frac{p}{t\_1}\\
\mathbf{if}\;r \leq 1.15 \cdot 10^{-291}:\\
\;\;\;\;\mathsf{fma}\left(\frac{r}{t\_1}, t\_2, \left(\left|p\right| - \mathsf{hypot}\left(p, q\_m \cdot 2\right)\right) + \left|r\right|\right) \cdot 0.5\\
\mathbf{elif}\;r \leq 1.15 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{fma}\left(\frac{r}{\mathsf{fma}\left(0.0625 \cdot {4}^{0.25}, \sqrt{{\left({q\_m}^{3}\right)}^{-1}} \cdot \left(p \cdot p\right), \sqrt{q\_m} \cdot {4}^{0.25}\right)}, t\_2, \left(\left|p\right| + \left|r\right|\right) - t\_0\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q\_m \cdot q\_m, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\
\end{array}
\end{array}
if r < 1.15e-291Initial program 27.5%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites19.6%
Applied rewrites22.6%
Applied rewrites38.0%
Applied rewrites45.2%
if 1.15e-291 < r < 1.1500000000000001e38Initial program 39.9%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites32.1%
Applied rewrites34.5%
Applied rewrites52.7%
Taylor expanded in p around 0
Applied rewrites36.8%
if 1.1500000000000001e38 < r Initial program 4.9%
Taylor expanded in p around 0
Applied rewrites6.3%
Taylor expanded in q around 0
Applied rewrites62.7%
Final simplification47.3%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(let* ((t_0 (pow (hypot (* 2.0 q_m) p) 0.5)))
(if (<= r 1.8e+38)
(*
(fma (/ r t_0) (/ p t_0) (+ (- (fabs p) (hypot p (* q_m 2.0))) (fabs r)))
0.5)
(fma
(fma
(-
(fma p (/ (+ (/ p (* r r)) (pow r -1.0)) (* r r)) (pow (* r r) -1.0)))
p
(/ -1.0 r))
(* q_m q_m)
(* 0.5 (+ (+ p (- (fabs r) r)) (fabs p)))))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double t_0 = pow(hypot((2.0 * q_m), p), 0.5);
double tmp;
if (r <= 1.8e+38) {
tmp = fma((r / t_0), (p / t_0), ((fabs(p) - hypot(p, (q_m * 2.0))) + fabs(r))) * 0.5;
} else {
tmp = fma(fma(-fma(p, (((p / (r * r)) + pow(r, -1.0)) / (r * r)), pow((r * r), -1.0)), p, (-1.0 / r)), (q_m * q_m), (0.5 * ((p + (fabs(r) - r)) + fabs(p))));
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) t_0 = hypot(Float64(2.0 * q_m), p) ^ 0.5 tmp = 0.0 if (r <= 1.8e+38) tmp = Float64(fma(Float64(r / t_0), Float64(p / t_0), Float64(Float64(abs(p) - hypot(p, Float64(q_m * 2.0))) + abs(r))) * 0.5); else tmp = fma(fma(Float64(-fma(p, Float64(Float64(Float64(p / Float64(r * r)) + (r ^ -1.0)) / Float64(r * r)), (Float64(r * r) ^ -1.0))), p, Float64(-1.0 / r)), Float64(q_m * q_m), Float64(0.5 * Float64(Float64(p + Float64(abs(r) - r)) + abs(p)))); end return tmp end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := Block[{t$95$0 = N[Power[N[Sqrt[N[(2.0 * q$95$m), $MachinePrecision] ^ 2 + p ^ 2], $MachinePrecision], 0.5], $MachinePrecision]}, If[LessEqual[r, 1.8e+38], N[(N[(N[(r / t$95$0), $MachinePrecision] * N[(p / t$95$0), $MachinePrecision] + N[(N[(N[Abs[p], $MachinePrecision] - N[Sqrt[p ^ 2 + N[(q$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[((-N[(p * N[(N[(N[(p / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[r, -1.0], $MachinePrecision]), $MachinePrecision] / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[N[(r * r), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]) * p + N[(-1.0 / r), $MachinePrecision]), $MachinePrecision] * N[(q$95$m * q$95$m), $MachinePrecision] + N[(0.5 * N[(N[(p + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
t_0 := {\left(\mathsf{hypot}\left(2 \cdot q\_m, p\right)\right)}^{0.5}\\
\mathbf{if}\;r \leq 1.8 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{fma}\left(\frac{r}{t\_0}, \frac{p}{t\_0}, \left(\left|p\right| - \mathsf{hypot}\left(p, q\_m \cdot 2\right)\right) + \left|r\right|\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q\_m \cdot q\_m, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\
\end{array}
\end{array}
if r < 1.79999999999999985e38Initial program 31.5%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites23.7%
Applied rewrites26.5%
Applied rewrites42.7%
Applied rewrites48.9%
if 1.79999999999999985e38 < r Initial program 4.9%
Taylor expanded in p around 0
Applied rewrites6.3%
Taylor expanded in q around 0
Applied rewrites62.7%
Final simplification52.2%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(let* ((t_0 (hypot p (* q_m 2.0))) (t_1 (sqrt t_0)))
(if (<= r -2.35e-6)
(* (fma (+ (+ (fabs p) p) (fabs r)) (/ 0.5 r) -0.5) r)
(if (<= r 1.15e+38)
(* (fma (/ r t_1) (/ p t_1) (- (+ (fabs r) (fabs p)) t_0)) 0.5)
(fma
(fma
(-
(fma
p
(/ (+ (/ p (* r r)) (pow r -1.0)) (* r r))
(pow (* r r) -1.0)))
p
(/ -1.0 r))
(* q_m q_m)
(* 0.5 (+ (+ p (- (fabs r) r)) (fabs p))))))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double t_0 = hypot(p, (q_m * 2.0));
double t_1 = sqrt(t_0);
double tmp;
if (r <= -2.35e-6) {
tmp = fma(((fabs(p) + p) + fabs(r)), (0.5 / r), -0.5) * r;
} else if (r <= 1.15e+38) {
tmp = fma((r / t_1), (p / t_1), ((fabs(r) + fabs(p)) - t_0)) * 0.5;
} else {
tmp = fma(fma(-fma(p, (((p / (r * r)) + pow(r, -1.0)) / (r * r)), pow((r * r), -1.0)), p, (-1.0 / r)), (q_m * q_m), (0.5 * ((p + (fabs(r) - r)) + fabs(p))));
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) t_0 = hypot(p, Float64(q_m * 2.0)) t_1 = sqrt(t_0) tmp = 0.0 if (r <= -2.35e-6) tmp = Float64(fma(Float64(Float64(abs(p) + p) + abs(r)), Float64(0.5 / r), -0.5) * r); elseif (r <= 1.15e+38) tmp = Float64(fma(Float64(r / t_1), Float64(p / t_1), Float64(Float64(abs(r) + abs(p)) - t_0)) * 0.5); else tmp = fma(fma(Float64(-fma(p, Float64(Float64(Float64(p / Float64(r * r)) + (r ^ -1.0)) / Float64(r * r)), (Float64(r * r) ^ -1.0))), p, Float64(-1.0 / r)), Float64(q_m * q_m), Float64(0.5 * Float64(Float64(p + Float64(abs(r) - r)) + abs(p)))); end return tmp end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := Block[{t$95$0 = N[Sqrt[p ^ 2 + N[(q$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[t$95$0], $MachinePrecision]}, If[LessEqual[r, -2.35e-6], N[(N[(N[(N[(N[Abs[p], $MachinePrecision] + p), $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] * N[(0.5 / r), $MachinePrecision] + -0.5), $MachinePrecision] * r), $MachinePrecision], If[LessEqual[r, 1.15e+38], N[(N[(N[(r / t$95$1), $MachinePrecision] * N[(p / t$95$1), $MachinePrecision] + N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[((-N[(p * N[(N[(N[(p / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[r, -1.0], $MachinePrecision]), $MachinePrecision] / N[(r * r), $MachinePrecision]), $MachinePrecision] + N[Power[N[(r * r), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]) * p + N[(-1.0 / r), $MachinePrecision]), $MachinePrecision] * N[(q$95$m * q$95$m), $MachinePrecision] + N[(0.5 * N[(N[(p + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(p, q\_m \cdot 2\right)\\
t_1 := \sqrt{t\_0}\\
\mathbf{if}\;r \leq -2.35 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left|p\right| + p\right) + \left|r\right|, \frac{0.5}{r}, -0.5\right) \cdot r\\
\mathbf{elif}\;r \leq 1.15 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{fma}\left(\frac{r}{t\_1}, \frac{p}{t\_1}, \left(\left|r\right| + \left|p\right|\right) - t\_0\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-\mathsf{fma}\left(p, \frac{\frac{p}{r \cdot r} + {r}^{-1}}{r \cdot r}, {\left(r \cdot r\right)}^{-1}\right), p, \frac{-1}{r}\right), q\_m \cdot q\_m, 0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\right)\\
\end{array}
\end{array}
if r < -2.34999999999999995e-6Initial program 17.3%
Taylor expanded in r around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites3.3%
Applied rewrites10.1%
if -2.34999999999999995e-6 < r < 1.1500000000000001e38Initial program 39.8%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites33.2%
Applied rewrites36.9%
Applied rewrites51.2%
Applied rewrites51.2%
if 1.1500000000000001e38 < r Initial program 4.9%
Taylor expanded in p around 0
Applied rewrites6.3%
Taylor expanded in q around 0
Applied rewrites62.7%
Final simplification42.4%
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 (if (<= (pow q_m 2.0) 2e-198) (* 0.5 (+ (+ p (- (fabs r) r)) (fabs p))) (- q_m)))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (pow(q_m, 2.0) <= 2e-198) {
tmp = 0.5 * ((p + (fabs(r) - r)) + fabs(p));
} else {
tmp = -q_m;
}
return tmp;
}
q_m = abs(q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
real(8) function code(p, r, q_m)
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if ((q_m ** 2.0d0) <= 2d-198) then
tmp = 0.5d0 * ((p + (abs(r) - r)) + abs(p))
else
tmp = -q_m
end if
code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
double tmp;
if (Math.pow(q_m, 2.0) <= 2e-198) {
tmp = 0.5 * ((p + (Math.abs(r) - r)) + Math.abs(p));
} else {
tmp = -q_m;
}
return tmp;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): tmp = 0 if math.pow(q_m, 2.0) <= 2e-198: tmp = 0.5 * ((p + (math.fabs(r) - r)) + math.fabs(p)) else: tmp = -q_m return tmp
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if ((q_m ^ 2.0) <= 2e-198) tmp = Float64(0.5 * Float64(Float64(p + Float64(abs(r) - r)) + abs(p))); else tmp = Float64(-q_m); end return tmp end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
tmp = 0.0;
if ((q_m ^ 2.0) <= 2e-198)
tmp = 0.5 * ((p + (abs(r) - r)) + abs(p));
else
tmp = -q_m;
end
tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[N[Power[q$95$m, 2.0], $MachinePrecision], 2e-198], N[(0.5 * N[(N[(p + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-q$95$m)]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;{q\_m}^{2} \leq 2 \cdot 10^{-198}:\\
\;\;\;\;0.5 \cdot \left(\left(p + \left(\left|r\right| - r\right)\right) + \left|p\right|\right)\\
\mathbf{else}:\\
\;\;\;\;-q\_m\\
\end{array}
\end{array}
if (pow.f64 q #s(literal 2 binary64)) < 1.9999999999999998e-198Initial program 21.5%
Taylor expanded in p around 0
Applied rewrites3.7%
Taylor expanded in q around 0
Applied rewrites40.5%
if 1.9999999999999998e-198 < (pow.f64 q #s(literal 2 binary64)) Initial program 27.2%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f6429.5
Applied rewrites29.5%
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 (if (<= (pow q_m 2.0) 2e-198) (* (+ (+ p (fabs r)) (fabs p)) 0.5) (- q_m)))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (pow(q_m, 2.0) <= 2e-198) {
tmp = ((p + fabs(r)) + fabs(p)) * 0.5;
} else {
tmp = -q_m;
}
return tmp;
}
q_m = abs(q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
real(8) function code(p, r, q_m)
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if ((q_m ** 2.0d0) <= 2d-198) then
tmp = ((p + abs(r)) + abs(p)) * 0.5d0
else
tmp = -q_m
end if
code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
double tmp;
if (Math.pow(q_m, 2.0) <= 2e-198) {
tmp = ((p + Math.abs(r)) + Math.abs(p)) * 0.5;
} else {
tmp = -q_m;
}
return tmp;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): tmp = 0 if math.pow(q_m, 2.0) <= 2e-198: tmp = ((p + math.fabs(r)) + math.fabs(p)) * 0.5 else: tmp = -q_m return tmp
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if ((q_m ^ 2.0) <= 2e-198) tmp = Float64(Float64(Float64(p + abs(r)) + abs(p)) * 0.5); else tmp = Float64(-q_m); end return tmp end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
tmp = 0.0;
if ((q_m ^ 2.0) <= 2e-198)
tmp = ((p + abs(r)) + abs(p)) * 0.5;
else
tmp = -q_m;
end
tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[N[Power[q$95$m, 2.0], $MachinePrecision], 2e-198], N[(N[(N[(p + N[Abs[r], $MachinePrecision]), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], (-q$95$m)]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;{q\_m}^{2} \leq 2 \cdot 10^{-198}:\\
\;\;\;\;\left(\left(p + \left|r\right|\right) + \left|p\right|\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;-q\_m\\
\end{array}
\end{array}
if (pow.f64 q #s(literal 2 binary64)) < 1.9999999999999998e-198Initial program 21.5%
Taylor expanded in r around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites13.0%
Taylor expanded in r around 0
Applied rewrites16.5%
if 1.9999999999999998e-198 < (pow.f64 q #s(literal 2 binary64)) Initial program 27.2%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f6429.5
Applied rewrites29.5%
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 (- q_m))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
return -q_m;
}
q_m = abs(q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
real(8) function code(p, r, q_m)
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
code = -q_m
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
return -q_m;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): return -q_m
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) return Float64(-q_m) end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp = code(p, r, q_m)
tmp = -q_m;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := (-q$95$m)
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
-q\_m
\end{array}
Initial program 25.1%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f6421.1
Applied rewrites21.1%
herbie shell --seed 2024318
(FPCore (p r q)
:name "1/2(abs(p)+abs(r) - sqrt((p-r)^2 + 4q^2))"
:precision binary64
(* (/ 1.0 2.0) (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))