
(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.5e+118)
(/ b (- a))
(if (<= b 1.1e-41)
(/ (- (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 <= -2.5e+118) {
tmp = b / -a;
} else if (b <= 1.1e-41) {
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 <= -2.5e+118) tmp = Float64(b / Float64(-a)); elseif (b <= 1.1e-41) 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, -2.5e+118], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.1e-41], 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 -2.5 \cdot 10^{+118}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.1 \cdot 10^{-41}:\\
\;\;\;\;\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 < -2.49999999999999986e118Initial program 57.3%
*-commutative57.3%
Simplified57.3%
Taylor expanded in b around -inf 96.7%
mul-1-neg96.7%
Simplified96.7%
if -2.49999999999999986e118 < b < 1.1e-41Initial program 84.7%
*-commutative84.7%
Simplified84.7%
if 1.1e-41 < b Initial program 12.4%
*-commutative12.4%
Simplified12.4%
Taylor expanded in b around inf 90.1%
associate-*r/90.1%
mul-1-neg90.1%
Simplified90.1%
Final simplification89.1%
(FPCore (a b c)
:precision binary64
(if (<= b -3.1e+118)
(/ b (- a))
(if (<= b 2.2e-41)
(/ (- (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 <= -3.1e+118) {
tmp = b / -a;
} else if (b <= 2.2e-41) {
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 <= (-3.1d+118)) then
tmp = b / -a
else if (b <= 2.2d-41) 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 <= -3.1e+118) {
tmp = b / -a;
} else if (b <= 2.2e-41) {
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 <= -3.1e+118: tmp = b / -a elif b <= 2.2e-41: 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 <= -3.1e+118) tmp = Float64(b / Float64(-a)); elseif (b <= 2.2e-41) 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 <= -3.1e+118) tmp = b / -a; elseif (b <= 2.2e-41) 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, -3.1e+118], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 2.2e-41], 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 -3.1 \cdot 10^{+118}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-41}:\\
\;\;\;\;\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 < -3.09999999999999986e118Initial program 57.3%
*-commutative57.3%
Simplified57.3%
Taylor expanded in b around -inf 96.7%
mul-1-neg96.7%
Simplified96.7%
if -3.09999999999999986e118 < b < 2.2e-41Initial program 84.7%
if 2.2e-41 < b Initial program 12.4%
*-commutative12.4%
Simplified12.4%
Taylor expanded in b around inf 90.1%
associate-*r/90.1%
mul-1-neg90.1%
Simplified90.1%
Final simplification89.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1e-15)
(/ b (- a))
(if (<= b 1.9e-41)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-15) {
tmp = b / -a;
} else if (b <= 1.9e-41) {
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 <= (-1d-15)) then
tmp = b / -a
else if (b <= 1.9d-41) 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 <= -1e-15) {
tmp = b / -a;
} else if (b <= 1.9e-41) {
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 <= -1e-15: tmp = b / -a elif b <= 1.9e-41: 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 <= -1e-15) tmp = Float64(b / Float64(-a)); elseif (b <= 1.9e-41) 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 <= -1e-15) tmp = b / -a; elseif (b <= 1.9e-41) 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, -1e-15], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 1.9e-41], 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 \cdot 10^{-15}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-41}:\\
\;\;\;\;\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.0000000000000001e-15Initial program 69.6%
*-commutative69.6%
Simplified69.6%
Taylor expanded in b around -inf 93.5%
mul-1-neg93.5%
Simplified93.5%
if -1.0000000000000001e-15 < b < 1.8999999999999999e-41Initial program 81.9%
*-commutative81.9%
Simplified81.9%
Taylor expanded in b around 0 74.1%
*-commutative74.1%
associate-*r*74.1%
Simplified74.1%
if 1.8999999999999999e-41 < b Initial program 12.4%
*-commutative12.4%
Simplified12.4%
Taylor expanded in b around inf 90.1%
associate-*r/90.1%
mul-1-neg90.1%
Simplified90.1%
Final simplification85.7%
(FPCore (a b c) :precision binary64 (if (<= b -9.5e-15) (/ b (- a)) (if (<= b 2.9e-41) (* (sqrt (* a (* c -4.0))) (/ 0.5 a)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.5e-15) {
tmp = b / -a;
} else if (b <= 2.9e-41) {
tmp = sqrt((a * (c * -4.0))) * (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 <= (-9.5d-15)) then
tmp = b / -a
else if (b <= 2.9d-41) then
tmp = sqrt((a * (c * (-4.0d0)))) * (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 <= -9.5e-15) {
tmp = b / -a;
} else if (b <= 2.9e-41) {
tmp = Math.sqrt((a * (c * -4.0))) * (0.5 / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9.5e-15: tmp = b / -a elif b <= 2.9e-41: tmp = math.sqrt((a * (c * -4.0))) * (0.5 / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9.5e-15) tmp = Float64(b / Float64(-a)); elseif (b <= 2.9e-41) tmp = Float64(sqrt(Float64(a * Float64(c * -4.0))) * Float64(0.5 / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9.5e-15) tmp = b / -a; elseif (b <= 2.9e-41) tmp = sqrt((a * (c * -4.0))) * (0.5 / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9.5e-15], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 2.9e-41], N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.5 \cdot 10^{-15}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 2.9 \cdot 10^{-41}:\\
\;\;\;\;\sqrt{a \cdot \left(c \cdot -4\right)} \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -9.5000000000000005e-15Initial program 69.6%
*-commutative69.6%
Simplified69.6%
Taylor expanded in b around -inf 93.5%
mul-1-neg93.5%
Simplified93.5%
if -9.5000000000000005e-15 < b < 2.89999999999999977e-41Initial program 81.9%
*-commutative81.9%
Simplified81.9%
Applied egg-rr81.8%
sub-neg81.8%
distribute-rgt-out--81.8%
Simplified81.8%
sub-neg81.8%
add-sqr-sqrt52.1%
sqrt-unprod81.8%
sqr-neg81.8%
sqrt-prod29.8%
add-sqr-sqrt72.4%
flip-+71.6%
add-sqr-sqrt71.7%
fma-undefine71.7%
unpow271.7%
associate--l+71.8%
*-commutative71.8%
associate-*r*71.8%
+-inverses71.8%
sub-neg71.8%
add-sqr-sqrt42.4%
sqrt-unprod73.0%
sqr-neg73.0%
sqrt-prod30.7%
add-sqr-sqrt73.9%
Applied egg-rr71.8%
clear-num71.7%
frac-times71.6%
metadata-eval71.6%
clear-num71.6%
pow171.6%
pow1/271.6%
pow-div72.4%
metadata-eval72.4%
pow1/272.4%
div-inv72.5%
+-rgt-identity72.5%
associate-*l*72.5%
*-commutative72.5%
Applied egg-rr72.5%
associate-/r/72.5%
Simplified72.5%
if 2.89999999999999977e-41 < b Initial program 12.4%
*-commutative12.4%
Simplified12.4%
Taylor expanded in b around inf 90.1%
associate-*r/90.1%
mul-1-neg90.1%
Simplified90.1%
Final simplification85.2%
(FPCore (a b c) :precision binary64 (if (<= b -9e-15) (/ b (- a)) (if (<= b 3.4e-41) (/ (/ (sqrt (* a (* c -4.0))) a) 2.0) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-15) {
tmp = b / -a;
} else if (b <= 3.4e-41) {
tmp = (sqrt((a * (c * -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 <= (-9d-15)) then
tmp = b / -a
else if (b <= 3.4d-41) then
tmp = (sqrt((a * (c * (-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 <= -9e-15) {
tmp = b / -a;
} else if (b <= 3.4e-41) {
tmp = (Math.sqrt((a * (c * -4.0))) / a) / 2.0;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-15: tmp = b / -a elif b <= 3.4e-41: tmp = (math.sqrt((a * (c * -4.0))) / a) / 2.0 else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-15) tmp = Float64(b / Float64(-a)); elseif (b <= 3.4e-41) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) / 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 <= -9e-15) tmp = b / -a; elseif (b <= 3.4e-41) tmp = (sqrt((a * (c * -4.0))) / a) / 2.0; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-15], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 3.4e-41], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision] / 2.0), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-15}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{-41}:\\
\;\;\;\;\frac{\frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -8.9999999999999995e-15Initial program 69.6%
*-commutative69.6%
Simplified69.6%
Taylor expanded in b around -inf 93.5%
mul-1-neg93.5%
Simplified93.5%
if -8.9999999999999995e-15 < b < 3.3999999999999998e-41Initial program 81.9%
*-commutative81.9%
Simplified81.9%
Applied egg-rr81.8%
sub-neg81.8%
distribute-rgt-out--81.8%
Simplified81.8%
Applied egg-rr72.6%
pow1/272.6%
metadata-eval72.6%
pow-div71.8%
pow171.8%
pow1/271.8%
+-rgt-identity71.8%
associate-*l*71.8%
associate-/l*72.5%
*-commutative72.5%
+-rgt-identity72.5%
associate-*l*72.5%
*-commutative72.5%
Applied egg-rr72.5%
associate-*r/71.8%
rem-square-sqrt71.8%
associate-*r/71.9%
*-inverses72.6%
*-rgt-identity72.6%
Simplified72.6%
if 3.3999999999999998e-41 < b Initial program 12.4%
*-commutative12.4%
Simplified12.4%
Taylor expanded in b around inf 90.1%
associate-*r/90.1%
mul-1-neg90.1%
Simplified90.1%
Final simplification85.2%
(FPCore (a b c) :precision binary64 (if (<= b 7.2e+24) (/ b (- a)) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 7.2e+24) {
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.2d+24) 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.2e+24) {
tmp = b / -a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 7.2e+24: tmp = b / -a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 7.2e+24) 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 <= 7.2e+24) tmp = b / -a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 7.2e+24], N[(b / (-a)), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7.2 \cdot 10^{+24}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 7.19999999999999966e24Initial program 73.5%
*-commutative73.5%
Simplified73.5%
Taylor expanded in b around -inf 50.5%
mul-1-neg50.5%
Simplified50.5%
if 7.19999999999999966e24 < b Initial program 9.5%
*-commutative9.5%
Simplified9.5%
Taylor expanded in b around -inf 2.3%
mul-1-neg2.3%
*-commutative2.3%
distribute-rgt-neg-in2.3%
+-commutative2.3%
mul-1-neg2.3%
unsub-neg2.3%
Simplified2.3%
Taylor expanded in a around inf 27.6%
Final simplification44.0%
(FPCore (a b c) :precision binary64 (if (<= b 1.8e-232) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.8e-232) {
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 <= 1.8d-232) 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 <= 1.8e-232) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.8e-232: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.8e-232) 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 <= 1.8e-232) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.8e-232], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.8 \cdot 10^{-232}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 1.80000000000000008e-232Initial program 75.2%
*-commutative75.2%
Simplified75.2%
Taylor expanded in b around -inf 62.8%
mul-1-neg62.8%
Simplified62.8%
if 1.80000000000000008e-232 < b Initial program 29.2%
*-commutative29.2%
Simplified29.2%
Taylor expanded in b around inf 72.0%
associate-*r/72.0%
mul-1-neg72.0%
Simplified72.0%
Final simplification66.8%
(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 55.3%
*-commutative55.3%
Simplified55.3%
*-un-lft-identity55.3%
*-un-lft-identity55.3%
prod-diff55.3%
*-commutative55.3%
*-un-lft-identity55.3%
fma-define55.3%
*-un-lft-identity55.3%
+-commutative55.3%
add-sqr-sqrt41.0%
sqrt-unprod53.6%
sqr-neg53.6%
sqrt-prod12.5%
add-sqr-sqrt36.8%
pow236.8%
add-sqr-sqrt24.9%
sqrt-unprod36.8%
sqr-neg36.8%
sqrt-prod12.5%
add-sqr-sqrt36.5%
*-commutative36.5%
*-un-lft-identity36.5%
Applied egg-rr36.5%
+-commutative36.5%
associate-+l+36.5%
fma-undefine36.5%
*-rgt-identity36.5%
Simplified36.5%
Taylor expanded in b around -inf 2.3%
Final simplification2.3%
(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 55.3%
*-commutative55.3%
Simplified55.3%
Taylor expanded in b around -inf 36.3%
mul-1-neg36.3%
*-commutative36.3%
distribute-rgt-neg-in36.3%
+-commutative36.3%
mul-1-neg36.3%
unsub-neg36.3%
Simplified36.3%
Taylor expanded in a around inf 10.3%
Final simplification10.3%
(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 2024059
(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)))