
(FPCore (x y) :precision binary64 (+ (+ (* x 2.0) (* x x)) (* y y)))
double code(double x, double y) {
return ((x * 2.0) + (x * x)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 2.0d0) + (x * x)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * 2.0) + (x * x)) + (y * y);
}
def code(x, y): return ((x * 2.0) + (x * x)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * 2.0) + Float64(x * x)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * 2.0) + (x * x)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 2 + x \cdot x\right) + y \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ (* x 2.0) (* x x)) (* y y)))
double code(double x, double y) {
return ((x * 2.0) + (x * x)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 2.0d0) + (x * x)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * 2.0) + (x * x)) + (y * y);
}
def code(x, y): return ((x * 2.0) + (x * x)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * 2.0) + Float64(x * x)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * 2.0) + (x * x)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 2 + x \cdot x\right) + y \cdot y
\end{array}
(FPCore (x y) :precision binary64 (+ (* x (+ x 2.0)) (* y y)))
double code(double x, double y) {
return (x * (x + 2.0)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * (x + 2.0d0)) + (y * y)
end function
public static double code(double x, double y) {
return (x * (x + 2.0)) + (y * y);
}
def code(x, y): return (x * (x + 2.0)) + (y * y)
function code(x, y) return Float64(Float64(x * Float64(x + 2.0)) + Float64(y * y)) end
function tmp = code(x, y) tmp = (x * (x + 2.0)) + (y * y); end
code[x_, y_] := N[(N[(x * N[(x + 2.0), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x + 2\right) + y \cdot y
\end{array}
Initial program 99.6%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -800000000000.0)
(* x x)
(if (<= x -2.8e-40)
(* y y)
(if (<= x -4.2e-107)
(+ x x)
(if (<= x 1.75e-84)
(* y y)
(if (<= x 4.2e-69) (+ x x) (if (<= x 6e+38) (* y y) (* x x))))))))
double code(double x, double y) {
double tmp;
if (x <= -800000000000.0) {
tmp = x * x;
} else if (x <= -2.8e-40) {
tmp = y * y;
} else if (x <= -4.2e-107) {
tmp = x + x;
} else if (x <= 1.75e-84) {
tmp = y * y;
} else if (x <= 4.2e-69) {
tmp = x + x;
} else if (x <= 6e+38) {
tmp = y * y;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-800000000000.0d0)) then
tmp = x * x
else if (x <= (-2.8d-40)) then
tmp = y * y
else if (x <= (-4.2d-107)) then
tmp = x + x
else if (x <= 1.75d-84) then
tmp = y * y
else if (x <= 4.2d-69) then
tmp = x + x
else if (x <= 6d+38) then
tmp = y * y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -800000000000.0) {
tmp = x * x;
} else if (x <= -2.8e-40) {
tmp = y * y;
} else if (x <= -4.2e-107) {
tmp = x + x;
} else if (x <= 1.75e-84) {
tmp = y * y;
} else if (x <= 4.2e-69) {
tmp = x + x;
} else if (x <= 6e+38) {
tmp = y * y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -800000000000.0: tmp = x * x elif x <= -2.8e-40: tmp = y * y elif x <= -4.2e-107: tmp = x + x elif x <= 1.75e-84: tmp = y * y elif x <= 4.2e-69: tmp = x + x elif x <= 6e+38: tmp = y * y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= -800000000000.0) tmp = Float64(x * x); elseif (x <= -2.8e-40) tmp = Float64(y * y); elseif (x <= -4.2e-107) tmp = Float64(x + x); elseif (x <= 1.75e-84) tmp = Float64(y * y); elseif (x <= 4.2e-69) tmp = Float64(x + x); elseif (x <= 6e+38) tmp = Float64(y * y); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -800000000000.0) tmp = x * x; elseif (x <= -2.8e-40) tmp = y * y; elseif (x <= -4.2e-107) tmp = x + x; elseif (x <= 1.75e-84) tmp = y * y; elseif (x <= 4.2e-69) tmp = x + x; elseif (x <= 6e+38) tmp = y * y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -800000000000.0], N[(x * x), $MachinePrecision], If[LessEqual[x, -2.8e-40], N[(y * y), $MachinePrecision], If[LessEqual[x, -4.2e-107], N[(x + x), $MachinePrecision], If[LessEqual[x, 1.75e-84], N[(y * y), $MachinePrecision], If[LessEqual[x, 4.2e-69], N[(x + x), $MachinePrecision], If[LessEqual[x, 6e+38], N[(y * y), $MachinePrecision], N[(x * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -800000000000:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq -2.8 \cdot 10^{-40}:\\
\;\;\;\;y \cdot y\\
\mathbf{elif}\;x \leq -4.2 \cdot 10^{-107}:\\
\;\;\;\;x + x\\
\mathbf{elif}\;x \leq 1.75 \cdot 10^{-84}:\\
\;\;\;\;y \cdot y\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-69}:\\
\;\;\;\;x + x\\
\mathbf{elif}\;x \leq 6 \cdot 10^{+38}:\\
\;\;\;\;y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -8e11 or 6.0000000000000002e38 < x Initial program 99.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in x around inf 91.1%
Simplified91.1%
if -8e11 < x < -2.8e-40 or -4.1999999999999998e-107 < x < 1.7500000000000001e-84 or 4.1999999999999999e-69 < x < 6.0000000000000002e38Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 75.0%
unpow275.0%
Simplified75.0%
Taylor expanded in x around 0 73.6%
Simplified73.6%
if -2.8e-40 < x < -4.1999999999999998e-107 or 1.7500000000000001e-84 < x < 4.1999999999999999e-69Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around inf 81.3%
Simplified81.3%
Final simplification81.2%
(FPCore (x y) :precision binary64 (if (or (<= x -6800000000.0) (not (<= x 2.0))) (+ (* y y) (* x x)) (+ (* y y) (+ x x))))
double code(double x, double y) {
double tmp;
if ((x <= -6800000000.0) || !(x <= 2.0)) {
tmp = (y * y) + (x * x);
} else {
tmp = (y * y) + (x + x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-6800000000.0d0)) .or. (.not. (x <= 2.0d0))) then
tmp = (y * y) + (x * x)
else
tmp = (y * y) + (x + x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -6800000000.0) || !(x <= 2.0)) {
tmp = (y * y) + (x * x);
} else {
tmp = (y * y) + (x + x);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -6800000000.0) or not (x <= 2.0): tmp = (y * y) + (x * x) else: tmp = (y * y) + (x + x) return tmp
function code(x, y) tmp = 0.0 if ((x <= -6800000000.0) || !(x <= 2.0)) tmp = Float64(Float64(y * y) + Float64(x * x)); else tmp = Float64(Float64(y * y) + Float64(x + x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -6800000000.0) || ~((x <= 2.0))) tmp = (y * y) + (x * x); else tmp = (y * y) + (x + x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -6800000000.0], N[Not[LessEqual[x, 2.0]], $MachinePrecision]], N[(N[(y * y), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(y * y), $MachinePrecision] + N[(x + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6800000000 \lor \neg \left(x \leq 2\right):\\
\;\;\;\;y \cdot y + x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y + \left(x + x\right)\\
\end{array}
\end{array}
if x < -6.8e9 or 2 < x Initial program 99.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 99.7%
unpow299.7%
Simplified99.7%
if -6.8e9 < x < 2Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 99.5%
count-299.5%
Simplified99.5%
Final simplification99.6%
(FPCore (x y) :precision binary64 (if (<= y 6e-279) (* x x) (if (<= y 2.7e-160) (+ x x) (+ (* y y) (* x x)))))
double code(double x, double y) {
double tmp;
if (y <= 6e-279) {
tmp = x * x;
} else if (y <= 2.7e-160) {
tmp = x + x;
} else {
tmp = (y * y) + (x * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 6d-279) then
tmp = x * x
else if (y <= 2.7d-160) then
tmp = x + x
else
tmp = (y * y) + (x * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6e-279) {
tmp = x * x;
} else if (y <= 2.7e-160) {
tmp = x + x;
} else {
tmp = (y * y) + (x * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6e-279: tmp = x * x elif y <= 2.7e-160: tmp = x + x else: tmp = (y * y) + (x * x) return tmp
function code(x, y) tmp = 0.0 if (y <= 6e-279) tmp = Float64(x * x); elseif (y <= 2.7e-160) tmp = Float64(x + x); else tmp = Float64(Float64(y * y) + Float64(x * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6e-279) tmp = x * x; elseif (y <= 2.7e-160) tmp = x + x; else tmp = (y * y) + (x * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6e-279], N[(x * x), $MachinePrecision], If[LessEqual[y, 2.7e-160], N[(x + x), $MachinePrecision], N[(N[(y * y), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{-279}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-160}:\\
\;\;\;\;x + x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y + x \cdot x\\
\end{array}
\end{array}
if y < 5.9999999999999999e-279Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 76.7%
unpow276.7%
Simplified76.7%
Taylor expanded in x around inf 40.6%
Simplified40.6%
if 5.9999999999999999e-279 < y < 2.7000000000000001e-160Initial program 100.0%
distribute-lft-out99.9%
Simplified99.9%
Taylor expanded in x around 0 90.9%
count-290.9%
Simplified90.9%
Taylor expanded in x around inf 90.9%
Simplified90.9%
if 2.7000000000000001e-160 < y Initial program 99.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 96.1%
unpow296.1%
Simplified96.1%
Final simplification66.4%
(FPCore (x y) :precision binary64 (if (<= x -4.2e+19) (* x x) (if (<= x 9.6e+38) (* y y) (* x x))))
double code(double x, double y) {
double tmp;
if (x <= -4.2e+19) {
tmp = x * x;
} else if (x <= 9.6e+38) {
tmp = y * y;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-4.2d+19)) then
tmp = x * x
else if (x <= 9.6d+38) then
tmp = y * y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.2e+19) {
tmp = x * x;
} else if (x <= 9.6e+38) {
tmp = y * y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.2e+19: tmp = x * x elif x <= 9.6e+38: tmp = y * y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= -4.2e+19) tmp = Float64(x * x); elseif (x <= 9.6e+38) tmp = Float64(y * y); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.2e+19) tmp = x * x; elseif (x <= 9.6e+38) tmp = y * y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.2e+19], N[(x * x), $MachinePrecision], If[LessEqual[x, 9.6e+38], N[(y * y), $MachinePrecision], N[(x * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{+19}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{+38}:\\
\;\;\;\;y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -4.2e19 or 9.60000000000000069e38 < x Initial program 99.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in x around inf 91.1%
Simplified91.1%
if -4.2e19 < x < 9.60000000000000069e38Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 69.4%
unpow269.4%
Simplified69.4%
Taylor expanded in x around 0 68.1%
Simplified68.1%
Final simplification77.5%
(FPCore (x y) :precision binary64 (* x x))
double code(double x, double y) {
return x * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * x
end function
public static double code(double x, double y) {
return x * x;
}
def code(x, y): return x * x
function code(x, y) return Float64(x * x) end
function tmp = code(x, y) tmp = x * x; end
code[x_, y_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 99.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 81.9%
unpow281.9%
Simplified81.9%
Taylor expanded in x around inf 40.4%
Simplified40.4%
Final simplification40.4%
(FPCore (x y) :precision binary64 (+ (* y y) (+ (* 2.0 x) (* x x))))
double code(double x, double y) {
return (y * y) + ((2.0 * x) + (x * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * y) + ((2.0d0 * x) + (x * x))
end function
public static double code(double x, double y) {
return (y * y) + ((2.0 * x) + (x * x));
}
def code(x, y): return (y * y) + ((2.0 * x) + (x * x))
function code(x, y) return Float64(Float64(y * y) + Float64(Float64(2.0 * x) + Float64(x * x))) end
function tmp = code(x, y) tmp = (y * y) + ((2.0 * x) + (x * x)); end
code[x_, y_] := N[(N[(y * y), $MachinePrecision] + N[(N[(2.0 * x), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot y + \left(2 \cdot x + x \cdot x\right)
\end{array}
herbie shell --seed 2023285
(FPCore (x y)
:name "Numeric.Log:$clog1p from log-domain-0.10.2.1, A"
:precision binary64
:herbie-target
(+ (* y y) (+ (* 2.0 x) (* x x)))
(+ (+ (* x 2.0) (* x x)) (* y y)))