
(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 8 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
(let* ((t_0
(+
(pow (+ (* a a) (* b b)) 2.0)
(* 4.0 (+ (* (* a a) (- 1.0 a)) (* (* b b) (+ a 3.0)))))))
(if (<= t_0 INFINITY) (+ t_0 -1.0) (+ (* (pow a 3.0) (+ a -4.0)) -1.0))))
double code(double a, double b) {
double t_0 = pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))));
double tmp;
if (t_0 <= ((double) INFINITY)) {
tmp = t_0 + -1.0;
} else {
tmp = (pow(a, 3.0) * (a + -4.0)) + -1.0;
}
return tmp;
}
public static double code(double a, double b) {
double t_0 = Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))));
double tmp;
if (t_0 <= Double.POSITIVE_INFINITY) {
tmp = t_0 + -1.0;
} else {
tmp = (Math.pow(a, 3.0) * (a + -4.0)) + -1.0;
}
return tmp;
}
def code(a, b): t_0 = math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0)))) tmp = 0 if t_0 <= math.inf: tmp = t_0 + -1.0 else: tmp = (math.pow(a, 3.0) * (a + -4.0)) + -1.0 return tmp
function code(a, b) t_0 = 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(a + 3.0))))) tmp = 0.0 if (t_0 <= Inf) tmp = Float64(t_0 + -1.0); else tmp = Float64(Float64((a ^ 3.0) * Float64(a + -4.0)) + -1.0); end return tmp end
function tmp_2 = code(a, b) t_0 = (((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0)))); tmp = 0.0; if (t_0 <= Inf) tmp = t_0 + -1.0; else tmp = ((a ^ 3.0) * (a + -4.0)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = 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[(a + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], N[(t$95$0 + -1.0), $MachinePrecision], N[(N[(N[Power[a, 3.0], $MachinePrecision] * N[(a + -4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\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(a + 3\right)\right)\\
\mathbf{if}\;t_0 \leq \infty:\\
\;\;\;\;t_0 + -1\\
\mathbf{else}:\\
\;\;\;\;{a}^{3} \cdot \left(a + -4\right) + -1\\
\end{array}
\end{array}
if (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (-.f64 1 a)) (*.f64 (*.f64 b b) (+.f64 3 a))))) < +inf.0Initial program 99.8%
if +inf.0 < (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (-.f64 1 a)) (*.f64 (*.f64 b b) (+.f64 3 a))))) Initial program 0.0%
Taylor expanded in b around 0 32.5%
unpow232.5%
associate-*l*32.5%
Simplified32.5%
Taylor expanded in a around inf 32.5%
unpow232.5%
mul-1-neg32.5%
distribute-rgt-neg-in32.5%
Simplified32.5%
Taylor expanded in a around 0 32.5%
*-commutative32.5%
metadata-eval32.5%
pow-plus32.5%
distribute-lft-out97.1%
Simplified97.1%
Final simplification99.1%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1e+89) (+ (+ (pow a 4.0) (* (* a a) 4.0)) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1e+89) {
tmp = (pow(a, 4.0) + ((a * a) * 4.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 * b) <= 1d+89) then
tmp = ((a ** 4.0d0) + ((a * a) * 4.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 * b) <= 1e+89) {
tmp = (Math.pow(a, 4.0) + ((a * a) * 4.0)) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1e+89: tmp = (math.pow(a, 4.0) + ((a * a) * 4.0)) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1e+89) tmp = Float64(Float64((a ^ 4.0) + Float64(Float64(a * a) * 4.0)) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1e+89) tmp = ((a ^ 4.0) + ((a * a) * 4.0)) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1e+89], N[(N[(N[Power[a, 4.0], $MachinePrecision] + N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 10^{+89}:\\
\;\;\;\;\left({a}^{4} + \left(a \cdot a\right) \cdot 4\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 9.99999999999999995e88Initial program 83.3%
Taylor expanded in b around 0 78.7%
unpow278.7%
associate-*l*78.7%
Simplified78.7%
Taylor expanded in a around 0 93.4%
unpow293.4%
Simplified93.4%
if 9.99999999999999995e88 < (*.f64 b b) Initial program 61.8%
associate--l+61.8%
fma-def61.8%
+-commutative61.8%
sqr-neg61.8%
+-commutative61.8%
fma-def64.7%
sqr-neg64.7%
+-commutative64.7%
Simplified64.7%
Taylor expanded in b around inf 97.3%
Final simplification95.0%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1e+89) (+ (* (* a a) (+ (* a a) 4.0)) -1.0) (pow b 4.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1e+89) {
tmp = ((a * a) * ((a * a) + 4.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 * b) <= 1d+89) then
tmp = ((a * a) * ((a * a) + 4.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 * b) <= 1e+89) {
tmp = ((a * a) * ((a * a) + 4.0)) + -1.0;
} else {
tmp = Math.pow(b, 4.0);
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1e+89: tmp = ((a * a) * ((a * a) + 4.0)) + -1.0 else: tmp = math.pow(b, 4.0) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1e+89) tmp = Float64(Float64(Float64(a * a) * Float64(Float64(a * a) + 4.0)) + -1.0); else tmp = b ^ 4.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1e+89) tmp = ((a * a) * ((a * a) + 4.0)) + -1.0; else tmp = b ^ 4.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1e+89], N[(N[(N[(a * a), $MachinePrecision] * N[(N[(a * a), $MachinePrecision] + 4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 10^{+89}:\\
\;\;\;\;\left(a \cdot a\right) \cdot \left(a \cdot a + 4\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{b}^{4}\\
\end{array}
\end{array}
if (*.f64 b b) < 9.99999999999999995e88Initial program 83.3%
Taylor expanded in b around 0 78.7%
unpow278.7%
associate-*l*78.7%
Simplified78.7%
Taylor expanded in a around 0 93.4%
unpow293.4%
Simplified93.4%
+-commutative93.4%
metadata-eval93.4%
pow-sqr93.3%
pow-prod-down93.3%
pow293.3%
distribute-rgt-out93.3%
Applied egg-rr93.3%
if 9.99999999999999995e88 < (*.f64 b b) Initial program 61.8%
associate--l+61.8%
fma-def61.8%
+-commutative61.8%
sqr-neg61.8%
+-commutative61.8%
fma-def64.7%
sqr-neg64.7%
+-commutative64.7%
Simplified64.7%
Taylor expanded in b around inf 97.3%
Final simplification94.9%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1e+89) (+ (* (* a a) (+ (* a a) 4.0)) -1.0) (+ (* (* b b) (* b b)) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1e+89) {
tmp = ((a * a) * ((a * a) + 4.0)) + -1.0;
} else {
tmp = ((b * b) * (b * b)) + -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 * b) <= 1d+89) then
tmp = ((a * a) * ((a * a) + 4.0d0)) + (-1.0d0)
else
tmp = ((b * b) * (b * b)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 1e+89) {
tmp = ((a * a) * ((a * a) + 4.0)) + -1.0;
} else {
tmp = ((b * b) * (b * b)) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1e+89: tmp = ((a * a) * ((a * a) + 4.0)) + -1.0 else: tmp = ((b * b) * (b * b)) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1e+89) tmp = Float64(Float64(Float64(a * a) * Float64(Float64(a * a) + 4.0)) + -1.0); else tmp = Float64(Float64(Float64(b * b) * Float64(b * b)) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1e+89) tmp = ((a * a) * ((a * a) + 4.0)) + -1.0; else tmp = ((b * b) * (b * b)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1e+89], N[(N[(N[(a * a), $MachinePrecision] * N[(N[(a * a), $MachinePrecision] + 4.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(b * b), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 10^{+89}:\\
\;\;\;\;\left(a \cdot a\right) \cdot \left(a \cdot a + 4\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\left(b \cdot b\right) \cdot \left(b \cdot b\right) + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 9.99999999999999995e88Initial program 83.3%
Taylor expanded in b around 0 78.7%
unpow278.7%
associate-*l*78.7%
Simplified78.7%
Taylor expanded in a around 0 93.4%
unpow293.4%
Simplified93.4%
+-commutative93.4%
metadata-eval93.4%
pow-sqr93.3%
pow-prod-down93.3%
pow293.3%
distribute-rgt-out93.3%
Applied egg-rr93.3%
if 9.99999999999999995e88 < (*.f64 b b) Initial program 61.8%
Taylor expanded in a around 0 63.8%
+-commutative63.8%
+-commutative63.8%
associate-+l+63.8%
+-commutative63.8%
unpow263.8%
unpow263.8%
associate-*r*63.8%
distribute-rgt-out78.1%
Simplified78.1%
Taylor expanded in a around 0 97.3%
unpow297.3%
Simplified97.3%
+-commutative97.3%
metadata-eval97.3%
pow-sqr97.2%
pow-prod-down97.2%
pow297.2%
distribute-rgt-out97.2%
Applied egg-rr97.2%
Taylor expanded in b around inf 97.2%
unpow297.2%
Simplified97.2%
Final simplification94.9%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1.0) (+ (* (* a a) 4.0) -1.0) (* 2.0 (* a (* a (* b b))))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1.0) {
tmp = ((a * a) * 4.0) + -1.0;
} else {
tmp = 2.0 * (a * (a * (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) <= 1.0d0) then
tmp = ((a * a) * 4.0d0) + (-1.0d0)
else
tmp = 2.0d0 * (a * (a * (b * b)))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 1.0) {
tmp = ((a * a) * 4.0) + -1.0;
} else {
tmp = 2.0 * (a * (a * (b * b)));
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1.0: tmp = ((a * a) * 4.0) + -1.0 else: tmp = 2.0 * (a * (a * (b * b))) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1.0) tmp = Float64(Float64(Float64(a * a) * 4.0) + -1.0); else tmp = Float64(2.0 * Float64(a * Float64(a * Float64(b * b)))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1.0) tmp = ((a * a) * 4.0) + -1.0; else tmp = 2.0 * (a * (a * (b * b))); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1.0], N[(N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], N[(2.0 * N[(a * N[(a * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 1:\\
\;\;\;\;\left(a \cdot a\right) \cdot 4 + -1\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(a \cdot \left(a \cdot \left(b \cdot b\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 1Initial program 84.1%
Taylor expanded in b around 0 84.0%
unpow284.0%
associate-*l*84.0%
Simplified84.0%
Taylor expanded in a around 0 74.0%
unpow274.0%
Simplified74.0%
if 1 < (*.f64 b b) Initial program 64.1%
associate--l+64.1%
fma-def64.1%
+-commutative64.1%
sqr-neg64.1%
+-commutative64.1%
fma-def66.5%
sqr-neg66.5%
+-commutative66.5%
Simplified66.5%
Taylor expanded in a around inf 44.1%
Taylor expanded in b around inf 56.6%
unpow256.6%
unpow256.6%
associate-*l*70.4%
*-commutative70.4%
associate-*l*59.4%
Simplified59.4%
Taylor expanded in b around 0 70.4%
unpow270.4%
Simplified70.4%
Final simplification72.3%
(FPCore (a b) :precision binary64 (if (<= (* b b) 500.0) (+ (* (* a a) 4.0) -1.0) (+ (* (* b b) (* b b)) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 500.0) {
tmp = ((a * a) * 4.0) + -1.0;
} else {
tmp = ((b * b) * (b * b)) + -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 * b) <= 500.0d0) then
tmp = ((a * a) * 4.0d0) + (-1.0d0)
else
tmp = ((b * b) * (b * b)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 500.0) {
tmp = ((a * a) * 4.0) + -1.0;
} else {
tmp = ((b * b) * (b * b)) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 500.0: tmp = ((a * a) * 4.0) + -1.0 else: tmp = ((b * b) * (b * b)) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 500.0) tmp = Float64(Float64(Float64(a * a) * 4.0) + -1.0); else tmp = Float64(Float64(Float64(b * b) * Float64(b * b)) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 500.0) tmp = ((a * a) * 4.0) + -1.0; else tmp = ((b * b) * (b * b)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 500.0], N[(N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(b * b), $MachinePrecision] * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 500:\\
\;\;\;\;\left(a \cdot a\right) \cdot 4 + -1\\
\mathbf{else}:\\
\;\;\;\;\left(b \cdot b\right) \cdot \left(b \cdot b\right) + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 500Initial program 83.5%
Taylor expanded in b around 0 83.4%
unpow283.4%
associate-*l*83.4%
Simplified83.4%
Taylor expanded in a around 0 73.5%
unpow273.5%
Simplified73.5%
if 500 < (*.f64 b b) Initial program 64.6%
Taylor expanded in a around 0 61.8%
+-commutative61.8%
+-commutative61.8%
associate-+l+61.8%
+-commutative61.8%
unpow261.8%
unpow261.8%
associate-*r*61.8%
distribute-rgt-out74.1%
Simplified74.1%
Taylor expanded in a around 0 90.6%
unpow290.6%
Simplified90.6%
+-commutative90.6%
metadata-eval90.6%
pow-sqr90.5%
pow-prod-down90.5%
pow290.5%
distribute-rgt-out90.5%
Applied egg-rr90.5%
Taylor expanded in b around inf 90.2%
unpow290.2%
Simplified90.2%
Final simplification81.5%
(FPCore (a b) :precision binary64 (if (<= (* b b) 2e+301) (+ (* (* a a) 4.0) -1.0) (+ (* b (* b 12.0)) -1.0)))
double code(double a, double b) {
double tmp;
if ((b * b) <= 2e+301) {
tmp = ((a * a) * 4.0) + -1.0;
} else {
tmp = (b * (b * 12.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 ((b * b) <= 2d+301) then
tmp = ((a * a) * 4.0d0) + (-1.0d0)
else
tmp = (b * (b * 12.0d0)) + (-1.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 2e+301) {
tmp = ((a * a) * 4.0) + -1.0;
} else {
tmp = (b * (b * 12.0)) + -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 2e+301: tmp = ((a * a) * 4.0) + -1.0 else: tmp = (b * (b * 12.0)) + -1.0 return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 2e+301) tmp = Float64(Float64(Float64(a * a) * 4.0) + -1.0); else tmp = Float64(Float64(b * Float64(b * 12.0)) + -1.0); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 2e+301) tmp = ((a * a) * 4.0) + -1.0; else tmp = (b * (b * 12.0)) + -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e+301], N[(N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(b * N[(b * 12.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2 \cdot 10^{+301}:\\
\;\;\;\;\left(a \cdot a\right) \cdot 4 + -1\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(b \cdot 12\right) + -1\\
\end{array}
\end{array}
if (*.f64 b b) < 2.00000000000000011e301Initial program 79.6%
Taylor expanded in b around 0 67.0%
unpow267.0%
associate-*l*67.0%
Simplified67.0%
Taylor expanded in a around 0 60.4%
unpow260.4%
Simplified60.4%
if 2.00000000000000011e301 < (*.f64 b b) Initial program 58.7%
Taylor expanded in a around 0 55.6%
+-commutative55.6%
+-commutative55.6%
associate-+l+55.6%
+-commutative55.6%
unpow255.6%
unpow255.6%
associate-*r*55.6%
distribute-rgt-out79.4%
Simplified79.4%
Taylor expanded in a around 0 100.0%
unpow2100.0%
Simplified100.0%
+-commutative100.0%
metadata-eval100.0%
pow-sqr100.0%
pow-prod-down100.0%
pow2100.0%
distribute-rgt-out100.0%
Applied egg-rr100.0%
Taylor expanded in b around 0 100.0%
unpow2100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification70.1%
(FPCore (a b) :precision binary64 (+ (* (* a a) 4.0) -1.0))
double code(double a, double b) {
return ((a * a) * 4.0) + -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = ((a * a) * 4.0d0) + (-1.0d0)
end function
public static double code(double a, double b) {
return ((a * a) * 4.0) + -1.0;
}
def code(a, b): return ((a * a) * 4.0) + -1.0
function code(a, b) return Float64(Float64(Float64(a * a) * 4.0) + -1.0) end
function tmp = code(a, b) tmp = ((a * a) * 4.0) + -1.0; end
code[a_, b_] := N[(N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(a \cdot a\right) \cdot 4 + -1
\end{array}
Initial program 74.5%
Taylor expanded in b around 0 55.1%
unpow255.1%
associate-*l*55.1%
Simplified55.1%
Taylor expanded in a around 0 52.9%
unpow252.9%
Simplified52.9%
Final simplification52.9%
herbie shell --seed 2023280
(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))