
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (+ (- b) t_0) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (2.0d0 * c) / (-b - t_0)
else
tmp = (-b + t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (-b - t_0) else: tmp = (-b + t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b >= 0.0) tmp = (2.0 * c) / (-b - t_0); else tmp = (-b + t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\end{array}
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (+ (- b) t_0) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (2.0d0 * c) / (-b - t_0)
else
tmp = (-b + t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (-b - t_0) else: tmp = (-b + t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b >= 0.0) tmp = (2.0 * c) / (-b - t_0); else tmp = (-b + t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\end{array}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma -4.0 (* a c) (* b b)))))
(if (<= b -5e-20)
(if (>= b 0.0)
(/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))
(/
(fma (sqrt (- 1.0 (* (* a 4.0) (/ c (* b b))))) (fabs b) (- b))
(* 2.0 a)))
(if (<= b 5e+114)
(if (>= b 0.0) (/ (* -2.0 c) (+ t_0 b)) (/ (- t_0 b) (+ a a)))
(if (>= b 0.0)
(/ (* 2.0 c) (* -2.0 b))
(/ (fma 1.0 (fabs b) (- b)) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma(-4.0, (a * c), (b * b)));
double tmp_1;
if (b <= -5e-20) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (-b - sqrt(((b * b) - ((4.0 * a) * c))));
} else {
tmp_2 = fma(sqrt((1.0 - ((a * 4.0) * (c / (b * b))))), fabs(b), -b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 5e+114) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-2.0 * c) / (t_0 + b);
} else {
tmp_3 = (t_0 - b) / (a + a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-2.0 * b);
} else {
tmp_1 = fma(1.0, fabs(b), -b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(-4.0, Float64(a * c), Float64(b * b))) tmp_1 = 0.0 if (b <= -5e-20) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))))); else tmp_2 = Float64(fma(sqrt(Float64(1.0 - Float64(Float64(a * 4.0) * Float64(c / Float64(b * b))))), abs(b), Float64(-b)) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 5e+114) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(-2.0 * c) / Float64(t_0 + b)); else tmp_3 = Float64(Float64(t_0 - b) / Float64(a + a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(-2.0 * b)); else tmp_1 = Float64(fma(1.0, abs(b), Float64(-b)) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -5e-20], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(1.0 - N[(N[(a * 4.0), $MachinePrecision] * N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Abs[b], $MachinePrecision] + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 5e+114], If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 * N[Abs[b], $MachinePrecision] + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)}\\
\mathbf{if}\;b \leq -5 \cdot 10^{-20}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sqrt{1 - \left(a \cdot 4\right) \cdot \frac{c}{b \cdot b}}, \left|b\right|, -b\right)}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+114}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{t\_0 + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a + a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, \left|b\right|, -b\right)}{2 \cdot a}\\
\end{array}
\end{array}
if b < -4.9999999999999999e-20Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
if -4.9999999999999999e-20 < b < 5.0000000000000001e114Initial program 71.9%
Applied rewrites72.0%
if 5.0000000000000001e114 < b Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around inf
lower-*.f6467.8
Applied rewrites67.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma -4.0 (* a c) (* b b)))))
(if (<= b -3.3e+77)
(if (>= b 0.0) (* -1.0 (/ b a)) (/ (- (* 1.0 (fabs b)) b) (+ a a)))
(if (<= b 5e+114)
(if (>= b 0.0) (/ (* -2.0 c) (+ t_0 b)) (/ (- t_0 b) (+ a a)))
(if (>= b 0.0)
(/ (* 2.0 c) (* -2.0 b))
(/ (fma 1.0 (fabs b) (- b)) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma(-4.0, (a * c), (b * b)));
double tmp_1;
if (b <= -3.3e+77) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -1.0 * (b / a);
} else {
tmp_2 = ((1.0 * fabs(b)) - b) / (a + a);
}
tmp_1 = tmp_2;
} else if (b <= 5e+114) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-2.0 * c) / (t_0 + b);
} else {
tmp_3 = (t_0 - b) / (a + a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-2.0 * b);
} else {
tmp_1 = fma(1.0, fabs(b), -b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(-4.0, Float64(a * c), Float64(b * b))) tmp_1 = 0.0 if (b <= -3.3e+77) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-1.0 * Float64(b / a)); else tmp_2 = Float64(Float64(Float64(1.0 * abs(b)) - b) / Float64(a + a)); end tmp_1 = tmp_2; elseif (b <= 5e+114) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(-2.0 * c) / Float64(t_0 + b)); else tmp_3 = Float64(Float64(t_0 - b) / Float64(a + a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(-2.0 * b)); else tmp_1 = Float64(fma(1.0, abs(b), Float64(-b)) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -3.3e+77], If[GreaterEqual[b, 0.0], N[(-1.0 * N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 * N[Abs[b], $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 5e+114], If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 * N[Abs[b], $MachinePrecision] + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)}\\
\mathbf{if}\;b \leq -3.3 \cdot 10^{+77}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-1 \cdot \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 \cdot \left|b\right| - b}{a + a}\\
\end{array}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+114}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{t\_0 + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a + a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, \left|b\right|, -b\right)}{2 \cdot a}\\
\end{array}
\end{array}
if b < -3.2999999999999998e77Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.5
Applied rewrites35.5%
lift-fma.f64N/A
lift-neg.f64N/A
sub-flip-reverseN/A
lower--.f64N/A
lower-*.f6435.5
lift-*.f64N/A
count-2-revN/A
lift-+.f6435.5
Applied rewrites35.5%
if -3.2999999999999998e77 < b < 5.0000000000000001e114Initial program 71.9%
Applied rewrites72.0%
if 5.0000000000000001e114 < b Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around inf
lower-*.f6467.8
Applied rewrites67.8%
(FPCore (a b c)
:precision binary64
(if (<= b -4.9e-39)
(if (>= b 0.0) (* -1.0 (/ b a)) (/ (- (* 1.0 (fabs b)) b) (+ a a)))
(if (<= b 1.55e-46)
(if (>= b 0.0)
(/ (+ c c) (- (- b) (sqrt (* (* a c) -4.0))))
(/ (- (sqrt (* -4.0 (* a c))) b) (+ a a)))
(if (>= b 0.0)
(/ (* 2.0 c) (* -2.0 b))
(/ (fma 1.0 (fabs b) (- b)) (* 2.0 a))))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -4.9e-39) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -1.0 * (b / a);
} else {
tmp_2 = ((1.0 * fabs(b)) - b) / (a + a);
}
tmp_1 = tmp_2;
} else if (b <= 1.55e-46) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c + c) / (-b - sqrt(((a * c) * -4.0)));
} else {
tmp_3 = (sqrt((-4.0 * (a * c))) - b) / (a + a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-2.0 * b);
} else {
tmp_1 = fma(1.0, fabs(b), -b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -4.9e-39) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-1.0 * Float64(b / a)); else tmp_2 = Float64(Float64(Float64(1.0 * abs(b)) - b) / Float64(a + a)); end tmp_1 = tmp_2; elseif (b <= 1.55e-46) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c + c) / Float64(Float64(-b) - sqrt(Float64(Float64(a * c) * -4.0)))); else tmp_3 = Float64(Float64(sqrt(Float64(-4.0 * Float64(a * c))) - b) / Float64(a + a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(-2.0 * b)); else tmp_1 = Float64(fma(1.0, abs(b), Float64(-b)) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -4.9e-39], If[GreaterEqual[b, 0.0], N[(-1.0 * N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 * N[Abs[b], $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1.55e-46], If[GreaterEqual[b, 0.0], N[(N[(c + c), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 * N[Abs[b], $MachinePrecision] + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.9 \cdot 10^{-39}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-1 \cdot \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 \cdot \left|b\right| - b}{a + a}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{-46}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c + c}{\left(-b\right) - \sqrt{\left(a \cdot c\right) \cdot -4}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(a \cdot c\right)} - b}{a + a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, \left|b\right|, -b\right)}{2 \cdot a}\\
\end{array}
\end{array}
if b < -4.89999999999999974e-39Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.5
Applied rewrites35.5%
lift-fma.f64N/A
lift-neg.f64N/A
sub-flip-reverseN/A
lower--.f64N/A
lower-*.f6435.5
lift-*.f64N/A
count-2-revN/A
lift-+.f6435.5
Applied rewrites35.5%
if -4.89999999999999974e-39 < b < 1.55e-46Initial program 71.9%
Taylor expanded in a around inf
lower-*.f64N/A
lower-*.f6456.1
Applied rewrites56.1%
Taylor expanded in a around inf
lower-*.f64N/A
lower-*.f6440.4
Applied rewrites40.4%
lift-*.f64N/A
count-2-revN/A
lower-+.f6440.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6440.4
Applied rewrites40.4%
lift-+.f64N/A
lift-neg.f64N/A
sub-flip-reverseN/A
lower--.f6440.4
lift-*.f64N/A
*-commutativeN/A
lift-*.f6440.4
Applied rewrites40.4%
if 1.55e-46 < b Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around inf
lower-*.f6467.8
Applied rewrites67.8%
(FPCore (a b c)
:precision binary64
(if (<= b -1.8e-160)
(if (>= b 0.0) (* -1.0 (/ b a)) (/ (- (* 1.0 (fabs b)) b) (+ a a)))
(if (<= b 1.55e-46)
(if (>= b 0.0)
(/ (+ c c) (- (- b) (sqrt (* (* a c) -4.0))))
(* -0.5 (* c (sqrt (/ -4.0 (* a c))))))
(if (>= b 0.0)
(/ (* 2.0 c) (* -2.0 b))
(/ (fma 1.0 (fabs b) (- b)) (* 2.0 a))))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -1.8e-160) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -1.0 * (b / a);
} else {
tmp_2 = ((1.0 * fabs(b)) - b) / (a + a);
}
tmp_1 = tmp_2;
} else if (b <= 1.55e-46) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c + c) / (-b - sqrt(((a * c) * -4.0)));
} else {
tmp_3 = -0.5 * (c * sqrt((-4.0 / (a * c))));
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-2.0 * b);
} else {
tmp_1 = fma(1.0, fabs(b), -b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -1.8e-160) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-1.0 * Float64(b / a)); else tmp_2 = Float64(Float64(Float64(1.0 * abs(b)) - b) / Float64(a + a)); end tmp_1 = tmp_2; elseif (b <= 1.55e-46) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c + c) / Float64(Float64(-b) - sqrt(Float64(Float64(a * c) * -4.0)))); else tmp_3 = Float64(-0.5 * Float64(c * sqrt(Float64(-4.0 / Float64(a * c))))); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(-2.0 * b)); else tmp_1 = Float64(fma(1.0, abs(b), Float64(-b)) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -1.8e-160], If[GreaterEqual[b, 0.0], N[(-1.0 * N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 * N[Abs[b], $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1.55e-46], If[GreaterEqual[b, 0.0], N[(N[(c + c), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(c * N[Sqrt[N[(-4.0 / N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 * N[Abs[b], $MachinePrecision] + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.8 \cdot 10^{-160}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-1 \cdot \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 \cdot \left|b\right| - b}{a + a}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{-46}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c + c}{\left(-b\right) - \sqrt{\left(a \cdot c\right) \cdot -4}}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(c \cdot \sqrt{\frac{-4}{a \cdot c}}\right)\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, \left|b\right|, -b\right)}{2 \cdot a}\\
\end{array}
\end{array}
if b < -1.7999999999999999e-160Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.5
Applied rewrites35.5%
lift-fma.f64N/A
lift-neg.f64N/A
sub-flip-reverseN/A
lower--.f64N/A
lower-*.f6435.5
lift-*.f64N/A
count-2-revN/A
lift-+.f6435.5
Applied rewrites35.5%
if -1.7999999999999999e-160 < b < 1.55e-46Initial program 71.9%
Taylor expanded in a around inf
lower-*.f64N/A
lower-*.f6456.1
Applied rewrites56.1%
Taylor expanded in a around inf
lower-*.f64N/A
lower-*.f6440.4
Applied rewrites40.4%
lift-*.f64N/A
count-2-revN/A
lower-+.f6440.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6440.4
Applied rewrites40.4%
Taylor expanded in a around -inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6427.5
Applied rewrites27.5%
Taylor expanded in c around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6434.5
Applied rewrites34.5%
if 1.55e-46 < b Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around inf
lower-*.f6467.8
Applied rewrites67.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (fma 1.0 (fabs b) (- b)) (* 2.0 a))))
(if (<= b 4.6e-47)
(if (>= b 0.0) (* -2.0 (/ c (sqrt (- (* 4.0 (* a c)))))) t_0)
(if (>= b 0.0) (/ (* 2.0 c) (* -2.0 b)) t_0))))
double code(double a, double b, double c) {
double t_0 = fma(1.0, fabs(b), -b) / (2.0 * a);
double tmp_1;
if (b <= 4.6e-47) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -2.0 * (c / sqrt(-(4.0 * (a * c))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-2.0 * b);
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(fma(1.0, abs(b), Float64(-b)) / Float64(2.0 * a)) tmp_1 = 0.0 if (b <= 4.6e-47) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(-2.0 * Float64(c / sqrt(Float64(-Float64(4.0 * Float64(a * c)))))); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(-2.0 * b)); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(1.0 * N[Abs[b], $MachinePrecision] + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 4.6e-47], If[GreaterEqual[b, 0.0], N[(-2.0 * N[(c / N[Sqrt[(-N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(1, \left|b\right|, -b\right)}{2 \cdot a}\\
\mathbf{if}\;b \leq 4.6 \cdot 10^{-47}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-2 \cdot \frac{c}{\sqrt{-4 \cdot \left(a \cdot c\right)}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < 4.59999999999999964e-47Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around 0
lower-*.f64N/A
lower-/.f64N/A
lower-sqrt.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-*.f6446.9
Applied rewrites46.9%
if 4.59999999999999964e-47 < b Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around inf
lower-*.f6467.8
Applied rewrites67.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (fma 1.0 (fabs b) (- b)) (* 2.0 a))))
(if (<= b 4.6e-47)
(if (>= b 0.0) (/ 2.0 (* a (sqrt (/ -4.0 (* a c))))) t_0)
(if (>= b 0.0) (/ (* 2.0 c) (* -2.0 b)) t_0))))
double code(double a, double b, double c) {
double t_0 = fma(1.0, fabs(b), -b) / (2.0 * a);
double tmp_1;
if (b <= 4.6e-47) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = 2.0 / (a * sqrt((-4.0 / (a * c))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-2.0 * b);
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(fma(1.0, abs(b), Float64(-b)) / Float64(2.0 * a)) tmp_1 = 0.0 if (b <= 4.6e-47) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(2.0 / Float64(a * sqrt(Float64(-4.0 / Float64(a * c))))); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(-2.0 * b)); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(1.0 * N[Abs[b], $MachinePrecision] + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 4.6e-47], If[GreaterEqual[b, 0.0], N[(2.0 / N[(a * N[Sqrt[N[(-4.0 / N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(1, \left|b\right|, -b\right)}{2 \cdot a}\\
\mathbf{if}\;b \leq 4.6 \cdot 10^{-47}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2}{a \cdot \sqrt{\frac{-4}{a \cdot c}}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < 4.59999999999999964e-47Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in a around -inf
lower-*.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6441.1
Applied rewrites41.1%
Taylor expanded in c around inf
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6448.4
Applied rewrites48.4%
if 4.59999999999999964e-47 < b Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around inf
lower-*.f6467.8
Applied rewrites67.8%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (* -2.0 b)) (/ (fma 1.0 (fabs b) (- b)) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-2.0 * b);
} else {
tmp = fma(1.0, fabs(b), -b) / (2.0 * a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(-2.0 * b)); else tmp = Float64(fma(1.0, abs(b), Float64(-b)) / Float64(2.0 * a)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 * N[Abs[b], $MachinePrecision] + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, \left|b\right|, -b\right)}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around inf
lower-*.f6467.8
Applied rewrites67.8%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ -2.0 (sqrt (* -4.0 (/ a c)))) (/ (fma 1.0 (fabs b) (- b)) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -2.0 / sqrt((-4.0 * (a / c)));
} else {
tmp = fma(1.0, fabs(b), -b) / (2.0 * a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(-2.0 / sqrt(Float64(-4.0 * Float64(a / c)))); else tmp = Float64(fma(1.0, abs(b), Float64(-b)) / Float64(2.0 * a)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(-2.0 / N[Sqrt[N[(-4.0 * N[(a / c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 * N[Abs[b], $MachinePrecision] + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2}{\sqrt{-4 \cdot \frac{a}{c}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, \left|b\right|, -b\right)}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in c around inf
lower-/.f64N/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6442.5
Applied rewrites42.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* -1.0 (/ b a)) (/ (- (* 1.0 (fabs b)) b) (+ a a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -1.0 * (b / a);
} else {
tmp = ((1.0 * fabs(b)) - b) / (a + a);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(a, b, c)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b >= 0.0d0) then
tmp = (-1.0d0) * (b / a)
else
tmp = ((1.0d0 * abs(b)) - b) / (a + a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -1.0 * (b / a);
} else {
tmp = ((1.0 * Math.abs(b)) - b) / (a + a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -1.0 * (b / a) else: tmp = ((1.0 * math.fabs(b)) - b) / (a + a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(-1.0 * Float64(b / a)); else tmp = Float64(Float64(Float64(1.0 * abs(b)) - b) / Float64(a + a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -1.0 * (b / a); else tmp = ((1.0 * abs(b)) - b) / (a + a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(-1.0 * N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 * N[Abs[b], $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-1 \cdot \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 \cdot \left|b\right| - b}{a + a}\\
\end{array}
\end{array}
Initial program 71.9%
lift-+.f64N/A
+-commutativeN/A
lift-sqrt.f64N/A
lift--.f64N/A
sub-to-multN/A
sqrt-prodN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
lower-fma.f64N/A
Applied rewrites74.2%
Taylor expanded in a around 0
Applied rewrites69.9%
Taylor expanded in b around -inf
lower-*.f64N/A
lower-/.f6435.5
Applied rewrites35.5%
lift-fma.f64N/A
lift-neg.f64N/A
sub-flip-reverseN/A
lower--.f64N/A
lower-*.f6435.5
lift-*.f64N/A
count-2-revN/A
lift-+.f6435.5
Applied rewrites35.5%
herbie shell --seed 2025149
(FPCore (a b c)
:name "jeff quadratic root 2"
:precision binary64
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))