
(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 6 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%
Simplified100.0%
Final simplification100.0%
(FPCore (a b)
:precision binary64
(if (<= a 2.1e-111)
(pow b 4.0)
(if (<= a 2.35e-87)
-1.0
(if (<= a 9e-31) (pow b 4.0) (if (<= a 1.0) -1.0 (pow a 4.0))))))
double code(double a, double b) {
double tmp;
if (a <= 2.1e-111) {
tmp = pow(b, 4.0);
} else if (a <= 2.35e-87) {
tmp = -1.0;
} else if (a <= 9e-31) {
tmp = pow(b, 4.0);
} else 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 <= 2.1d-111) then
tmp = b ** 4.0d0
else if (a <= 2.35d-87) then
tmp = -1.0d0
else if (a <= 9d-31) then
tmp = b ** 4.0d0
else 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 <= 2.1e-111) {
tmp = Math.pow(b, 4.0);
} else if (a <= 2.35e-87) {
tmp = -1.0;
} else if (a <= 9e-31) {
tmp = Math.pow(b, 4.0);
} else if (a <= 1.0) {
tmp = -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= 2.1e-111: tmp = math.pow(b, 4.0) elif a <= 2.35e-87: tmp = -1.0 elif a <= 9e-31: tmp = math.pow(b, 4.0) elif a <= 1.0: tmp = -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (a <= 2.1e-111) tmp = b ^ 4.0; elseif (a <= 2.35e-87) tmp = -1.0; elseif (a <= 9e-31) tmp = b ^ 4.0; elseif (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 <= 2.1e-111) tmp = b ^ 4.0; elseif (a <= 2.35e-87) tmp = -1.0; elseif (a <= 9e-31) tmp = b ^ 4.0; elseif (a <= 1.0) tmp = -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, 2.1e-111], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, 2.35e-87], -1.0, If[LessEqual[a, 9e-31], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, 1.0], -1.0, N[Power[a, 4.0], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.1 \cdot 10^{-111}:\\
\;\;\;\;{b}^{4}\\
\mathbf{elif}\;a \leq 2.35 \cdot 10^{-87}:\\
\;\;\;\;-1\\
\mathbf{elif}\;a \leq 9 \cdot 10^{-31}:\\
\;\;\;\;{b}^{4}\\
\mathbf{elif}\;a \leq 1:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 2.0999999999999999e-111 or 2.35e-87 < a < 9.0000000000000008e-31Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around 0 72.9%
Taylor expanded in b around inf 46.8%
if 2.0999999999999999e-111 < a < 2.35e-87 or 9.0000000000000008e-31 < a < 1Initial program 100.0%
associate--l+100.0%
sqr-pow100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 77.1%
if 1 < a Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around inf 97.0%
Taylor expanded in a around inf 89.5%
Final simplification58.9%
(FPCore (a b) :precision binary64 (if (<= b 26000000000.0) (+ (pow a 4.0) -1.0) (if (or (<= b 1.3e+50) (not (<= b 1.75e+72))) (pow b 4.0) (pow a 4.0))))
double code(double a, double b) {
double tmp;
if (b <= 26000000000.0) {
tmp = pow(a, 4.0) + -1.0;
} else if ((b <= 1.3e+50) || !(b <= 1.75e+72)) {
tmp = pow(b, 4.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 (b <= 26000000000.0d0) then
tmp = (a ** 4.0d0) + (-1.0d0)
else if ((b <= 1.3d+50) .or. (.not. (b <= 1.75d+72))) then
tmp = b ** 4.0d0
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 26000000000.0) {
tmp = Math.pow(a, 4.0) + -1.0;
} else if ((b <= 1.3e+50) || !(b <= 1.75e+72)) {
tmp = Math.pow(b, 4.0);
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 26000000000.0: tmp = math.pow(a, 4.0) + -1.0 elif (b <= 1.3e+50) or not (b <= 1.75e+72): tmp = math.pow(b, 4.0) else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 26000000000.0) tmp = Float64((a ^ 4.0) + -1.0); elseif ((b <= 1.3e+50) || !(b <= 1.75e+72)) tmp = b ^ 4.0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 26000000000.0) tmp = (a ^ 4.0) + -1.0; elseif ((b <= 1.3e+50) || ~((b <= 1.75e+72))) tmp = b ^ 4.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 26000000000.0], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], If[Or[LessEqual[b, 1.3e+50], N[Not[LessEqual[b, 1.75e+72]], $MachinePrecision]], N[Power[b, 4.0], $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 26000000000:\\
\;\;\;\;{a}^{4} + -1\\
\mathbf{elif}\;b \leq 1.3 \cdot 10^{+50} \lor \neg \left(b \leq 1.75 \cdot 10^{+72}\right):\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if b < 2.6e10Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around inf 91.5%
Taylor expanded in b around 0 81.0%
if 2.6e10 < b < 1.3000000000000001e50 or 1.75000000000000005e72 < b Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around 0 91.4%
Taylor expanded in b around inf 91.4%
if 1.3000000000000001e50 < b < 1.75000000000000005e72Initial program 99.8%
associate--l+99.8%
sqr-pow99.8%
Simplified100.0%
Taylor expanded in a around inf 78.9%
Taylor expanded in a around inf 78.2%
Final simplification83.3%
(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.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%
Simplified100.0%
Taylor expanded in a around 0 74.8%
Taylor expanded in b around 0 30.8%
if 1 < a Initial program 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around inf 97.0%
Taylor expanded in a around inf 89.5%
Final simplification45.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 99.9%
associate--l+99.9%
sqr-pow99.9%
Simplified100.0%
Taylor expanded in a around 0 64.8%
Taylor expanded in b around 0 23.4%
Final simplification23.4%
herbie shell --seed 2024017
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))