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

Feat/poly #216

Merged
merged 8 commits into from
Jul 7, 2022
Merged

Feat/poly #216

merged 8 commits into from
Jul 7, 2022

Conversation

Tabaie
Copy link
Contributor

@Tabaie Tabaie commented Jun 29, 2022

Polynomial module from gkr project. If most things look good I'll clean up into a proper PR.

@Tabaie Tabaie changed the base branch from master to develop June 29, 2022 19:39
)

// Memory management for polynomials
// Copied verbatim from gkr repo
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer true

go.mod Outdated Show resolved Hide resolved
@@ -121,3 +147,75 @@ func (p *Polynomial) Equal(p1 Polynomial) bool {

return true
}

func signedBigInt(v *fr.Element) big.Int {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've seen the Text method does something similar to this. Should we extract that logic into a ToSignedBigInt that Text also calls?

Copy link
Collaborator

Choose a reason for hiding this comment

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

mmhh for the Text one, it actually did give me issues in the past; I think the Text / String should never output "negative" formating. And we should add a "prettyString" or something like that which does.

Current way it's done in Text doesn't allocate a big int I believe ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does!
https://github.com/ConsenSys/gnark-crypto/blob/master/ecc/bn254/fp/element.go#L824

Also, in this case using a pool makes sense because big.Int.SetBytes does sometimes reuse previously allocated memory correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes correct . We should by the way probably mutualize the big int pool declared in fr/ fp/ on each curves. Will create a ticket 👍


func (p Polynomial) Text(base int) string {
//TODO: Okay to use bavard in non-code-generation context?
builder := bavard.StringBuilderPool.Get().(*strings.Builder)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gbotrel Is it actually useful to pool string builders? I read somewhere that when a builder is done, the buffer is handed to the generated string and another buffer would be allocated for the next use. If that's the case, it makes no sense to pool these.

Copy link
Collaborator

Choose a reason for hiding this comment

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

probably not useful, and fine to do like the go std string builder 👍

@ThomasPiellard
Copy link
Contributor

ThomasPiellard commented Jul 6, 2022

@Tabaie I don't understand what does computeLagrangeBasis do ? Also, for multilinear polynomials I don't think that it's necessary to express them in another basis than the Lagrange basis on the hypercube. My understanding was that each time we deal with a vector [a0, .. , a_n], the i-th entry would implicitly correspond to the the i-th corner of the cube (i decomposed in base 2)

@Tabaie
Copy link
Contributor Author

Tabaie commented Jul 6, 2022

In the GKR project they do a lot of extrapolations on small domains of the form {0, 1, ..., n-1} into an explicit polynomial (I think, I haven't seen all of the repo yet but I assume that's how it is used). So this function is used to precompute the polynomials p_0 = (X-1)...(X-n)/ ((-1)(-2)...(-n)), p_1 = X(X-2)(X-3)...(X-n)/((1-0)(1-2)...(1-n)) etc so that a function X: {0, 1, ..., n-1} can be easily extrapolated as \sum_{i=0}^{n-1} X(i) p_i.

@Tabaie
Copy link
Contributor Author

Tabaie commented Jul 6, 2022

The multilinear ones are denoted by their values on the hypercube. This Lagrange thing is for univariate functions.

@ThomasPiellard
Copy link
Contributor

Ah ok. And why the FFT isn't used for this ? Are the degrees in play too small ?

@Tabaie
Copy link
Contributor Author

Tabaie commented Jul 6, 2022

Yes the maximum size is 12. I think that's too small for FFT to pay off. What do you think?

@ThomasPiellard
Copy link
Contributor

oh ok yes in that case it's better to do it by hands.

@Tabaie Tabaie marked this pull request as ready for review July 7, 2022 15:43
@Tabaie Tabaie merged commit b646d9e into develop Jul 7, 2022
@Tabaie Tabaie deleted the feat/poly branch July 7, 2022 15:44
@gbotrel gbotrel mentioned this pull request Aug 3, 2022
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