
(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 -2e+146)
(/ (- b) a)
(if (<= b 4.6e-60)
(/ (* (- b (sqrt (- (* b b) (* a (* c 4.0))))) -0.5) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e+146) {
tmp = -b / a;
} else if (b <= 4.6e-60) {
tmp = ((b - sqrt(((b * b) - (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 <= (-2d+146)) then
tmp = -b / a
else if (b <= 4.6d-60) then
tmp = ((b - sqrt(((b * b) - (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 <= -2e+146) {
tmp = -b / a;
} else if (b <= 4.6e-60) {
tmp = ((b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e+146: tmp = -b / a elif b <= 4.6e-60: tmp = ((b - math.sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e+146) tmp = Float64(Float64(-b) / a); elseif (b <= 4.6e-60) tmp = Float64(Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * -0.5) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e+146) tmp = -b / a; elseif (b <= 4.6e-60) tmp = ((b - sqrt(((b * b) - (a * (c * 4.0))))) * -0.5) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e+146], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 4.6e-60], N[(N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+146}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 4.6 \cdot 10^{-60}:\\
\;\;\;\;\frac{\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot -0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.99999999999999987e146Initial program 45.4%
neg-sub045.4%
associate-+l-45.4%
sub0-neg45.4%
neg-mul-145.4%
*-commutative45.4%
associate-*r/45.4%
Simplified45.4%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -1.99999999999999987e146 < b < 4.6000000000000003e-60Initial program 79.6%
neg-sub079.6%
associate-+l-79.6%
sub0-neg79.6%
neg-mul-179.6%
*-commutative79.6%
associate-*r/79.4%
Simplified79.4%
fma-udef79.4%
associate-*r*79.4%
metadata-eval79.4%
distribute-rgt-neg-in79.4%
*-commutative79.4%
+-commutative79.4%
sub-neg79.4%
*-commutative79.4%
associate-*l*79.4%
Applied egg-rr79.4%
associate-*r/79.6%
Applied egg-rr79.6%
if 4.6000000000000003e-60 < b Initial program 10.9%
neg-sub010.9%
associate-+l-10.9%
sub0-neg10.9%
neg-mul-110.9%
*-commutative10.9%
associate-*r/10.9%
Simplified10.9%
Taylor expanded in b around inf 91.4%
associate-*r/91.4%
neg-mul-191.4%
Simplified91.4%
Final simplification87.3%
(FPCore (a b c)
:precision binary64
(if (<= b -4.1e+121)
(/ (- b) a)
(if (<= b 1.22e-60)
(* (- b (sqrt (- (* b b) (* a (* c 4.0))))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.1e+121) {
tmp = -b / a;
} else if (b <= 1.22e-60) {
tmp = (b - sqrt(((b * b) - (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 <= (-4.1d+121)) then
tmp = -b / a
else if (b <= 1.22d-60) then
tmp = (b - sqrt(((b * b) - (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 <= -4.1e+121) {
tmp = -b / a;
} else if (b <= 1.22e-60) {
tmp = (b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.1e+121: tmp = -b / a elif b <= 1.22e-60: tmp = (b - math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.1e+121) tmp = Float64(Float64(-b) / a); elseif (b <= 1.22e-60) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.1e+121) tmp = -b / a; elseif (b <= 1.22e-60) tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.1e+121], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.22e-60], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.1 \cdot 10^{+121}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.22 \cdot 10^{-60}:\\
\;\;\;\;\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.1e121Initial program 49.9%
neg-sub049.9%
associate-+l-49.9%
sub0-neg49.9%
neg-mul-149.9%
*-commutative49.9%
associate-*r/49.8%
Simplified49.8%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -4.1e121 < b < 1.22e-60Initial program 79.0%
neg-sub079.0%
associate-+l-79.0%
sub0-neg79.0%
neg-mul-179.0%
*-commutative79.0%
associate-*r/78.8%
Simplified78.8%
fma-udef78.8%
associate-*r*78.8%
metadata-eval78.8%
distribute-rgt-neg-in78.8%
*-commutative78.8%
+-commutative78.8%
sub-neg78.8%
*-commutative78.8%
associate-*l*78.8%
Applied egg-rr78.8%
if 1.22e-60 < b Initial program 10.9%
neg-sub010.9%
associate-+l-10.9%
sub0-neg10.9%
neg-mul-110.9%
*-commutative10.9%
associate-*r/10.9%
Simplified10.9%
Taylor expanded in b around inf 91.4%
associate-*r/91.4%
neg-mul-191.4%
Simplified91.4%
Final simplification87.2%
(FPCore (a b c)
:precision binary64
(if (<= b -2.5e-109)
(- (/ c b) (/ b a))
(if (<= b 6.2e-61)
(* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.5e-109) {
tmp = (c / b) - (b / a);
} else if (b <= 6.2e-61) {
tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.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 <= (-2.5d-109)) then
tmp = (c / b) - (b / a)
else if (b <= 6.2d-61) then
tmp = ((-0.5d0) / a) * (b - sqrt((a * (c * (-4.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 <= -2.5e-109) {
tmp = (c / b) - (b / a);
} else if (b <= 6.2e-61) {
tmp = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.5e-109: tmp = (c / b) - (b / a) elif b <= 6.2e-61: tmp = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.5e-109) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 6.2e-61) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.5e-109) tmp = (c / b) - (b / a); elseif (b <= 6.2e-61) tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.5e-109], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.2e-61], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.5 \cdot 10^{-109}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{-61}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.5000000000000001e-109Initial program 68.2%
neg-sub068.2%
associate-+l-68.2%
sub0-neg68.2%
neg-mul-168.2%
*-commutative68.2%
associate-*r/68.1%
Simplified68.1%
Taylor expanded in b around -inf 80.9%
mul-1-neg80.9%
unsub-neg80.9%
Simplified80.9%
if -2.5000000000000001e-109 < b < 6.1999999999999999e-61Initial program 73.9%
neg-sub073.9%
associate-+l-73.9%
sub0-neg73.9%
neg-mul-173.9%
*-commutative73.9%
associate-*r/73.8%
Simplified73.8%
Taylor expanded in a around inf 72.5%
*-commutative72.5%
*-commutative72.5%
associate-*r*72.5%
Simplified72.5%
if 6.1999999999999999e-61 < b Initial program 10.9%
neg-sub010.9%
associate-+l-10.9%
sub0-neg10.9%
neg-mul-110.9%
*-commutative10.9%
associate-*r/10.9%
Simplified10.9%
Taylor expanded in b around inf 91.4%
associate-*r/91.4%
neg-mul-191.4%
Simplified91.4%
Final simplification82.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 69.4%
neg-sub069.4%
associate-+l-69.4%
sub0-neg69.4%
neg-mul-169.4%
*-commutative69.4%
associate-*r/69.2%
Simplified69.2%
Taylor expanded in b around -inf 66.7%
mul-1-neg66.7%
unsub-neg66.7%
Simplified66.7%
if -4.999999999999985e-310 < b Initial program 30.0%
neg-sub030.0%
associate-+l-30.0%
sub0-neg30.0%
neg-mul-130.0%
*-commutative30.0%
associate-*r/30.0%
Simplified30.0%
Taylor expanded in b around inf 68.4%
associate-*r/68.4%
neg-mul-168.4%
Simplified68.4%
Final simplification67.5%
(FPCore (a b c) :precision binary64 (if (<= b 1.95e-58) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.95e-58) {
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.95d-58) 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.95e-58) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.95e-58: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.95e-58) 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 <= 1.95e-58) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.95e-58], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.95 \cdot 10^{-58}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.94999999999999996e-58Initial program 70.5%
neg-sub070.5%
associate-+l-70.5%
sub0-neg70.5%
neg-mul-170.5%
*-commutative70.5%
associate-*r/70.3%
Simplified70.3%
Taylor expanded in b around -inf 51.8%
associate-*r/51.8%
mul-1-neg51.8%
Simplified51.8%
if 1.94999999999999996e-58 < b Initial program 10.9%
neg-sub010.9%
associate-+l-10.9%
sub0-neg10.9%
neg-mul-110.9%
*-commutative10.9%
associate-*r/10.9%
Simplified10.9%
Taylor expanded in b around -inf 2.3%
mul-1-neg2.3%
unsub-neg2.3%
*-commutative2.3%
associate-/l*2.3%
Simplified2.3%
Taylor expanded in b around 0 35.9%
Final simplification46.3%
(FPCore (a b c) :precision binary64 (if (<= b 6.1e-297) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 6.1e-297) {
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 <= 6.1d-297) 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 <= 6.1e-297) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 6.1e-297: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 6.1e-297) 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 <= 6.1e-297) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 6.1e-297], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.1 \cdot 10^{-297}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 6.1e-297Initial program 69.8%
neg-sub069.8%
associate-+l-69.8%
sub0-neg69.8%
neg-mul-169.8%
*-commutative69.8%
associate-*r/69.6%
Simplified69.6%
Taylor expanded in b around -inf 63.8%
associate-*r/63.8%
mul-1-neg63.8%
Simplified63.8%
if 6.1e-297 < b Initial program 27.9%
neg-sub027.9%
associate-+l-27.9%
sub0-neg27.9%
neg-mul-127.9%
*-commutative27.9%
associate-*r/27.9%
Simplified27.9%
Taylor expanded in b around inf 71.0%
associate-*r/71.0%
neg-mul-171.0%
Simplified71.0%
Final simplification67.2%
(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 50.0%
neg-sub050.0%
associate-+l-50.0%
sub0-neg50.0%
neg-mul-150.0%
*-commutative50.0%
associate-*r/49.9%
Simplified49.9%
associate-*r/50.0%
frac-2neg50.0%
Applied egg-rr50.0%
distribute-rgt-neg-in50.0%
metadata-eval50.0%
*-commutative50.0%
associate-/l*49.9%
fma-def49.9%
+-commutative49.9%
fma-def49.9%
Simplified49.9%
Taylor expanded in a around 0 34.8%
Taylor expanded in a around inf 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 50.0%
neg-sub050.0%
associate-+l-50.0%
sub0-neg50.0%
neg-mul-150.0%
*-commutative50.0%
associate-*r/49.9%
Simplified49.9%
Taylor expanded in b around -inf 34.5%
mul-1-neg34.5%
unsub-neg34.5%
*-commutative34.5%
associate-/l*34.6%
Simplified34.6%
Taylor expanded in b around 0 14.3%
Final simplification14.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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $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 - 4 \cdot \left(a \cdot c\right)}\\
\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 2023228
(FPCore (a b c)
:name "quadp (p42, positive)"
: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)))