
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -4.4e+121)
(- (/ c b) (/ b a))
(if (<= b 2.5e-10)
(/ (- (sqrt (+ (* b b) (* a (* c -4.0)))) b) (* a 2.0))
(- 0.0 (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.4e+121) {
tmp = (c / b) - (b / a);
} else if (b <= 2.5e-10) {
tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) / (a * 2.0);
} else {
tmp = 0.0 - (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.4d+121)) then
tmp = (c / b) - (b / a)
else if (b <= 2.5d-10) then
tmp = (sqrt(((b * b) + (a * (c * (-4.0d0))))) - b) / (a * 2.0d0)
else
tmp = 0.0d0 - (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.4e+121) {
tmp = (c / b) - (b / a);
} else if (b <= 2.5e-10) {
tmp = (Math.sqrt(((b * b) + (a * (c * -4.0)))) - b) / (a * 2.0);
} else {
tmp = 0.0 - (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.4e+121: tmp = (c / b) - (b / a) elif b <= 2.5e-10: tmp = (math.sqrt(((b * b) + (a * (c * -4.0)))) - b) / (a * 2.0) else: tmp = 0.0 - (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.4e+121) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.5e-10) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(0.0 - Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.4e+121) tmp = (c / b) - (b / a); elseif (b <= 2.5e-10) tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) / (a * 2.0); else tmp = 0.0 - (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.4e+121], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.5e-10], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.4 \cdot 10^{+121}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-10}:\\
\;\;\;\;\frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0 - \frac{c}{b}\\
\end{array}
\end{array}
if b < -4.40000000000000003e121Initial program 48.9%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified48.9%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
*-commutativeN/A
associate-*l/N/A
*-lft-identityN/A
unsub-negN/A
--lowering--.f64N/A
mul-1-negN/A
distribute-rgt-neg-outN/A
remove-double-negN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f6498.4%
Simplified98.4%
*-commutativeN/A
div-invN/A
associate-*l*N/A
pow2N/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
div-invN/A
/-lowering-/.f6498.4%
Applied egg-rr98.4%
if -4.40000000000000003e121 < b < 2.50000000000000016e-10Initial program 81.3%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified81.3%
if 2.50000000000000016e-10 < b Initial program 15.5%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified15.5%
Taylor expanded in b around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6492.9%
Simplified92.9%
sub0-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f6492.9%
Applied egg-rr92.9%
Final simplification88.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.2e+121)
(- (/ c b) (/ b a))
(if (<= b 3.6e-8)
(/ 0.5 (/ a (- (sqrt (+ (* b b) (* a (* c -4.0)))) b)))
(- 0.0 (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e+121) {
tmp = (c / b) - (b / a);
} else if (b <= 3.6e-8) {
tmp = 0.5 / (a / (sqrt(((b * b) + (a * (c * -4.0)))) - b));
} else {
tmp = 0.0 - (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.2d+121)) then
tmp = (c / b) - (b / a)
else if (b <= 3.6d-8) then
tmp = 0.5d0 / (a / (sqrt(((b * b) + (a * (c * (-4.0d0))))) - b))
else
tmp = 0.0d0 - (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.2e+121) {
tmp = (c / b) - (b / a);
} else if (b <= 3.6e-8) {
tmp = 0.5 / (a / (Math.sqrt(((b * b) + (a * (c * -4.0)))) - b));
} else {
tmp = 0.0 - (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.2e+121: tmp = (c / b) - (b / a) elif b <= 3.6e-8: tmp = 0.5 / (a / (math.sqrt(((b * b) + (a * (c * -4.0)))) - b)) else: tmp = 0.0 - (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.2e+121) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 3.6e-8) tmp = Float64(0.5 / Float64(a / Float64(sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))) - b))); else tmp = Float64(0.0 - Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.2e+121) tmp = (c / b) - (b / a); elseif (b <= 3.6e-8) tmp = 0.5 / (a / (sqrt(((b * b) + (a * (c * -4.0)))) - b)); else tmp = 0.0 - (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.2e+121], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.6e-8], N[(0.5 / N[(a / N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.2 \cdot 10^{+121}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 3.6 \cdot 10^{-8}:\\
\;\;\;\;\frac{0.5}{\frac{a}{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}}\\
\mathbf{else}:\\
\;\;\;\;0 - \frac{c}{b}\\
\end{array}
\end{array}
if b < -1.2e121Initial program 48.9%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified48.9%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
*-commutativeN/A
associate-*l/N/A
*-lft-identityN/A
unsub-negN/A
--lowering--.f64N/A
mul-1-negN/A
distribute-rgt-neg-outN/A
remove-double-negN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f6498.4%
Simplified98.4%
*-commutativeN/A
div-invN/A
associate-*l*N/A
pow2N/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
div-invN/A
/-lowering-/.f6498.4%
Applied egg-rr98.4%
if -1.2e121 < b < 3.59999999999999981e-8Initial program 81.3%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified81.3%
clear-numN/A
*-commutativeN/A
associate-/l*N/A
associate-/r*N/A
metadata-evalN/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6481.1%
Applied egg-rr81.1%
if 3.59999999999999981e-8 < b Initial program 15.5%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified15.5%
Taylor expanded in b around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6492.9%
Simplified92.9%
sub0-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f6492.9%
Applied egg-rr92.9%
Final simplification88.6%
(FPCore (a b c)
:precision binary64
(if (<= b -5.8e+119)
(- (/ c b) (/ b a))
(if (<= b 2.5e-10)
(* (- (sqrt (+ (* b b) (* a (* c -4.0)))) b) (/ 0.5 a))
(- 0.0 (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e+119) {
tmp = (c / b) - (b / a);
} else if (b <= 2.5e-10) {
tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a);
} else {
tmp = 0.0 - (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.8d+119)) then
tmp = (c / b) - (b / a)
else if (b <= 2.5d-10) then
tmp = (sqrt(((b * b) + (a * (c * (-4.0d0))))) - b) * (0.5d0 / a)
else
tmp = 0.0d0 - (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.8e+119) {
tmp = (c / b) - (b / a);
} else if (b <= 2.5e-10) {
tmp = (Math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a);
} else {
tmp = 0.0 - (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.8e+119: tmp = (c / b) - (b / a) elif b <= 2.5e-10: tmp = (math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a) else: tmp = 0.0 - (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.8e+119) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.5e-10) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))) - b) * Float64(0.5 / a)); else tmp = Float64(0.0 - Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.8e+119) tmp = (c / b) - (b / a); elseif (b <= 2.5e-10) tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a); else tmp = 0.0 - (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.8e+119], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.5e-10], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.8 \cdot 10^{+119}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-10}:\\
\;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;0 - \frac{c}{b}\\
\end{array}
\end{array}
if b < -5.80000000000000014e119Initial program 48.9%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified48.9%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
*-commutativeN/A
associate-*l/N/A
*-lft-identityN/A
unsub-negN/A
--lowering--.f64N/A
mul-1-negN/A
distribute-rgt-neg-outN/A
remove-double-negN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f6498.4%
Simplified98.4%
*-commutativeN/A
div-invN/A
associate-*l*N/A
pow2N/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
div-invN/A
/-lowering-/.f6498.4%
Applied egg-rr98.4%
if -5.80000000000000014e119 < b < 2.50000000000000016e-10Initial program 81.3%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified81.3%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-/r*N/A
metadata-evalN/A
/-lowering-/.f64N/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6481.0%
Applied egg-rr81.0%
if 2.50000000000000016e-10 < b Initial program 15.5%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified15.5%
Taylor expanded in b around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6492.9%
Simplified92.9%
sub0-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f6492.9%
Applied egg-rr92.9%
Final simplification88.6%
(FPCore (a b c)
:precision binary64
(if (<= b -1.1e-115)
(- (/ c b) (/ b a))
(if (<= b 8.2e-31)
(/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))
(- 0.0 (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e-115) {
tmp = (c / b) - (b / a);
} else if (b <= 8.2e-31) {
tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = 0.0 - (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.1d-115)) then
tmp = (c / b) - (b / a)
else if (b <= 8.2d-31) then
tmp = (sqrt((c * (a * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = 0.0d0 - (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e-115) {
tmp = (c / b) - (b / a);
} else if (b <= 8.2e-31) {
tmp = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
} else {
tmp = 0.0 - (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.1e-115: tmp = (c / b) - (b / a) elif b <= 8.2e-31: tmp = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) else: tmp = 0.0 - (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.1e-115) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 8.2e-31) tmp = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(0.0 - Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.1e-115) tmp = (c / b) - (b / a); elseif (b <= 8.2e-31) tmp = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); else tmp = 0.0 - (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.1e-115], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 8.2e-31], N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1 \cdot 10^{-115}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 8.2 \cdot 10^{-31}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0 - \frac{c}{b}\\
\end{array}
\end{array}
if b < -1.1e-115Initial program 70.8%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified70.8%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
*-commutativeN/A
associate-*l/N/A
*-lft-identityN/A
unsub-negN/A
--lowering--.f64N/A
mul-1-negN/A
distribute-rgt-neg-outN/A
remove-double-negN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f6486.1%
Simplified86.1%
*-commutativeN/A
div-invN/A
associate-*l*N/A
pow2N/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
div-invN/A
/-lowering-/.f6486.1%
Applied egg-rr86.1%
if -1.1e-115 < b < 8.1999999999999993e-31Initial program 70.8%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified70.8%
Taylor expanded in b around 0
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6469.0%
Simplified69.0%
if 8.1999999999999993e-31 < b Initial program 16.5%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified16.5%
Taylor expanded in b around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6491.8%
Simplified91.8%
sub0-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f6491.8%
Applied egg-rr91.8%
Final simplification83.6%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (- 0.0 (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = 0.0 - (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 = 0.0d0 - (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 = 0.0 - (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = 0.0 - (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(0.0 - 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 = 0.0 - (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[(0.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;0 - \frac{c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 71.9%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified71.9%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
*-commutativeN/A
associate-*l/N/A
*-lft-identityN/A
unsub-negN/A
--lowering--.f64N/A
mul-1-negN/A
distribute-rgt-neg-outN/A
remove-double-negN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f6475.3%
Simplified75.3%
*-commutativeN/A
div-invN/A
associate-*l*N/A
pow2N/A
pow-flipN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
inv-powN/A
div-invN/A
/-lowering-/.f6476.1%
Applied egg-rr76.1%
if -4.999999999999985e-310 < b Initial program 34.9%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified34.9%
Taylor expanded in b around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6464.2%
Simplified64.2%
sub0-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f6464.2%
Applied egg-rr64.2%
Final simplification70.5%
(FPCore (a b c) :precision binary64 (if (<= b 1.35e-304) (- 0.0 (/ b a)) (- 0.0 (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.35e-304) {
tmp = 0.0 - (b / a);
} else {
tmp = 0.0 - (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.35d-304) then
tmp = 0.0d0 - (b / a)
else
tmp = 0.0d0 - (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.35e-304) {
tmp = 0.0 - (b / a);
} else {
tmp = 0.0 - (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.35e-304: tmp = 0.0 - (b / a) else: tmp = 0.0 - (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.35e-304) tmp = Float64(0.0 - Float64(b / a)); else tmp = Float64(0.0 - Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.35e-304) tmp = 0.0 - (b / a); else tmp = 0.0 - (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.35e-304], N[(0.0 - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.35 \cdot 10^{-304}:\\
\;\;\;\;0 - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;0 - \frac{c}{b}\\
\end{array}
\end{array}
if b < 1.35000000000000005e-304Initial program 70.9%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified70.9%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
/-lowering-/.f64N/A
mul-1-negN/A
neg-sub0N/A
--lowering--.f6475.0%
Simplified75.0%
sub0-negN/A
neg-lowering-neg.f6475.0%
Applied egg-rr75.0%
if 1.35000000000000005e-304 < b Initial program 35.5%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified35.5%
Taylor expanded in b around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6465.2%
Simplified65.2%
sub0-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f6465.2%
Applied egg-rr65.2%
Final simplification70.4%
(FPCore (a b c) :precision binary64 (- 0.0 (/ c b)))
double code(double a, double b, double c) {
return 0.0 - (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 = 0.0d0 - (c / b)
end function
public static double code(double a, double b, double c) {
return 0.0 - (c / b);
}
def code(a, b, c): return 0.0 - (c / b)
function code(a, b, c) return Float64(0.0 - Float64(c / b)) end
function tmp = code(a, b, c) tmp = 0.0 - (c / b); end
code[a_, b_, c_] := N[(0.0 - N[(c / b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0 - \frac{c}{b}
\end{array}
Initial program 54.4%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified54.4%
Taylor expanded in b around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
/-lowering-/.f6431.5%
Simplified31.5%
sub0-negN/A
neg-lowering-neg.f64N/A
/-lowering-/.f6431.5%
Applied egg-rr31.5%
Final simplification31.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 54.4%
/-lowering-/.f64N/A
+-commutativeN/A
unsub-negN/A
--lowering--.f64N/A
sqrt-lowering-sqrt.f64N/A
sub-negN/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
metadata-evalN/A
*-commutativeN/A
Simplified54.4%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
*-commutativeN/A
associate-*l/N/A
*-lft-identityN/A
unsub-negN/A
--lowering--.f64N/A
mul-1-negN/A
distribute-rgt-neg-outN/A
remove-double-negN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
/-lowering-/.f6440.7%
Simplified40.7%
Taylor expanded in b around 0
/-lowering-/.f6411.9%
Simplified11.9%
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $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 - \left(4 \cdot a\right) \cdot c}\\
\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 2024186
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (- (* b b) (* (* 4 a) c)))) (let ((r1 (/ (+ (- b) (sqrt d)) (* 2 a)))) (let ((r2 (/ (- (- b) (sqrt d)) (* 2 a)))) (if (< b 0) r1 (/ c (* a r2)))))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))