
(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
(if (<=
(+
(pow (+ (* a a) (* b b)) 2.0)
(* 4.0 (+ (* (* a a) (- 1.0 a)) (* (* b b) (+ a 3.0)))))
INFINITY)
(+
(pow (hypot a b) 4.0)
(fma 4.0 (- (fma (* b b) (+ a 3.0) (* a a)) (pow a 3.0)) -1.0))
(+ -1.0 (pow a 4.0))))
double code(double a, double b) {
double tmp;
if ((pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))))) <= ((double) INFINITY)) {
tmp = pow(hypot(a, b), 4.0) + fma(4.0, (fma((b * b), (a + 3.0), (a * a)) - pow(a, 3.0)), -1.0);
} else {
tmp = -1.0 + pow(a, 4.0);
}
return tmp;
}
function code(a, b) tmp = 0.0 if (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))))) <= Inf) tmp = Float64((hypot(a, b) ^ 4.0) + fma(4.0, Float64(fma(Float64(b * b), Float64(a + 3.0), Float64(a * a)) - (a ^ 3.0)), -1.0)); else tmp = Float64(-1.0 + (a ^ 4.0)); end return tmp end
code[a_, b_] := If[LessEqual[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], Infinity], N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(b * b), $MachinePrecision] * N[(a + 3.0), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision] - N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{\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) \leq \infty:\\
\;\;\;\;{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(4, \mathsf{fma}\left(b \cdot b, a + 3, a \cdot a\right) - {a}^{3}, -1\right)\\
\mathbf{else}:\\
\;\;\;\;-1 + {a}^{4}\\
\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.7%
associate--l+99.7%
Simplified100.0%
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%
sub-neg0.0%
fma-def0.0%
fma-def9.1%
+-commutative9.1%
metadata-eval9.1%
Simplified9.1%
Taylor expanded in a around inf 92.9%
Final simplification98.2%
(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) (+ -1.0 (pow a 4.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 = -1.0 + pow(a, 4.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 = -1.0 + Math.pow(a, 4.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 = -1.0 + math.pow(a, 4.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(-1.0 + (a ^ 4.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 = -1.0 + (a ^ 4.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[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $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}:\\
\;\;\;\;-1 + {a}^{4}\\
\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.7%
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%
sub-neg0.0%
fma-def0.0%
fma-def9.1%
+-commutative9.1%
metadata-eval9.1%
Simplified9.1%
Taylor expanded in a around inf 92.9%
Final simplification97.9%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1000000.0) (+ -1.0 (pow a 4.0)) (+ -1.0 (+ (* (* b b) 12.0) (pow b 4.0)))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1000000.0) {
tmp = -1.0 + pow(a, 4.0);
} else {
tmp = -1.0 + (((b * b) * 12.0) + 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) <= 1000000.0d0) then
tmp = (-1.0d0) + (a ** 4.0d0)
else
tmp = (-1.0d0) + (((b * b) * 12.0d0) + (b ** 4.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 1000000.0) {
tmp = -1.0 + Math.pow(a, 4.0);
} else {
tmp = -1.0 + (((b * b) * 12.0) + Math.pow(b, 4.0));
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1000000.0: tmp = -1.0 + math.pow(a, 4.0) else: tmp = -1.0 + (((b * b) * 12.0) + math.pow(b, 4.0)) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1000000.0) tmp = Float64(-1.0 + (a ^ 4.0)); else tmp = Float64(-1.0 + Float64(Float64(Float64(b * b) * 12.0) + (b ^ 4.0))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1000000.0) tmp = -1.0 + (a ^ 4.0); else tmp = -1.0 + (((b * b) * 12.0) + (b ^ 4.0)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1000000.0], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(N[(b * b), $MachinePrecision] * 12.0), $MachinePrecision] + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 1000000:\\
\;\;\;\;-1 + {a}^{4}\\
\mathbf{else}:\\
\;\;\;\;-1 + \left(\left(b \cdot b\right) \cdot 12 + {b}^{4}\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 1e6Initial program 82.1%
sub-neg82.1%
fma-def82.1%
fma-def82.1%
+-commutative82.1%
metadata-eval82.1%
Simplified82.1%
Taylor expanded in a around inf 99.1%
if 1e6 < (*.f64 b b) Initial program 64.8%
sub-neg64.8%
fma-def64.8%
fma-def69.8%
+-commutative69.8%
metadata-eval69.8%
Simplified69.8%
Taylor expanded in a around 0 61.0%
associate-+r+61.0%
associate-*r*61.0%
distribute-rgt-out73.5%
metadata-eval73.5%
distribute-lft-in73.5%
unpow273.5%
distribute-rgt-in73.5%
metadata-eval73.5%
Simplified73.5%
Taylor expanded in a around 0 90.7%
unpow290.7%
Simplified90.7%
Final simplification95.1%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1000000.0) (+ -1.0 (pow a 4.0)) (+ -1.0 (* b (* b (fma b b 12.0))))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1000000.0) {
tmp = -1.0 + pow(a, 4.0);
} else {
tmp = -1.0 + (b * (b * fma(b, b, 12.0)));
}
return tmp;
}
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1000000.0) tmp = Float64(-1.0 + (a ^ 4.0)); else tmp = Float64(-1.0 + Float64(b * Float64(b * fma(b, b, 12.0)))); end return tmp end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1000000.0], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(b * N[(b * N[(b * b + 12.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 1000000:\\
\;\;\;\;-1 + {a}^{4}\\
\mathbf{else}:\\
\;\;\;\;-1 + b \cdot \left(b \cdot \mathsf{fma}\left(b, b, 12\right)\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 1e6Initial program 82.1%
sub-neg82.1%
fma-def82.1%
fma-def82.1%
+-commutative82.1%
metadata-eval82.1%
Simplified82.1%
Taylor expanded in a around inf 99.1%
if 1e6 < (*.f64 b b) Initial program 64.8%
sub-neg64.8%
fma-def64.8%
fma-def69.8%
+-commutative69.8%
metadata-eval69.8%
Simplified69.8%
Taylor expanded in a around 0 61.0%
associate-+r+61.0%
associate-*r*61.0%
distribute-rgt-out73.5%
metadata-eval73.5%
distribute-lft-in73.5%
unpow273.5%
distribute-rgt-in73.5%
metadata-eval73.5%
Simplified73.5%
Taylor expanded in a around 0 90.7%
unpow290.7%
Simplified90.7%
Taylor expanded in b around 0 90.7%
unpow290.7%
metadata-eval90.7%
pow-sqr90.5%
unpow290.5%
unpow290.5%
distribute-rgt-in90.5%
associate-*l*90.5%
+-commutative90.5%
fma-def90.5%
Simplified90.5%
Final simplification95.1%
(FPCore (a b) :precision binary64 (if (<= (* b b) 1000000.0) (+ -1.0 (pow a 4.0)) (+ -1.0 (* (* b b) (+ (* b b) 12.0)))))
double code(double a, double b) {
double tmp;
if ((b * b) <= 1000000.0) {
tmp = -1.0 + pow(a, 4.0);
} else {
tmp = -1.0 + ((b * b) * ((b * b) + 12.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) <= 1000000.0d0) then
tmp = (-1.0d0) + (a ** 4.0d0)
else
tmp = (-1.0d0) + ((b * b) * ((b * b) + 12.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if ((b * b) <= 1000000.0) {
tmp = -1.0 + Math.pow(a, 4.0);
} else {
tmp = -1.0 + ((b * b) * ((b * b) + 12.0));
}
return tmp;
}
def code(a, b): tmp = 0 if (b * b) <= 1000000.0: tmp = -1.0 + math.pow(a, 4.0) else: tmp = -1.0 + ((b * b) * ((b * b) + 12.0)) return tmp
function code(a, b) tmp = 0.0 if (Float64(b * b) <= 1000000.0) tmp = Float64(-1.0 + (a ^ 4.0)); else tmp = Float64(-1.0 + Float64(Float64(b * b) * Float64(Float64(b * b) + 12.0))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if ((b * b) <= 1000000.0) tmp = -1.0 + (a ^ 4.0); else tmp = -1.0 + ((b * b) * ((b * b) + 12.0)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 1000000.0], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(b * b), $MachinePrecision] * N[(N[(b * b), $MachinePrecision] + 12.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 1000000:\\
\;\;\;\;-1 + {a}^{4}\\
\mathbf{else}:\\
\;\;\;\;-1 + \left(b \cdot b\right) \cdot \left(b \cdot b + 12\right)\\
\end{array}
\end{array}
if (*.f64 b b) < 1e6Initial program 82.1%
sub-neg82.1%
fma-def82.1%
fma-def82.1%
+-commutative82.1%
metadata-eval82.1%
Simplified82.1%
Taylor expanded in a around inf 99.1%
if 1e6 < (*.f64 b b) Initial program 64.8%
sub-neg64.8%
fma-def64.8%
fma-def69.8%
+-commutative69.8%
metadata-eval69.8%
Simplified69.8%
Taylor expanded in a around 0 61.0%
associate-+r+61.0%
associate-*r*61.0%
distribute-rgt-out73.5%
metadata-eval73.5%
distribute-lft-in73.5%
unpow273.5%
distribute-rgt-in73.5%
metadata-eval73.5%
Simplified73.5%
Taylor expanded in a around 0 90.7%
unpow290.7%
Simplified90.7%
+-commutative90.7%
metadata-eval90.7%
pow-prod-up90.5%
pow-prod-down90.5%
pow290.5%
distribute-rgt-out90.5%
Applied egg-rr90.5%
Final simplification95.1%
(FPCore (a b) :precision binary64 (if (<= b 4.5e-8) (+ -1.0 (* a (* a 4.0))) (+ -1.0 (* (* b b) (+ (* b b) 12.0)))))
double code(double a, double b) {
double tmp;
if (b <= 4.5e-8) {
tmp = -1.0 + (a * (a * 4.0));
} else {
tmp = -1.0 + ((b * b) * ((b * b) + 12.0));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 4.5d-8) then
tmp = (-1.0d0) + (a * (a * 4.0d0))
else
tmp = (-1.0d0) + ((b * b) * ((b * b) + 12.0d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 4.5e-8) {
tmp = -1.0 + (a * (a * 4.0));
} else {
tmp = -1.0 + ((b * b) * ((b * b) + 12.0));
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 4.5e-8: tmp = -1.0 + (a * (a * 4.0)) else: tmp = -1.0 + ((b * b) * ((b * b) + 12.0)) return tmp
function code(a, b) tmp = 0.0 if (b <= 4.5e-8) tmp = Float64(-1.0 + Float64(a * Float64(a * 4.0))); else tmp = Float64(-1.0 + Float64(Float64(b * b) * Float64(Float64(b * b) + 12.0))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 4.5e-8) tmp = -1.0 + (a * (a * 4.0)); else tmp = -1.0 + ((b * b) * ((b * b) + 12.0)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 4.5e-8], N[(-1.0 + N[(a * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(b * b), $MachinePrecision] * N[(N[(b * b), $MachinePrecision] + 12.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.5 \cdot 10^{-8}:\\
\;\;\;\;-1 + a \cdot \left(a \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;-1 + \left(b \cdot b\right) \cdot \left(b \cdot b + 12\right)\\
\end{array}
\end{array}
if b < 4.49999999999999993e-8Initial program 78.1%
sub-neg78.1%
fma-def78.1%
fma-def79.7%
+-commutative79.7%
metadata-eval79.7%
Simplified79.7%
Taylor expanded in b around 0 64.1%
associate-*r*64.1%
unpow264.1%
Simplified64.1%
Taylor expanded in a around 0 55.8%
unpow255.8%
associate-*r*55.8%
Simplified55.8%
if 4.49999999999999993e-8 < b Initial program 62.5%
sub-neg62.5%
fma-def62.5%
fma-def67.0%
+-commutative67.0%
metadata-eval67.0%
Simplified67.0%
Taylor expanded in a around 0 60.0%
associate-+r+60.0%
associate-*r*60.0%
distribute-rgt-out70.4%
metadata-eval70.4%
distribute-lft-in70.4%
unpow270.4%
distribute-rgt-in70.4%
metadata-eval70.4%
Simplified70.4%
Taylor expanded in a around 0 90.3%
unpow290.3%
Simplified90.3%
+-commutative90.3%
metadata-eval90.3%
pow-prod-up90.1%
pow-prod-down90.1%
pow290.1%
distribute-rgt-out90.1%
Applied egg-rr90.1%
Final simplification64.8%
(FPCore (a b) :precision binary64 (if (<= b 3.7e+153) (+ -1.0 (* a (* a 4.0))) (+ -1.0 (* (* b b) 12.0))))
double code(double a, double b) {
double tmp;
if (b <= 3.7e+153) {
tmp = -1.0 + (a * (a * 4.0));
} else {
tmp = -1.0 + ((b * b) * 12.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 3.7d+153) then
tmp = (-1.0d0) + (a * (a * 4.0d0))
else
tmp = (-1.0d0) + ((b * b) * 12.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 3.7e+153) {
tmp = -1.0 + (a * (a * 4.0));
} else {
tmp = -1.0 + ((b * b) * 12.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.7e+153: tmp = -1.0 + (a * (a * 4.0)) else: tmp = -1.0 + ((b * b) * 12.0) return tmp
function code(a, b) tmp = 0.0 if (b <= 3.7e+153) tmp = Float64(-1.0 + Float64(a * Float64(a * 4.0))); else tmp = Float64(-1.0 + Float64(Float64(b * b) * 12.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 3.7e+153) tmp = -1.0 + (a * (a * 4.0)); else tmp = -1.0 + ((b * b) * 12.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3.7e+153], N[(-1.0 + N[(a * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(N[(b * b), $MachinePrecision] * 12.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.7 \cdot 10^{+153}:\\
\;\;\;\;-1 + a \cdot \left(a \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;-1 + \left(b \cdot b\right) \cdot 12\\
\end{array}
\end{array}
if b < 3.7000000000000002e153Initial program 77.2%
sub-neg77.2%
fma-def77.2%
fma-def78.5%
+-commutative78.5%
metadata-eval78.5%
Simplified78.5%
Taylor expanded in b around 0 59.5%
associate-*r*59.5%
unpow259.5%
Simplified59.5%
Taylor expanded in a around 0 50.1%
unpow250.1%
associate-*r*50.1%
Simplified50.1%
if 3.7000000000000002e153 < b Initial program 50.0%
sub-neg50.0%
fma-def50.0%
fma-def60.0%
+-commutative60.0%
metadata-eval60.0%
Simplified60.0%
Taylor expanded in a around 0 50.0%
associate-+r+50.0%
associate-*r*50.0%
distribute-rgt-out73.3%
metadata-eval73.3%
distribute-lft-in73.3%
unpow273.3%
distribute-rgt-in73.3%
metadata-eval73.3%
Simplified73.3%
Taylor expanded in a around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
unpow2100.0%
metadata-eval100.0%
pow-sqr100.0%
unpow2100.0%
unpow2100.0%
distribute-rgt-in100.0%
associate-*l*100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
unpow2100.0%
Simplified100.0%
Final simplification56.0%
(FPCore (a b) :precision binary64 (+ -1.0 (* (* b b) 12.0)))
double code(double a, double b) {
return -1.0 + ((b * b) * 12.0);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (-1.0d0) + ((b * b) * 12.0d0)
end function
public static double code(double a, double b) {
return -1.0 + ((b * b) * 12.0);
}
def code(a, b): return -1.0 + ((b * b) * 12.0)
function code(a, b) return Float64(-1.0 + Float64(Float64(b * b) * 12.0)) end
function tmp = code(a, b) tmp = -1.0 + ((b * b) * 12.0); end
code[a_, b_] := N[(-1.0 + N[(N[(b * b), $MachinePrecision] * 12.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \left(b \cdot b\right) \cdot 12
\end{array}
Initial program 74.0%
sub-neg74.0%
fma-def74.0%
fma-def76.3%
+-commutative76.3%
metadata-eval76.3%
Simplified76.3%
Taylor expanded in a around 0 51.6%
associate-+r+51.6%
associate-*r*51.6%
distribute-rgt-out57.4%
metadata-eval57.4%
distribute-lft-in57.4%
unpow257.4%
distribute-rgt-in57.4%
metadata-eval57.4%
Simplified57.4%
Taylor expanded in a around 0 65.4%
unpow265.4%
Simplified65.4%
Taylor expanded in b around 0 65.4%
unpow265.4%
metadata-eval65.4%
pow-sqr65.3%
unpow265.3%
unpow265.3%
distribute-rgt-in65.3%
associate-*l*65.3%
+-commutative65.3%
fma-def65.3%
Simplified65.3%
Taylor expanded in b around 0 46.3%
unpow246.3%
Simplified46.3%
Final simplification46.3%
herbie shell --seed 2023222
(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))