
(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 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(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.6e-53)
(/ (- c) b)
(if (<= b 1.12e+78)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ (- b) a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-53) {
tmp = -c / b;
} else if (b <= 1.12e+78) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} 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 <= (-1.6d-53)) then
tmp = -c / b
else if (b <= 1.12d+78) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = -b / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-53) {
tmp = -c / b;
} else if (b <= 1.12e+78) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.6e-53: tmp = -c / b elif b <= 1.12e+78: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.6e-53) tmp = Float64(Float64(-c) / b); elseif (b <= 1.12e+78) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.6e-53) tmp = -c / b; elseif (b <= 1.12e+78) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.6e-53], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.12e+78], 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[((-b) / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.6 \cdot 10^{-53}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.12 \cdot 10^{+78}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.6e-53Initial program 14.8%
*-commutative14.8%
sqr-neg14.8%
*-commutative14.8%
sqr-neg14.8%
*-commutative14.8%
associate-*r*14.8%
*-commutative14.8%
Simplified14.8%
Taylor expanded in b around -inf 85.7%
mul-1-neg85.7%
distribute-neg-frac85.7%
Simplified85.7%
if -1.6e-53 < b < 1.12e78Initial program 75.7%
if 1.12e78 < b Initial program 62.6%
*-commutative62.6%
sqr-neg62.6%
*-commutative62.6%
sqr-neg62.6%
*-commutative62.6%
associate-*r*62.6%
*-commutative62.6%
Simplified62.6%
Taylor expanded in b around inf 96.8%
associate-*r/96.8%
mul-1-neg96.8%
Simplified96.8%
Final simplification84.0%
(FPCore (a b c)
:precision binary64
(if (<= b -2.3e-80)
(/ (- c) b)
(if (<= b 4.1e-47)
(* (+ b (sqrt (* a (* c -4.0)))) (/ -0.5 a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.3e-80) {
tmp = -c / b;
} else if (b <= 4.1e-47) {
tmp = (b + sqrt((a * (c * -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 <= (-2.3d-80)) then
tmp = -c / b
else if (b <= 4.1d-47) then
tmp = (b + sqrt((a * (c * (-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 <= -2.3e-80) {
tmp = -c / b;
} else if (b <= 4.1e-47) {
tmp = (b + Math.sqrt((a * (c * -4.0)))) * (-0.5 / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.3e-80: tmp = -c / b elif b <= 4.1e-47: tmp = (b + math.sqrt((a * (c * -4.0)))) * (-0.5 / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.3e-80) tmp = Float64(Float64(-c) / b); elseif (b <= 4.1e-47) tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) * Float64(-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 <= -2.3e-80) tmp = -c / b; elseif (b <= 4.1e-47) tmp = (b + sqrt((a * (c * -4.0)))) * (-0.5 / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.3e-80], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4.1e-47], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.3 \cdot 10^{-80}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4.1 \cdot 10^{-47}:\\
\;\;\;\;\left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.2999999999999998e-80Initial program 15.4%
*-commutative15.4%
sqr-neg15.4%
*-commutative15.4%
sqr-neg15.4%
*-commutative15.4%
associate-*r*15.4%
*-commutative15.4%
Simplified15.4%
Taylor expanded in b around -inf 84.1%
mul-1-neg84.1%
distribute-neg-frac84.1%
Simplified84.1%
if -2.2999999999999998e-80 < b < 4.10000000000000002e-47Initial program 73.2%
*-commutative73.2%
sqr-neg73.2%
*-commutative73.2%
sqr-neg73.2%
*-commutative73.2%
associate-*r*73.2%
*-commutative73.2%
Simplified73.2%
frac-2neg73.2%
div-inv73.1%
Applied egg-rr73.1%
Taylor expanded in b around 0 69.4%
*-commutative69.4%
associate-*r*69.4%
Simplified69.4%
add-log-exp6.1%
*-commutative6.1%
exp-prod3.9%
inv-pow3.9%
inv-pow3.9%
metadata-eval3.9%
div-inv3.9%
clear-num3.9%
+-commutative3.9%
Applied egg-rr3.9%
log-pow4.2%
+-commutative4.2%
rem-log-exp69.4%
Simplified69.4%
if 4.10000000000000002e-47 < b Initial program 70.5%
*-commutative70.5%
sqr-neg70.5%
*-commutative70.5%
sqr-neg70.5%
*-commutative70.5%
associate-*r*70.5%
*-commutative70.5%
Simplified70.5%
Taylor expanded in b around inf 88.2%
+-commutative88.2%
mul-1-neg88.2%
unsub-neg88.2%
Simplified88.2%
Final simplification80.9%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e-80)
(/ (- c) b)
(if (<= b 1.65e-47)
(/ (+ b (sqrt (* a (* c -4.0)))) (* a -2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e-80) {
tmp = -c / b;
} else if (b <= 1.65e-47) {
tmp = (b + sqrt((a * (c * -4.0)))) / (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 <= (-5.8d-80)) then
tmp = -c / b
else if (b <= 1.65d-47) then
tmp = (b + sqrt((a * (c * (-4.0d0))))) / (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 <= -5.8e-80) {
tmp = -c / b;
} else if (b <= 1.65e-47) {
tmp = (b + Math.sqrt((a * (c * -4.0)))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.8e-80: tmp = -c / b elif b <= 1.65e-47: tmp = (b + math.sqrt((a * (c * -4.0)))) / (a * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.8e-80) tmp = Float64(Float64(-c) / b); elseif (b <= 1.65e-47) tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) / 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 <= -5.8e-80) tmp = -c / b; elseif (b <= 1.65e-47) tmp = (b + sqrt((a * (c * -4.0)))) / (a * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.8e-80], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.65e-47], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $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 -5.8 \cdot 10^{-80}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.65 \cdot 10^{-47}:\\
\;\;\;\;\frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -5.79999999999999996e-80Initial program 15.4%
*-commutative15.4%
sqr-neg15.4%
*-commutative15.4%
sqr-neg15.4%
*-commutative15.4%
associate-*r*15.4%
*-commutative15.4%
Simplified15.4%
Taylor expanded in b around -inf 84.1%
mul-1-neg84.1%
distribute-neg-frac84.1%
Simplified84.1%
if -5.79999999999999996e-80 < b < 1.65000000000000002e-47Initial program 73.2%
*-commutative73.2%
sqr-neg73.2%
*-commutative73.2%
sqr-neg73.2%
*-commutative73.2%
associate-*r*73.2%
*-commutative73.2%
Simplified73.2%
frac-2neg73.2%
div-inv73.1%
Applied egg-rr73.1%
Taylor expanded in b around 0 69.4%
*-commutative69.4%
associate-*r*69.4%
Simplified69.4%
un-div-inv69.5%
+-commutative69.5%
Applied egg-rr69.5%
if 1.65000000000000002e-47 < b Initial program 70.5%
*-commutative70.5%
sqr-neg70.5%
*-commutative70.5%
sqr-neg70.5%
*-commutative70.5%
associate-*r*70.5%
*-commutative70.5%
Simplified70.5%
Taylor expanded in b around inf 88.2%
+-commutative88.2%
mul-1-neg88.2%
unsub-neg88.2%
Simplified88.2%
Final simplification81.0%
(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 31.7%
*-commutative31.7%
sqr-neg31.7%
*-commutative31.7%
sqr-neg31.7%
*-commutative31.7%
associate-*r*31.7%
*-commutative31.7%
Simplified31.7%
Taylor expanded in b around -inf 65.7%
mul-1-neg65.7%
distribute-neg-frac65.7%
Simplified65.7%
if -4.999999999999985e-310 < b Initial program 72.1%
*-commutative72.1%
sqr-neg72.1%
*-commutative72.1%
sqr-neg72.1%
*-commutative72.1%
associate-*r*72.1%
*-commutative72.1%
Simplified72.1%
Taylor expanded in b around inf 66.2%
+-commutative66.2%
mul-1-neg66.2%
unsub-neg66.2%
Simplified66.2%
Final simplification66.0%
(FPCore (a b c) :precision binary64 (if (<= b -3e+74) (/ c b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e+74) {
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 <= (-3d+74)) 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 <= -3e+74) {
tmp = c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e+74: tmp = c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e+74) tmp = 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 <= -3e+74) tmp = c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e+74], N[(c / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{+74}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -3e74Initial program 11.0%
*-commutative11.0%
sqr-neg11.0%
*-commutative11.0%
sqr-neg11.0%
*-commutative11.0%
associate-*r*11.0%
*-commutative11.0%
Simplified11.0%
Taylor expanded in b around -inf 77.4%
associate-*r/77.4%
associate-*r*77.4%
*-commutative77.4%
Simplified77.4%
expm1-log1p-u69.2%
expm1-udef45.7%
associate-/l/45.5%
*-commutative45.5%
times-frac48.6%
add-sqr-sqrt20.9%
sqrt-unprod33.6%
swap-sqr33.6%
metadata-eval33.6%
metadata-eval33.6%
swap-sqr33.6%
sqrt-unprod22.1%
add-sqr-sqrt40.2%
Applied egg-rr40.2%
expm1-def39.7%
expm1-log1p39.9%
associate-*l/40.1%
associate-*r/39.8%
*-commutative39.8%
associate-*r/40.0%
associate-*l/39.9%
*-inverses39.9%
*-lft-identity39.9%
Simplified39.9%
if -3e74 < b Initial program 63.9%
*-commutative63.9%
sqr-neg63.9%
*-commutative63.9%
sqr-neg63.9%
*-commutative63.9%
associate-*r*63.9%
*-commutative63.9%
Simplified63.9%
Taylor expanded in b around inf 42.1%
associate-*r/42.1%
mul-1-neg42.1%
Simplified42.1%
Final simplification41.5%
(FPCore (a b c) :precision binary64 (if (<= b -2e-305) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-305) {
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 <= (-2d-305)) 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 <= -2e-305) {
tmp = -c / b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-305: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-305) 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 <= -2e-305) tmp = -c / b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-305], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-305}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1.99999999999999999e-305Initial program 31.2%
*-commutative31.2%
sqr-neg31.2%
*-commutative31.2%
sqr-neg31.2%
*-commutative31.2%
associate-*r*31.2%
*-commutative31.2%
Simplified31.2%
Taylor expanded in b around -inf 66.2%
mul-1-neg66.2%
distribute-neg-frac66.2%
Simplified66.2%
if -1.99999999999999999e-305 < b Initial program 72.3%
*-commutative72.3%
sqr-neg72.3%
*-commutative72.3%
sqr-neg72.3%
*-commutative72.3%
associate-*r*72.3%
*-commutative72.3%
Simplified72.3%
Taylor expanded in b around inf 65.1%
associate-*r/65.1%
mul-1-neg65.1%
Simplified65.1%
Final simplification65.7%
(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.5%
*-commutative50.5%
sqr-neg50.5%
*-commutative50.5%
sqr-neg50.5%
*-commutative50.5%
associate-*r*50.5%
*-commutative50.5%
Simplified50.5%
Taylor expanded in b around -inf 30.1%
associate-*r/30.1%
associate-*r*30.1%
*-commutative30.1%
Simplified30.1%
expm1-log1p-u26.1%
expm1-udef14.8%
associate-/l/14.3%
*-commutative14.3%
times-frac15.1%
add-sqr-sqrt6.8%
sqrt-unprod10.8%
swap-sqr10.8%
metadata-eval10.8%
metadata-eval10.8%
swap-sqr10.8%
sqrt-unprod6.9%
add-sqr-sqrt12.3%
Applied egg-rr12.3%
expm1-def12.1%
expm1-log1p12.5%
associate-*l/12.4%
associate-*r/12.3%
*-commutative12.3%
associate-*r/12.4%
associate-*l/12.4%
*-inverses12.4%
*-lft-identity12.4%
Simplified12.4%
Final simplification12.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 2023309
(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)))