
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -1.08e-120)
(/ (- c) b)
(if (<= b 2.2e+114)
(* -0.5 (/ (+ b (sqrt (fma a (* c -4.0) (* b b)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.08e-120) {
tmp = -c / b;
} else if (b <= 2.2e+114) {
tmp = -0.5 * ((b + sqrt(fma(a, (c * -4.0), (b * b)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.08e-120) tmp = Float64(Float64(-c) / b); elseif (b <= 2.2e+114) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(fma(a, Float64(c * -4.0), Float64(b * b)))) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.08e-120], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.2e+114], N[(-0.5 * N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.08 \cdot 10^{-120}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{+114}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.0800000000000001e-120Initial program 16.5%
Taylor expanded in b around -inf 83.8%
associate-*r/83.8%
neg-mul-183.8%
Simplified83.8%
if -1.0800000000000001e-120 < b < 2.2e114Initial program 81.2%
sub-neg81.2%
distribute-neg-out81.2%
neg-mul-181.2%
times-frac82.1%
metadata-eval82.1%
sub-neg82.1%
+-commutative82.1%
*-commutative82.1%
distribute-lft-neg-in82.1%
distribute-rgt-neg-out82.1%
associate-*l*81.2%
fma-def81.2%
distribute-lft-neg-in81.2%
distribute-rgt-neg-in81.2%
metadata-eval81.2%
Simplified81.2%
if 2.2e114 < b Initial program 54.4%
Taylor expanded in b around inf 98.0%
+-commutative98.0%
mul-1-neg98.0%
unsub-neg98.0%
Simplified98.0%
Final simplification85.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.1e-119)
(/ (- c) b)
(if (<= b 2e+114)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-119) {
tmp = -c / b;
} else if (b <= 2e+114) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-2.1d-119)) then
tmp = -c / b
else if (b <= 2d+114) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-119) {
tmp = -c / b;
} else if (b <= 2e+114) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.1e-119: tmp = -c / b elif b <= 2e+114: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.1e-119) tmp = Float64(Float64(-c) / b); elseif (b <= 2e+114) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.1e-119) tmp = -c / b; elseif (b <= 2e+114) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.1e-119], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2e+114], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.1 \cdot 10^{-119}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+114}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.1e-119Initial program 16.5%
Taylor expanded in b around -inf 83.8%
associate-*r/83.8%
neg-mul-183.8%
Simplified83.8%
if -2.1e-119 < b < 2e114Initial program 81.2%
if 2e114 < b Initial program 54.4%
Taylor expanded in b around inf 98.0%
+-commutative98.0%
mul-1-neg98.0%
unsub-neg98.0%
Simplified98.0%
Final simplification85.3%
(FPCore (a b c)
:precision binary64
(if (<= b -3.7e-125)
(/ (- c) b)
(if (<= b 1.22e-33)
(* -0.5 (/ (+ b (sqrt (* -4.0 (* c a)))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.7e-125) {
tmp = -c / b;
} else if (b <= 1.22e-33) {
tmp = -0.5 * ((b + sqrt((-4.0 * (c * a)))) / a);
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-3.7d-125)) then
tmp = -c / b
else if (b <= 1.22d-33) then
tmp = (-0.5d0) * ((b + sqrt(((-4.0d0) * (c * a)))) / a)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.7e-125) {
tmp = -c / b;
} else if (b <= 1.22e-33) {
tmp = -0.5 * ((b + Math.sqrt((-4.0 * (c * a)))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.7e-125: tmp = -c / b elif b <= 1.22e-33: tmp = -0.5 * ((b + math.sqrt((-4.0 * (c * a)))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.7e-125) tmp = Float64(Float64(-c) / b); elseif (b <= 1.22e-33) tmp = Float64(-0.5 * Float64(Float64(b + sqrt(Float64(-4.0 * Float64(c * a)))) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.7e-125) tmp = -c / b; elseif (b <= 1.22e-33) tmp = -0.5 * ((b + sqrt((-4.0 * (c * a)))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.7e-125], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.22e-33], N[(-0.5 * N[(N[(b + N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.7 \cdot 10^{-125}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.22 \cdot 10^{-33}:\\
\;\;\;\;-0.5 \cdot \frac{b + \sqrt{-4 \cdot \left(c \cdot a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.6999999999999999e-125Initial program 16.5%
Taylor expanded in b around -inf 83.8%
associate-*r/83.8%
neg-mul-183.8%
Simplified83.8%
if -3.6999999999999999e-125 < b < 1.22e-33Initial program 77.5%
sub-neg77.5%
distribute-neg-out77.5%
neg-mul-177.5%
times-frac77.5%
metadata-eval77.5%
sub-neg77.5%
+-commutative77.5%
*-commutative77.5%
distribute-lft-neg-in77.5%
distribute-rgt-neg-out77.5%
associate-*l*76.1%
fma-def76.1%
distribute-lft-neg-in76.1%
distribute-rgt-neg-in76.1%
metadata-eval76.1%
Simplified76.1%
Taylor expanded in a around inf 72.2%
if 1.22e-33 < b Initial program 69.0%
Taylor expanded in b around inf 91.6%
+-commutative91.6%
mul-1-neg91.6%
unsub-neg91.6%
Simplified91.6%
Final simplification83.1%
(FPCore (a b c)
:precision binary64
(if (<= b -4.8e-120)
(/ (- c) b)
(if (<= b 1.22e-33)
(* -0.5 (/ (pow (* c (* a -4.0)) 0.5) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e-120) {
tmp = -c / b;
} else if (b <= 1.22e-33) {
tmp = -0.5 * (pow((c * (a * -4.0)), 0.5) / a);
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-4.8d-120)) then
tmp = -c / b
else if (b <= 1.22d-33) then
tmp = (-0.5d0) * (((c * (a * (-4.0d0))) ** 0.5d0) / a)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e-120) {
tmp = -c / b;
} else if (b <= 1.22e-33) {
tmp = -0.5 * (Math.pow((c * (a * -4.0)), 0.5) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.8e-120: tmp = -c / b elif b <= 1.22e-33: tmp = -0.5 * (math.pow((c * (a * -4.0)), 0.5) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.8e-120) tmp = Float64(Float64(-c) / b); elseif (b <= 1.22e-33) tmp = Float64(-0.5 * Float64((Float64(c * Float64(a * -4.0)) ^ 0.5) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.8e-120) tmp = -c / b; elseif (b <= 1.22e-33) tmp = -0.5 * (((c * (a * -4.0)) ^ 0.5) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.8e-120], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.22e-33], N[(-0.5 * N[(N[Power[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision], 0.5], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.8 \cdot 10^{-120}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.22 \cdot 10^{-33}:\\
\;\;\;\;-0.5 \cdot \frac{{\left(c \cdot \left(a \cdot -4\right)\right)}^{0.5}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.7999999999999999e-120Initial program 16.5%
Taylor expanded in b around -inf 83.8%
associate-*r/83.8%
neg-mul-183.8%
Simplified83.8%
if -4.7999999999999999e-120 < b < 1.22e-33Initial program 77.5%
sub-neg77.5%
distribute-neg-out77.5%
neg-mul-177.5%
times-frac77.5%
metadata-eval77.5%
sub-neg77.5%
+-commutative77.5%
*-commutative77.5%
distribute-lft-neg-in77.5%
distribute-rgt-neg-out77.5%
associate-*l*76.1%
fma-def76.1%
distribute-lft-neg-in76.1%
distribute-rgt-neg-in76.1%
metadata-eval76.1%
Simplified76.1%
add-sqr-sqrt75.7%
pow275.7%
pow1/275.7%
sqrt-pow175.7%
pow275.7%
metadata-eval75.7%
Applied egg-rr75.7%
Taylor expanded in a around inf 42.4%
unpow242.4%
exp-prod41.5%
exp-prod40.8%
pow-sqr40.8%
*-commutative40.8%
mul-1-neg40.8%
log-rec40.8%
remove-double-neg40.8%
Simplified40.8%
Taylor expanded in b around 0 42.4%
*-commutative42.4%
*-commutative42.4%
log-prod65.7%
exp-to-pow70.3%
*-commutative70.3%
associate-*l*71.6%
Simplified71.6%
if 1.22e-33 < b Initial program 69.0%
Taylor expanded in b around inf 91.6%
+-commutative91.6%
mul-1-neg91.6%
unsub-neg91.6%
Simplified91.6%
Final simplification83.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.2e-122)
(/ (- c) b)
(if (<= b 3.6e-33)
(* -0.5 (/ (sqrt (* a (* c -4.0))) a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-122) {
tmp = -c / b;
} else if (b <= 3.6e-33) {
tmp = -0.5 * (sqrt((a * (c * -4.0))) / a);
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-3.2d-122)) then
tmp = -c / b
else if (b <= 3.6d-33) then
tmp = (-0.5d0) * (sqrt((a * (c * (-4.0d0)))) / a)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.2e-122) {
tmp = -c / b;
} else if (b <= 3.6e-33) {
tmp = -0.5 * (Math.sqrt((a * (c * -4.0))) / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.2e-122: tmp = -c / b elif b <= 3.6e-33: tmp = -0.5 * (math.sqrt((a * (c * -4.0))) / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.2e-122) tmp = Float64(Float64(-c) / b); elseif (b <= 3.6e-33) tmp = Float64(-0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.2e-122) tmp = -c / b; elseif (b <= 3.6e-33) tmp = -0.5 * (sqrt((a * (c * -4.0))) / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.2e-122], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.6e-33], N[(-0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.2 \cdot 10^{-122}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.6 \cdot 10^{-33}:\\
\;\;\;\;-0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.2000000000000002e-122Initial program 16.5%
Taylor expanded in b around -inf 83.8%
associate-*r/83.8%
neg-mul-183.8%
Simplified83.8%
if -3.2000000000000002e-122 < b < 3.60000000000000034e-33Initial program 77.5%
sub-neg77.5%
distribute-neg-out77.5%
neg-mul-177.5%
times-frac77.5%
metadata-eval77.5%
sub-neg77.5%
+-commutative77.5%
*-commutative77.5%
distribute-lft-neg-in77.5%
distribute-rgt-neg-out77.5%
associate-*l*76.1%
fma-def76.1%
distribute-lft-neg-in76.1%
distribute-rgt-neg-in76.1%
metadata-eval76.1%
Simplified76.1%
add-sqr-sqrt75.7%
pow275.7%
pow1/275.7%
sqrt-pow175.7%
pow275.7%
metadata-eval75.7%
Applied egg-rr75.7%
Taylor expanded in a around inf 42.4%
Taylor expanded in b around 0 42.4%
Simplified70.3%
if 3.60000000000000034e-33 < b Initial program 69.0%
Taylor expanded in b around inf 91.6%
+-commutative91.6%
mul-1-neg91.6%
unsub-neg91.6%
Simplified91.6%
Final simplification82.6%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / 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) :: tmp
if (b <= (-5d-310)) then
tmp = -c / b
else
tmp = (c / b) - (b / a)
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;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 27.1%
Taylor expanded in b around -inf 68.4%
associate-*r/68.4%
neg-mul-168.4%
Simplified68.4%
if -4.999999999999985e-310 < b Initial program 74.6%
Taylor expanded in b around inf 66.7%
+-commutative66.7%
mul-1-neg66.7%
unsub-neg66.7%
Simplified66.7%
Final simplification67.6%
(FPCore (a b c) :precision binary64 (if (<= b -4.8e-308) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e-308) {
tmp = -c / b;
} else {
tmp = -b / 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) :: tmp
if (b <= (-4.8d-308)) then
tmp = -c / b
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e-308) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.8e-308: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.8e-308) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.8e-308) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.8e-308], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.8 \cdot 10^{-308}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.80000000000000016e-308Initial program 26.5%
Taylor expanded in b around -inf 68.8%
associate-*r/68.8%
neg-mul-168.8%
Simplified68.8%
if -4.80000000000000016e-308 < b Initial program 74.8%
Taylor expanded in b around inf 65.8%
associate-*r/65.8%
mul-1-neg65.8%
Simplified65.8%
Final simplification67.4%
(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(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 49.3%
Taylor expanded in b around inf 32.4%
associate-*r/32.4%
mul-1-neg32.4%
Simplified32.4%
Final simplification32.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-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 = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = 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 = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2024024
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))