
(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 7 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) (* x 2.0)) (* y y)))
double code(double x, double y) {
return ((x * 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) + (x * 2.0d0)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * x) + (x * 2.0)) + (y * y);
}
def code(x, y): return ((x * x) + (x * 2.0)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * x) + Float64(x * 2.0)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * x) + (x * 2.0)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + x \cdot 2\right) + y \cdot y
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -1.45e+117)
(* x x)
(if (<= x -5.4e-18)
(* y y)
(if (<= x -1.4e-50)
(+ x x)
(if (<= x 16800000000000.0) (* y y) (* x x))))))
double code(double x, double y) {
double tmp;
if (x <= -1.45e+117) {
tmp = x * x;
} else if (x <= -5.4e-18) {
tmp = y * y;
} else if (x <= -1.4e-50) {
tmp = x + x;
} else if (x <= 16800000000000.0) {
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 <= (-1.45d+117)) then
tmp = x * x
else if (x <= (-5.4d-18)) then
tmp = y * y
else if (x <= (-1.4d-50)) then
tmp = x + x
else if (x <= 16800000000000.0d0) 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 <= -1.45e+117) {
tmp = x * x;
} else if (x <= -5.4e-18) {
tmp = y * y;
} else if (x <= -1.4e-50) {
tmp = x + x;
} else if (x <= 16800000000000.0) {
tmp = y * y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.45e+117: tmp = x * x elif x <= -5.4e-18: tmp = y * y elif x <= -1.4e-50: tmp = x + x elif x <= 16800000000000.0: tmp = y * y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.45e+117) tmp = Float64(x * x); elseif (x <= -5.4e-18) tmp = Float64(y * y); elseif (x <= -1.4e-50) tmp = Float64(x + x); elseif (x <= 16800000000000.0) tmp = Float64(y * y); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.45e+117) tmp = x * x; elseif (x <= -5.4e-18) tmp = y * y; elseif (x <= -1.4e-50) tmp = x + x; elseif (x <= 16800000000000.0) tmp = y * y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.45e+117], N[(x * x), $MachinePrecision], If[LessEqual[x, -5.4e-18], N[(y * y), $MachinePrecision], If[LessEqual[x, -1.4e-50], N[(x + x), $MachinePrecision], If[LessEqual[x, 16800000000000.0], N[(y * y), $MachinePrecision], N[(x * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{+117}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq -5.4 \cdot 10^{-18}:\\
\;\;\;\;y \cdot y\\
\mathbf{elif}\;x \leq -1.4 \cdot 10^{-50}:\\
\;\;\;\;x + x\\
\mathbf{elif}\;x \leq 16800000000000:\\
\;\;\;\;y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -1.45000000000000014e117 or 1.68e13 < x Initial program 100.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 84.7%
unpow284.7%
Simplified84.7%
if -1.45000000000000014e117 < x < -5.39999999999999977e-18 or -1.3999999999999999e-50 < x < 1.68e13Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 93.6%
Taylor expanded in x around 0 75.9%
unpow275.9%
Simplified75.9%
if -5.39999999999999977e-18 < x < -1.3999999999999999e-50Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around inf 85.9%
count-285.9%
Simplified85.9%
Final simplification79.7%
(FPCore (x y) :precision binary64 (if (or (<= x -7.6e+28) (not (<= x 1.75))) (+ (* x x) (* y y)) (+ (* y y) (* x 2.0))))
double code(double x, double y) {
double tmp;
if ((x <= -7.6e+28) || !(x <= 1.75)) {
tmp = (x * x) + (y * y);
} else {
tmp = (y * y) + (x * 2.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-7.6d+28)) .or. (.not. (x <= 1.75d0))) then
tmp = (x * x) + (y * y)
else
tmp = (y * y) + (x * 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -7.6e+28) || !(x <= 1.75)) {
tmp = (x * x) + (y * y);
} else {
tmp = (y * y) + (x * 2.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -7.6e+28) or not (x <= 1.75): tmp = (x * x) + (y * y) else: tmp = (y * y) + (x * 2.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -7.6e+28) || !(x <= 1.75)) tmp = Float64(Float64(x * x) + Float64(y * y)); else tmp = Float64(Float64(y * y) + Float64(x * 2.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -7.6e+28) || ~((x <= 1.75))) tmp = (x * x) + (y * y); else tmp = (y * y) + (x * 2.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -7.6e+28], N[Not[LessEqual[x, 1.75]], $MachinePrecision]], N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision], N[(N[(y * y), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.6 \cdot 10^{+28} \lor \neg \left(x \leq 1.75\right):\\
\;\;\;\;x \cdot x + y \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot y + x \cdot 2\\
\end{array}
\end{array}
if x < -7.5999999999999998e28 or 1.75 < x Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
if -7.5999999999999998e28 < x < 1.75Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 98.0%
Final simplification99.0%
(FPCore (x y) :precision binary64 (if (<= x -9.5e+116) (* x x) (if (<= x 2.3e+24) (+ (* y y) (* x 2.0)) (* x x))))
double code(double x, double y) {
double tmp;
if (x <= -9.5e+116) {
tmp = x * x;
} else if (x <= 2.3e+24) {
tmp = (y * y) + (x * 2.0);
} 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 <= (-9.5d+116)) then
tmp = x * x
else if (x <= 2.3d+24) then
tmp = (y * y) + (x * 2.0d0)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -9.5e+116) {
tmp = x * x;
} else if (x <= 2.3e+24) {
tmp = (y * y) + (x * 2.0);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9.5e+116: tmp = x * x elif x <= 2.3e+24: tmp = (y * y) + (x * 2.0) else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= -9.5e+116) tmp = Float64(x * x); elseif (x <= 2.3e+24) tmp = Float64(Float64(y * y) + Float64(x * 2.0)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -9.5e+116) tmp = x * x; elseif (x <= 2.3e+24) tmp = (y * y) + (x * 2.0); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9.5e+116], N[(x * x), $MachinePrecision], If[LessEqual[x, 2.3e+24], N[(N[(y * y), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+116}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{+24}:\\
\;\;\;\;y \cdot y + x \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -9.5000000000000004e116 or 2.2999999999999999e24 < x Initial program 100.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 85.3%
unpow285.3%
Simplified85.3%
if -9.5000000000000004e116 < x < 2.2999999999999999e24Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 93.4%
Final simplification90.2%
(FPCore (x y) :precision binary64 (+ (* y y) (* x (+ x 2.0))))
double code(double x, double y) {
return (y * y) + (x * (x + 2.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * y) + (x * (x + 2.0d0))
end function
public static double code(double x, double y) {
return (y * y) + (x * (x + 2.0));
}
def code(x, y): return (y * y) + (x * (x + 2.0))
function code(x, y) return Float64(Float64(y * y) + Float64(x * Float64(x + 2.0))) end
function tmp = code(x, y) tmp = (y * y) + (x * (x + 2.0)); end
code[x_, y_] := N[(N[(y * y), $MachinePrecision] + N[(x * N[(x + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot y + x \cdot \left(x + 2\right)
\end{array}
Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -1.1e+117) (* x x) (if (<= x 3.9e+16) (* y y) (* x x))))
double code(double x, double y) {
double tmp;
if (x <= -1.1e+117) {
tmp = x * x;
} else if (x <= 3.9e+16) {
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 <= (-1.1d+117)) then
tmp = x * x
else if (x <= 3.9d+16) 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 <= -1.1e+117) {
tmp = x * x;
} else if (x <= 3.9e+16) {
tmp = y * y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.1e+117: tmp = x * x elif x <= 3.9e+16: tmp = y * y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.1e+117) tmp = Float64(x * x); elseif (x <= 3.9e+16) tmp = Float64(y * y); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.1e+117) tmp = x * x; elseif (x <= 3.9e+16) tmp = y * y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.1e+117], N[(x * x), $MachinePrecision], If[LessEqual[x, 3.9e+16], N[(y * y), $MachinePrecision], N[(x * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+117}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \leq 3.9 \cdot 10^{+16}:\\
\;\;\;\;y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < -1.10000000000000007e117 or 3.9e16 < x Initial program 100.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 84.7%
unpow284.7%
Simplified84.7%
if -1.10000000000000007e117 < x < 3.9e16Initial program 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 93.9%
Taylor expanded in x around 0 73.2%
unpow273.2%
Simplified73.2%
Final simplification77.8%
(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 100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 86.6%
unpow286.6%
Simplified86.6%
Taylor expanded in x around inf 38.8%
unpow238.8%
Simplified38.8%
Final simplification38.8%
(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 2023263
(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)))