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

cross product utility function. #1031

Merged
merged 1 commit into from
Feb 9, 2024
Merged

cross product utility function. #1031

merged 1 commit into from
Feb 9, 2024

Conversation

chriseth
Copy link
Member

@chriseth chriseth commented Feb 7, 2024

No description provided.

@chriseth chriseth force-pushed the split_bits branch 2 times, most recently from 1a01778 to 0dd85cf Compare February 7, 2024 17:11
std/binary.asm Outdated
col fixed P_B(i) { (i >> 8) % 256 };
col fixed P_operation(i) { (i / (256 * 256)) % 3 };
// TOOD would be nice with destructuring assignment for arrays.
let inputs: (int -> int)[] = split_bits([2, 8, 8]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let inputs: (int -> int)[] = split_bits([2, 8, 8]);
let input_output_pairs: (int -> int)[] = cross_product([3, 256, 256]);

What do you think of this? Two changes:

  • I'm thinking of it in terms of a cross product, so at least for me it would be a better name.
  • I think the function could be rewritten to support cross products of ranges of arbitrary size. This would actually yield a different result and enforce that 0 <= op < 3. Then the match below would actually be exhaustive, like it was before.

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good!

Copy link
Member Author

Choose a reason for hiding this comment

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

We could even have a type at some point that stores a function and its cycle size. I think that is useful for implementing the [....]*-opreator as well.

@chriseth chriseth force-pushed the split_bits branch 2 times, most recently from e15b0b7 to b861a84 Compare February 8, 2024 08:04
let op = inputs[0];
col fixed P_A(i) { a(i) };
col fixed P_B(i) { b(i) };
col fixed P_operation(i) { op(i)};
Copy link
Member

Choose a reason for hiding this comment

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

Why do we still need PA PB...?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are used in the lookup below. Also, a and b are int -> int functions (we need that because if the binary operators) and the columns have the implicit conversion to fe.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe cross_product could return an array of columns (i.e., (int -> fe)[])? I think it would be cleaner overall, I don't find the int conversion below too bad.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or, another idea, cross_product() could also receive a (int[] -> int) to populate the result. But that assumes that there is only one output column.


let cross_product_internal: int, int[] -> (int -> int)[] = |cycle_len, len, sizes|
if len == 0 {
// We could assert here that the degree is at least `cycle_len`
Copy link
Collaborator

Choose a reason for hiding this comment

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

That would be great! Can we do it in this PR, or is there something blocking it?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have access to the degree. I think we should do this at a later point.

let op = inputs[0];
col fixed P_A(i) { a(i) };
col fixed P_B(i) { b(i) };
col fixed P_operation(i) { op(i)};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe cross_product could return an array of columns (i.e., (int -> fe)[])? I think it would be cleaner overall, I don't find the int conversion below too bad.

let op = inputs[0];
col fixed P_A(i) { a(i) };
col fixed P_B(i) { b(i) };
col fixed P_operation(i) { op(i)};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Or, another idea, cross_product() could also receive a (int[] -> int) to populate the result. But that assumes that there is only one output column.

@chriseth chriseth changed the title split_bits utility function. cross product utility function. Feb 9, 2024
@chriseth
Copy link
Member Author

chriseth commented Feb 9, 2024

I think the proper way to do this (but that requires structs) is to make cross_product accept an array of 'Ranges' over an arbitrary type.

@chriseth
Copy link
Member Author

chriseth commented Feb 9, 2024

The idea with the output function is good, but I think we need destructuring assignments first to make it nice.

@chriseth chriseth added this pull request to the merge queue Feb 9, 2024
Merged via the queue into main with commit 259f35d Feb 9, 2024
5 checks passed
@chriseth chriseth deleted the split_bits branch February 9, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants