(FPCore (a b c)
:precision binary64
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
↓
(FPCore (a b c)
:precision binary64
(if (<= b -6.5e-64)
(/ (- c) b)
(if (<= b 6.6e+110)
(/ (- (- b) (sqrt (+ (* b b) (* (* c a) -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
return (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
↓
double code(double a, double b, double c) {
double tmp;
if (b <= -6.5e-64) {
tmp = -c / b;
} else if (b <= 6.6e+110) {
tmp = (-b - sqrt(((b * b) + ((c * a) * -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
code = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
↓
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.5d-64)) then
tmp = -c / b
else if (b <= 6.6d+110) then
tmp = (-b - sqrt(((b * b) + ((c * a) * (-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) {
return (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
↓
public static double code(double a, double b, double c) {
double tmp;
if (b <= -6.5e-64) {
tmp = -c / b;
} else if (b <= 6.6e+110) {
tmp = (-b - Math.sqrt(((b * b) + ((c * a) * -4.0)))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c):
return (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
↓
def code(a, b, c):
tmp = 0
if b <= -6.5e-64:
tmp = -c / b
elif b <= 6.6e+110:
tmp = (-b - math.sqrt(((b * b) + ((c * a) * -4.0)))) / (a * 2.0)
else:
tmp = (c / b) - (b / a)
return tmp
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 code(a, b, c)
tmp = 0.0
if (b <= -6.5e-64)
tmp = Float64(Float64(-c) / b);
elseif (b <= 6.6e+110)
tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) + Float64(Float64(c * a) * -4.0)))) / Float64(a * 2.0));
else
tmp = Float64(Float64(c / b) - Float64(b / a));
end
return tmp
end
function tmp = code(a, b, c)
tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
end
↓
function tmp_2 = code(a, b, c)
tmp = 0.0;
if (b <= -6.5e-64)
tmp = -c / b;
elseif (b <= 6.6e+110)
tmp = (-b - sqrt(((b * b) + ((c * a) * -4.0)))) / (a * 2.0);
else
tmp = (c / b) - (b / a);
end
tmp_2 = tmp;
end
(*.f64 (+.f64 b (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4))))) (/.f64 -1/2 a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c (Rewrite<= metadata-eval (neg.f64 4))))))) (/.f64 -1/2 a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (fma.f64 b b (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a c) (neg.f64 4)))))) (/.f64 -1/2 a)): 2 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (fma.f64 b b (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (*.f64 a c) 4)))))) (/.f64 -1/2 a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (fma.f64 b b (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 4 (*.f64 a c))))))) (/.f64 -1/2 a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c)))))) (/.f64 -1/2 a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (/.f64 (Rewrite<= metadata-eval (/.f64 -1 2)) a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (Rewrite<= associate-/r*_binary64 (/.f64 -1 (*.f64 2 a)))): 0 points increase in error, 0 points decrease in error
(Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) -1) (*.f64 2 a))): 8 points increase in error, 26 points decrease in error
(/.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))))) (*.f64 2 a)): 0 points increase in error, 0 points decrease in error
(/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))))) (*.f64 2 a)): 0 points increase in error, 0 points decrease in error
(/.f64 (Rewrite<= distribute-neg-out_binary64 (+.f64 (neg.f64 b) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))))) (*.f64 2 a)): 0 points increase in error, 0 points decrease in error
(/.f64 (Rewrite<= sub-neg_binary64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c)))))) (*.f64 2 a)): 0 points increase in error, 0 points decrease in error
Applied egg-rr57.9
\[\leadsto \left(b + \color{blue}{e^{\log \left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\right) \cdot 0.5}}\right) \cdot \frac{-0.5}{a}
\]
Taylor expanded in b around -inf 8.4
\[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}
\]
Simplified8.4
\[\leadsto \color{blue}{\frac{-c}{b}}
\]
Proof
(/.f64 (neg.f64 c) b): 0 points increase in error, 0 points decrease in error
(/.f64 (Rewrite<= mul-1-neg_binary64 (*.f64 -1 c)) b): 0 points increase in error, 0 points decrease in error
(Rewrite<= associate-*r/_binary64 (*.f64 -1 (/.f64 c b))): 0 points increase in error, 0 points decrease in error
if -6.5000000000000004e-64 < b < 6.59999999999999942e110
(*.f64 (+.f64 b (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c -4))))) (/.f64 -1/2 a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (fma.f64 b b (*.f64 a (*.f64 c (Rewrite<= metadata-eval (neg.f64 4))))))) (/.f64 -1/2 a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (fma.f64 b b (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 a c) (neg.f64 4)))))) (/.f64 -1/2 a)): 2 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (fma.f64 b b (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (*.f64 a c) 4)))))) (/.f64 -1/2 a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (fma.f64 b b (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 4 (*.f64 a c))))))) (/.f64 -1/2 a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c)))))) (/.f64 -1/2 a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (/.f64 (Rewrite<= metadata-eval (/.f64 -1 2)) a)): 0 points increase in error, 0 points decrease in error
(*.f64 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) (Rewrite<= associate-/r*_binary64 (/.f64 -1 (*.f64 2 a)))): 0 points increase in error, 0 points decrease in error
(Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))) -1) (*.f64 2 a))): 8 points increase in error, 26 points decrease in error
(/.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))))) (*.f64 2 a)): 0 points increase in error, 0 points decrease in error
(/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (+.f64 b (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))))) (*.f64 2 a)): 0 points increase in error, 0 points decrease in error
(/.f64 (Rewrite<= distribute-neg-out_binary64 (+.f64 (neg.f64 b) (neg.f64 (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c))))))) (*.f64 2 a)): 0 points increase in error, 0 points decrease in error
(/.f64 (Rewrite<= sub-neg_binary64 (-.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 4 (*.f64 a c)))))) (*.f64 2 a)): 0 points increase in error, 0 points decrease in error
Applied egg-rr50.8
\[\leadsto \left(b + \color{blue}{e^{\log \left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\right) \cdot 0.5}}\right) \cdot \frac{-0.5}{a}
\]
herbie shell --seed 2022298
(FPCore (a b c)
:name "quadm (p42, negative)"
: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)))