
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -4e+117)
(- (/ c b) (/ b a))
(if (or (<= b 5e-95) (and (not (<= b 2.35e-80)) (<= b 0.135)))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e+117) {
tmp = (c / b) - (b / a);
} else if ((b <= 5e-95) || (!(b <= 2.35e-80) && (b <= 0.135))) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-4d+117)) then
tmp = (c / b) - (b / a)
else if ((b <= 5d-95) .or. (.not. (b <= 2.35d-80)) .and. (b <= 0.135d0)) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4e+117) {
tmp = (c / b) - (b / a);
} else if ((b <= 5e-95) || (!(b <= 2.35e-80) && (b <= 0.135))) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e+117: tmp = (c / b) - (b / a) elif (b <= 5e-95) or (not (b <= 2.35e-80) and (b <= 0.135)): tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e+117) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif ((b <= 5e-95) || (!(b <= 2.35e-80) && (b <= 0.135))) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e+117) tmp = (c / b) - (b / a); elseif ((b <= 5e-95) || (~((b <= 2.35e-80)) && (b <= 0.135))) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e+117], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 5e-95], And[N[Not[LessEqual[b, 2.35e-80]], $MachinePrecision], LessEqual[b, 0.135]]], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{+117}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{-95} \lor \neg \left(b \leq 2.35 \cdot 10^{-80}\right) \land b \leq 0.135:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.0000000000000002e117Initial program 47.7%
Taylor expanded in b around -inf 96.8%
+-commutative96.8%
mul-1-neg96.8%
unsub-neg96.8%
Simplified96.8%
if -4.0000000000000002e117 < b < 4.9999999999999998e-95 or 2.34999999999999986e-80 < b < 0.13500000000000001Initial program 83.0%
if 4.9999999999999998e-95 < b < 2.34999999999999986e-80 or 0.13500000000000001 < b Initial program 16.5%
Taylor expanded in b around inf 83.2%
associate-*r/83.2%
neg-mul-183.2%
Simplified83.2%
Final simplification86.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.25e-75)
(- (/ c b) (/ b a))
(if (<= b 8e-95)
(/ (- (pow (/ (* c 4.0) (/ -1.0 a)) 0.5) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.25e-75) {
tmp = (c / b) - (b / a);
} else if (b <= 8e-95) {
tmp = (pow(((c * 4.0) / (-1.0 / a)), 0.5) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.25d-75)) then
tmp = (c / b) - (b / a)
else if (b <= 8d-95) then
tmp = ((((c * 4.0d0) / ((-1.0d0) / a)) ** 0.5d0) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.25e-75) {
tmp = (c / b) - (b / a);
} else if (b <= 8e-95) {
tmp = (Math.pow(((c * 4.0) / (-1.0 / a)), 0.5) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.25e-75: tmp = (c / b) - (b / a) elif b <= 8e-95: tmp = (math.pow(((c * 4.0) / (-1.0 / a)), 0.5) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.25e-75) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 8e-95) tmp = Float64(Float64((Float64(Float64(c * 4.0) / Float64(-1.0 / a)) ^ 0.5) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.25e-75) tmp = (c / b) - (b / a); elseif (b <= 8e-95) tmp = ((((c * 4.0) / (-1.0 / a)) ^ 0.5) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.25e-75], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8e-95], N[(N[(N[Power[N[(N[(c * 4.0), $MachinePrecision] / N[(-1.0 / a), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.25 \cdot 10^{-75}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 8 \cdot 10^{-95}:\\
\;\;\;\;\frac{{\left(\frac{c \cdot 4}{\frac{-1}{a}}\right)}^{0.5} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.24999999999999995e-75Initial program 68.0%
Taylor expanded in b around -inf 93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
if -1.24999999999999995e-75 < b < 7.99999999999999992e-95Initial program 80.2%
pow1/280.2%
pow-to-exp74.8%
fma-neg74.8%
*-commutative74.8%
distribute-rgt-neg-in74.8%
*-commutative74.8%
distribute-rgt-neg-in74.8%
metadata-eval74.8%
Applied egg-rr74.8%
Taylor expanded in a around -inf 46.5%
mul-1-neg46.5%
unsub-neg46.5%
*-commutative46.5%
Simplified46.5%
exp-prod39.6%
diff-log67.2%
add-exp-log71.8%
Applied egg-rr71.8%
if 7.99999999999999992e-95 < b Initial program 23.4%
Taylor expanded in b around inf 74.3%
associate-*r/74.3%
neg-mul-174.3%
Simplified74.3%
Final simplification81.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.1e-69)
(- (/ c b) (/ b a))
(if (<= b 2.2e-94)
(* (- (sqrt (* c (/ a -0.25))) b) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e-69) {
tmp = (c / b) - (b / a);
} else if (b <= 2.2e-94) {
tmp = (sqrt((c * (a / -0.25))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.1d-69)) then
tmp = (c / b) - (b / a)
else if (b <= 2.2d-94) then
tmp = (sqrt((c * (a / (-0.25d0)))) - b) * (0.5d0 / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e-69) {
tmp = (c / b) - (b / a);
} else if (b <= 2.2e-94) {
tmp = (Math.sqrt((c * (a / -0.25))) - b) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.1e-69: tmp = (c / b) - (b / a) elif b <= 2.2e-94: tmp = (math.sqrt((c * (a / -0.25))) - b) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.1e-69) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.2e-94) tmp = Float64(Float64(sqrt(Float64(c * Float64(a / -0.25))) - b) * Float64(0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.1e-69) tmp = (c / b) - (b / a); elseif (b <= 2.2e-94) tmp = (sqrt((c * (a / -0.25))) - b) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.1e-69], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.2e-94], N[(N[(N[Sqrt[N[(c * N[(a / -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1 \cdot 10^{-69}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-94}:\\
\;\;\;\;\left(\sqrt{c \cdot \frac{a}{-0.25}} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.1e-69Initial program 68.0%
Taylor expanded in b around -inf 93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
if -1.1e-69 < b < 2.20000000000000001e-94Initial program 80.2%
pow1/280.2%
pow-to-exp74.8%
fma-neg74.8%
*-commutative74.8%
distribute-rgt-neg-in74.8%
*-commutative74.8%
distribute-rgt-neg-in74.8%
metadata-eval74.8%
Applied egg-rr74.8%
Taylor expanded in c around -inf 33.5%
mul-1-neg33.5%
unsub-neg33.5%
*-commutative33.5%
Simplified33.5%
Taylor expanded in a around 0 33.5%
Simplified71.7%
if 2.20000000000000001e-94 < b Initial program 23.4%
Taylor expanded in b around inf 74.3%
associate-*r/74.3%
neg-mul-174.3%
Simplified74.3%
Final simplification81.0%
(FPCore (a b c)
:precision binary64
(if (<= b -4.5e-69)
(- (/ c b) (/ b a))
(if (<= b 3.9e-95)
(/ (- (sqrt (* c (/ a -0.25))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-69) {
tmp = (c / b) - (b / a);
} else if (b <= 3.9e-95) {
tmp = (sqrt((c * (a / -0.25))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-4.5d-69)) then
tmp = (c / b) - (b / a)
else if (b <= 3.9d-95) then
tmp = (sqrt((c * (a / (-0.25d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e-69) {
tmp = (c / b) - (b / a);
} else if (b <= 3.9e-95) {
tmp = (Math.sqrt((c * (a / -0.25))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.5e-69: tmp = (c / b) - (b / a) elif b <= 3.9e-95: tmp = (math.sqrt((c * (a / -0.25))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.5e-69) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.9e-95) tmp = Float64(Float64(sqrt(Float64(c * Float64(a / -0.25))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.5e-69) tmp = (c / b) - (b / a); elseif (b <= 3.9e-95) tmp = (sqrt((c * (a / -0.25))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.5e-69], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.9e-95], N[(N[(N[Sqrt[N[(c * N[(a / -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.5 \cdot 10^{-69}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.9 \cdot 10^{-95}:\\
\;\;\;\;\frac{\sqrt{c \cdot \frac{a}{-0.25}} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.50000000000000009e-69Initial program 68.0%
Taylor expanded in b around -inf 93.4%
+-commutative93.4%
mul-1-neg93.4%
unsub-neg93.4%
Simplified93.4%
if -4.50000000000000009e-69 < b < 3.9e-95Initial program 80.2%
pow1/280.2%
pow-to-exp74.8%
fma-neg74.8%
*-commutative74.8%
distribute-rgt-neg-in74.8%
*-commutative74.8%
distribute-rgt-neg-in74.8%
metadata-eval74.8%
Applied egg-rr74.8%
Taylor expanded in c around -inf 33.5%
mul-1-neg33.5%
unsub-neg33.5%
*-commutative33.5%
Simplified33.5%
Taylor expanded in b around 0 33.5%
neg-mul-133.5%
sub-neg33.5%
*-commutative33.5%
log-prod33.5%
+-commutative33.5%
log-prod33.5%
log-div67.2%
exp-to-pow71.8%
unpow1/271.8%
associate-/r/71.8%
*-commutative71.8%
associate-/l*71.8%
metadata-eval71.8%
Simplified71.8%
if 3.9e-95 < b Initial program 23.4%
Taylor expanded in b around inf 74.3%
associate-*r/74.3%
neg-mul-174.3%
Simplified74.3%
Final simplification81.0%
(FPCore (a b c) :precision binary64 (if (<= b -7.6e-95) (- (/ c b) (/ b a)) (if (<= b 2.15e-94) (* (/ 0.5 a) (sqrt (* a (/ c -0.25)))) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.6e-95) {
tmp = (c / b) - (b / a);
} else if (b <= 2.15e-94) {
tmp = (0.5 / a) * sqrt((a * (c / -0.25)));
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-7.6d-95)) then
tmp = (c / b) - (b / a)
else if (b <= 2.15d-94) then
tmp = (0.5d0 / a) * sqrt((a * (c / (-0.25d0))))
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.6e-95) {
tmp = (c / b) - (b / a);
} else if (b <= 2.15e-94) {
tmp = (0.5 / a) * Math.sqrt((a * (c / -0.25)));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.6e-95: tmp = (c / b) - (b / a) elif b <= 2.15e-94: tmp = (0.5 / a) * math.sqrt((a * (c / -0.25))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.6e-95) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.15e-94) tmp = Float64(Float64(0.5 / a) * sqrt(Float64(a * Float64(c / -0.25)))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.6e-95) tmp = (c / b) - (b / a); elseif (b <= 2.15e-94) tmp = (0.5 / a) * sqrt((a * (c / -0.25))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.6e-95], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.15e-94], N[(N[(0.5 / a), $MachinePrecision] * N[Sqrt[N[(a * N[(c / -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.6 \cdot 10^{-95}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.15 \cdot 10^{-94}:\\
\;\;\;\;\frac{0.5}{a} \cdot \sqrt{a \cdot \frac{c}{-0.25}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.5999999999999995e-95Initial program 69.3%
Taylor expanded in b around -inf 91.8%
+-commutative91.8%
mul-1-neg91.8%
unsub-neg91.8%
Simplified91.8%
if -7.5999999999999995e-95 < b < 2.1499999999999999e-94Initial program 78.9%
pow1/278.9%
pow-to-exp73.7%
fma-neg73.7%
*-commutative73.7%
distribute-rgt-neg-in73.7%
*-commutative73.7%
distribute-rgt-neg-in73.7%
metadata-eval73.7%
Applied egg-rr73.7%
Taylor expanded in a around -inf 49.6%
mul-1-neg49.6%
unsub-neg49.6%
*-commutative49.6%
Simplified49.6%
Taylor expanded in b around 0 49.8%
associate-*r/49.8%
*-lft-identity49.8%
*-commutative49.8%
*-commutative49.8%
log-div67.9%
exp-to-pow72.6%
*-commutative72.6%
times-frac72.6%
/-rgt-identity72.6%
unpow1/272.6%
associate-/r/72.5%
*-commutative72.5%
associate-/l*72.5%
metadata-eval72.5%
Simplified72.5%
if 2.1499999999999999e-94 < b Initial program 23.4%
Taylor expanded in b around inf 74.3%
associate-*r/74.3%
neg-mul-174.3%
Simplified74.3%
Final simplification80.9%
(FPCore (a b c) :precision binary64 (if (<= b -4.3e-95) (- (/ c b) (/ b a)) (if (<= b 2.15e-94) (/ (* 0.5 (sqrt (* c (/ a -0.25)))) a) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.3e-95) {
tmp = (c / b) - (b / a);
} else if (b <= 2.15e-94) {
tmp = (0.5 * sqrt((c * (a / -0.25)))) / a;
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-4.3d-95)) then
tmp = (c / b) - (b / a)
else if (b <= 2.15d-94) then
tmp = (0.5d0 * sqrt((c * (a / (-0.25d0))))) / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.3e-95) {
tmp = (c / b) - (b / a);
} else if (b <= 2.15e-94) {
tmp = (0.5 * Math.sqrt((c * (a / -0.25)))) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.3e-95: tmp = (c / b) - (b / a) elif b <= 2.15e-94: tmp = (0.5 * math.sqrt((c * (a / -0.25)))) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.3e-95) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.15e-94) tmp = Float64(Float64(0.5 * sqrt(Float64(c * Float64(a / -0.25)))) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.3e-95) tmp = (c / b) - (b / a); elseif (b <= 2.15e-94) tmp = (0.5 * sqrt((c * (a / -0.25)))) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.3e-95], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.15e-94], N[(N[(0.5 * N[Sqrt[N[(c * N[(a / -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.3 \cdot 10^{-95}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.15 \cdot 10^{-94}:\\
\;\;\;\;\frac{0.5 \cdot \sqrt{c \cdot \frac{a}{-0.25}}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.29999999999999997e-95Initial program 69.3%
Taylor expanded in b around -inf 91.8%
+-commutative91.8%
mul-1-neg91.8%
unsub-neg91.8%
Simplified91.8%
if -4.29999999999999997e-95 < b < 2.1499999999999999e-94Initial program 78.9%
pow1/278.9%
pow-to-exp73.7%
fma-neg73.7%
*-commutative73.7%
distribute-rgt-neg-in73.7%
*-commutative73.7%
distribute-rgt-neg-in73.7%
metadata-eval73.7%
Applied egg-rr73.7%
Taylor expanded in c around -inf 32.4%
mul-1-neg32.4%
unsub-neg32.4%
*-commutative32.4%
Simplified32.4%
Taylor expanded in b around 0 32.4%
associate-*r/32.4%
*-commutative32.4%
log-prod32.4%
+-commutative32.4%
log-prod32.4%
log-div67.9%
exp-to-pow72.5%
unpow1/272.5%
associate-/r/72.5%
*-commutative72.5%
associate-/l*72.5%
metadata-eval72.5%
Simplified72.5%
if 2.1499999999999999e-94 < b Initial program 23.4%
Taylor expanded in b around inf 74.3%
associate-*r/74.3%
neg-mul-174.3%
Simplified74.3%
Final simplification80.9%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2d-310)) then
tmp = (c / b) - (b / a)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 72.7%
Taylor expanded in b around -inf 76.4%
+-commutative76.4%
mul-1-neg76.4%
unsub-neg76.4%
Simplified76.4%
if -1.999999999999994e-310 < b Initial program 36.2%
Taylor expanded in b around inf 58.1%
associate-*r/58.1%
neg-mul-158.1%
Simplified58.1%
Final simplification67.2%
(FPCore (a b c) :precision binary64 (if (<= b 7.1e+72) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.1e+72) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 7.1d+72) then
tmp = -b / a
else
tmp = c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 7.1e+72) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.1e+72: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.1e+72) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 7.1e+72) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.1e+72], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.1 \cdot 10^{+72}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 7.0999999999999993e72Initial program 66.0%
Taylor expanded in b around -inf 49.5%
associate-*r/49.5%
mul-1-neg49.5%
Simplified49.5%
if 7.0999999999999993e72 < b Initial program 11.4%
pow1/211.4%
pow-to-exp6.4%
fma-neg6.4%
*-commutative6.4%
distribute-rgt-neg-in6.4%
*-commutative6.4%
distribute-rgt-neg-in6.4%
metadata-eval6.4%
Applied egg-rr6.4%
Taylor expanded in b around -inf 2.5%
neg-mul-12.5%
+-commutative2.5%
unsub-neg2.5%
associate-/l*2.6%
*-commutative2.6%
associate-*l/2.6%
Simplified2.6%
Taylor expanded in b around 0 37.2%
Final simplification46.9%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2d-310)) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 72.7%
Taylor expanded in b around -inf 76.3%
associate-*r/76.3%
mul-1-neg76.3%
Simplified76.3%
if -1.999999999999994e-310 < b Initial program 36.2%
Taylor expanded in b around inf 58.1%
associate-*r/58.1%
neg-mul-158.1%
Simplified58.1%
Final simplification67.2%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 54.5%
pow1/254.5%
pow-to-exp50.9%
fma-neg50.9%
*-commutative50.9%
distribute-rgt-neg-in50.9%
*-commutative50.9%
distribute-rgt-neg-in50.9%
metadata-eval50.9%
Applied egg-rr50.9%
Taylor expanded in b around -inf 37.0%
neg-mul-137.0%
+-commutative37.0%
unsub-neg37.0%
associate-/l*39.3%
*-commutative39.3%
associate-*l/39.3%
Simplified39.3%
Taylor expanded in b around 0 10.1%
Final simplification10.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* a (/ (- (- 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-b - t_0) / (2.0 * a)));
}
return tmp;
}
real(8) function code(a, b, c)
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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-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(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023279
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))