
(FPCore (a b) :precision binary64 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 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 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 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[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 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 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 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[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1
\end{array}
(FPCore (a b) :precision binary64 (if (<= (* a a) 0.005) (+ (+ (* 4.0 (* b b)) (pow b 4.0)) -1.0) (+ (+ (pow a 4.0) (* b (* b (* a (+ a a))))) -1.0)))
double code(double a, double b) {
double tmp;
if ((a * a) <= 0.005) {
tmp = ((4.0 * (b * b)) + pow(b, 4.0)) + -1.0;
} else {
tmp = (pow(a, 4.0) + (b * (b * (a * (a + a))))) + -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 * a) <= 0.005d0) then
tmp = ((4.0d0 * (b * b)) + (b ** 4.0d0)) + (-1.0d0)
else
tmp = ((a ** 4.0d0) + (b * (b * (a * (a + a))))) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a * a) <= 0.005) {
tmp = ((4.0 * (b * b)) + Math.pow(b, 4.0)) + -1.0;
} else {
tmp = (Math.pow(a, 4.0) + (b * (b * (a * (a + a))))) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (a * a) <= 0.005: tmp = ((4.0 * (b * b)) + math.pow(b, 4.0)) + -1.0 else: tmp = (math.pow(a, 4.0) + (b * (b * (a * (a + a))))) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(a * a) <= 0.005) tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + (b ^ 4.0)) + -1.0); else tmp = Float64(Float64((a ^ 4.0) + Float64(b * Float64(b * Float64(a * Float64(a + a))))) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a * a) <= 0.005) tmp = ((4.0 * (b * b)) + (b ^ 4.0)) + -1.0; else tmp = ((a ^ 4.0) + (b * (b * (a * (a + a))))) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(a * a), $MachinePrecision], 0.005], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[Power[a, 4.0], $MachinePrecision] + N[(b * N[(b * N[(a * N[(a + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot a \leq 0.005:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + {b}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left({a}^{4} + b \cdot \left(b \cdot \left(a \cdot \left(a + a\right)\right)\right)\right) + -1\\
\end{array}
\end{array}
if (*.f64 a a) < 0.0050000000000000001Initial program 99.9%
Taylor expanded in a around 0 99.9%
unpow299.9%
Simplified99.9%
Taylor expanded in b around 0 100.0%
if 0.0050000000000000001 < (*.f64 a a) Initial program 99.8%
Taylor expanded in b around 0 87.8%
unpow287.8%
unpow287.8%
Simplified87.8%
Taylor expanded in a around inf 88.5%
unpow288.5%
unpow288.5%
associate-*r*87.8%
*-commutative87.8%
associate-*l*100.0%
count-2100.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (+ (pow (hypot a b) 4.0) (fma b (* b 4.0) -1.0)))
double code(double a, double b) {
return pow(hypot(a, b), 4.0) + fma(b, (b * 4.0), -1.0);
}
function code(a, b) return Float64((hypot(a, b) ^ 4.0) + fma(b, Float64(b * 4.0), -1.0)) end
code[a_, b_] := N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(b * N[(b * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b, b \cdot 4, -1\right)
\end{array}
Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= (* b b) 4e-30) (+ (pow a 4.0) -1.0) (+ (pow b 4.0) (* (* b b) (+ 4.0 (* (* a a) 2.0))))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 4e-30) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = pow(b, 4.0) + ((b * b) * (4.0 + ((a * a) * 2.0)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b * b) <= 4d-30) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = (b ** 4.0d0) + ((b * b) * (4.0d0 + ((a * a) * 2.0d0)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 4e-30) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = Math.pow(b, 4.0) + ((b * b) * (4.0 + ((a * a) * 2.0)));
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 4e-30: tmp = math.pow(a, 4.0) + -1.0 else: tmp = math.pow(b, 4.0) + ((b * b) * (4.0 + ((a * a) * 2.0))) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 4e-30) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64((b ^ 4.0) + Float64(Float64(b * b) * Float64(4.0 + Float64(Float64(a * a) * 2.0)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 4e-30) tmp = (a ^ 4.0) + -1.0; else tmp = (b ^ 4.0) + ((b * b) * (4.0 + ((a * a) * 2.0))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 4e-30], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[b, 4.0], $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(N[(a * a), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 4 \cdot 10^{-30}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4} + \left(b \cdot b\right) \cdot \left(4 + \left(a \cdot a\right) \cdot 2\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 4e-30Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 100.0%
if 4e-30 < (*.f64 b b) Initial program 99.8%
associate--l+99.8%
unpow299.8%
unpow199.8%
sqr-pow99.8%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around inf 95.3%
unpow295.3%
unpow295.3%
Simplified95.3%
Final simplification97.5%
(FPCore (a b) :precision binary64 (+ (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) -1.0))
double code(double a, double b) {
return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) + -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 * (b * b))) + (-1.0d0)
end function
public static double code(double a, double b) {
return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) + -1.0;
}
def code(a, b): return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) + -1.0
function code(a, b) return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) + -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[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) + -1
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= a 1.45e+19) (+ (+ (* 4.0 (* b b)) (pow b 4.0)) -1.0) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.45e+19) {
tmp = ((4.0 * (b * b)) + pow(b, 4.0)) + -1.0;
} else {
tmp = pow(a, 4.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= 1.45d+19) then
tmp = ((4.0d0 * (b * b)) + (b ** 4.0d0)) + (-1.0d0)
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 1.45e+19) {
tmp = ((4.0 * (b * b)) + Math.pow(b, 4.0)) + -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.45e+19: tmp = ((4.0 * (b * b)) + math.pow(b, 4.0)) + -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 1.45e+19) tmp = Float64(Float64(Float64(4.0 * Float64(b * b)) + (b ^ 4.0)) + -1.0); else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.45e+19) tmp = ((4.0 * (b * b)) + (b ^ 4.0)) + -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.45e+19], N[(N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.45 \cdot 10^{+19}:\\
\;\;\;\;\left(4 \cdot \left(b \cdot b\right) + {b}^{4}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 1.45e19Initial program 99.8%
Taylor expanded in a around 0 77.8%
unpow277.8%
Simplified77.8%
Taylor expanded in b around 0 77.9%
if 1.45e19 < a Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around inf 95.4%
Final simplification82.1%
(FPCore (a b) :precision binary64 (if (<= a 1.4e+19) (+ (* (* b b) (+ 4.0 (* b b))) -1.0) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.4e+19) {
tmp = ((b * b) * (4.0 + (b * b))) + -1.0;
} else {
tmp = pow(a, 4.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= 1.4d+19) then
tmp = ((b * b) * (4.0d0 + (b * b))) + (-1.0d0)
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 1.4e+19) {
tmp = ((b * b) * (4.0 + (b * b))) + -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.4e+19: tmp = ((b * b) * (4.0 + (b * b))) + -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 1.4e+19) tmp = Float64(Float64(Float64(b * b) * Float64(4.0 + Float64(b * b))) + -1.0); else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.4e+19) tmp = ((b * b) * (4.0 + (b * b))) + -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.4e+19], N[(N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.4 \cdot 10^{+19}:\\
\;\;\;\;\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 1.4e19Initial program 99.8%
Taylor expanded in a around 0 77.8%
unpow277.8%
Simplified77.8%
+-commutative77.8%
unpow277.8%
distribute-rgt-out77.8%
Applied egg-rr77.8%
if 1.4e19 < a Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in a around inf 95.4%
Final simplification82.0%
(FPCore (a b) :precision binary64 (+ (* (* b b) (+ 4.0 (* b b))) -1.0))
double code(double a, double b) {
return ((b * b) * (4.0 + (b * b))) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((b * b) * (4.0d0 + (b * b))) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((b * b) * (4.0 + (b * b))) + -1.0;
}
def code(a, b): return ((b * b) * (4.0 + (b * b))) + -1.0
function code(a, b) return Float64(Float64(Float64(b * b) * Float64(4.0 + Float64(b * b))) + -1.0) end
function tmp = code(a, b) tmp = ((b * b) * (4.0 + (b * b))) + -1.0; end
code[a_, b_] := N[(N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right) + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around 0 68.5%
unpow268.5%
Simplified68.5%
+-commutative68.5%
unpow268.5%
distribute-rgt-out68.5%
Applied egg-rr68.5%
Final simplification68.5%
(FPCore (a b) :precision binary64 (+ (* 4.0 (* b b)) -1.0))
double code(double a, double b) {
return (4.0 * (b * b)) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (4.0d0 * (b * b)) + (-1.0d0)
end function
public static double code(double a, double b) {
return (4.0 * (b * b)) + -1.0;
}
def code(a, b): return (4.0 * (b * b)) + -1.0
function code(a, b) return Float64(Float64(4.0 * Float64(b * b)) + -1.0) end
function tmp = code(a, b) tmp = (4.0 * (b * b)) + -1.0; end
code[a_, b_] := N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(b \cdot b\right) + -1
\end{array}
Initial program 99.9%
Taylor expanded in a around 0 68.5%
unpow268.5%
Simplified68.5%
+-commutative68.5%
unpow268.5%
distribute-rgt-out68.5%
Applied egg-rr68.5%
Taylor expanded in b around 0 49.6%
Simplified49.6%
Final simplification49.6%
herbie shell --seed 2023242
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))