
(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 -4.5e+85)
(- (/ c b) (/ b a))
(if (<= b 1.15e-87)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.5e+85) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-87) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - 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 <= (-4.5d+85)) then
tmp = (c / b) - (b / a)
else if (b <= 1.15d-87) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - 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 <= -4.5e+85) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-87) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.5e+85: tmp = (c / b) - (b / a) elif b <= 1.15e-87: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.5e+85) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.15e-87) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.5e+85) tmp = (c / b) - (b / a); elseif (b <= 1.15e-87) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.5e+85], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.15e-87], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $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 -4.5 \cdot 10^{+85}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-87}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.50000000000000007e85Initial program 50.3%
*-commutative50.3%
Simplified50.3%
Taylor expanded in b around -inf 91.7%
mul-1-neg91.7%
*-commutative91.7%
distribute-rgt-neg-in91.7%
+-commutative91.7%
mul-1-neg91.7%
unsub-neg91.7%
Simplified91.7%
expm1-log1p-u91.7%
expm1-undefine91.7%
div-inv91.7%
pow-flip91.7%
metadata-eval91.7%
Applied egg-rr91.7%
expm1-define91.7%
Simplified91.7%
Taylor expanded in a around inf 91.8%
+-commutative91.8%
mul-1-neg91.8%
unsub-neg91.8%
Simplified91.8%
if -4.50000000000000007e85 < b < 1.1500000000000001e-87Initial program 81.5%
if 1.1500000000000001e-87 < b Initial program 15.3%
*-commutative15.3%
Simplified15.3%
Taylor expanded in b around inf 83.9%
associate-*r/83.9%
neg-mul-183.9%
Simplified83.9%
Final simplification84.3%
(FPCore (a b c)
:precision binary64
(if (<= b -5.2e+85)
(- (/ c b) (/ b a))
(if (<= b 3.8e-86)
(/ -0.5 (/ a (- b (sqrt (+ (* b b) (* (* c a) -4.0))))))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e+85) {
tmp = (c / b) - (b / a);
} else if (b <= 3.8e-86) {
tmp = -0.5 / (a / (b - sqrt(((b * b) + ((c * a) * -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 <= (-5.2d+85)) then
tmp = (c / b) - (b / a)
else if (b <= 3.8d-86) then
tmp = (-0.5d0) / (a / (b - sqrt(((b * b) + ((c * a) * (-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 <= -5.2e+85) {
tmp = (c / b) - (b / a);
} else if (b <= 3.8e-86) {
tmp = -0.5 / (a / (b - Math.sqrt(((b * b) + ((c * a) * -4.0)))));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e+85: tmp = (c / b) - (b / a) elif b <= 3.8e-86: tmp = -0.5 / (a / (b - math.sqrt(((b * b) + ((c * a) * -4.0))))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e+85) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.8e-86) tmp = Float64(-0.5 / Float64(a / Float64(b - sqrt(Float64(Float64(b * b) + Float64(Float64(c * a) * -4.0)))))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.2e+85) tmp = (c / b) - (b / a); elseif (b <= 3.8e-86) tmp = -0.5 / (a / (b - sqrt(((b * b) + ((c * a) * -4.0))))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e+85], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.8e-86], N[(-0.5 / N[(a / N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.2 \cdot 10^{+85}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-86}:\\
\;\;\;\;\frac{-0.5}{\frac{a}{b - \sqrt{b \cdot b + \left(c \cdot a\right) \cdot -4}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.20000000000000021e85Initial program 50.3%
*-commutative50.3%
Simplified50.3%
Taylor expanded in b around -inf 91.7%
mul-1-neg91.7%
*-commutative91.7%
distribute-rgt-neg-in91.7%
+-commutative91.7%
mul-1-neg91.7%
unsub-neg91.7%
Simplified91.7%
expm1-log1p-u91.7%
expm1-undefine91.7%
div-inv91.7%
pow-flip91.7%
metadata-eval91.7%
Applied egg-rr91.7%
expm1-define91.7%
Simplified91.7%
Taylor expanded in a around inf 91.8%
+-commutative91.8%
mul-1-neg91.8%
unsub-neg91.8%
Simplified91.8%
if -5.20000000000000021e85 < b < 3.8e-86Initial program 81.5%
*-commutative81.5%
Simplified81.5%
add-sqr-sqrt44.8%
pow244.8%
Applied egg-rr44.8%
unpow244.8%
add-sqr-sqrt81.5%
clear-num81.3%
*-commutative81.3%
*-un-lft-identity81.3%
times-frac81.3%
metadata-eval81.3%
Applied egg-rr81.3%
associate-/r*81.3%
metadata-eval81.3%
Simplified81.3%
fma-undefine81.3%
Applied egg-rr81.3%
unpow281.3%
Applied egg-rr81.3%
if 3.8e-86 < b Initial program 15.3%
*-commutative15.3%
Simplified15.3%
Taylor expanded in b around inf 83.9%
associate-*r/83.9%
neg-mul-183.9%
Simplified83.9%
Final simplification84.2%
(FPCore (a b c)
:precision binary64
(if (<= b -5.2e-91)
(- (/ c b) (/ b a))
(if (<= b 1.05e-85)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.2e-91) {
tmp = (c / b) - (b / a);
} else if (b <= 1.05e-85) {
tmp = (sqrt((c * (a * -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 <= (-5.2d-91)) then
tmp = (c / b) - (b / a)
else if (b <= 1.05d-85) then
tmp = (sqrt((c * (a * (-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 <= -5.2e-91) {
tmp = (c / b) - (b / a);
} else if (b <= 1.05e-85) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.2e-91: tmp = (c / b) - (b / a) elif b <= 1.05e-85: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.2e-91) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.05e-85) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.2e-91) tmp = (c / b) - (b / a); elseif (b <= 1.05e-85) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.2e-91], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.05e-85], N[(N[(N[Sqrt[N[(c * N[(a * -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 -5.2 \cdot 10^{-91}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{-85}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.20000000000000028e-91Initial program 69.3%
*-commutative69.3%
Simplified69.3%
Taylor expanded in b around -inf 84.9%
mul-1-neg84.9%
*-commutative84.9%
distribute-rgt-neg-in84.9%
+-commutative84.9%
mul-1-neg84.9%
unsub-neg84.9%
Simplified84.9%
expm1-log1p-u82.1%
expm1-undefine81.9%
div-inv81.9%
pow-flip81.9%
metadata-eval81.9%
Applied egg-rr81.9%
expm1-define82.1%
Simplified82.1%
Taylor expanded in a around inf 85.1%
+-commutative85.1%
mul-1-neg85.1%
unsub-neg85.1%
Simplified85.1%
if -5.20000000000000028e-91 < b < 1.05e-85Initial program 75.0%
*-commutative75.0%
Simplified75.0%
Taylor expanded in b around 0 71.2%
associate-*r*71.2%
*-commutative71.2%
*-commutative71.2%
Simplified71.2%
if 1.05e-85 < b Initial program 15.3%
*-commutative15.3%
Simplified15.3%
Taylor expanded in b around inf 83.9%
associate-*r/83.9%
neg-mul-183.9%
Simplified83.9%
Final simplification80.8%
(FPCore (a b c)
:precision binary64
(if (<= b -5e-86)
(- (/ c b) (/ b a))
(if (<= b 1.85e-86)
(/ -0.5 (/ a (- b (sqrt (* (* c a) -4.0)))))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-86) {
tmp = (c / b) - (b / a);
} else if (b <= 1.85e-86) {
tmp = -0.5 / (a / (b - sqrt(((c * a) * -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 <= (-5d-86)) then
tmp = (c / b) - (b / a)
else if (b <= 1.85d-86) then
tmp = (-0.5d0) / (a / (b - sqrt(((c * a) * (-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 <= -5e-86) {
tmp = (c / b) - (b / a);
} else if (b <= 1.85e-86) {
tmp = -0.5 / (a / (b - Math.sqrt(((c * a) * -4.0))));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-86: tmp = (c / b) - (b / a) elif b <= 1.85e-86: tmp = -0.5 / (a / (b - math.sqrt(((c * a) * -4.0)))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-86) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.85e-86) tmp = Float64(-0.5 / Float64(a / Float64(b - sqrt(Float64(Float64(c * a) * -4.0))))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-86) tmp = (c / b) - (b / a); elseif (b <= 1.85e-86) tmp = -0.5 / (a / (b - sqrt(((c * a) * -4.0)))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-86], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.85e-86], N[(-0.5 / N[(a / N[(b - N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-86}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.85 \cdot 10^{-86}:\\
\;\;\;\;\frac{-0.5}{\frac{a}{b - \sqrt{\left(c \cdot a\right) \cdot -4}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -4.9999999999999999e-86Initial program 69.3%
*-commutative69.3%
Simplified69.3%
Taylor expanded in b around -inf 84.9%
mul-1-neg84.9%
*-commutative84.9%
distribute-rgt-neg-in84.9%
+-commutative84.9%
mul-1-neg84.9%
unsub-neg84.9%
Simplified84.9%
expm1-log1p-u82.1%
expm1-undefine81.9%
div-inv81.9%
pow-flip81.9%
metadata-eval81.9%
Applied egg-rr81.9%
expm1-define82.1%
Simplified82.1%
Taylor expanded in a around inf 85.1%
+-commutative85.1%
mul-1-neg85.1%
unsub-neg85.1%
Simplified85.1%
if -4.9999999999999999e-86 < b < 1.8499999999999999e-86Initial program 75.0%
*-commutative75.0%
Simplified75.0%
add-sqr-sqrt37.3%
pow237.3%
Applied egg-rr37.3%
unpow237.3%
add-sqr-sqrt75.0%
clear-num74.9%
*-commutative74.9%
*-un-lft-identity74.9%
times-frac74.9%
metadata-eval74.9%
Applied egg-rr74.9%
associate-/r*74.9%
metadata-eval74.9%
Simplified74.9%
Taylor expanded in a around inf 71.1%
if 1.8499999999999999e-86 < b Initial program 15.3%
*-commutative15.3%
Simplified15.3%
Taylor expanded in b around inf 83.9%
associate-*r/83.9%
neg-mul-183.9%
Simplified83.9%
Final simplification80.8%
(FPCore (a b c) :precision binary64 (if (<= b -2e-312) (- (/ c b) (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-312) {
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 <= (-2d-312)) 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 <= -2e-312) {
tmp = (c / b) - (b / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-312: tmp = (c / b) - (b / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-312) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-312) tmp = (c / b) - (b / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-312], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-312}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.0000000000019e-312Initial program 72.7%
*-commutative72.7%
Simplified72.7%
Taylor expanded in b around -inf 62.3%
mul-1-neg62.3%
*-commutative62.3%
distribute-rgt-neg-in62.3%
+-commutative62.3%
mul-1-neg62.3%
unsub-neg62.3%
Simplified62.3%
expm1-log1p-u59.2%
expm1-undefine59.1%
div-inv59.1%
pow-flip59.1%
metadata-eval59.1%
Applied egg-rr59.1%
expm1-define59.2%
Simplified59.2%
Taylor expanded in a around inf 63.4%
+-commutative63.4%
mul-1-neg63.4%
unsub-neg63.4%
Simplified63.4%
if -2.0000000000019e-312 < b Initial program 28.8%
*-commutative28.8%
Simplified28.8%
Taylor expanded in b around inf 68.2%
associate-*r/68.2%
neg-mul-168.2%
Simplified68.2%
Final simplification66.0%
(FPCore (a b c) :precision binary64 (if (<= b -2e-312) (/ (- b) a) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-312) {
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 <= (-2d-312)) 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 <= -2e-312) {
tmp = -b / a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-312: tmp = -b / a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-312) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e-312) tmp = -b / a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-312], N[((-b) / a), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{-312}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.0000000000019e-312Initial program 72.7%
*-commutative72.7%
Simplified72.7%
Taylor expanded in b around -inf 62.9%
associate-*r/62.9%
mul-1-neg62.9%
Simplified62.9%
if -2.0000000000019e-312 < b Initial program 28.8%
*-commutative28.8%
Simplified28.8%
Taylor expanded in b around inf 68.2%
associate-*r/68.2%
neg-mul-168.2%
Simplified68.2%
Final simplification65.8%
(FPCore (a b c) :precision binary64 (if (<= b 5.1e+14) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 5.1e+14) {
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 <= 5.1d+14) 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 <= 5.1e+14) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 5.1e+14: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 5.1e+14) 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 <= 5.1e+14) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 5.1e+14], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.1 \cdot 10^{+14}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 5.1e14Initial program 66.7%
*-commutative66.7%
Simplified66.7%
Taylor expanded in b around -inf 43.3%
associate-*r/43.3%
mul-1-neg43.3%
Simplified43.3%
if 5.1e14 < b Initial program 11.3%
*-commutative11.3%
Simplified11.3%
Taylor expanded in b around -inf 2.5%
mul-1-neg2.5%
*-commutative2.5%
distribute-rgt-neg-in2.5%
+-commutative2.5%
mul-1-neg2.5%
unsub-neg2.5%
Simplified2.5%
Taylor expanded in a around inf 18.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 48.7%
*-commutative48.7%
Simplified48.7%
Taylor expanded in b around -inf 29.5%
mul-1-neg29.5%
*-commutative29.5%
distribute-rgt-neg-in29.5%
+-commutative29.5%
mul-1-neg29.5%
unsub-neg29.5%
Simplified29.5%
Taylor expanded in a around inf 8.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 48.7%
*-commutative48.7%
Simplified48.7%
clear-num48.6%
inv-pow48.6%
add-sqr-sqrt32.8%
sqrt-unprod46.8%
sqr-neg46.8%
sqrt-prod14.0%
add-sqr-sqrt31.1%
sub-neg31.1%
+-commutative31.1%
*-commutative31.1%
distribute-rgt-neg-in31.1%
fma-define31.1%
metadata-eval31.1%
pow231.1%
Applied egg-rr31.1%
unpow-131.1%
*-commutative31.1%
Simplified31.1%
Taylor expanded in a around 0 2.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ (- t_2 (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) t_2)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = (t_2 - (b / 2.0)) / a else: tmp_1 = -c / ((b / 2.0) + t_2) return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(Float64(t_2 - Float64(b / 2.0)) / a); else tmp_1 = Float64(Float64(-c) / Float64(Float64(b / 2.0) + t_2)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = (t_2 - (b / 2.0)) / a; else tmp_2 = -c / ((b / 2.0) + t_2); end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t\_0 - t\_1} \cdot \sqrt{t\_0 + t\_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t\_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{t\_2 - \frac{b}{2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{\frac{b}{2} + t\_2}\\
\end{array}
\end{array}
herbie shell --seed 2024184
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ (- sqtD (/ b 2)) a) (/ (- c) (+ (/ b 2) sqtD)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))