
(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 9 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 -2.1e-26)
(/ b (- a))
(if (<= b 2.4e-99)
(* 0.5 (- (/ (hypot b (sqrt (* a (* c -4.0)))) a) (/ b a)))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-26) {
tmp = b / -a;
} else if (b <= 2.4e-99) {
tmp = 0.5 * ((hypot(b, sqrt((a * (c * -4.0)))) / a) - (b / a));
} else {
tmp = c / -b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-26) {
tmp = b / -a;
} else if (b <= 2.4e-99) {
tmp = 0.5 * ((Math.hypot(b, Math.sqrt((a * (c * -4.0)))) / a) - (b / a));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.1e-26: tmp = b / -a elif b <= 2.4e-99: tmp = 0.5 * ((math.hypot(b, math.sqrt((a * (c * -4.0)))) / a) - (b / a)) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.1e-26) tmp = Float64(b / Float64(-a)); elseif (b <= 2.4e-99) tmp = Float64(0.5 * Float64(Float64(hypot(b, sqrt(Float64(a * Float64(c * -4.0)))) / a) - Float64(b / a))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.1e-26) tmp = b / -a; elseif (b <= 2.4e-99) tmp = 0.5 * ((hypot(b, sqrt((a * (c * -4.0)))) / a) - (b / a)); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.1e-26], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 2.4e-99], N[(0.5 * N[(N[(N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] / a), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.1 \cdot 10^{-26}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{-99}:\\
\;\;\;\;0.5 \cdot \left(\frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}{a} - \frac{b}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.10000000000000008e-26Initial program 59.6%
*-commutative59.6%
Simplified59.6%
Taylor expanded in b around -inf 98.9%
associate-*r/98.9%
mul-1-neg98.9%
Simplified98.9%
if -2.10000000000000008e-26 < b < 2.4e-99Initial program 81.4%
*-commutative81.4%
Simplified81.4%
Applied egg-rr82.9%
sub-neg82.9%
distribute-lft-out--82.9%
Simplified82.9%
if 2.4e-99 < b Initial program 24.4%
*-commutative24.4%
Simplified24.4%
Taylor expanded in b around inf 82.1%
associate-*r/82.1%
mul-1-neg82.1%
Simplified82.1%
Final simplification87.5%
(FPCore (a b c)
:precision binary64
(if (<= b -5e+152)
(/ b (- a))
(if (<= b 1.3e-99)
(/ (- (sqrt (fma a (* c -4.0) (* b b))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e+152) {
tmp = b / -a;
} else if (b <= 1.3e-99) {
tmp = (sqrt(fma(a, (c * -4.0), (b * b))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5e+152) tmp = Float64(b / Float64(-a)); elseif (b <= 1.3e-99) tmp = Float64(Float64(sqrt(fma(a, Float64(c * -4.0), Float64(b * b))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5e+152], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.3e-99], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $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 -5 \cdot 10^{+152}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.3 \cdot 10^{-99}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5e152Initial program 37.0%
*-commutative37.0%
Simplified37.0%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -5e152 < b < 1.30000000000000003e-99Initial program 85.9%
*-commutative85.9%
Simplified85.9%
if 1.30000000000000003e-99 < b Initial program 24.4%
*-commutative24.4%
Simplified24.4%
Taylor expanded in b around inf 82.1%
associate-*r/82.1%
mul-1-neg82.1%
Simplified82.1%
Final simplification87.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e+152)
(/ b (- a))
(if (<= b 1.7e-99)
(/ (- (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 <= -1.5e+152) {
tmp = b / -a;
} else if (b <= 1.7e-99) {
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 <= (-1.5d+152)) then
tmp = b / -a
else if (b <= 1.7d-99) 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 <= -1.5e+152) {
tmp = b / -a;
} else if (b <= 1.7e-99) {
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 <= -1.5e+152: tmp = b / -a elif b <= 1.7e-99: 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 <= -1.5e+152) tmp = Float64(b / Float64(-a)); elseif (b <= 1.7e-99) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.5e+152) tmp = b / -a; elseif (b <= 1.7e-99) 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, -1.5e+152], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.7e-99], 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 -1.5 \cdot 10^{+152}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-99}:\\
\;\;\;\;\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 < -1.49999999999999995e152Initial program 37.0%
*-commutative37.0%
Simplified37.0%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -1.49999999999999995e152 < b < 1.70000000000000003e-99Initial program 85.9%
if 1.70000000000000003e-99 < b Initial program 24.4%
*-commutative24.4%
Simplified24.4%
Taylor expanded in b around inf 82.1%
associate-*r/82.1%
mul-1-neg82.1%
Simplified82.1%
Final simplification87.3%
(FPCore (a b c)
:precision binary64
(if (<= b -5.2e-77)
(/ b (- a))
(if (<= b 2.2e-99)
(/ (+ b (sqrt (* c (* a -4.0)))) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-77) {
tmp = b / -a;
} else if (b <= 2.2e-99) {
tmp = (b + sqrt((c * (a * -4.0)))) / (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 <= (-5.2d-77)) then
tmp = b / -a
else if (b <= 2.2d-99) then
tmp = (b + sqrt((c * (a * (-4.0d0))))) / (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 <= -5.2e-77) {
tmp = b / -a;
} else if (b <= 2.2e-99) {
tmp = (b + Math.sqrt((c * (a * -4.0)))) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e-77: tmp = b / -a elif b <= 2.2e-99: tmp = (b + math.sqrt((c * (a * -4.0)))) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e-77) tmp = Float64(b / Float64(-a)); elseif (b <= 2.2e-99) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.2e-77) tmp = b / -a; elseif (b <= 2.2e-99) tmp = (b + sqrt((c * (a * -4.0)))) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e-77], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 2.2e-99], N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{-77}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-99}:\\
\;\;\;\;\frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.2000000000000002e-77Initial program 62.5%
*-commutative62.5%
Simplified62.5%
Taylor expanded in b around -inf 95.8%
associate-*r/95.8%
mul-1-neg95.8%
Simplified95.8%
if -5.2000000000000002e-77 < b < 2.20000000000000004e-99Initial program 80.0%
*-commutative80.0%
Simplified80.0%
Taylor expanded in b around 0 75.9%
*-commutative75.9%
associate-*r*75.9%
Simplified75.9%
*-un-lft-identity75.9%
*-un-lft-identity75.9%
*-commutative75.9%
times-frac75.9%
metadata-eval75.9%
add-sqr-sqrt41.3%
sqrt-unprod75.5%
sqr-neg75.5%
sqrt-unprod34.6%
add-sqr-sqrt74.4%
Applied egg-rr74.4%
*-lft-identity74.4%
metadata-eval74.4%
times-frac74.4%
*-lft-identity74.4%
associate-*r*74.4%
*-commutative74.4%
associate-*r*74.4%
rem-square-sqrt0.0%
unpow20.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt74.4%
*-commutative74.4%
Simplified74.4%
if 2.20000000000000004e-99 < b Initial program 24.4%
*-commutative24.4%
Simplified24.4%
Taylor expanded in b around inf 82.1%
associate-*r/82.1%
mul-1-neg82.1%
Simplified82.1%
Final simplification84.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.85e-75)
(/ b (- a))
(if (<= b 7.5e-88)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.85e-75) {
tmp = b / -a;
} else if (b <= 7.5e-88) {
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 <= (-1.85d-75)) then
tmp = b / -a
else if (b <= 7.5d-88) 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 <= -1.85e-75) {
tmp = b / -a;
} else if (b <= 7.5e-88) {
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 <= -1.85e-75: tmp = b / -a elif b <= 7.5e-88: 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 <= -1.85e-75) tmp = Float64(b / Float64(-a)); elseif (b <= 7.5e-88) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.85e-75) tmp = b / -a; elseif (b <= 7.5e-88) 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, -1.85e-75], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 7.5e-88], 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 -1.85 \cdot 10^{-75}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 7.5 \cdot 10^{-88}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.85000000000000012e-75Initial program 62.5%
*-commutative62.5%
Simplified62.5%
Taylor expanded in b around -inf 95.8%
associate-*r/95.8%
mul-1-neg95.8%
Simplified95.8%
if -1.85000000000000012e-75 < b < 7.50000000000000041e-88Initial program 79.3%
*-commutative79.3%
Simplified79.3%
Taylor expanded in b around 0 75.3%
*-commutative75.3%
associate-*r*75.3%
Simplified75.3%
if 7.50000000000000041e-88 < b Initial program 23.8%
*-commutative23.8%
Simplified23.8%
Taylor expanded in b around inf 82.7%
associate-*r/82.7%
mul-1-neg82.7%
Simplified82.7%
Final simplification84.6%
(FPCore (a b c) :precision binary64 (if (<= b 2.85e+48) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.85e+48) {
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.85d+48) 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.85e+48) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.85e+48: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.85e+48) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.85e+48) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.85e+48], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.85 \cdot 10^{+48}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.84999999999999984e48Initial program 64.9%
*-commutative64.9%
Simplified64.9%
Taylor expanded in b around -inf 44.5%
associate-*r/44.5%
mul-1-neg44.5%
Simplified44.5%
if 2.84999999999999984e48 < b Initial program 12.6%
*-commutative12.6%
Simplified12.6%
Taylor expanded in b around -inf 2.7%
mul-1-neg2.7%
*-commutative2.7%
distribute-rgt-neg-in2.7%
+-commutative2.7%
mul-1-neg2.7%
unsub-neg2.7%
Simplified2.7%
Taylor expanded in a around inf 37.2%
Final simplification43.0%
(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(b / Float64(-a)); else tmp = Float64(c / Float64(-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 68.1%
*-commutative68.1%
Simplified68.1%
Taylor expanded in b around -inf 68.1%
associate-*r/68.1%
mul-1-neg68.1%
Simplified68.1%
if -1.999999999999994e-310 < b Initial program 40.2%
*-commutative40.2%
Simplified40.2%
Taylor expanded in b around inf 61.7%
associate-*r/61.7%
mul-1-neg61.7%
Simplified61.7%
Final simplification65.0%
(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 54.5%
*-commutative54.5%
Simplified54.5%
*-un-lft-identity54.5%
times-frac54.4%
Applied egg-rr30.9%
Taylor expanded in b around inf 2.5%
Taylor expanded in a around 0 2.5%
Final simplification2.5%
(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%
*-commutative54.5%
Simplified54.5%
Taylor expanded in b around -inf 34.9%
mul-1-neg34.9%
*-commutative34.9%
distribute-rgt-neg-in34.9%
+-commutative34.9%
mul-1-neg34.9%
unsub-neg34.9%
Simplified34.9%
Taylor expanded in a around inf 9.5%
Final simplification9.5%
(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 2024058
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(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)))