
(FPCore (p r q) :precision binary64 :pre TRUE (* (/ 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)
use fmin_fmax_functions
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]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = ((1) / (2)) * (((abs(p)) + (abs(r))) + (sqrt((((p - r) ^ (2)) + ((4) * (q ^ (2))))))) END code
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (p r q) :precision binary64 :pre TRUE (* (/ 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)
use fmin_fmax_functions
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]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = ((1) / (2)) * (((abs(p)) + (abs(r))) + (sqrt((((p - r) ^ (2)) + ((4) * (q ^ (2))))))) END code
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
(FPCore (p r q)
:precision binary64
:pre TRUE
(let* ((t_0 (fabs (fmin p r)))
(t_1 (fabs (fmax p r)))
(t_2 (* -1.0 (fmax p r))))
(if (<= (fmin p r) -58411768126780620.0)
(fma
-0.5
t_2
(*
0.5
(+
t_0
(* -1.0 (* (fmin p r) (+ 1.0 (* -1.0 (/ t_1 (fmin p r)))))))))
(fma -0.5 t_2 (* 0.5 (+ t_0 (+ t_1 (* 2.0 (fabs q)))))))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r));
double t_1 = fabs(fmax(p, r));
double t_2 = -1.0 * fmax(p, r);
double tmp;
if (fmin(p, r) <= -58411768126780620.0) {
tmp = fma(-0.5, t_2, (0.5 * (t_0 + (-1.0 * (fmin(p, r) * (1.0 + (-1.0 * (t_1 / fmin(p, r)))))))));
} else {
tmp = fma(-0.5, t_2, (0.5 * (t_0 + (t_1 + (2.0 * fabs(q))))));
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) t_2 = Float64(-1.0 * fmax(p, r)) tmp = 0.0 if (fmin(p, r) <= -58411768126780620.0) tmp = fma(-0.5, t_2, Float64(0.5 * Float64(t_0 + Float64(-1.0 * Float64(fmin(p, r) * Float64(1.0 + Float64(-1.0 * Float64(t_1 / fmin(p, r))))))))); else tmp = fma(-0.5, t_2, Float64(0.5 * Float64(t_0 + Float64(t_1 + Float64(2.0 * abs(q)))))); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(-1.0 * N[Max[p, r], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Min[p, r], $MachinePrecision], -58411768126780620.0], N[(-0.5 * t$95$2 + N[(0.5 * N[(t$95$0 + N[(-1.0 * N[(N[Min[p, r], $MachinePrecision] * N[(1.0 + N[(-1.0 * N[(t$95$1 / N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * t$95$2 + N[(0.5 * N[(t$95$0 + N[(t$95$1 + N[(2.0 * N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = LET tmp = IF (p < r) THEN p ELSE r ENDIF IN LET t_0 = (abs(tmp)) IN LET tmp_1 = IF (p > r) THEN p ELSE r ENDIF IN LET t_1 = (abs(tmp_1)) IN LET tmp_2 = IF (p > r) THEN p ELSE r ENDIF IN LET t_2 = ((-1) * tmp_2) IN LET tmp_6 = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_7 = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_8 = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_5 = IF (tmp_6 <= (-58411768126780624)) THEN (((-5e-1) * t_2) + ((5e-1) * (t_0 + ((-1) * (tmp_7 * ((1) + ((-1) * (t_1 / tmp_8)))))))) ELSE (((-5e-1) * t_2) + ((5e-1) * (t_0 + (t_1 + ((2) * (abs(q))))))) ENDIF IN tmp_5 END code
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{max}\left(p, r\right)\right|\\
t_2 := -1 \cdot \mathsf{max}\left(p, r\right)\\
\mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -58411768126780620:\\
\;\;\;\;\mathsf{fma}\left(-0.5, t\_2, 0.5 \cdot \left(t\_0 + -1 \cdot \left(\mathsf{min}\left(p, r\right) \cdot \left(1 + -1 \cdot \frac{t\_1}{\mathsf{min}\left(p, r\right)}\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, t\_2, 0.5 \cdot \left(t\_0 + \left(t\_1 + 2 \cdot \left|q\right|\right)\right)\right)\\
\end{array}
if p < -58411768126780624Initial program 43.7%
Taylor expanded in r around 0
Applied rewrites36.0%
Applied rewrites36.0%
Taylor expanded in p around -inf
Applied rewrites43.8%
Taylor expanded in p around -inf
Applied rewrites31.2%
if -58411768126780624 < p Initial program 43.7%
Taylor expanded in r around 0
Applied rewrites36.0%
Applied rewrites36.0%
Taylor expanded in p around -inf
Applied rewrites43.8%
Taylor expanded in q around inf
Applied rewrites39.5%
(FPCore (p r q)
:precision binary64
:pre TRUE
(let* ((t_0 (fabs (fmin p r))) (t_1 (fabs (fmax p r))))
(if (<= (fmin p r) -58411768126780620.0)
(* 0.5 (+ (+ t_0 t_1) (- (fmax p r) (fmin p r))))
(fma
-0.5
(* -1.0 (fmax p r))
(* 0.5 (+ t_0 (+ t_1 (* 2.0 (fabs q)))))))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r));
double t_1 = fabs(fmax(p, r));
double tmp;
if (fmin(p, r) <= -58411768126780620.0) {
tmp = 0.5 * ((t_0 + t_1) + (fmax(p, r) - fmin(p, r)));
} else {
tmp = fma(-0.5, (-1.0 * fmax(p, r)), (0.5 * (t_0 + (t_1 + (2.0 * fabs(q))))));
}
return tmp;
}
function code(p, r, q) t_0 = abs(fmin(p, r)) t_1 = abs(fmax(p, r)) tmp = 0.0 if (fmin(p, r) <= -58411768126780620.0) tmp = Float64(0.5 * Float64(Float64(t_0 + t_1) + Float64(fmax(p, r) - fmin(p, r)))); else tmp = fma(-0.5, Float64(-1.0 * fmax(p, r)), Float64(0.5 * Float64(t_0 + Float64(t_1 + Float64(2.0 * abs(q)))))); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Min[p, r], $MachinePrecision], -58411768126780620.0], N[(0.5 * N[(N[(t$95$0 + t$95$1), $MachinePrecision] + N[(N[Max[p, r], $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(-1.0 * N[Max[p, r], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(t$95$0 + N[(t$95$1 + N[(2.0 * N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = LET tmp = IF (p < r) THEN p ELSE r ENDIF IN LET t_0 = (abs(tmp)) IN LET tmp_1 = IF (p > r) THEN p ELSE r ENDIF IN LET t_1 = (abs(tmp_1)) IN LET tmp_5 = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_6 = IF (p > r) THEN p ELSE r ENDIF IN LET tmp_7 = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_8 = IF (p > r) THEN p ELSE r ENDIF IN LET tmp_4 = IF (tmp_5 <= (-58411768126780624)) THEN ((5e-1) * ((t_0 + t_1) + (tmp_6 - tmp_7))) ELSE (((-5e-1) * ((-1) * tmp_8)) + ((5e-1) * (t_0 + (t_1 + ((2) * (abs(q))))))) ENDIF IN tmp_4 END code
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right|\\
t_1 := \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -58411768126780620:\\
\;\;\;\;0.5 \cdot \left(\left(t\_0 + t\_1\right) + \left(\mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.5, -1 \cdot \mathsf{max}\left(p, r\right), 0.5 \cdot \left(t\_0 + \left(t\_1 + 2 \cdot \left|q\right|\right)\right)\right)\\
\end{array}
if p < -58411768126780624Initial program 43.7%
Taylor expanded in r around inf
Applied rewrites30.3%
Applied rewrites35.3%
if -58411768126780624 < p Initial program 43.7%
Taylor expanded in r around 0
Applied rewrites36.0%
Applied rewrites36.0%
Taylor expanded in p around -inf
Applied rewrites43.8%
Taylor expanded in q around inf
Applied rewrites39.5%
(FPCore (p r q)
:precision binary64
:pre TRUE
(let* ((t_0 (+ (fabs (fmin p r)) (fabs (fmax p r)))))
(if (<= (pow (fabs q) 2.0) 1e+263)
(* 0.5 (+ t_0 (- (fmax p r) (fmin p r))))
(fma t_0 0.5 (fabs q)))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r)) + fabs(fmax(p, r));
double tmp;
if (pow(fabs(q), 2.0) <= 1e+263) {
tmp = 0.5 * (t_0 + (fmax(p, r) - fmin(p, r)));
} else {
tmp = fma(t_0, 0.5, fabs(q));
}
return tmp;
}
function code(p, r, q) t_0 = Float64(abs(fmin(p, r)) + abs(fmax(p, r))) tmp = 0.0 if ((abs(q) ^ 2.0) <= 1e+263) tmp = Float64(0.5 * Float64(t_0 + Float64(fmax(p, r) - fmin(p, r)))); else tmp = fma(t_0, 0.5, abs(q)); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision] + N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision], 1e+263], N[(0.5 * N[(t$95$0 + N[(N[Max[p, r], $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * 0.5 + N[Abs[q], $MachinePrecision]), $MachinePrecision]]]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = LET tmp = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_1 = IF (p > r) THEN p ELSE r ENDIF IN LET t_0 = ((abs(tmp)) + (abs(tmp_1))) IN LET tmp_5 = IF (p > r) THEN p ELSE r ENDIF IN LET tmp_6 = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_4 = IF (((abs(q)) ^ (2)) <= (100000000000000001617283929500958347809617271215324681096755776296054153530035788436133522496440536428819053303318396315116321724674929173953241540025456475844343490985646025955809392324929988807089135627070664687603614947110183136436054375358690154446666302750720)) THEN ((5e-1) * (t_0 + (tmp_5 - tmp_6))) ELSE ((t_0 * (5e-1)) + (abs(q))) ENDIF IN tmp_4 END code
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right| + \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 10^{+263}:\\
\;\;\;\;0.5 \cdot \left(t\_0 + \left(\mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, 0.5, \left|q\right|\right)\\
\end{array}
if (pow.f64 q #s(literal 2 binary64)) < 1e263Initial program 43.7%
Taylor expanded in r around inf
Applied rewrites30.3%
Applied rewrites35.3%
if 1e263 < (pow.f64 q #s(literal 2 binary64)) Initial program 43.7%
Taylor expanded in q around inf
Applied rewrites26.6%
Taylor expanded in q around 0
Applied rewrites29.2%
Applied rewrites29.2%
(FPCore (p r q)
:precision binary64
:pre TRUE
(let* ((t_0 (+ (fabs (fmin p r)) (fabs (fmax p r)))))
(if (<= (pow (fabs q) 2.0) 1e+263)
(* 0.5 (+ t_0 (- (fmax p r) (fmin p r))))
(* (fabs q) (+ 1.0 (* 0.5 (/ t_0 (fabs q))))))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r)) + fabs(fmax(p, r));
double tmp;
if (pow(fabs(q), 2.0) <= 1e+263) {
tmp = 0.5 * (t_0 + (fmax(p, r) - fmin(p, r)));
} else {
tmp = fabs(q) * (1.0 + (0.5 * (t_0 / fabs(q))));
}
return tmp;
}
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: t_0
real(8) :: tmp
t_0 = abs(fmin(p, r)) + abs(fmax(p, r))
if ((abs(q) ** 2.0d0) <= 1d+263) then
tmp = 0.5d0 * (t_0 + (fmax(p, r) - fmin(p, r)))
else
tmp = abs(q) * (1.0d0 + (0.5d0 * (t_0 / abs(q))))
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double t_0 = Math.abs(fmin(p, r)) + Math.abs(fmax(p, r));
double tmp;
if (Math.pow(Math.abs(q), 2.0) <= 1e+263) {
tmp = 0.5 * (t_0 + (fmax(p, r) - fmin(p, r)));
} else {
tmp = Math.abs(q) * (1.0 + (0.5 * (t_0 / Math.abs(q))));
}
return tmp;
}
def code(p, r, q): t_0 = math.fabs(fmin(p, r)) + math.fabs(fmax(p, r)) tmp = 0 if math.pow(math.fabs(q), 2.0) <= 1e+263: tmp = 0.5 * (t_0 + (fmax(p, r) - fmin(p, r))) else: tmp = math.fabs(q) * (1.0 + (0.5 * (t_0 / math.fabs(q)))) return tmp
function code(p, r, q) t_0 = Float64(abs(fmin(p, r)) + abs(fmax(p, r))) tmp = 0.0 if ((abs(q) ^ 2.0) <= 1e+263) tmp = Float64(0.5 * Float64(t_0 + Float64(fmax(p, r) - fmin(p, r)))); else tmp = Float64(abs(q) * Float64(1.0 + Float64(0.5 * Float64(t_0 / abs(q))))); end return tmp end
function tmp_2 = code(p, r, q) t_0 = abs(min(p, r)) + abs(max(p, r)); tmp = 0.0; if ((abs(q) ^ 2.0) <= 1e+263) tmp = 0.5 * (t_0 + (max(p, r) - min(p, r))); else tmp = abs(q) * (1.0 + (0.5 * (t_0 / abs(q)))); end tmp_2 = tmp; end
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision] + N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision], 1e+263], N[(0.5 * N[(t$95$0 + N[(N[Max[p, r], $MachinePrecision] - N[Min[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Abs[q], $MachinePrecision] * N[(1.0 + N[(0.5 * N[(t$95$0 / N[Abs[q], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = LET tmp = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_1 = IF (p > r) THEN p ELSE r ENDIF IN LET t_0 = ((abs(tmp)) + (abs(tmp_1))) IN LET tmp_5 = IF (p > r) THEN p ELSE r ENDIF IN LET tmp_6 = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_4 = IF (((abs(q)) ^ (2)) <= (100000000000000001617283929500958347809617271215324681096755776296054153530035788436133522496440536428819053303318396315116321724674929173953241540025456475844343490985646025955809392324929988807089135627070664687603614947110183136436054375358690154446666302750720)) THEN ((5e-1) * (t_0 + (tmp_5 - tmp_6))) ELSE ((abs(q)) * ((1) + ((5e-1) * (t_0 / (abs(q)))))) ENDIF IN tmp_4 END code
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right| + \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 10^{+263}:\\
\;\;\;\;0.5 \cdot \left(t\_0 + \left(\mathsf{max}\left(p, r\right) - \mathsf{min}\left(p, r\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left|q\right| \cdot \left(1 + 0.5 \cdot \frac{t\_0}{\left|q\right|}\right)\\
\end{array}
if (pow.f64 q #s(literal 2 binary64)) < 1e263Initial program 43.7%
Taylor expanded in r around inf
Applied rewrites30.3%
Applied rewrites35.3%
if 1e263 < (pow.f64 q #s(literal 2 binary64)) Initial program 43.7%
Taylor expanded in q around inf
Applied rewrites26.6%
(FPCore (p r q)
:precision binary64
:pre TRUE
(let* ((t_0 (+ (fabs (fmin p r)) (fabs (fmax p r)))))
(if (<= (fmin p r) -58411768126780620.0)
(* 0.5 (+ t_0 (- (fmin p r))))
(fma t_0 0.5 (fabs q)))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r)) + fabs(fmax(p, r));
double tmp;
if (fmin(p, r) <= -58411768126780620.0) {
tmp = 0.5 * (t_0 + -fmin(p, r));
} else {
tmp = fma(t_0, 0.5, fabs(q));
}
return tmp;
}
function code(p, r, q) t_0 = Float64(abs(fmin(p, r)) + abs(fmax(p, r))) tmp = 0.0 if (fmin(p, r) <= -58411768126780620.0) tmp = Float64(0.5 * Float64(t_0 + Float64(-fmin(p, r)))); else tmp = fma(t_0, 0.5, abs(q)); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision] + N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Min[p, r], $MachinePrecision], -58411768126780620.0], N[(0.5 * N[(t$95$0 + (-N[Min[p, r], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * 0.5 + N[Abs[q], $MachinePrecision]), $MachinePrecision]]]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = LET tmp = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_1 = IF (p > r) THEN p ELSE r ENDIF IN LET t_0 = ((abs(tmp)) + (abs(tmp_1))) IN LET tmp_4 = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_5 = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_3 = IF (tmp_4 <= (-58411768126780624)) THEN ((5e-1) * (t_0 + (- tmp_5))) ELSE ((t_0 * (5e-1)) + (abs(q))) ENDIF IN tmp_3 END code
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right| + \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;\mathsf{min}\left(p, r\right) \leq -58411768126780620:\\
\;\;\;\;0.5 \cdot \left(t\_0 + \left(-\mathsf{min}\left(p, r\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, 0.5, \left|q\right|\right)\\
\end{array}
if p < -58411768126780624Initial program 43.7%
Taylor expanded in p around -inf
Applied rewrites24.4%
Applied rewrites24.4%
if -58411768126780624 < p Initial program 43.7%
Taylor expanded in q around inf
Applied rewrites26.6%
Taylor expanded in q around 0
Applied rewrites29.2%
Applied rewrites29.2%
(FPCore (p r q)
:precision binary64
:pre TRUE
(let* ((t_0 (+ (fabs (fmin p r)) (fabs (fmax p r)))))
(if (<= (pow (fabs q) 2.0) 5e-170)
(* 0.5 (+ t_0 (fmax p r)))
(fma t_0 0.5 (fabs q)))))double code(double p, double r, double q) {
double t_0 = fabs(fmin(p, r)) + fabs(fmax(p, r));
double tmp;
if (pow(fabs(q), 2.0) <= 5e-170) {
tmp = 0.5 * (t_0 + fmax(p, r));
} else {
tmp = fma(t_0, 0.5, fabs(q));
}
return tmp;
}
function code(p, r, q) t_0 = Float64(abs(fmin(p, r)) + abs(fmax(p, r))) tmp = 0.0 if ((abs(q) ^ 2.0) <= 5e-170) tmp = Float64(0.5 * Float64(t_0 + fmax(p, r))); else tmp = fma(t_0, 0.5, abs(q)); end return tmp end
code[p_, r_, q_] := Block[{t$95$0 = N[(N[Abs[N[Min[p, r], $MachinePrecision]], $MachinePrecision] + N[Abs[N[Max[p, r], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision], 5e-170], N[(0.5 * N[(t$95$0 + N[Max[p, r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * 0.5 + N[Abs[q], $MachinePrecision]), $MachinePrecision]]]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = LET tmp = IF (p < r) THEN p ELSE r ENDIF IN LET tmp_1 = IF (p > r) THEN p ELSE r ENDIF IN LET t_0 = ((abs(tmp)) + (abs(tmp_1))) IN LET tmp_4 = IF (p > r) THEN p ELSE r ENDIF IN LET tmp_3 = IF (((abs(q)) ^ (2)) <= (50000000000000001005897896399759447471663533251681488230631673082178993512233877041951504141337718672782395574383719360739346127312822404793014987451483155735953233572139998721523190708243228387841467383029606869434144008536067884865524710326518014000764983693195045464120416181063784414611472713361231600365858598841095313775215944350820782849125325027755638627155853348802458171985828261675066213273201619349261903835213161073625087738037109375e-615)) THEN ((5e-1) * (t_0 + tmp_4)) ELSE ((t_0 * (5e-1)) + (abs(q))) ENDIF IN tmp_3 END code
\begin{array}{l}
t_0 := \left|\mathsf{min}\left(p, r\right)\right| + \left|\mathsf{max}\left(p, r\right)\right|\\
\mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 5 \cdot 10^{-170}:\\
\;\;\;\;0.5 \cdot \left(t\_0 + \mathsf{max}\left(p, r\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, 0.5, \left|q\right|\right)\\
\end{array}
if (pow.f64 q #s(literal 2 binary64)) < 5.0000000000000001e-170Initial program 43.7%
Taylor expanded in r around inf
Applied rewrites30.3%
Applied rewrites35.3%
Taylor expanded in p around 0
Applied rewrites24.8%
if 5.0000000000000001e-170 < (pow.f64 q #s(literal 2 binary64)) Initial program 43.7%
Taylor expanded in q around inf
Applied rewrites26.6%
Taylor expanded in q around 0
Applied rewrites29.2%
Applied rewrites29.2%
(FPCore (p r q) :precision binary64 :pre TRUE (fma (+ (fabs p) (fabs r)) 0.5 (fabs q)))
double code(double p, double r, double q) {
return fma((fabs(p) + fabs(r)), 0.5, fabs(q));
}
function code(p, r, q) return fma(Float64(abs(p) + abs(r)), 0.5, abs(q)) end
code[p_, r_, q_] := N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] * 0.5 + N[Abs[q], $MachinePrecision]), $MachinePrecision]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = (((abs(p)) + (abs(r))) * (5e-1)) + (abs(q)) END code
\mathsf{fma}\left(\left|p\right| + \left|r\right|, 0.5, \left|q\right|\right)
Initial program 43.7%
Taylor expanded in q around inf
Applied rewrites26.6%
Taylor expanded in q around 0
Applied rewrites29.2%
Applied rewrites29.2%
(FPCore (p r q) :precision binary64 :pre TRUE (if (<= (pow (fabs q) 2.0) 5e-191) (* 0.5 (+ (fabs p) (fabs r))) (* (fabs q) 1.0)))
double code(double p, double r, double q) {
double tmp;
if (pow(fabs(q), 2.0) <= 5e-191) {
tmp = 0.5 * (fabs(p) + fabs(r));
} else {
tmp = fabs(q) * 1.0;
}
return tmp;
}
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
real(8) :: tmp
if ((abs(q) ** 2.0d0) <= 5d-191) then
tmp = 0.5d0 * (abs(p) + abs(r))
else
tmp = abs(q) * 1.0d0
end if
code = tmp
end function
public static double code(double p, double r, double q) {
double tmp;
if (Math.pow(Math.abs(q), 2.0) <= 5e-191) {
tmp = 0.5 * (Math.abs(p) + Math.abs(r));
} else {
tmp = Math.abs(q) * 1.0;
}
return tmp;
}
def code(p, r, q): tmp = 0 if math.pow(math.fabs(q), 2.0) <= 5e-191: tmp = 0.5 * (math.fabs(p) + math.fabs(r)) else: tmp = math.fabs(q) * 1.0 return tmp
function code(p, r, q) tmp = 0.0 if ((abs(q) ^ 2.0) <= 5e-191) tmp = Float64(0.5 * Float64(abs(p) + abs(r))); else tmp = Float64(abs(q) * 1.0); end return tmp end
function tmp_2 = code(p, r, q) tmp = 0.0; if ((abs(q) ^ 2.0) <= 5e-191) tmp = 0.5 * (abs(p) + abs(r)); else tmp = abs(q) * 1.0; end tmp_2 = tmp; end
code[p_, r_, q_] := If[LessEqual[N[Power[N[Abs[q], $MachinePrecision], 2.0], $MachinePrecision], 5e-191], N[(0.5 * N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Abs[q], $MachinePrecision] * 1.0), $MachinePrecision]]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = LET tmp = IF (((abs(q)) ^ (2)) <= (50000000000000000942551789279165077655128973232649790772620887129032407459291021743169337641389297212198941154372058224760853099565741627214967626395102181370270746629944267464794990958050845661040964938525483075519980913353731727320837054697313531092421556456303078458350442613230095608530729597341794983149860033481636690818522354026582444713528564815853745850819418461955121683473357921370785834258646975253512312133358029888087576404083053470501162539318951161249060533009469509124755859375e-684)) THEN ((5e-1) * ((abs(p)) + (abs(r)))) ELSE ((abs(q)) * (1)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;{\left(\left|q\right|\right)}^{2} \leq 5 \cdot 10^{-191}:\\
\;\;\;\;0.5 \cdot \left(\left|p\right| + \left|r\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\left|q\right| \cdot 1\\
\end{array}
if (pow.f64 q #s(literal 2 binary64)) < 5.0000000000000001e-191Initial program 43.7%
Taylor expanded in q around inf
Applied rewrites26.6%
Taylor expanded in q around 0
Applied rewrites14.5%
if 5.0000000000000001e-191 < (pow.f64 q #s(literal 2 binary64)) Initial program 43.7%
Taylor expanded in q around inf
Applied rewrites26.6%
Taylor expanded in p around inf
Applied rewrites14.2%
Taylor expanded in q around inf
Applied rewrites18.3%
(FPCore (p r q) :precision binary64 :pre TRUE (* (fabs q) 1.0))
double code(double p, double r, double q) {
return fabs(q) * 1.0;
}
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = abs(q) * 1.0d0
end function
public static double code(double p, double r, double q) {
return Math.abs(q) * 1.0;
}
def code(p, r, q): return math.fabs(q) * 1.0
function code(p, r, q) return Float64(abs(q) * 1.0) end
function tmp = code(p, r, q) tmp = abs(q) * 1.0; end
code[p_, r_, q_] := N[(N[Abs[q], $MachinePrecision] * 1.0), $MachinePrecision]
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = (abs(q)) * (1) END code
\left|q\right| \cdot 1
Initial program 43.7%
Taylor expanded in q around inf
Applied rewrites26.6%
Taylor expanded in p around inf
Applied rewrites14.2%
Taylor expanded in q around inf
Applied rewrites18.3%
(FPCore (p r q) :precision binary64 :pre TRUE (- q))
double code(double p, double r, double q) {
return -q;
}
real(8) function code(p, r, q)
use fmin_fmax_functions
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = -q
end function
public static double code(double p, double r, double q) {
return -q;
}
def code(p, r, q): return -q
function code(p, r, q) return Float64(-q) end
function tmp = code(p, r, q) tmp = -q; end
code[p_, r_, q_] := (-q)
f(p, r, q): p in [-inf, +inf], r in [-inf, +inf], q in [-inf, +inf] code: THEORY BEGIN f(p, r, q: real): real = - q END code
-q
Initial program 43.7%
Taylor expanded in q around -inf
Applied rewrites17.5%
Applied rewrites17.5%
herbie shell --seed 2026089 +o generate:egglog
(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)))))))