
(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 8 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 -1.2e+159)
(/ (- b) a)
(if (<= b 1.45e-102)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(if (<= b 1.25e-38)
(/ 1.0 (- (/ a b) (/ b c)))
(if (<= b 5100000.0)
(/
(- (pow (exp (* 0.25 (- (log (* 4.0 c)) (log (/ -1.0 a))))) 2.0) b)
(* a 2.0))
(/ (- c) b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e+159) {
tmp = -b / a;
} else if (b <= 1.45e-102) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else if (b <= 1.25e-38) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 5100000.0) {
tmp = (pow(exp((0.25 * (log((4.0 * c)) - log((-1.0 / a))))), 2.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 <= (-1.2d+159)) then
tmp = -b / a
else if (b <= 1.45d-102) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else if (b <= 1.25d-38) then
tmp = 1.0d0 / ((a / b) - (b / c))
else if (b <= 5100000.0d0) then
tmp = ((exp((0.25d0 * (log((4.0d0 * c)) - log(((-1.0d0) / a))))) ** 2.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 <= -1.2e+159) {
tmp = -b / a;
} else if (b <= 1.45e-102) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else if (b <= 1.25e-38) {
tmp = 1.0 / ((a / b) - (b / c));
} else if (b <= 5100000.0) {
tmp = (Math.pow(Math.exp((0.25 * (Math.log((4.0 * c)) - Math.log((-1.0 / a))))), 2.0) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e+159: tmp = -b / a elif b <= 1.45e-102: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) elif b <= 1.25e-38: tmp = 1.0 / ((a / b) - (b / c)) elif b <= 5100000.0: tmp = (math.pow(math.exp((0.25 * (math.log((4.0 * c)) - math.log((-1.0 / a))))), 2.0) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.2e+159) tmp = Float64(Float64(-b) / a); elseif (b <= 1.45e-102) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); elseif (b <= 1.25e-38) tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); elseif (b <= 5100000.0) tmp = Float64(Float64((exp(Float64(0.25 * Float64(log(Float64(4.0 * c)) - log(Float64(-1.0 / a))))) ^ 2.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 <= -1.2e+159) tmp = -b / a; elseif (b <= 1.45e-102) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); elseif (b <= 1.25e-38) tmp = 1.0 / ((a / b) - (b / c)); elseif (b <= 5100000.0) tmp = ((exp((0.25 * (log((4.0 * c)) - log((-1.0 / a))))) ^ 2.0) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.2e+159], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.45e-102], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.25e-38], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5100000.0], N[(N[(N[Power[N[Exp[N[(0.25 * N[(N[Log[N[(4.0 * c), $MachinePrecision]], $MachinePrecision] - N[Log[N[(-1.0 / a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.2 \cdot 10^{+159}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.45 \cdot 10^{-102}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-38}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\mathbf{elif}\;b \leq 5100000:\\
\;\;\;\;\frac{{\left(e^{0.25 \cdot \left(\log \left(4 \cdot c\right) - \log \left(\frac{-1}{a}\right)\right)}\right)}^{2} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.2e159Initial program 56.7%
*-commutative56.7%
Simplified56.7%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -1.2e159 < b < 1.44999999999999993e-102Initial program 83.4%
if 1.44999999999999993e-102 < b < 1.25000000000000008e-38Initial program 36.0%
*-commutative36.0%
Simplified36.0%
Applied egg-rr36.0%
*-commutative36.0%
associate-/r*36.0%
metadata-eval36.0%
Simplified36.0%
associate-*r/36.0%
clear-num36.1%
Applied egg-rr36.1%
Taylor expanded in a around 0 64.0%
+-commutative64.0%
mul-1-neg64.0%
sub-neg64.0%
Simplified64.0%
if 1.25000000000000008e-38 < b < 5.1e6Initial program 39.1%
*-commutative39.1%
Simplified39.1%
add-sqr-sqrt39.3%
pow239.3%
pow1/239.3%
sqrt-pow139.3%
sub-neg39.3%
+-commutative39.3%
distribute-lft-neg-in39.3%
*-commutative39.3%
distribute-rgt-neg-in39.3%
metadata-eval39.3%
associate-*r*39.3%
*-commutative39.3%
fma-udef39.3%
pow239.3%
metadata-eval39.3%
Applied egg-rr39.3%
Taylor expanded in a around -inf 68.7%
if 5.1e6 < b Initial program 9.8%
*-commutative9.8%
Simplified9.8%
Taylor expanded in b around inf 93.5%
mul-1-neg93.5%
distribute-neg-frac93.5%
Simplified93.5%
Final simplification87.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.2e+159)
(/ (- b) a)
(if (<= b 1.95e-103)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e+159) {
tmp = -b / a;
} else if (b <= 1.95e-103) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - 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.2d+159)) then
tmp = -b / a
else if (b <= 1.95d-103) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - 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.2e+159) {
tmp = -b / a;
} else if (b <= 1.95e-103) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e+159: tmp = -b / a elif b <= 1.95e-103: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.2e+159) tmp = Float64(Float64(-b) / a); elseif (b <= 1.95e-103) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - 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.2e+159) tmp = -b / a; elseif (b <= 1.95e-103) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.2e+159], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.95e-103], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $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 -1.2 \cdot 10^{+159}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.95 \cdot 10^{-103}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.2e159Initial program 56.7%
*-commutative56.7%
Simplified56.7%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -1.2e159 < b < 1.9500000000000001e-103Initial program 83.4%
if 1.9500000000000001e-103 < b Initial program 15.6%
*-commutative15.6%
Simplified15.6%
Taylor expanded in b around inf 83.7%
mul-1-neg83.7%
distribute-neg-frac83.7%
Simplified83.7%
Final simplification85.5%
(FPCore (a b c)
:precision binary64
(if (<= b -8.8e-48)
(- (/ c b) (/ b a))
(if (<= b 1.35e-103)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.8e-48) {
tmp = (c / b) - (b / a);
} else if (b <= 1.35e-103) {
tmp = (sqrt((a * (c * -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 <= (-8.8d-48)) then
tmp = (c / b) - (b / a)
else if (b <= 1.35d-103) then
tmp = (sqrt((a * (c * (-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 <= -8.8e-48) {
tmp = (c / b) - (b / a);
} else if (b <= 1.35e-103) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.8e-48: tmp = (c / b) - (b / a) elif b <= 1.35e-103: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.8e-48) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.35e-103) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -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 <= -8.8e-48) tmp = (c / b) - (b / a); elseif (b <= 1.35e-103) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.8e-48], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e-103], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $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 -8.8 \cdot 10^{-48}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{-103}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.8000000000000005e-48Initial program 79.7%
*-commutative79.7%
Simplified79.7%
Taylor expanded in b around -inf 83.8%
+-commutative83.8%
mul-1-neg83.8%
unsub-neg83.8%
Simplified83.8%
if -8.8000000000000005e-48 < b < 1.35000000000000005e-103Initial program 75.5%
*-commutative75.5%
Simplified75.5%
Taylor expanded in b around 0 70.6%
*-commutative70.6%
associate-*r*70.6%
Simplified70.6%
if 1.35000000000000005e-103 < b Initial program 15.6%
*-commutative15.6%
Simplified15.6%
Taylor expanded in b around inf 83.7%
mul-1-neg83.7%
distribute-neg-frac83.7%
Simplified83.7%
Final simplification80.3%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-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 <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-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 -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 81.5%
*-commutative81.5%
Simplified81.5%
Taylor expanded in b around -inf 63.8%
+-commutative63.8%
mul-1-neg63.8%
unsub-neg63.8%
Simplified63.8%
if -4.999999999999985e-310 < b Initial program 27.1%
*-commutative27.1%
Simplified27.1%
Taylor expanded in b around inf 66.0%
mul-1-neg66.0%
distribute-neg-frac66.0%
Simplified66.0%
Final simplification65.0%
(FPCore (a b c) :precision binary64 (if (<= b 2.4e+19) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.4e+19) {
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 <= 2.4d+19) 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 <= 2.4e+19) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.4e+19: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.4e+19) 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 <= 2.4e+19) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.4e+19], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.4 \cdot 10^{+19}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.4e19Initial program 72.4%
*-commutative72.4%
Simplified72.4%
Taylor expanded in b around -inf 42.7%
associate-*r/42.7%
mul-1-neg42.7%
Simplified42.7%
if 2.4e19 < b Initial program 6.4%
*-commutative6.4%
Simplified6.4%
Taylor expanded in b around -inf 2.4%
+-commutative2.4%
mul-1-neg2.4%
unsub-neg2.4%
Simplified2.4%
Taylor expanded in c around inf 23.9%
Final simplification36.8%
(FPCore (a b c) :precision binary64 (if (<= b 5.2e-281) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.2e-281) {
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 <= 5.2d-281) 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 <= 5.2e-281) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 5.2e-281: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 5.2e-281) 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 <= 5.2e-281) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 5.2e-281], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.2 \cdot 10^{-281}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 5.2000000000000001e-281Initial program 80.2%
*-commutative80.2%
Simplified80.2%
Taylor expanded in b around -inf 62.4%
associate-*r/62.4%
mul-1-neg62.4%
Simplified62.4%
if 5.2000000000000001e-281 < b Initial program 27.5%
*-commutative27.5%
Simplified27.5%
Taylor expanded in b around inf 66.9%
mul-1-neg66.9%
distribute-neg-frac66.9%
Simplified66.9%
Final simplification64.9%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / 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 / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 51.6%
Simplified51.6%
*-un-lft-identity51.6%
*-un-lft-identity51.6%
prod-diff51.6%
*-commutative51.6%
*-un-lft-identity51.6%
fma-def51.6%
*-un-lft-identity51.6%
+-commutative51.6%
add-sqr-sqrt36.6%
sqrt-unprod49.7%
sqr-neg49.7%
sqrt-prod13.1%
add-sqr-sqrt34.4%
pow234.4%
add-sqr-sqrt21.9%
sqrt-unprod34.4%
sqr-neg34.4%
sqrt-prod13.1%
add-sqr-sqrt34.0%
*-commutative34.0%
*-un-lft-identity34.0%
Applied egg-rr34.0%
+-commutative34.0%
associate-+l+34.0%
fma-udef34.0%
*-rgt-identity34.0%
Simplified34.0%
Taylor expanded in b around -inf 2.6%
Final simplification2.6%
(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 51.6%
*-commutative51.6%
Simplified51.6%
Taylor expanded in b around -inf 29.8%
+-commutative29.8%
mul-1-neg29.8%
unsub-neg29.8%
Simplified29.8%
Taylor expanded in c around inf 9.8%
Final simplification9.8%
(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 2024027
(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)))