
(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 7 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 -1e+154)
(/ (- b) a)
(if (<= b -5.2e-292)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(if (<= b 5.4e+35)
(/ (* c -2.0) (+ b (hypot b (sqrt (* c (* a -4.0))))))
(/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+154) {
tmp = -b / a;
} else if (b <= -5.2e-292) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else if (b <= 5.4e+35) {
tmp = (c * -2.0) / (b + hypot(b, sqrt((c * (a * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1e+154) {
tmp = -b / a;
} else if (b <= -5.2e-292) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else if (b <= 5.4e+35) {
tmp = (c * -2.0) / (b + Math.hypot(b, Math.sqrt((c * (a * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e+154: tmp = -b / a elif b <= -5.2e-292: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) elif b <= 5.4e+35: tmp = (c * -2.0) / (b + math.hypot(b, math.sqrt((c * (a * -4.0))))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e+154) tmp = Float64(Float64(-b) / a); elseif (b <= -5.2e-292) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); elseif (b <= 5.4e+35) tmp = Float64(Float64(c * -2.0) / Float64(b + hypot(b, sqrt(Float64(c * Float64(a * -4.0)))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e+154) tmp = -b / a; elseif (b <= -5.2e-292) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); elseif (b <= 5.4e+35) tmp = (c * -2.0) / (b + hypot(b, sqrt((c * (a * -4.0))))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e+154], N[((-b) / a), $MachinePrecision], If[LessEqual[b, -5.2e-292], 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, 5.4e+35], N[(N[(c * -2.0), $MachinePrecision] / N[(b + N[Sqrt[b ^ 2 + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq -5.2 \cdot 10^{-292}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 5.4 \cdot 10^{+35}:\\
\;\;\;\;\frac{c \cdot -2}{b + \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.00000000000000004e154Initial program 42.1%
neg-sub042.1%
associate-+l-42.1%
sub0-neg42.1%
neg-mul-142.1%
associate-*l/42.1%
*-commutative42.1%
associate-/r*42.1%
/-rgt-identity42.1%
metadata-eval42.1%
Simplified42.4%
Taylor expanded in b around -inf 97.7%
associate-*r/97.7%
mul-1-neg97.7%
Simplified97.7%
if -1.00000000000000004e154 < b < -5.20000000000000027e-292Initial program 90.0%
if -5.20000000000000027e-292 < b < 5.40000000000000005e35Initial program 60.9%
neg-sub060.9%
associate-+l-60.9%
sub0-neg60.9%
neg-mul-160.9%
associate-*l/60.8%
*-commutative60.8%
associate-/r*60.8%
/-rgt-identity60.8%
metadata-eval60.8%
Simplified60.8%
*-commutative60.8%
clear-num60.8%
flip--60.3%
frac-times47.8%
*-un-lft-identity47.8%
add-sqr-sqrt48.0%
div-inv48.0%
metadata-eval48.0%
Applied egg-rr48.0%
fma-def48.0%
+-commutative48.0%
fma-def48.0%
*-commutative48.0%
fma-def48.0%
+-commutative48.0%
fma-def48.0%
*-commutative48.0%
Simplified48.0%
Taylor expanded in b around 0 60.2%
*-commutative60.2%
associate-*l*60.5%
Simplified60.5%
expm1-log1p-u50.0%
expm1-udef22.2%
Applied egg-rr24.8%
expm1-def74.3%
expm1-log1p85.4%
associate-*l/85.4%
associate-/r*85.4%
*-commutative85.4%
associate-/l*85.4%
*-inverses85.4%
metadata-eval85.4%
metadata-eval85.4%
associate-*r*87.1%
*-commutative87.1%
associate-*l*85.4%
Simplified85.4%
if 5.40000000000000005e35 < b Initial program 11.5%
neg-sub011.5%
associate-+l-11.5%
sub0-neg11.5%
neg-mul-111.5%
associate-*l/11.5%
*-commutative11.5%
associate-/r*11.5%
/-rgt-identity11.5%
metadata-eval11.5%
Simplified11.5%
Taylor expanded in b around inf 95.1%
mul-1-neg95.1%
distribute-neg-frac95.1%
Simplified95.1%
Final simplification91.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1e+154)
(/ (- b) a)
(if (<= b 5.5e-8)
(/ (- (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 <= -1e+154) {
tmp = -b / a;
} else if (b <= 5.5e-8) {
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 <= (-1d+154)) then
tmp = -b / a
else if (b <= 5.5d-8) 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 <= -1e+154) {
tmp = -b / a;
} else if (b <= 5.5e-8) {
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 <= -1e+154: tmp = -b / a elif b <= 5.5e-8: 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 <= -1e+154) tmp = Float64(Float64(-b) / a); elseif (b <= 5.5e-8) 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 <= -1e+154) tmp = -b / a; elseif (b <= 5.5e-8) 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, -1e+154], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 5.5e-8], 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 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{-8}:\\
\;\;\;\;\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.00000000000000004e154Initial program 42.1%
neg-sub042.1%
associate-+l-42.1%
sub0-neg42.1%
neg-mul-142.1%
associate-*l/42.1%
*-commutative42.1%
associate-/r*42.1%
/-rgt-identity42.1%
metadata-eval42.1%
Simplified42.4%
Taylor expanded in b around -inf 97.7%
associate-*r/97.7%
mul-1-neg97.7%
Simplified97.7%
if -1.00000000000000004e154 < b < 5.5000000000000003e-8Initial program 81.4%
if 5.5000000000000003e-8 < b Initial program 15.2%
neg-sub015.2%
associate-+l-15.2%
sub0-neg15.2%
neg-mul-115.2%
associate-*l/15.1%
*-commutative15.1%
associate-/r*15.1%
/-rgt-identity15.1%
metadata-eval15.1%
Simplified15.1%
Taylor expanded in b around inf 91.4%
mul-1-neg91.4%
distribute-neg-frac91.4%
Simplified91.4%
Final simplification87.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.65e-93)
(- (/ c b) (/ b a))
(if (<= b 1.4e-14)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.65e-93) {
tmp = (c / b) - (b / a);
} else if (b <= 1.4e-14) {
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.65d-93)) then
tmp = (c / b) - (b / a)
else if (b <= 1.4d-14) 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.65e-93) {
tmp = (c / b) - (b / a);
} else if (b <= 1.4e-14) {
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.65e-93: tmp = (c / b) - (b / a) elif b <= 1.4e-14: 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.65e-93) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.4e-14) 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 <= -1.65e-93) tmp = (c / b) - (b / a); elseif (b <= 1.4e-14) 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.65e-93], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.4e-14], 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.65 \cdot 10^{-93}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.4 \cdot 10^{-14}:\\
\;\;\;\;\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.6500000000000001e-93Initial program 73.4%
neg-sub073.4%
associate-+l-73.4%
sub0-neg73.4%
neg-mul-173.4%
associate-*l/73.4%
*-commutative73.4%
associate-/r*73.4%
/-rgt-identity73.4%
metadata-eval73.4%
Simplified73.5%
Taylor expanded in b around -inf 87.0%
mul-1-neg87.0%
unsub-neg87.0%
Simplified87.0%
if -1.6500000000000001e-93 < b < 1.4e-14Initial program 72.1%
Taylor expanded in b around 0 65.1%
*-commutative65.1%
*-commutative65.1%
associate-*r*65.1%
Simplified65.1%
expm1-log1p-u62.0%
expm1-udef41.6%
neg-mul-141.6%
fma-def41.6%
Applied egg-rr41.6%
expm1-def62.0%
expm1-log1p65.1%
rem-log-exp5.7%
fma-udef5.7%
neg-mul-15.7%
prod-exp5.7%
*-commutative5.7%
prod-exp5.7%
rem-log-exp65.1%
unsub-neg65.1%
*-commutative65.1%
Simplified65.1%
if 1.4e-14 < b Initial program 16.0%
neg-sub016.0%
associate-+l-16.0%
sub0-neg16.0%
neg-mul-116.0%
associate-*l/16.0%
*-commutative16.0%
associate-/r*16.0%
/-rgt-identity16.0%
metadata-eval16.0%
Simplified16.0%
Taylor expanded in b around inf 90.5%
mul-1-neg90.5%
distribute-neg-frac90.5%
Simplified90.5%
Final simplification81.9%
(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 75.6%
neg-sub075.6%
associate-+l-75.6%
sub0-neg75.6%
neg-mul-175.6%
associate-*l/75.5%
*-commutative75.5%
associate-/r*75.5%
/-rgt-identity75.5%
metadata-eval75.5%
Simplified75.6%
Taylor expanded in b around -inf 70.0%
mul-1-neg70.0%
unsub-neg70.0%
Simplified70.0%
if -4.999999999999985e-310 < b Initial program 31.7%
neg-sub031.7%
associate-+l-31.7%
sub0-neg31.7%
neg-mul-131.7%
associate-*l/31.7%
*-commutative31.7%
associate-/r*31.7%
/-rgt-identity31.7%
metadata-eval31.7%
Simplified31.7%
Taylor expanded in b around inf 68.9%
mul-1-neg68.9%
distribute-neg-frac68.9%
Simplified68.9%
Final simplification69.4%
(FPCore (a b c) :precision binary64 (if (<= b 2.55e-10) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.55e-10) {
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.55d-10) 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.55e-10) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.55e-10: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.55e-10) 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.55e-10) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.55e-10], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.55 \cdot 10^{-10}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.54999999999999998e-10Initial program 72.8%
neg-sub072.8%
associate-+l-72.8%
sub0-neg72.8%
neg-mul-172.8%
associate-*l/72.8%
*-commutative72.8%
associate-/r*72.8%
/-rgt-identity72.8%
metadata-eval72.8%
Simplified72.8%
Taylor expanded in b around -inf 52.9%
associate-*r/52.9%
mul-1-neg52.9%
Simplified52.9%
if 2.54999999999999998e-10 < b Initial program 16.0%
neg-sub016.0%
associate-+l-16.0%
sub0-neg16.0%
neg-mul-116.0%
associate-*l/16.0%
*-commutative16.0%
associate-/r*16.0%
/-rgt-identity16.0%
metadata-eval16.0%
Simplified16.0%
Taylor expanded in b around -inf 2.1%
mul-1-neg2.1%
unsub-neg2.1%
Simplified2.1%
Taylor expanded in c around inf 24.9%
Final simplification43.3%
(FPCore (a b c) :precision binary64 (if (<= b 3e-309) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 3e-309) {
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 <= 3d-309) 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 <= 3e-309) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 3e-309: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 3e-309) 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 <= 3e-309) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 3e-309], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3 \cdot 10^{-309}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 3.000000000000001e-309Initial program 75.6%
neg-sub075.6%
associate-+l-75.6%
sub0-neg75.6%
neg-mul-175.6%
associate-*l/75.5%
*-commutative75.5%
associate-/r*75.5%
/-rgt-identity75.5%
metadata-eval75.5%
Simplified75.6%
Taylor expanded in b around -inf 69.5%
associate-*r/69.5%
mul-1-neg69.5%
Simplified69.5%
if 3.000000000000001e-309 < b Initial program 31.7%
neg-sub031.7%
associate-+l-31.7%
sub0-neg31.7%
neg-mul-131.7%
associate-*l/31.7%
*-commutative31.7%
associate-/r*31.7%
/-rgt-identity31.7%
metadata-eval31.7%
Simplified31.7%
Taylor expanded in b around inf 68.9%
mul-1-neg68.9%
distribute-neg-frac68.9%
Simplified68.9%
Final simplification69.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 53.3%
neg-sub053.3%
associate-+l-53.3%
sub0-neg53.3%
neg-mul-153.3%
associate-*l/53.3%
*-commutative53.3%
associate-/r*53.3%
/-rgt-identity53.3%
metadata-eval53.3%
Simplified53.3%
Taylor expanded in b around -inf 35.5%
mul-1-neg35.5%
unsub-neg35.5%
Simplified35.5%
Taylor expanded in c around inf 10.5%
Final simplification10.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 2023217
(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)))