
(FPCore (a b) :precision binary64 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* (* a a) (- 1.0 a)) (* (* b b) (+ 3.0 a))))) 1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (3.0 + a))))) - 1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (((a * a) * (1.0d0 - a)) + ((b * b) * (3.0d0 + a))))) - 1.0d0
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (3.0 + a))))) - 1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (3.0 + a))))) - 1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 - a)) + Float64(Float64(b * b) * Float64(3.0 + a))))) - 1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (3.0 + a))))) - 1.0; end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a * a), $MachinePrecision] * N[(1.0 - a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(3.0 + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(b \cdot b\right) \cdot \left(3 + a\right)\right)\right) - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* (* a a) (- 1.0 a)) (* (* b b) (+ 3.0 a))))) 1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (3.0 + a))))) - 1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (((a * a) * (1.0d0 - a)) + ((b * b) * (3.0d0 + a))))) - 1.0d0
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (3.0 + a))))) - 1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (3.0 + a))))) - 1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 - a)) + Float64(Float64(b * b) * Float64(3.0 + a))))) - 1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (3.0 + a))))) - 1.0; end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a * a), $MachinePrecision] * N[(1.0 - a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(3.0 + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(b \cdot b\right) \cdot \left(3 + a\right)\right)\right) - 1
\end{array}
(FPCore (a b)
:precision binary64
(if (<=
(+
(+
(pow (+ (* a a) (* b b)) 2.0)
(* 4.0 (+ (* (* a a) (- 1.0 a)) (* (* b b) (+ a 3.0)))))
-1.0)
INFINITY)
(+
(+ (pow b 4.0) (fma 2.0 (* a (* b (* a b))) (pow a 4.0)))
(+ (* 4.0 (fma (* a a) (- 1.0 a) (* b (* b (+ a 3.0))))) -1.0))
(* (pow a 3.0) (+ a -4.0))))
double code(double a, double b) {
double tmp;
if (((pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))))) + -1.0) <= ((double) INFINITY)) {
tmp = (pow(b, 4.0) + fma(2.0, (a * (b * (a * b))), pow(a, 4.0))) + ((4.0 * fma((a * a), (1.0 - a), (b * (b * (a + 3.0))))) + -1.0);
} else {
tmp = pow(a, 3.0) * (a + -4.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 - a)) + Float64(Float64(b * b) * Float64(a + 3.0))))) + -1.0) <= Inf) tmp = Float64(Float64((b ^ 4.0) + fma(2.0, Float64(a * Float64(b * Float64(a * b))), (a ^ 4.0))) + Float64(Float64(4.0 * fma(Float64(a * a), Float64(1.0 - a), Float64(b * Float64(b * Float64(a + 3.0))))) + -1.0)); else tmp = Float64((a ^ 3.0) * Float64(a + -4.0)); end return tmp end
code[a_, b_] := If[LessEqual[N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a * a), $MachinePrecision] * N[(1.0 - a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(a + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], Infinity], N[(N[(N[Power[b, 4.0], $MachinePrecision] + N[(2.0 * N[(a * N[(b * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(4.0 * N[(N[(a * a), $MachinePrecision] * N[(1.0 - a), $MachinePrecision] + N[(b * N[(b * N[(a + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[Power[a, 3.0], $MachinePrecision] * N[(a + -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(b \cdot b\right) \cdot \left(a + 3\right)\right)\right) + -1 \leq \infty:\\
\;\;\;\;\left({b}^{4} + \mathsf{fma}\left(2, a \cdot \left(b \cdot \left(a \cdot b\right)\right), {a}^{4}\right)\right) + \left(4 \cdot \mathsf{fma}\left(a \cdot a, 1 - a, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) + -1\right)\\
\mathbf{else}:\\
\;\;\;\;{a}^{3} \cdot \left(a + -4\right)\\
\end{array}
\end{array}
if (-.f64 (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (-.f64 1 a)) (*.f64 (*.f64 b b) (+.f64 3 a))))) 1) < +inf.0Initial program 99.9%
associate--l+99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
distribute-rgt-in99.9%
sqr-neg99.9%
distribute-rgt-in99.9%
fma-def99.9%
sqr-neg99.9%
Simplified99.9%
Taylor expanded in a around 0 89.4%
associate-+r+89.4%
+-commutative89.4%
fma-def89.4%
unpow289.4%
unpow289.4%
swap-sqr100.0%
unpow2100.0%
*-commutative100.0%
Simplified100.0%
unpow2100.0%
associate-*r*100.0%
Applied egg-rr100.0%
if +inf.0 < (-.f64 (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (-.f64 1 a)) (*.f64 (*.f64 b b) (+.f64 3 a))))) 1) Initial program 0.0%
associate--l+0.0%
fma-def0.0%
sqr-neg0.0%
fma-def0.0%
distribute-rgt-in0.0%
sqr-neg0.0%
distribute-rgt-in0.0%
fma-def0.0%
sqr-neg0.0%
Simplified5.3%
Taylor expanded in a around 0 5.3%
associate-+r+5.3%
+-commutative5.3%
fma-def5.3%
unpow25.3%
unpow25.3%
swap-sqr5.3%
unpow25.3%
*-commutative5.3%
Simplified5.3%
unpow25.3%
associate-*r*5.3%
Applied egg-rr5.3%
Taylor expanded in a around inf 33.0%
+-commutative33.0%
metadata-eval33.0%
pow-plus33.0%
*-commutative33.0%
distribute-lft-out97.5%
Simplified97.5%
Final simplification99.3%
(FPCore (a b)
:precision binary64
(let* ((t_0
(+
(+
(pow (+ (* a a) (* b b)) 2.0)
(* 4.0 (+ (* (* a a) (- 1.0 a)) (* (* b b) (+ a 3.0)))))
-1.0)))
(if (<= t_0 INFINITY) t_0 (* (pow a 3.0) (+ a -4.0)))))
double code(double a, double b) {
double t_0 = (pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))))) + -1.0;
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0;
} else {
tmp = pow(a, 3.0) * (a + -4.0);
}
return tmp;
}
public static double code(double a, double b) {
double t_0 = (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))))) + -1.0;
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0;
} else {
tmp = Math.pow(a, 3.0) * (a + -4.0);
}
return tmp;
}
def code(a, b): t_0 = (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))))) + -1.0 tmp = 0 if t_0 <= math.inf: tmp = t_0 else: tmp = math.pow(a, 3.0) * (a + -4.0) return tmp
function code(a, b) t_0 = Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 - a)) + Float64(Float64(b * b) * Float64(a + 3.0))))) + -1.0) tmp = 0.0 if (t_0 <= Inf) tmp = t_0; else tmp = Float64((a ^ 3.0) * Float64(a + -4.0)); end return tmp end
function tmp_2 = code(a, b) t_0 = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))))) + -1.0; tmp = 0.0; if (t_0 <= Inf) tmp = t_0; else tmp = (a ^ 3.0) * (a + -4.0); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a * a), $MachinePrecision] * N[(1.0 - a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(a + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], t$95$0, N[(N[Power[a, 3.0], $MachinePrecision] * N[(a + -4.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(b \cdot b\right) \cdot \left(a + 3\right)\right)\right) + -1\\
\mathbf{if}\;t_0 \leq \infty:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;{a}^{3} \cdot \left(a + -4\right)\\
\end{array}
\end{array}
if (-.f64 (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (-.f64 1 a)) (*.f64 (*.f64 b b) (+.f64 3 a))))) 1) < +inf.0Initial program 99.9%
if +inf.0 < (-.f64 (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (-.f64 1 a)) (*.f64 (*.f64 b b) (+.f64 3 a))))) 1) Initial program 0.0%
associate--l+0.0%
fma-def0.0%
sqr-neg0.0%
fma-def0.0%
distribute-rgt-in0.0%
sqr-neg0.0%
distribute-rgt-in0.0%
fma-def0.0%
sqr-neg0.0%
Simplified5.3%
Taylor expanded in a around 0 5.3%
associate-+r+5.3%
+-commutative5.3%
fma-def5.3%
unpow25.3%
unpow25.3%
swap-sqr5.3%
unpow25.3%
*-commutative5.3%
Simplified5.3%
unpow25.3%
associate-*r*5.3%
Applied egg-rr5.3%
Taylor expanded in a around inf 33.0%
+-commutative33.0%
metadata-eval33.0%
pow-plus33.0%
*-commutative33.0%
distribute-lft-out97.5%
Simplified97.5%
Final simplification99.2%
(FPCore (a b)
:precision binary64
(if (<= b 5.2e-280)
(* (pow a 3.0) (+ a -4.0))
(if (<= b 1.95e-9)
(* (+ 1.0 (* a 2.0)) (+ (* a 2.0) -1.0))
(if (<= b 1400000000.0) (pow a 4.0) (pow b 4.0)))))
double code(double a, double b) {
double tmp;
if (b <= 5.2e-280) {
tmp = pow(a, 3.0) * (a + -4.0);
} else if (b <= 1.95e-9) {
tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0);
} else if (b <= 1400000000.0) {
tmp = pow(a, 4.0);
} else {
tmp = pow(b, 4.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 5.2d-280) then
tmp = (a ** 3.0d0) * (a + (-4.0d0))
else if (b <= 1.95d-9) then
tmp = (1.0d0 + (a * 2.0d0)) * ((a * 2.0d0) + (-1.0d0))
else if (b <= 1400000000.0d0) then
tmp = a ** 4.0d0
else
tmp = b ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 5.2e-280) {
tmp = Math.pow(a, 3.0) * (a + -4.0);
} else if (b <= 1.95e-9) {
tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0);
} else if (b <= 1400000000.0) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 5.2e-280: tmp = math.pow(a, 3.0) * (a + -4.0) elif b <= 1.95e-9: tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0) elif b <= 1400000000.0: tmp = math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 5.2e-280) tmp = Float64((a ^ 3.0) * Float64(a + -4.0)); elseif (b <= 1.95e-9) tmp = Float64(Float64(1.0 + Float64(a * 2.0)) * Float64(Float64(a * 2.0) + -1.0)); elseif (b <= 1400000000.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 5.2e-280) tmp = (a ^ 3.0) * (a + -4.0); elseif (b <= 1.95e-9) tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0); elseif (b <= 1400000000.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 5.2e-280], N[(N[Power[a, 3.0], $MachinePrecision] * N[(a + -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.95e-9], N[(N[(1.0 + N[(a * 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(a * 2.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1400000000.0], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.2 \cdot 10^{-280}:\\
\;\;\;\;{a}^{3} \cdot \left(a + -4\right)\\
\mathbf{elif}\;b \leq 1.95 \cdot 10^{-9}:\\
\;\;\;\;\left(1 + a \cdot 2\right) \cdot \left(a \cdot 2 + -1\right)\\
\mathbf{elif}\;b \leq 1400000000:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 5.2e-280Initial program 70.0%
associate--l+70.0%
fma-def70.0%
sqr-neg70.0%
fma-def70.0%
distribute-rgt-in70.0%
sqr-neg70.0%
distribute-rgt-in70.0%
fma-def70.0%
sqr-neg70.0%
Simplified71.3%
Taylor expanded in a around 0 63.9%
associate-+r+63.9%
+-commutative63.9%
fma-def63.9%
unpow263.9%
unpow263.9%
swap-sqr71.4%
unpow271.4%
*-commutative71.4%
Simplified71.4%
unpow271.4%
associate-*r*71.4%
Applied egg-rr71.4%
Taylor expanded in a around inf 35.4%
+-commutative35.4%
metadata-eval35.4%
pow-plus35.3%
*-commutative35.3%
distribute-lft-out52.3%
Simplified52.3%
if 5.2e-280 < b < 1.9500000000000001e-9Initial program 80.3%
associate--l+80.3%
fma-def80.3%
sqr-neg80.3%
fma-def80.3%
distribute-rgt-in80.3%
sqr-neg80.3%
distribute-rgt-in80.3%
fma-def80.3%
sqr-neg80.3%
Simplified80.3%
Taylor expanded in b around 0 80.4%
Taylor expanded in a around 0 79.9%
pow279.9%
add-sqr-sqrt79.9%
difference-of-sqr-179.9%
sqrt-prod79.9%
metadata-eval79.9%
sqrt-prod43.7%
add-sqr-sqrt67.3%
sqrt-prod67.3%
metadata-eval67.3%
sqrt-prod43.7%
add-sqr-sqrt79.9%
Applied egg-rr79.9%
if 1.9500000000000001e-9 < b < 1.4e9Initial program 20.0%
associate--l+20.0%
fma-def20.0%
sqr-neg20.0%
fma-def20.0%
distribute-rgt-in20.0%
sqr-neg20.0%
distribute-rgt-in20.0%
fma-def20.0%
sqr-neg20.0%
Simplified20.0%
Taylor expanded in a around inf 100.0%
if 1.4e9 < b Initial program 66.0%
associate--l+66.0%
fma-def66.0%
sqr-neg66.0%
fma-def66.0%
distribute-rgt-in66.0%
sqr-neg66.0%
distribute-rgt-in66.0%
fma-def66.0%
sqr-neg66.0%
Simplified69.8%
Taylor expanded in b around inf 96.5%
Final simplification67.9%
(FPCore (a b) :precision binary64 (if (or (<= a -3.5e-13) (not (<= a 1.3e-18))) (pow a 4.0) -1.0))
double code(double a, double b) {
double tmp;
if ((a <= -3.5e-13) || !(a <= 1.3e-18)) {
tmp = pow(a, 4.0);
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((a <= (-3.5d-13)) .or. (.not. (a <= 1.3d-18))) then
tmp = a ** 4.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a <= -3.5e-13) || !(a <= 1.3e-18)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -3.5e-13) or not (a <= 1.3e-18): tmp = math.pow(a, 4.0) else: tmp = -1.0 return tmp
function code(a, b) tmp = 0.0 if ((a <= -3.5e-13) || !(a <= 1.3e-18)) tmp = a ^ 4.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -3.5e-13) || ~((a <= 1.3e-18))) tmp = a ^ 4.0; else tmp = -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -3.5e-13], N[Not[LessEqual[a, 1.3e-18]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -3.5 \cdot 10^{-13} \lor \neg \left(a \leq 1.3 \cdot 10^{-18}\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if a < -3.5000000000000002e-13 or 1.3e-18 < a Initial program 46.0%
associate--l+46.0%
fma-def46.0%
sqr-neg46.0%
fma-def46.0%
distribute-rgt-in46.0%
sqr-neg46.0%
distribute-rgt-in46.0%
fma-def46.0%
sqr-neg46.0%
Simplified48.8%
Taylor expanded in a around inf 88.0%
if -3.5000000000000002e-13 < a < 1.3e-18Initial program 99.9%
associate--l+99.9%
fma-def99.9%
sqr-neg99.9%
fma-def99.9%
distribute-rgt-in99.9%
sqr-neg99.9%
distribute-rgt-in99.9%
fma-def99.9%
sqr-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 52.5%
Taylor expanded in a around 0 52.5%
Taylor expanded in a around 0 52.5%
Final simplification72.1%
(FPCore (a b) :precision binary64 (if (<= b 3.5e-11) (* (+ 1.0 (* a 2.0)) (+ (* a 2.0) -1.0)) (if (<= b 4800000000.0) (pow a 4.0) (pow b 4.0))))
double code(double a, double b) {
double tmp;
if (b <= 3.5e-11) {
tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0);
} else if (b <= 4800000000.0) {
tmp = pow(a, 4.0);
} else {
tmp = pow(b, 4.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 3.5d-11) then
tmp = (1.0d0 + (a * 2.0d0)) * ((a * 2.0d0) + (-1.0d0))
else if (b <= 4800000000.0d0) then
tmp = a ** 4.0d0
else
tmp = b ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 3.5e-11) {
tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0);
} else if (b <= 4800000000.0) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.5e-11: tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0) elif b <= 4800000000.0: tmp = math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 3.5e-11) tmp = Float64(Float64(1.0 + Float64(a * 2.0)) * Float64(Float64(a * 2.0) + -1.0)); elseif (b <= 4800000000.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 3.5e-11) tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0); elseif (b <= 4800000000.0) tmp = a ^ 4.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3.5e-11], N[(N[(1.0 + N[(a * 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(a * 2.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4800000000.0], N[Power[a, 4.0], $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.5 \cdot 10^{-11}:\\
\;\;\;\;\left(1 + a \cdot 2\right) \cdot \left(a \cdot 2 + -1\right)\\
\mathbf{elif}\;b \leq 4800000000:\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 3.50000000000000019e-11Initial program 72.6%
associate--l+72.6%
fma-def72.6%
sqr-neg72.6%
fma-def72.6%
distribute-rgt-in72.6%
sqr-neg72.6%
distribute-rgt-in72.6%
fma-def72.6%
sqr-neg72.6%
Simplified73.6%
Taylor expanded in b around 0 63.5%
Taylor expanded in a around 0 61.3%
pow261.3%
add-sqr-sqrt61.3%
difference-of-sqr-161.3%
sqrt-prod61.3%
metadata-eval61.3%
sqrt-prod33.5%
add-sqr-sqrt45.8%
sqrt-prod45.8%
metadata-eval45.8%
sqrt-prod33.5%
add-sqr-sqrt61.3%
Applied egg-rr61.3%
if 3.50000000000000019e-11 < b < 4.8e9Initial program 20.0%
associate--l+20.0%
fma-def20.0%
sqr-neg20.0%
fma-def20.0%
distribute-rgt-in20.0%
sqr-neg20.0%
distribute-rgt-in20.0%
fma-def20.0%
sqr-neg20.0%
Simplified20.0%
Taylor expanded in a around inf 100.0%
if 4.8e9 < b Initial program 66.0%
associate--l+66.0%
fma-def66.0%
sqr-neg66.0%
fma-def66.0%
distribute-rgt-in66.0%
sqr-neg66.0%
distribute-rgt-in66.0%
fma-def66.0%
sqr-neg66.0%
Simplified69.8%
Taylor expanded in b around inf 96.5%
Final simplification69.4%
(FPCore (a b) :precision binary64 (* (+ 1.0 (* a 2.0)) (+ (* a 2.0) -1.0)))
double code(double a, double b) {
return (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (1.0d0 + (a * 2.0d0)) * ((a * 2.0d0) + (-1.0d0))
end function
public static double code(double a, double b) {
return (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0);
}
def code(a, b): return (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0)
function code(a, b) return Float64(Float64(1.0 + Float64(a * 2.0)) * Float64(Float64(a * 2.0) + -1.0)) end
function tmp = code(a, b) tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0); end
code[a_, b_] := N[(N[(1.0 + N[(a * 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(a * 2.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + a \cdot 2\right) \cdot \left(a \cdot 2 + -1\right)
\end{array}
Initial program 70.2%
associate--l+70.2%
fma-def70.2%
sqr-neg70.2%
fma-def70.2%
distribute-rgt-in70.2%
sqr-neg70.2%
distribute-rgt-in70.2%
fma-def70.2%
sqr-neg70.2%
Simplified71.8%
Taylor expanded in b around 0 53.2%
Taylor expanded in a around 0 53.3%
pow253.3%
add-sqr-sqrt53.3%
difference-of-sqr-153.3%
sqrt-prod53.3%
metadata-eval53.3%
sqrt-prod30.1%
add-sqr-sqrt39.6%
sqrt-prod39.6%
metadata-eval39.6%
sqrt-prod30.1%
add-sqr-sqrt53.3%
Applied egg-rr53.3%
Final simplification53.3%
(FPCore (a b) :precision binary64 -1.0)
double code(double a, double b) {
return -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = -1.0d0
end function
public static double code(double a, double b) {
return -1.0;
}
def code(a, b): return -1.0
function code(a, b) return -1.0 end
function tmp = code(a, b) tmp = -1.0; end
code[a_, b_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 70.2%
associate--l+70.2%
fma-def70.2%
sqr-neg70.2%
fma-def70.2%
distribute-rgt-in70.2%
sqr-neg70.2%
distribute-rgt-in70.2%
fma-def70.2%
sqr-neg70.2%
Simplified71.8%
Taylor expanded in b around 0 53.2%
Taylor expanded in a around 0 53.3%
Taylor expanded in a around 0 24.0%
Final simplification24.0%
herbie shell --seed 2023319
(FPCore (a b)
:name "Bouland and Aaronson, Equation (24)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* (* a a) (- 1.0 a)) (* (* b b) (+ 3.0 a))))) 1.0))