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

Replace BTree with Vec in LinComb #322

Merged
merged 16 commits into from
Apr 18, 2019
Merged

Replace BTree with Vec in LinComb #322

merged 16 commits into from
Apr 18, 2019

Conversation

eupn
Copy link
Contributor

@eupn eupn commented Apr 14, 2019

Resolves #312.

Replaced BTreeMap with Vec of pairs (var, value). Unit tests passed, although the order of sum items that was dependent on the order of keys inBTreeMap is changed.

?r @Schaeff

@Schaeff
Copy link
Member

Schaeff commented Apr 15, 2019

Awesome, let me have a look at it! It's true that the BTreeMap representation has the advantage of being deterministic so great for testing, let's see what we can do there.

@Schaeff Schaeff changed the base branch from master to develop April 15, 2019 08:09
Copy link
Member

@Schaeff Schaeff left a comment

Choose a reason for hiding this comment

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

I think this is moving in the right direction :)
The main suggested changes are about

  • Accepting all unreduced forms (even those where some variables have a canonical coefficient of 0) to remove linear complexity in addition and subtraction
  • Move canonicalisation to the edges: Display and communication with the back end (I'll have a think about the latter, maybe it's not even necessary)

zokrates_core/src/ir/expression.rs Show resolved Hide resolved
zokrates_core/src/ir/expression.rs Outdated Show resolved Hide resolved
zokrates_core/src/ir/expression.rs Outdated Show resolved Hide resolved
zokrates_core/src/ir/expression.rs Outdated Show resolved Hide resolved
zokrates_core/src/ir/expression.rs Outdated Show resolved Hide resolved
zokrates_core/src/ir/expression.rs Outdated Show resolved Hide resolved
zokrates_core/src/ir/expression.rs Outdated Show resolved Hide resolved
zokrates_core/src/ir/expression.rs Outdated Show resolved Hide resolved
@Schaeff
Copy link
Member

Schaeff commented Apr 15, 2019

@eupn
Copy link
Contributor Author

eupn commented Apr 16, 2019

@eupn I had a quick go here https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=07c263548f34a377c3497a8b94d62a32
maybe that can help!

Got it, thanks a lot!

@Schaeff
Copy link
Member

Schaeff commented Apr 16, 2019

Hey @eupn I realise we don't tell contributors to do it but we use https://github.com/rust-lang/rustfmt.
I'll add this somewhere so it's clear!

@Schaeff
Copy link
Member

Schaeff commented Apr 18, 2019

Hey @eupn I think we're getting there! just a bit of context in the last change: the breaking test on 01c4d18 was due to the fact that that equality on programs (which is being tested) is derived automatically, so two lincomb that are "equivalent" (ie have the same canonical representation) are not "equal" (as they can have different representation in a vector of pairs). Therefore instead of making the optimizer canonical, I changed the definition of equality between lincomb to canonical equivalence.

Let me know if you have any thoughts or I missed something!

@Schaeff
Copy link
Member

Schaeff commented Apr 18, 2019

@eupn and on this last change, I made sure (2*~one + 3*~one) * (...) is recognised as linear: before the change, it would not try to reduce to 5*~one as the lincomb is of size > 1. Any lincomb of pairs of the same variable is reducable to a summand (coefficient times variable), not just 1-sized (canonical) lincombs.

Copy link
Member

@Schaeff Schaeff left a comment

Choose a reason for hiding this comment

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

LGTM

@Schaeff Schaeff merged commit 726c499 into Zokrates:develop Apr 18, 2019
@Schaeff Schaeff mentioned this pull request Apr 18, 2019
@eupn eupn deleted the cs-variables-vec branch May 4, 2019 00:06
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.

2 participants