
(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 7 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 (+ (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%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Final simplification100.0%
(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 (<= b 7e+34) (+ (pow a 4.0) -1.0) (* b (+ (* b 4.0) (pow a 3.0)))))
double code(double a, double b) {
double tmp;
if (b <= 7e+34) {
tmp = pow(a, 4.0) + -1.0;
} else {
tmp = b * ((b * 4.0) + pow(a, 3.0));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 7d+34) then
tmp = (a ** 4.0d0) + (-1.0d0)
else
tmp = b * ((b * 4.0d0) + (a ** 3.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 7e+34) {
tmp = Math.pow(a, 4.0) + -1.0;
} else {
tmp = b * ((b * 4.0) + Math.pow(a, 3.0));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 7e+34: tmp = math.pow(a, 4.0) + -1.0 else: tmp = b * ((b * 4.0) + math.pow(a, 3.0)) return tmp
function code(a, b) tmp = 0.0 if (b <= 7e+34) tmp = Float64((a ^ 4.0) + -1.0); else tmp = Float64(b * Float64(Float64(b * 4.0) + (a ^ 3.0))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 7e+34) tmp = (a ^ 4.0) + -1.0; else tmp = b * ((b * 4.0) + (a ^ 3.0)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 7e+34], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[(b * N[(N[(b * 4.0), $MachinePrecision] + N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7 \cdot 10^{+34}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(b \cdot 4 + {a}^{3}\right)\\
\end{array}
\end{array}
if b < 6.99999999999999996e34Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 79.8%
if 6.99999999999999996e34 < b Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*l*99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in a around inf 57.1%
Taylor expanded in b around inf 51.6%
unpow251.6%
associate-*r*51.6%
distribute-rgt-out55.3%
Simplified55.3%
Final simplification74.6%
(FPCore (a b) :precision binary64 (if (<= a 1.0) -1.0 (if (or (<= a 1.2e+49) (not (<= a 1e+67))) (pow a 4.0) (pow a 8.0))))
double code(double a, double b) {
double tmp;
if (a <= 1.0) {
tmp = -1.0;
} else if ((a <= 1.2e+49) || !(a <= 1e+67)) {
tmp = pow(a, 4.0);
} else {
tmp = pow(a, 8.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.0d0) then
tmp = -1.0d0
else if ((a <= 1.2d+49) .or. (.not. (a <= 1d+67))) then
tmp = a ** 4.0d0
else
tmp = a ** 8.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= 1.0) {
tmp = -1.0;
} else if ((a <= 1.2e+49) || !(a <= 1e+67)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = Math.pow(a, 8.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.0: tmp = -1.0 elif (a <= 1.2e+49) or not (a <= 1e+67): tmp = math.pow(a, 4.0) else: tmp = math.pow(a, 8.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 1.0) tmp = -1.0; elseif ((a <= 1.2e+49) || !(a <= 1e+67)) tmp = a ^ 4.0; else tmp = a ^ 8.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.0) tmp = -1.0; elseif ((a <= 1.2e+49) || ~((a <= 1e+67))) tmp = a ^ 4.0; else tmp = a ^ 8.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.0], -1.0, If[Or[LessEqual[a, 1.2e+49], N[Not[LessEqual[a, 1e+67]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], N[Power[a, 8.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1:\\
\;\;\;\;-1\\
\mathbf{elif}\;a \leq 1.2 \cdot 10^{+49} \lor \neg \left(a \leq 10^{+67}\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{8}\\
\end{array}
\end{array}
if a < 1Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 64.6%
Taylor expanded in a around 0 31.9%
if 1 < a < 1.2e49 or 9.99999999999999983e66 < a Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in b around 0 94.4%
Taylor expanded in a around inf 93.0%
if 1.2e49 < a < 9.99999999999999983e66Initial program 100.0%
associate--l+100.0%
sqr-pow100.0%
sqr-pow100.0%
unpow2100.0%
unpow1100.0%
sqr-pow100.0%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in b around 0 6.4%
flip--100.0%
div-inv100.0%
metadata-eval100.0%
sub-neg100.0%
pow-prod-up100.0%
metadata-eval100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in a around inf 100.0%
Final simplification48.9%
(FPCore (a b) :precision binary64 (if (<= b 9.4e+14) (+ (pow a 4.0) -1.0) (if (<= b 9.5e+151) (pow a 8.0) (* 4.0 (pow b 2.0)))))
double code(double a, double b) {
double tmp;
if (b <= 9.4e+14) {
tmp = pow(a, 4.0) + -1.0;
} else if (b <= 9.5e+151) {
tmp = pow(a, 8.0);
} else {
tmp = 4.0 * pow(b, 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 <= 9.4d+14) then
tmp = (a ** 4.0d0) + (-1.0d0)
else if (b <= 9.5d+151) then
tmp = a ** 8.0d0
else
tmp = 4.0d0 * (b ** 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 9.4e+14) {
tmp = Math.pow(a, 4.0) + -1.0;
} else if (b <= 9.5e+151) {
tmp = Math.pow(a, 8.0);
} else {
tmp = 4.0 * Math.pow(b, 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 9.4e+14: tmp = math.pow(a, 4.0) + -1.0 elif b <= 9.5e+151: tmp = math.pow(a, 8.0) else: tmp = 4.0 * math.pow(b, 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 9.4e+14) tmp = Float64((a ^ 4.0) + -1.0); elseif (b <= 9.5e+151) tmp = a ^ 8.0; else tmp = Float64(4.0 * (b ^ 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 9.4e+14) tmp = (a ^ 4.0) + -1.0; elseif (b <= 9.5e+151) tmp = a ^ 8.0; else tmp = 4.0 * (b ^ 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 9.4e+14], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[b, 9.5e+151], N[Power[a, 8.0], $MachinePrecision], N[(4.0 * N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9.4 \cdot 10^{+14}:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{+151}:\\
\;\;\;\;{a}^{8}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot {b}^{2}\\
\end{array}
\end{array}
if b < 9.4e14Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 81.7%
if 9.4e14 < b < 9.5000000000000001e151Initial program 99.6%
associate--l+99.6%
sqr-pow99.6%
sqr-pow99.6%
unpow299.6%
unpow199.6%
sqr-pow99.6%
associate-*r*99.6%
Simplified100.0%
Taylor expanded in b around 0 24.8%
flip--12.4%
div-inv12.4%
metadata-eval12.4%
sub-neg12.4%
pow-prod-up12.4%
metadata-eval12.4%
metadata-eval12.4%
Applied egg-rr12.4%
Taylor expanded in a around 0 35.5%
Taylor expanded in a around inf 36.1%
if 9.5000000000000001e151 < b Initial program 100.0%
associate--l+100.0%
unpow2100.0%
unpow1100.0%
sqr-pow100.0%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in a around inf 73.5%
Taylor expanded in b around inf 100.0%
Final simplification79.5%
(FPCore (a b) :precision binary64 (if (<= a 1.0) -1.0 (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 1.0) {
tmp = -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.0d0) then
tmp = -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.0) {
tmp = -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 1.0: tmp = -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 1.0) tmp = -1.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= 1.0) tmp = -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 1.0], -1.0, N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 1Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 64.6%
Taylor expanded in a around 0 31.9%
if 1 < a Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in b around 0 90.7%
Taylor expanded in a around inf 89.4%
Final simplification47.9%
(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 99.9%
associate--l+99.9%
sqr-pow99.9%
sqr-pow99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Taylor expanded in b around 0 71.8%
Taylor expanded in a around 0 23.3%
Final simplification23.3%
herbie shell --seed 2023314
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))