
(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 10 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%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*99.9%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= (* b b) 5e+15) (+ -1.0 (pow a 4.0)) (+ (pow b 4.0) (* 2.0 (* (* a b) (* a b))))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 5e+15) {
tmp = -1.0 + pow(a, 4.0);
} else {
tmp = pow(b, 4.0) + (2.0 * ((a * b) * (a * b)));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b * b) <= 5d+15) then
tmp = (-1.0d0) + (a ** 4.0d0)
else
tmp = (b ** 4.0d0) + (2.0d0 * ((a * b) * (a * b)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 5e+15) {
tmp = -1.0 + Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0) + (2.0 * ((a * b) * (a * b)));
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 5e+15: tmp = -1.0 + math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) + (2.0 * ((a * b) * (a * b))) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 5e+15) tmp = Float64(-1.0 + (a ^ 4.0)); else tmp = Float64((b ^ 4.0) + Float64(2.0 * Float64(Float64(a * b) * Float64(a * b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 5e+15) tmp = -1.0 + (a ^ 4.0); else tmp = (b ^ 4.0) + (2.0 * ((a * b) * (a * b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 5e+15], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[(N[Power[b, 4.0], $MachinePrecision] + N[(2.0 * N[(N[(a * b), $MachinePrecision] * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 5 \cdot 10^{+15}:\\
\;\;\;\;-1 + {a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4} + 2 \cdot \left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 5e15Initial 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 98.2%
if 5e15 < (*.f64 b b) Initial 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 inf 97.7%
*-commutative97.7%
unpow297.7%
unpow297.7%
Simplified97.7%
Taylor expanded in a around inf 89.2%
unpow289.2%
unpow289.2%
unswap-sqr97.7%
Simplified97.7%
Final simplification97.9%
(FPCore (a b) :precision binary64 (+ -1.0 (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b)))))
double code(double a, double b) {
return -1.0 + (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (b * b)))
end function
public static double code(double a, double b) {
return -1.0 + (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)));
}
def code(a, b): return -1.0 + (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b)))
function code(a, b) return Float64(-1.0 + Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b)))) end
function tmp = code(a, b) tmp = -1.0 + ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))); end
code[a_, b_] := N[(-1.0 + 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]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ -1.0 (* b (* b 4.0)))))
(if (<= a -2.8e+41)
(pow a 4.0)
(if (<= a -9.4e-122)
t_0
(if (<= a -9e-182)
(* (* b b) (+ 4.0 (* b b)))
(if (<= a 4.7e+39) t_0 (pow a 4.0)))))))
double code(double a, double b) {
double t_0 = -1.0 + (b * (b * 4.0));
double tmp;
if (a <= -2.8e+41) {
tmp = pow(a, 4.0);
} else if (a <= -9.4e-122) {
tmp = t_0;
} else if (a <= -9e-182) {
tmp = (b * b) * (4.0 + (b * b));
} else if (a <= 4.7e+39) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (-1.0d0) + (b * (b * 4.0d0))
if (a <= (-2.8d+41)) then
tmp = a ** 4.0d0
else if (a <= (-9.4d-122)) then
tmp = t_0
else if (a <= (-9d-182)) then
tmp = (b * b) * (4.0d0 + (b * b))
else if (a <= 4.7d+39) then
tmp = t_0
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = -1.0 + (b * (b * 4.0));
double tmp;
if (a <= -2.8e+41) {
tmp = Math.pow(a, 4.0);
} else if (a <= -9.4e-122) {
tmp = t_0;
} else if (a <= -9e-182) {
tmp = (b * b) * (4.0 + (b * b));
} else if (a <= 4.7e+39) {
tmp = t_0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): t_0 = -1.0 + (b * (b * 4.0)) tmp = 0 if a <= -2.8e+41: tmp = math.pow(a, 4.0) elif a <= -9.4e-122: tmp = t_0 elif a <= -9e-182: tmp = (b * b) * (4.0 + (b * b)) elif a <= 4.7e+39: tmp = t_0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) t_0 = Float64(-1.0 + Float64(b * Float64(b * 4.0))) tmp = 0.0 if (a <= -2.8e+41) tmp = a ^ 4.0; elseif (a <= -9.4e-122) tmp = t_0; elseif (a <= -9e-182) tmp = Float64(Float64(b * b) * Float64(4.0 + Float64(b * b))); elseif (a <= 4.7e+39) tmp = t_0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) t_0 = -1.0 + (b * (b * 4.0)); tmp = 0.0; if (a <= -2.8e+41) tmp = a ^ 4.0; elseif (a <= -9.4e-122) tmp = t_0; elseif (a <= -9e-182) tmp = (b * b) * (4.0 + (b * b)); elseif (a <= 4.7e+39) tmp = t_0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(-1.0 + N[(b * N[(b * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -2.8e+41], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[a, -9.4e-122], t$95$0, If[LessEqual[a, -9e-182], N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 4.7e+39], t$95$0, N[Power[a, 4.0], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + b \cdot \left(b \cdot 4\right)\\
\mathbf{if}\;a \leq -2.8 \cdot 10^{+41}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;a \leq -9.4 \cdot 10^{-122}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;a \leq -9 \cdot 10^{-182}:\\
\;\;\;\;\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)\\
\mathbf{elif}\;a \leq 4.7 \cdot 10^{+39}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < -2.7999999999999999e41 or 4.6999999999999999e39 < a Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in a around inf 96.2%
if -2.7999999999999999e41 < a < -9.3999999999999999e-122 or -8.9999999999999998e-182 < a < 4.6999999999999999e39Initial 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 0 77.7%
Taylor expanded in b around 0 71.3%
fma-neg71.3%
unpow271.3%
metadata-eval71.3%
Simplified71.3%
fma-udef71.3%
associate-*r*71.3%
*-commutative71.3%
*-commutative71.3%
Applied egg-rr71.3%
if -9.3999999999999999e-122 < a < -8.9999999999999998e-182Initial 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 inf 87.0%
*-commutative87.0%
unpow287.0%
unpow287.0%
Simplified87.0%
Taylor expanded in a around 0 87.0%
unpow287.0%
Simplified87.0%
+-commutative87.0%
metadata-eval87.0%
pow-prod-up86.9%
pow286.9%
pow286.9%
distribute-rgt-out86.9%
Applied egg-rr86.9%
Final simplification81.5%
(FPCore (a b)
:precision binary64
(let* ((t_0 (+ -1.0 (* b (* b 4.0)))))
(if (<= a -2.8e+41)
(pow a 4.0)
(if (<= a -1.46e-120)
t_0
(if (<= a -2.1e-181)
(pow b 4.0)
(if (<= a 4.2e+39) t_0 (pow a 4.0)))))))
double code(double a, double b) {
double t_0 = -1.0 + (b * (b * 4.0));
double tmp;
if (a <= -2.8e+41) {
tmp = pow(a, 4.0);
} else if (a <= -1.46e-120) {
tmp = t_0;
} else if (a <= -2.1e-181) {
tmp = pow(b, 4.0);
} else if (a <= 4.2e+39) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (-1.0d0) + (b * (b * 4.0d0))
if (a <= (-2.8d+41)) then
tmp = a ** 4.0d0
else if (a <= (-1.46d-120)) then
tmp = t_0
else if (a <= (-2.1d-181)) then
tmp = b ** 4.0d0
else if (a <= 4.2d+39) then
tmp = t_0
else
tmp = a ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = -1.0 + (b * (b * 4.0));
double tmp;
if (a <= -2.8e+41) {
tmp = Math.pow(a, 4.0);
} else if (a <= -1.46e-120) {
tmp = t_0;
} else if (a <= -2.1e-181) {
tmp = Math.pow(b, 4.0);
} else if (a <= 4.2e+39) {
tmp = t_0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): t_0 = -1.0 + (b * (b * 4.0)) tmp = 0 if a <= -2.8e+41: tmp = math.pow(a, 4.0) elif a <= -1.46e-120: tmp = t_0 elif a <= -2.1e-181: tmp = math.pow(b, 4.0) elif a <= 4.2e+39: tmp = t_0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) t_0 = Float64(-1.0 + Float64(b * Float64(b * 4.0))) tmp = 0.0 if (a <= -2.8e+41) tmp = a ^ 4.0; elseif (a <= -1.46e-120) tmp = t_0; elseif (a <= -2.1e-181) tmp = b ^ 4.0; elseif (a <= 4.2e+39) tmp = t_0; else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) t_0 = -1.0 + (b * (b * 4.0)); tmp = 0.0; if (a <= -2.8e+41) tmp = a ^ 4.0; elseif (a <= -1.46e-120) tmp = t_0; elseif (a <= -2.1e-181) tmp = b ^ 4.0; elseif (a <= 4.2e+39) tmp = t_0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(-1.0 + N[(b * N[(b * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -2.8e+41], N[Power[a, 4.0], $MachinePrecision], If[LessEqual[a, -1.46e-120], t$95$0, If[LessEqual[a, -2.1e-181], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, 4.2e+39], t$95$0, N[Power[a, 4.0], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + b \cdot \left(b \cdot 4\right)\\
\mathbf{if}\;a \leq -2.8 \cdot 10^{+41}:\\
\;\;\;\;{a}^{4}\\
\mathbf{elif}\;a \leq -1.46 \cdot 10^{-120}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;a \leq -2.1 \cdot 10^{-181}:\\
\;\;\;\;{b}^{4}\\
\mathbf{elif}\;a \leq 4.2 \cdot 10^{+39}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < -2.7999999999999999e41 or 4.1999999999999997e39 < a Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in a around inf 96.2%
if -2.7999999999999999e41 < a < -1.4599999999999999e-120 or -2.10000000000000003e-181 < a < 4.1999999999999997e39Initial 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 0 77.7%
Taylor expanded in b around 0 71.3%
fma-neg71.3%
unpow271.3%
metadata-eval71.3%
Simplified71.3%
fma-udef71.3%
associate-*r*71.3%
*-commutative71.3%
*-commutative71.3%
Applied egg-rr71.3%
if -1.4599999999999999e-120 < a < -2.10000000000000003e-181Initial 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 inf 87.0%
Final simplification81.6%
(FPCore (a b) :precision binary64 (if (<= (* b b) 5e+15) (+ -1.0 (pow a 4.0)) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 5e+15) {
tmp = -1.0 + 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 * b) <= 5d+15) then
tmp = (-1.0d0) + (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 * b) <= 5e+15) {
tmp = -1.0 + Math.pow(a, 4.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 5e+15: tmp = -1.0 + math.pow(a, 4.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 5e+15) tmp = Float64(-1.0 + (a ^ 4.0)); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 5e+15) tmp = -1.0 + (a ^ 4.0); else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 5e+15], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 5 \cdot 10^{+15}:\\
\;\;\;\;-1 + {a}^{4}\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 5e15Initial 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 98.2%
if 5e15 < (*.f64 b b) Initial 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 inf 92.2%
Final simplification95.2%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1e-10) (+ -1.0 (* b (* b 4.0))) (* (* b b) (+ 4.0 (* b b)))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1e-10) {
tmp = -1.0 + (b * (b * 4.0));
} else {
tmp = (b * b) * (4.0 + (b * b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if ((b * b) <= 1d-10) then
tmp = (-1.0d0) + (b * (b * 4.0d0))
else
tmp = (b * b) * (4.0d0 + (b * b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 1e-10) {
tmp = -1.0 + (b * (b * 4.0));
} else {
tmp = (b * b) * (4.0 + (b * b));
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1e-10: tmp = -1.0 + (b * (b * 4.0)) else: tmp = (b * b) * (4.0 + (b * b)) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1e-10) tmp = Float64(-1.0 + Float64(b * Float64(b * 4.0))); else tmp = Float64(Float64(b * b) * Float64(4.0 + Float64(b * b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1e-10) tmp = -1.0 + (b * (b * 4.0)); else tmp = (b * b) * (4.0 + (b * b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1e-10], N[(-1.0 + N[(b * N[(b * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * b), $MachinePrecision] * N[(4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 10^{-10}:\\
\;\;\;\;-1 + b \cdot \left(b \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 1.00000000000000004e-10Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in a around 0 60.8%
Taylor expanded in b around 0 60.7%
fma-neg60.7%
unpow260.7%
metadata-eval60.7%
Simplified60.7%
fma-udef60.7%
associate-*r*60.7%
*-commutative60.7%
*-commutative60.7%
Applied egg-rr60.7%
if 1.00000000000000004e-10 < (*.f64 b b) Initial 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 inf 96.0%
*-commutative96.0%
unpow296.0%
unpow296.0%
Simplified96.0%
Taylor expanded in a around 0 90.6%
unpow290.6%
Simplified90.6%
+-commutative90.6%
metadata-eval90.6%
pow-prod-up90.5%
pow290.5%
pow290.5%
distribute-rgt-out90.5%
Applied egg-rr90.5%
Final simplification76.3%
(FPCore (a b) :precision binary64 (if (or (<= b -0.48) (not (<= b 3.2e-15))) (* b (* b 4.0)) -1.0))
double code(double a, double b) {
double tmp;
if ((b <= -0.48) || !(b <= 3.2e-15)) {
tmp = b * (b * 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 ((b <= (-0.48d0)) .or. (.not. (b <= 3.2d-15))) then
tmp = b * (b * 4.0d0)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b <= -0.48) || !(b <= 3.2e-15)) {
tmp = b * (b * 4.0);
} else {
tmp = -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b <= -0.48) or not (b <= 3.2e-15): tmp = b * (b * 4.0) else: tmp = -1.0 return tmp
function code(a, b) tmp = 0.0 if ((b <= -0.48) || !(b <= 3.2e-15)) tmp = Float64(b * Float64(b * 4.0)); else tmp = -1.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b <= -0.48) || ~((b <= 3.2e-15))) tmp = b * (b * 4.0); else tmp = -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[b, -0.48], N[Not[LessEqual[b, 3.2e-15]], $MachinePrecision]], N[(b * N[(b * 4.0), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.48 \lor \neg \left(b \leq 3.2 \cdot 10^{-15}\right):\\
\;\;\;\;b \cdot \left(b \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if b < -0.47999999999999998 or 3.1999999999999999e-15 < b Initial 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 inf 95.3%
*-commutative95.3%
unpow295.3%
unpow295.3%
Simplified95.3%
Taylor expanded in a around 0 89.4%
unpow289.4%
Simplified89.4%
Taylor expanded in b around 0 48.3%
unpow248.3%
*-commutative48.3%
associate-*r*48.3%
Simplified48.3%
if -0.47999999999999998 < b < 3.1999999999999999e-15Initial program 99.9%
associate--l+99.9%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*l*100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in a around 0 61.7%
Taylor expanded in b around 0 61.4%
Final simplification54.4%
(FPCore (a b) :precision binary64 (+ -1.0 (* b (* b 4.0))))
double code(double a, double b) {
return -1.0 + (b * (b * 4.0));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + (b * (b * 4.0d0))
end function
public static double code(double a, double b) {
return -1.0 + (b * (b * 4.0));
}
def code(a, b): return -1.0 + (b * (b * 4.0))
function code(a, b) return Float64(-1.0 + Float64(b * Float64(b * 4.0))) end
function tmp = code(a, b) tmp = -1.0 + (b * (b * 4.0)); end
code[a_, b_] := N[(-1.0 + N[(b * N[(b * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + b \cdot \left(b \cdot 4\right)
\end{array}
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 0 60.5%
Taylor expanded in b around 0 54.5%
fma-neg54.5%
unpow254.5%
metadata-eval54.5%
Simplified54.5%
fma-udef54.5%
associate-*r*54.5%
*-commutative54.5%
*-commutative54.5%
Applied egg-rr54.5%
Final simplification54.5%
(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%
unpow299.9%
unpow199.9%
sqr-pow99.9%
associate-*l*99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in a around 0 60.5%
Taylor expanded in b around 0 29.2%
Final simplification29.2%
herbie shell --seed 2023194
(FPCore (a b)
:name "Bouland and Aaronson, Equation (26)"
:precision binary64
(- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))