
(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 9 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 (<= a 5.1e+45) (+ (pow (fma a a (* b b)) 2.0) (+ (* 4.0 (* (pow a 2.0) (- 1.0 a))) -1.0)) (pow a 4.0)))
double code(double a, double b) {
double tmp;
if (a <= 5.1e+45) {
tmp = pow(fma(a, a, (b * b)), 2.0) + ((4.0 * (pow(a, 2.0) * (1.0 - a))) + -1.0);
} else {
tmp = pow(a, 4.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (a <= 5.1e+45) tmp = Float64((fma(a, a, Float64(b * b)) ^ 2.0) + Float64(Float64(4.0 * Float64((a ^ 2.0) * Float64(1.0 - a))) + -1.0)); else tmp = a ^ 4.0; end return tmp end
code[a_, b_] := If[LessEqual[a, 5.1e+45], N[(N[Power[N[(a * a + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(4.0 * N[(N[Power[a, 2.0], $MachinePrecision] * N[(1.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 5.1 \cdot 10^{+45}:\\
\;\;\;\;{\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(4 \cdot \left({a}^{2} \cdot \left(1 - a\right)\right) + -1\right)\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if a < 5.0999999999999997e45Initial program 88.9%
associate--l+88.9%
fma-define88.9%
sqr-neg88.9%
fma-define88.9%
distribute-rgt-in88.9%
sqr-neg88.9%
distribute-rgt-in88.9%
fma-define88.9%
sqr-neg88.9%
Simplified88.9%
Taylor expanded in b around 0 99.3%
if 5.0999999999999997e45 < a Initial program 25.4%
associate--l+25.4%
fma-define25.4%
sqr-neg25.4%
fma-define25.4%
distribute-rgt-in25.4%
sqr-neg25.4%
distribute-rgt-in25.4%
fma-define25.4%
sqr-neg25.4%
Simplified39.9%
Taylor expanded in a around inf 100.0%
Final simplification99.5%
(FPCore (a b)
:precision binary64
(let* ((t_0
(+
(pow (+ (* b b) (* a a)) 2.0)
(* 4.0 (+ (* (- 1.0 a) (* a a)) (* (* b b) (+ a 3.0)))))))
(if (<= t_0 INFINITY) (+ t_0 -1.0) (pow a 4.0))))
double code(double a, double b) {
double t_0 = pow(((b * b) + (a * a)), 2.0) + (4.0 * (((1.0 - a) * (a * a)) + ((b * b) * (a + 3.0))));
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0 + -1.0;
} else {
tmp = pow(a, 4.0);
}
return tmp;
}
public static double code(double a, double b) {
double t_0 = Math.pow(((b * b) + (a * a)), 2.0) + (4.0 * (((1.0 - a) * (a * a)) + ((b * b) * (a + 3.0))));
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0 + -1.0;
} else {
tmp = Math.pow(a, 4.0);
}
return tmp;
}
def code(a, b): t_0 = math.pow(((b * b) + (a * a)), 2.0) + (4.0 * (((1.0 - a) * (a * a)) + ((b * b) * (a + 3.0)))) tmp = 0 if t_0 <= math.inf: tmp = t_0 + -1.0 else: tmp = math.pow(a, 4.0) return tmp
function code(a, b) t_0 = Float64((Float64(Float64(b * b) + Float64(a * a)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(1.0 - a) * Float64(a * a)) + Float64(Float64(b * b) * Float64(a + 3.0))))) tmp = 0.0 if (t_0 <= Inf) tmp = Float64(t_0 + -1.0); else tmp = a ^ 4.0; end return tmp end
function tmp_2 = code(a, b) t_0 = (((b * b) + (a * a)) ^ 2.0) + (4.0 * (((1.0 - a) * (a * a)) + ((b * b) * (a + 3.0)))); tmp = 0.0; if (t_0 <= Inf) tmp = t_0 + -1.0; else tmp = a ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(N[Power[N[(N[(b * b), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(1.0 - a), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(a + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], N[(t$95$0 + -1.0), $MachinePrecision], N[Power[a, 4.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left(b \cdot b + a \cdot a\right)}^{2} + 4 \cdot \left(\left(1 - a\right) \cdot \left(a \cdot a\right) + \left(b \cdot b\right) \cdot \left(a + 3\right)\right)\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0 + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{4}\\
\end{array}
\end{array}
if (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) #s(literal 2 binary64)) (*.f64 #s(literal 4 binary64) (+.f64 (*.f64 (*.f64 a a) (-.f64 #s(literal 1 binary64) a)) (*.f64 (*.f64 b b) (+.f64 #s(literal 3 binary64) a))))) < +inf.0Initial program 99.8%
if +inf.0 < (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) #s(literal 2 binary64)) (*.f64 #s(literal 4 binary64) (+.f64 (*.f64 (*.f64 a a) (-.f64 #s(literal 1 binary64) a)) (*.f64 (*.f64 b b) (+.f64 #s(literal 3 binary64) a))))) Initial program 0.0%
associate--l+0.0%
fma-define0.0%
sqr-neg0.0%
fma-define0.0%
distribute-rgt-in0.0%
sqr-neg0.0%
distribute-rgt-in0.0%
fma-define0.0%
sqr-neg0.0%
Simplified12.7%
Taylor expanded in a around inf 95.5%
Final simplification98.8%
(FPCore (a b)
:precision binary64
(if (<= b 8000.0)
(+ (* (pow a 2.0) (+ 4.0 (* a (- a 4.0)))) -1.0)
(if (or (<= b 5.5e+34) (not (<= b 5.8e+64)))
(pow b 4.0)
(* (- a 4.0) (pow a 3.0)))))
double code(double a, double b) {
double tmp;
if (b <= 8000.0) {
tmp = (pow(a, 2.0) * (4.0 + (a * (a - 4.0)))) + -1.0;
} else if ((b <= 5.5e+34) || !(b <= 5.8e+64)) {
tmp = pow(b, 4.0);
} else {
tmp = (a - 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 <= 8000.0d0) then
tmp = ((a ** 2.0d0) * (4.0d0 + (a * (a - 4.0d0)))) + (-1.0d0)
else if ((b <= 5.5d+34) .or. (.not. (b <= 5.8d+64))) then
tmp = b ** 4.0d0
else
tmp = (a - 4.0d0) * (a ** 3.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 8000.0) {
tmp = (Math.pow(a, 2.0) * (4.0 + (a * (a - 4.0)))) + -1.0;
} else if ((b <= 5.5e+34) || !(b <= 5.8e+64)) {
tmp = Math.pow(b, 4.0);
} else {
tmp = (a - 4.0) * Math.pow(a, 3.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 8000.0: tmp = (math.pow(a, 2.0) * (4.0 + (a * (a - 4.0)))) + -1.0 elif (b <= 5.5e+34) or not (b <= 5.8e+64): tmp = math.pow(b, 4.0) else: tmp = (a - 4.0) * math.pow(a, 3.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 8000.0) tmp = Float64(Float64((a ^ 2.0) * Float64(4.0 + Float64(a * Float64(a - 4.0)))) + -1.0); elseif ((b <= 5.5e+34) || !(b <= 5.8e+64)) tmp = b ^ 4.0; else tmp = Float64(Float64(a - 4.0) * (a ^ 3.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 8000.0) tmp = ((a ^ 2.0) * (4.0 + (a * (a - 4.0)))) + -1.0; elseif ((b <= 5.5e+34) || ~((b <= 5.8e+64))) tmp = b ^ 4.0; else tmp = (a - 4.0) * (a ^ 3.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 8000.0], N[(N[(N[Power[a, 2.0], $MachinePrecision] * N[(4.0 + N[(a * N[(a - 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[Or[LessEqual[b, 5.5e+34], N[Not[LessEqual[b, 5.8e+64]], $MachinePrecision]], N[Power[b, 4.0], $MachinePrecision], N[(N[(a - 4.0), $MachinePrecision] * N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8000:\\
\;\;\;\;{a}^{2} \cdot \left(4 + a \cdot \left(a - 4\right)\right) + -1\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{+34} \lor \neg \left(b \leq 5.8 \cdot 10^{+64}\right):\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;\left(a - 4\right) \cdot {a}^{3}\\
\end{array}
\end{array}
if b < 8e3Initial program 78.7%
associate--l+78.8%
fma-define78.8%
sqr-neg78.8%
fma-define78.8%
distribute-rgt-in78.8%
sqr-neg78.8%
distribute-rgt-in78.8%
fma-define78.8%
sqr-neg78.8%
Simplified80.8%
Taylor expanded in b around 0 64.4%
Taylor expanded in a around 0 80.9%
if 8e3 < b < 5.4999999999999996e34 or 5.79999999999999986e64 < b Initial program 64.1%
associate--l+64.1%
fma-define64.1%
sqr-neg64.1%
fma-define64.1%
distribute-rgt-in64.1%
sqr-neg64.1%
distribute-rgt-in64.1%
fma-define64.1%
sqr-neg64.1%
Simplified71.7%
Taylor expanded in b around inf 99.3%
if 5.4999999999999996e34 < b < 5.79999999999999986e64Initial program 50.0%
associate--l+50.0%
fma-define50.0%
sqr-neg50.0%
fma-define50.0%
distribute-rgt-in50.0%
sqr-neg50.0%
distribute-rgt-in50.0%
fma-define50.0%
sqr-neg50.0%
Simplified50.0%
Taylor expanded in a around inf 75.6%
associate-*r/75.6%
metadata-eval75.6%
Simplified75.6%
Taylor expanded in a around 0 75.6%
Final simplification84.7%
(FPCore (a b)
:precision binary64
(if (<= b 8000.0)
(fma (* a 4.0) a -1.0)
(if (or (<= b 7.6e+34) (not (<= b 2.6e+64)))
(pow b 4.0)
(* (- a 4.0) (pow a 3.0)))))
double code(double a, double b) {
double tmp;
if (b <= 8000.0) {
tmp = fma((a * 4.0), a, -1.0);
} else if ((b <= 7.6e+34) || !(b <= 2.6e+64)) {
tmp = pow(b, 4.0);
} else {
tmp = (a - 4.0) * pow(a, 3.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 8000.0) tmp = fma(Float64(a * 4.0), a, -1.0); elseif ((b <= 7.6e+34) || !(b <= 2.6e+64)) tmp = b ^ 4.0; else tmp = Float64(Float64(a - 4.0) * (a ^ 3.0)); end return tmp end
code[a_, b_] := If[LessEqual[b, 8000.0], N[(N[(a * 4.0), $MachinePrecision] * a + -1.0), $MachinePrecision], If[Or[LessEqual[b, 7.6e+34], N[Not[LessEqual[b, 2.6e+64]], $MachinePrecision]], N[Power[b, 4.0], $MachinePrecision], N[(N[(a - 4.0), $MachinePrecision] * N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8000:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 4, a, -1\right)\\
\mathbf{elif}\;b \leq 7.6 \cdot 10^{+34} \lor \neg \left(b \leq 2.6 \cdot 10^{+64}\right):\\
\;\;\;\;{b}^{4}\\
\mathbf{else}:\\
\;\;\;\;\left(a - 4\right) \cdot {a}^{3}\\
\end{array}
\end{array}
if b < 8e3Initial program 78.7%
associate--l+78.8%
fma-define78.8%
sqr-neg78.8%
fma-define78.8%
distribute-rgt-in78.8%
sqr-neg78.8%
distribute-rgt-in78.8%
fma-define78.8%
sqr-neg78.8%
Simplified80.8%
Taylor expanded in b around 0 64.4%
Taylor expanded in a around 0 58.7%
add-sqr-sqrt58.7%
difference-of-sqr-158.6%
*-commutative58.6%
sqrt-prod58.6%
sqrt-pow142.3%
metadata-eval42.3%
pow142.3%
metadata-eval42.3%
*-commutative42.3%
sqrt-prod42.3%
sqrt-pow158.6%
metadata-eval58.6%
pow158.6%
metadata-eval58.6%
Applied egg-rr58.6%
difference-of-sqr-158.7%
swap-sqr58.7%
unpow258.7%
metadata-eval58.7%
*-commutative58.7%
unpow258.7%
associate-*r*58.7%
fma-neg58.7%
metadata-eval58.7%
Applied egg-rr58.7%
if 8e3 < b < 7.6000000000000003e34 or 2.59999999999999997e64 < b Initial program 64.1%
associate--l+64.1%
fma-define64.1%
sqr-neg64.1%
fma-define64.1%
distribute-rgt-in64.1%
sqr-neg64.1%
distribute-rgt-in64.1%
fma-define64.1%
sqr-neg64.1%
Simplified71.7%
Taylor expanded in b around inf 99.3%
if 7.6000000000000003e34 < b < 2.59999999999999997e64Initial program 50.0%
associate--l+50.0%
fma-define50.0%
sqr-neg50.0%
fma-define50.0%
distribute-rgt-in50.0%
sqr-neg50.0%
distribute-rgt-in50.0%
fma-define50.0%
sqr-neg50.0%
Simplified50.0%
Taylor expanded in a around inf 75.6%
associate-*r/75.6%
metadata-eval75.6%
Simplified75.6%
Taylor expanded in a around 0 75.6%
Final simplification67.3%
(FPCore (a b) :precision binary64 (if (or (<= a -9.8e-8) (not (<= a 5.0))) (pow a 4.0) (* (+ 1.0 (* a 2.0)) (+ (* a 2.0) -1.0))))
double code(double a, double b) {
double tmp;
if ((a <= -9.8e-8) || !(a <= 5.0)) {
tmp = pow(a, 4.0);
} else {
tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -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 <= (-9.8d-8)) .or. (.not. (a <= 5.0d0))) then
tmp = a ** 4.0d0
else
tmp = (1.0d0 + (a * 2.0d0)) * ((a * 2.0d0) + (-1.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((a <= -9.8e-8) || !(a <= 5.0)) {
tmp = Math.pow(a, 4.0);
} else {
tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (a <= -9.8e-8) or not (a <= 5.0): tmp = math.pow(a, 4.0) else: tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0) return tmp
function code(a, b) tmp = 0.0 if ((a <= -9.8e-8) || !(a <= 5.0)) tmp = a ^ 4.0; else tmp = Float64(Float64(1.0 + Float64(a * 2.0)) * Float64(Float64(a * 2.0) + -1.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((a <= -9.8e-8) || ~((a <= 5.0))) tmp = a ^ 4.0; else tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0); end tmp_2 = tmp; end
code[a_, b_] := If[Or[LessEqual[a, -9.8e-8], N[Not[LessEqual[a, 5.0]], $MachinePrecision]], N[Power[a, 4.0], $MachinePrecision], N[(N[(1.0 + N[(a * 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(a * 2.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -9.8 \cdot 10^{-8} \lor \neg \left(a \leq 5\right):\\
\;\;\;\;{a}^{4}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + a \cdot 2\right) \cdot \left(a \cdot 2 + -1\right)\\
\end{array}
\end{array}
if a < -9.8000000000000004e-8 or 5 < a Initial program 53.5%
associate--l+53.5%
fma-define53.5%
sqr-neg53.5%
fma-define53.5%
distribute-rgt-in53.5%
sqr-neg53.5%
distribute-rgt-in53.5%
fma-define53.5%
sqr-neg53.5%
Simplified59.4%
Taylor expanded in a around inf 88.1%
if -9.8000000000000004e-8 < a < 5Initial program 99.9%
associate--l+99.9%
fma-define99.9%
sqr-neg99.9%
fma-define99.9%
distribute-rgt-in99.9%
sqr-neg99.9%
distribute-rgt-in99.9%
fma-define99.9%
sqr-neg99.9%
Simplified99.9%
Taylor expanded in b around 0 52.6%
Taylor expanded in a around 0 51.9%
add-sqr-sqrt51.9%
difference-of-sqr-151.9%
*-commutative51.9%
sqrt-prod51.9%
sqrt-pow151.8%
metadata-eval51.8%
pow151.8%
metadata-eval51.8%
*-commutative51.8%
sqrt-prod51.8%
sqrt-pow151.9%
metadata-eval51.9%
pow151.9%
metadata-eval51.9%
Applied egg-rr51.9%
Final simplification71.1%
(FPCore (a b) :precision binary64 (if (<= b 7200.0) (fma (* a 4.0) a -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 7200.0) {
tmp = fma((a * 4.0), a, -1.0);
} else {
tmp = pow(b, 4.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (b <= 7200.0) tmp = fma(Float64(a * 4.0), a, -1.0); else tmp = b ^ 4.0; end return tmp end
code[a_, b_] := If[LessEqual[b, 7200.0], N[(N[(a * 4.0), $MachinePrecision] * a + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7200:\\
\;\;\;\;\mathsf{fma}\left(a \cdot 4, a, -1\right)\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 7200Initial program 78.7%
associate--l+78.8%
fma-define78.8%
sqr-neg78.8%
fma-define78.8%
distribute-rgt-in78.8%
sqr-neg78.8%
distribute-rgt-in78.8%
fma-define78.8%
sqr-neg78.8%
Simplified80.8%
Taylor expanded in b around 0 64.4%
Taylor expanded in a around 0 58.7%
add-sqr-sqrt58.7%
difference-of-sqr-158.6%
*-commutative58.6%
sqrt-prod58.6%
sqrt-pow142.3%
metadata-eval42.3%
pow142.3%
metadata-eval42.3%
*-commutative42.3%
sqrt-prod42.3%
sqrt-pow158.6%
metadata-eval58.6%
pow158.6%
metadata-eval58.6%
Applied egg-rr58.6%
difference-of-sqr-158.7%
swap-sqr58.7%
unpow258.7%
metadata-eval58.7%
*-commutative58.7%
unpow258.7%
associate-*r*58.7%
fma-neg58.7%
metadata-eval58.7%
Applied egg-rr58.7%
if 7200 < b Initial program 63.1%
associate--l+63.1%
fma-define63.1%
sqr-neg63.1%
fma-define63.1%
distribute-rgt-in63.1%
sqr-neg63.1%
distribute-rgt-in63.1%
fma-define63.1%
sqr-neg63.1%
Simplified70.1%
Taylor expanded in b around inf 94.3%
Final simplification66.6%
(FPCore (a b) :precision binary64 (if (<= b 7800.0) (* (+ 1.0 (* a 2.0)) (+ (* a 2.0) -1.0)) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if (b <= 7800.0) {
tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.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 <= 7800.0d0) then
tmp = (1.0d0 + (a * 2.0d0)) * ((a * 2.0d0) + (-1.0d0))
else
tmp = b ** 4.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 7800.0) {
tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0);
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 7800.0: tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0) else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 7800.0) tmp = Float64(Float64(1.0 + Float64(a * 2.0)) * Float64(Float64(a * 2.0) + -1.0)); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 7800.0) tmp = (1.0 + (a * 2.0)) * ((a * 2.0) + -1.0); else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 7800.0], N[(N[(1.0 + N[(a * 2.0), $MachinePrecision]), $MachinePrecision] * N[(N[(a * 2.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 7800:\\
\;\;\;\;\left(1 + a \cdot 2\right) \cdot \left(a \cdot 2 + -1\right)\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if b < 7800Initial program 78.7%
associate--l+78.8%
fma-define78.8%
sqr-neg78.8%
fma-define78.8%
distribute-rgt-in78.8%
sqr-neg78.8%
distribute-rgt-in78.8%
fma-define78.8%
sqr-neg78.8%
Simplified80.8%
Taylor expanded in b around 0 64.4%
Taylor expanded in a around 0 58.7%
add-sqr-sqrt58.7%
difference-of-sqr-158.6%
*-commutative58.6%
sqrt-prod58.6%
sqrt-pow142.3%
metadata-eval42.3%
pow142.3%
metadata-eval42.3%
*-commutative42.3%
sqrt-prod42.3%
sqrt-pow158.6%
metadata-eval58.6%
pow158.6%
metadata-eval58.6%
Applied egg-rr58.6%
if 7800 < b Initial program 63.1%
associate--l+63.1%
fma-define63.1%
sqr-neg63.1%
fma-define63.1%
distribute-rgt-in63.1%
sqr-neg63.1%
distribute-rgt-in63.1%
fma-define63.1%
sqr-neg63.1%
Simplified70.1%
Taylor expanded in b around inf 94.3%
Final simplification66.6%
(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 75.3%
associate--l+75.3%
fma-define75.3%
sqr-neg75.3%
fma-define75.3%
distribute-rgt-in75.3%
sqr-neg75.3%
distribute-rgt-in75.3%
fma-define75.3%
sqr-neg75.3%
Simplified78.4%
Taylor expanded in b around 0 56.1%
Taylor expanded in a around 0 51.5%
add-sqr-sqrt51.5%
difference-of-sqr-151.5%
*-commutative51.5%
sqrt-prod51.5%
sqrt-pow134.8%
metadata-eval34.8%
pow134.8%
metadata-eval34.8%
*-commutative34.8%
sqrt-prod34.8%
sqrt-pow151.5%
metadata-eval51.5%
pow151.5%
metadata-eval51.5%
Applied egg-rr51.5%
Final simplification51.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 75.3%
associate--l+75.3%
fma-define75.3%
sqr-neg75.3%
fma-define75.3%
distribute-rgt-in75.3%
sqr-neg75.3%
distribute-rgt-in75.3%
fma-define75.3%
sqr-neg75.3%
Simplified78.4%
Taylor expanded in b around 0 56.1%
Taylor expanded in a around 0 24.5%
herbie shell --seed 2024083
(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))