Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update reproducing.m, PTR-BCR-4 #54

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Volume_1/Book_about_Quadratization.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,7 @@ \subsection{PTR-BCR-4 (Boros, Crama, and Rodr\'{i}guez-Heck, 2018)}
%Suppose we have a monomial $b_1b_2b_3 \ldots b_k$.
This is a more general form of the previous reduction, PTR-BCR-4, in which $k=2^{m+1}$:
\begin{align}
b_1 \ldots b_k &\rightarrow \sum_{ij}b_ib_j + \sum_{ij}^m 2^{i+j}b_{a_i}b_{a_j} - \sum_i \sum_j^m 2^{j+1}b_ib_{a_i}.
b_1 \ldots b_k &\rightarrow \sum_{ij}b_ib_j + \sum_{ij}^m 2^{i+j}b_{a_i}b_{a_j} - \sum_i \sum_j^m 2^{j+1}b_ib_{a_j}.
\end{align}

\costsec
Expand All @@ -1619,7 +1619,12 @@ \subsection{PTR-BCR-4 (Boros, Crama, and Rodr\'{i}guez-Heck, 2018)}
\begin{eqnarray}
%b_1 b_2 b_3 b_4 = \min_{b_{a_1}, b_{a_2}} \frac{1}{2}
b_1 b_2 b_3 b_4 \rightarrow
\left( b_1 + b_2 + b_3 + b_4 - 2b_a \right)^2
\left( b_1 + b_2 + b_3 + b_4 - b_{a_1} - 2b_{a_2} \right)^2
\end{eqnarray}

\begin{eqnarray}
b_1 b_2 b_3 b_4 \rightarrow
\sum_{i=1}^{4}\sum_{j=1}^{4}b_ib_j + \sum_{i=0}^{1}\sum_{j=0}^{1} 2^{i+j}b_{a_i}b_{a_j} - \sum_{i=1}^{4}\sum_{j=0}^{1} 2^{j+1}b_ib_{a_j}
\end{eqnarray}

\altformsec
Expand Down
75 changes: 75 additions & 0 deletions everything_else/reproducing.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,81 @@
%% Pg. 21, PTR-BCR-2
%% Pg. 22, PTR-BCR-3 (example appears to be the same as PTR-BCR-1, and may have to be redone)
%% Pg. 23, PTR-BCR-4

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eq. 71 should come before Eq. 72.

% Eq. 72
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equation numbers can change, when new questions get added or old ones get removed. Instead of calling something "Eq. 72" it's better to give a description, such as "Equation in Summary section of PTR-BCR-4". Earlier we were using equation numbers in this file, but now things are changing and we're moving away from using equation numbers in that way (and we're moving more towards using descriptions).

b = dec2bin(2^6-1:-1:0)-'0';
b1=b(:,1);b2=b(:,2);b3=b(:,3);b4=b(:,4);ba1=b(:,5);ba2=b(:,6);
LHS = min(reshape(b1.*b2.*b3.*b4, 4, []));
RHS = min(reshape((b1 + b2 + b3 + b4 - ba1 - 2*ba2).^2, 4, []));
isequal(LHS,RHS); % Gives 1, confirmed by Nike on 6 April.

Copy link
Member

@ndattani ndattani Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I appreciate that it would take a long time to type out b1*b2 + b1*b3 + b1*b4 + ... for all terms, I think that it would be more "readable". For all other quadratizations verified in this file so far, it's easy to compare the equation in the book with the code and immediately see that they're the same. In this case, it's a lot more complicated. Perhaps you can use MATLAB's symbolic computing toolbox to help.

I think I'd prefer MATLAB code that looks as close as possible to the equations in the book, then we can also keep your code containing the for loops (so we have two different verifications for each equation: one "long" one that's easy to read, and one "compact" one which requires the reader to interpret a bunch of for and end statements).

% Eq. 73
b = dec2bin(2^6-1:-1:0)-'0';
LHS = ones(2^6,1);
for i = 1:4
LHS = LHS.*b(:,i);
end
LHS = min(reshape(LHS, 4, []));
RHS = zeros(2^6,1);
for i = 1:4
for j = 1:4
RHS = RHS + b(:,i).*b(:,j);
end
end
for i = 5:6
for j = 5:6
RHS = RHS + 2^(i+j-10)*b(:,i).*b(:,j);
end
end
for i = 1:4
for j = 5:6
RHS = RHS - 2^(j-4)*b(:,i).*b(:,j);
end
end
RHS = min(reshape(RHS, 4, []));
isequal(LHS, RHS);

% k = 8, Eq. 74
b = dec2bin(2^11-1:-1:0)-'0';
LHS = ones(2^11,1);
for i = 1:8
LHS = LHS.*b(:,i);
end
LHS = min(reshape(LHS, 8, []));
RHS = zeros(2^11,1);
for i=1:8
RHS = RHS + b(:,i);
end
RHS = RHS - b(:,9) - 2*b(:,10) - 4*b(:,11);
RHS = min(reshape(RHS.^2, 8, []));
isequal(LHS, RHS);

% k = 8, Eq. 71
b = dec2bin(2^11-1:-1:0)-'0';
LHS = ones(2^11,1);
for i = 1:8
LHS = LHS.*b(:,i);
end
LHS = min(reshape(LHS, 8, []));
RHS = zeros(2^11,1);
for i = 1:8
for j = 1:8
RHS = RHS + b(:,i).*b(:,j);
end
end
for i = 9:11
for j = 9:11
RHS = RHS + 2^(i+j-18)*b(:,i).*b(:,j);
end
end
for i = 1:8
for j = 9:11
RHS = RHS - 2^(j-8)*b(:,i).*b(:,j);
end
end
RHS = min(reshape(RHS, 8, []));
isequal(LHS, RHS);

%% Pg. 24, PTR-KZ (needs an example!)
%% PTR-KZ: b1b2b3 = min_ba(1 − (ba + b1 + b2 + b3) + ba (b1 + b2 + b3) + b1b2 + b1b3 + b2b3)

Expand Down