
(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 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(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 -1e+154)
(/ (- b) a)
(if (<= b 5.3e-8)
(* (/ (- b (sqrt (fma a (* c -4.0) (* b b)))) a) -0.5)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e+154) {
tmp = -b / a;
} else if (b <= 5.3e-8) {
tmp = ((b - sqrt(fma(a, (c * -4.0), (b * b)))) / a) * -0.5;
} 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.3e-8) tmp = Float64(Float64(Float64(b - sqrt(fma(a, Float64(c * -4.0), Float64(b * b)))) / a) * -0.5); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1e+154], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 5.3e-8], N[(N[(N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] * -0.5), $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.3 \cdot 10^{-8}:\\
\;\;\;\;\frac{b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}}{a} \cdot -0.5\\
\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%
*-commutative42.1%
associate-*r/42.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.2999999999999998e-8Initial program 81.4%
associate-/r*81.4%
/-rgt-identity81.4%
metadata-eval81.4%
metadata-eval81.4%
metadata-eval81.4%
associate-/l/81.4%
associate-/l*81.4%
associate-*r/81.3%
times-frac81.4%
*-commutative81.4%
times-frac81.4%
Simplified81.4%
if 5.2999999999999998e-8 < b Initial program 15.2%
neg-sub015.2%
associate-+l-15.2%
sub0-neg15.2%
neg-mul-115.2%
*-commutative15.2%
associate-*r/15.1%
Simplified15.1%
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 -1e+154)
(/ (- b) a)
(if (<= b 6.2e-8)
(/ (- (sqrt (- (* b b) (* 4.0 (* a 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 <= 6.2e-8) {
tmp = (sqrt(((b * b) - (4.0 * (a * 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 <= 6.2d-8) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * 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 <= 6.2e-8) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * 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 <= 6.2e-8: tmp = (math.sqrt(((b * b) - (4.0 * (a * 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 <= 6.2e-8) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * 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 <= 6.2e-8) tmp = (sqrt(((b * b) - (4.0 * (a * 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, 6.2e-8], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $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 -1 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{-8}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - 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%
*-commutative42.1%
associate-*r/42.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 < 6.2e-8Initial program 81.4%
if 6.2e-8 < b Initial program 15.2%
neg-sub015.2%
associate-+l-15.2%
sub0-neg15.2%
neg-mul-115.2%
*-commutative15.2%
associate-*r/15.1%
Simplified15.1%
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 -4.1e-131)
(- (/ c b) (/ b a))
(if (<= b 3.4e-12)
(* (+ b (sqrt (* c (* a -4.0)))) (/ 0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.1e-131) {
tmp = (c / b) - (b / a);
} else if (b <= 3.4e-12) {
tmp = (b + sqrt((c * (a * -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-131)) then
tmp = (c / b) - (b / a)
else if (b <= 3.4d-12) then
tmp = (b + sqrt((c * (a * (-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-131) {
tmp = (c / b) - (b / a);
} else if (b <= 3.4e-12) {
tmp = (b + Math.sqrt((c * (a * -4.0)))) * (0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.1e-131: tmp = (c / b) - (b / a) elif b <= 3.4e-12: tmp = (b + math.sqrt((c * (a * -4.0)))) * (0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.1e-131) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.4e-12) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -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-131) tmp = (c / b) - (b / a); elseif (b <= 3.4e-12) tmp = (b + sqrt((c * (a * -4.0)))) * (0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.1e-131], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.4e-12], N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $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^{-131}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{-12}:\\
\;\;\;\;\left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.1000000000000002e-131Initial program 75.0%
neg-sub075.0%
associate-+l-75.0%
sub0-neg75.0%
neg-mul-175.0%
*-commutative75.0%
associate-*r/74.9%
Simplified75.1%
Taylor expanded in b around -inf 85.0%
mul-1-neg85.0%
unsub-neg85.0%
Simplified85.0%
if -4.1000000000000002e-131 < b < 3.4000000000000001e-12Initial program 69.6%
Taylor expanded in b around 0 65.6%
associate-*r*65.7%
*-commutative65.7%
*-commutative65.7%
Simplified65.7%
expm1-log1p-u52.1%
expm1-udef21.3%
*-un-lft-identity21.3%
times-frac21.3%
metadata-eval21.3%
add-sqr-sqrt10.7%
sqrt-unprod21.8%
sqr-neg21.8%
sqrt-unprod11.0%
add-sqr-sqrt21.2%
Applied egg-rr21.2%
expm1-def51.9%
expm1-log1p65.5%
*-commutative65.5%
metadata-eval65.5%
times-frac65.5%
associate-*r/65.3%
*-lft-identity65.3%
*-lft-identity65.3%
associate-*r*65.3%
*-commutative65.3%
associate-*l*65.3%
*-commutative65.3%
associate-/r*65.3%
metadata-eval65.3%
Simplified65.3%
if 3.4000000000000001e-12 < b Initial program 16.0%
neg-sub016.0%
associate-+l-16.0%
sub0-neg16.0%
neg-mul-116.0%
*-commutative16.0%
associate-*r/16.0%
Simplified16.0%
Taylor expanded in b around inf 90.5%
associate-*r/90.5%
neg-mul-190.5%
Simplified90.5%
Final simplification81.7%
(FPCore (a b c)
:precision binary64
(if (<= b -3e-131)
(- (/ c b) (/ b a))
(if (<= b 1.75e-13)
(/ (+ b (sqrt (* c (* a -4.0)))) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-131) {
tmp = (c / b) - (b / a);
} else if (b <= 1.75e-13) {
tmp = (b + sqrt((c * (a * -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 <= (-3d-131)) then
tmp = (c / b) - (b / a)
else if (b <= 1.75d-13) then
tmp = (b + sqrt((c * (a * (-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 <= -3e-131) {
tmp = (c / b) - (b / a);
} else if (b <= 1.75e-13) {
tmp = (b + Math.sqrt((c * (a * -4.0)))) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-131: tmp = (c / b) - (b / a) elif b <= 1.75e-13: tmp = (b + math.sqrt((c * (a * -4.0)))) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-131) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.75e-13) tmp = Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) / 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 <= -3e-131) tmp = (c / b) - (b / a); elseif (b <= 1.75e-13) tmp = (b + sqrt((c * (a * -4.0)))) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-131], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.75e-13], N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-131}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.75 \cdot 10^{-13}:\\
\;\;\;\;\frac{b + \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.99999999999999996e-131Initial program 75.0%
neg-sub075.0%
associate-+l-75.0%
sub0-neg75.0%
neg-mul-175.0%
*-commutative75.0%
associate-*r/74.9%
Simplified75.1%
Taylor expanded in b around -inf 85.0%
mul-1-neg85.0%
unsub-neg85.0%
Simplified85.0%
if -2.99999999999999996e-131 < b < 1.7500000000000001e-13Initial program 69.6%
Taylor expanded in b around 0 65.6%
associate-*r*65.7%
*-commutative65.7%
*-commutative65.7%
Simplified65.7%
expm1-log1p-u62.4%
expm1-udef42.4%
add-sqr-sqrt14.8%
sqrt-unprod42.4%
sqr-neg42.4%
sqrt-unprod27.6%
add-sqr-sqrt42.4%
Applied egg-rr42.4%
expm1-def62.2%
expm1-log1p65.5%
associate-*r*65.4%
*-commutative65.4%
associate-*l*65.5%
Simplified65.5%
if 1.7500000000000001e-13 < b Initial program 16.0%
neg-sub016.0%
associate-+l-16.0%
sub0-neg16.0%
neg-mul-116.0%
*-commutative16.0%
associate-*r/16.0%
Simplified16.0%
Taylor expanded in b around inf 90.5%
associate-*r/90.5%
neg-mul-190.5%
Simplified90.5%
Final simplification81.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.65e-93)
(- (/ c b) (/ b a))
(if (<= b 6.5e-11)
(/ (- (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 <= 6.5e-11) {
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 <= 6.5d-11) 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 <= 6.5e-11) {
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 <= 6.5e-11: 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 <= 6.5e-11) 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 <= 6.5e-11) 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, 6.5e-11], 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 6.5 \cdot 10^{-11}:\\
\;\;\;\;\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%
*-commutative73.4%
associate-*r/73.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 < 6.49999999999999953e-11Initial program 72.1%
Taylor expanded in b around 0 65.1%
associate-*r*65.1%
*-commutative65.1%
*-commutative65.1%
Simplified65.1%
if 6.49999999999999953e-11 < b Initial program 16.0%
neg-sub016.0%
associate-+l-16.0%
sub0-neg16.0%
neg-mul-116.0%
*-commutative16.0%
associate-*r/16.0%
Simplified16.0%
Taylor expanded in b around inf 90.5%
associate-*r/90.5%
neg-mul-190.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%
*-commutative75.6%
associate-*r/75.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%
*-commutative31.7%
associate-*r/31.7%
Simplified31.7%
Taylor expanded in b around inf 68.9%
associate-*r/68.9%
neg-mul-168.9%
Simplified68.9%
Final simplification69.4%
(FPCore (a b c) :precision binary64 (if (<= b 6.2e-13) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 6.2e-13) {
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.2d-13) 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.2e-13) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 6.2e-13: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 6.2e-13) 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 <= 6.2e-13) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 6.2e-13], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.2 \cdot 10^{-13}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 6.1999999999999998e-13Initial program 72.8%
neg-sub072.8%
associate-+l-72.8%
sub0-neg72.8%
neg-mul-172.8%
*-commutative72.8%
associate-*r/72.7%
Simplified72.8%
Taylor expanded in b around -inf 52.9%
associate-*r/52.9%
mul-1-neg52.9%
Simplified52.9%
if 6.1999999999999998e-13 < b Initial program 16.0%
Taylor expanded in b around inf 70.8%
associate-/l*67.9%
Simplified67.9%
clear-num66.7%
inv-pow66.7%
times-frac66.7%
metadata-eval66.7%
associate-/r/75.6%
*-commutative75.6%
Applied egg-rr75.6%
unpow-175.6%
associate-*r/75.6%
neg-mul-175.6%
associate-*r/69.6%
associate-*l/67.1%
*-commutative67.1%
Simplified67.1%
Taylor expanded in a around 0 89.0%
associate-*r/89.0%
mul-1-neg89.0%
Simplified89.0%
add-sqr-sqrt61.4%
sqrt-unprod49.4%
frac-times47.9%
distribute-frac-neg47.9%
distribute-frac-neg47.9%
sqr-neg47.9%
frac-times49.4%
clear-num49.4%
clear-num49.5%
sqrt-unprod22.8%
add-sqr-sqrt24.9%
expm1-log1p-u24.8%
expm1-udef25.8%
Applied egg-rr25.8%
expm1-def24.8%
expm1-log1p24.9%
Simplified24.9%
Final simplification43.3%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
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 <= (-5d-310)) 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 <= -5e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) 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 <= -5e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\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%
*-commutative75.6%
associate-*r/75.5%
Simplified75.6%
Taylor expanded in b around -inf 69.5%
associate-*r/69.5%
mul-1-neg69.5%
Simplified69.5%
if -4.999999999999985e-310 < b Initial program 31.7%
neg-sub031.7%
associate-+l-31.7%
sub0-neg31.7%
neg-mul-131.7%
*-commutative31.7%
associate-*r/31.7%
Simplified31.7%
Taylor expanded in b around inf 68.9%
associate-*r/68.9%
neg-mul-168.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%
Taylor expanded in b around inf 27.6%
associate-/l*27.1%
Simplified27.1%
clear-num26.7%
inv-pow26.7%
times-frac26.7%
metadata-eval26.7%
associate-/r/29.8%
*-commutative29.8%
Applied egg-rr29.8%
unpow-129.8%
associate-*r/29.8%
neg-mul-129.8%
associate-*r/27.2%
associate-*l/26.8%
*-commutative26.8%
Simplified26.8%
Taylor expanded in a around 0 35.6%
associate-*r/35.6%
mul-1-neg35.6%
Simplified35.6%
add-sqr-sqrt24.0%
sqrt-unprod20.1%
frac-times19.5%
distribute-frac-neg19.5%
distribute-frac-neg19.5%
sqr-neg19.5%
frac-times20.1%
clear-num20.1%
clear-num20.2%
sqrt-unprod8.9%
add-sqr-sqrt10.5%
expm1-log1p-u10.0%
expm1-udef10.3%
Applied egg-rr10.3%
expm1-def10.0%
expm1-log1p10.5%
Simplified10.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(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 2023217
(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)))