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

Simplify expressions. #894

Merged
merged 1 commit into from
Nov 28, 2024
Merged

Simplify expressions. #894

merged 1 commit into from
Nov 28, 2024

Conversation

Alon-Ti
Copy link
Contributor

@Alon-Ti Alon-Ti commented Nov 19, 2024

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

@Alon-Ti Alon-Ti marked this pull request as ready for review November 19, 2024 11:49
@Alon-Ti Alon-Ti force-pushed the alont/formal-logup-sums-variables branch from 22d6538 to 86f314a Compare November 19, 2024 11:51
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from 1091abc to 9923962 Compare November 19, 2024 11:51
@Alon-Ti Alon-Ti force-pushed the alont/formal-logup-sums-variables branch from 86f314a to 1ed3739 Compare November 19, 2024 11:58
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from 9923962 to be9ba3a Compare November 19, 2024 11:58
@Alon-Ti Alon-Ti force-pushed the alont/formal-logup-sums-variables branch from 1ed3739 to 92a18c4 Compare November 19, 2024 12:55
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from be9ba3a to ab38c48 Compare November 19, 2024 12:55
@Alon-Ti Alon-Ti force-pushed the alont/formal-logup-sums-variables branch from 92a18c4 to 91ce7f8 Compare November 19, 2024 13:01
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from ab38c48 to 8f5fdc0 Compare November 19, 2024 13:01
@Alon-Ti Alon-Ti force-pushed the alont/formal-logup-sums-variables branch from 91ce7f8 to c45d810 Compare November 19, 2024 13:06
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from 8f5fdc0 to e39898f Compare November 19, 2024 13:06
@Alon-Ti Alon-Ti force-pushed the alont/formal-logup-sums-variables branch from c45d810 to e88e970 Compare November 19, 2024 13:09
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from e39898f to b9f2ff9 Compare November 19, 2024 13:09
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: d53fec3 Previous: cd8b37b Ratio
iffts/simd ifft/22 13528130 ns/iter (± 132749) 6306399 ns/iter (± 210024) 2.15
iffts/simd ifft/25 131797226 ns/iter (± 849972) 65891527 ns/iter (± 1735211) 2.00
iffts/simd ifft/28 1292042611 ns/iter (± 39669891) 643771030 ns/iter (± 19147376) 2.01
merkle throughput/simd merkle 30022184 ns/iter (± 492981) 13712527 ns/iter (± 579195) 2.19

This comment was automatically generated by workflow using github-action-benchmark.

CC: @shaharsamocha7

@codecov-commenter
Copy link

codecov-commenter commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 68.57143% with 22 lines in your changes missing coverage. Please review.

Project coverage is 91.56%. Comparing base (4d64300) to head (e4c2d1d).

Files with missing lines Patch % Lines
crates/prover/src/constraint_framework/expr.rs 68.57% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #894      +/-   ##
==========================================
- Coverage   91.69%   91.56%   -0.14%     
==========================================
  Files          93       93              
  Lines       13164    13228      +64     
  Branches    13164    13228      +64     
==========================================
+ Hits        12071    12112      +41     
- Misses        980     1003      +23     
  Partials      113      113              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@ohad-starkware ohad-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @Alon-Ti and @shaharsamocha7)


crates/prover/src/constraint_framework/expr.rs line 222 at r1 (raw file):

            }
        }
        Expr::Mul(a, b) => {

are you covering 1 * 1 => const(1)?


crates/prover/src/constraint_framework/expr.rs line 226 at r1 (raw file):

            let b = simplify(*b);
            if let (Expr::Const(a), Expr::Const(b)) = (a.clone(), b.clone()) {
                Expr::Const(a - b)

Suggestion:

a * b

Copy link
Contributor Author

@Alon-Ti Alon-Ti left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @ohad-starkware and @shaharsamocha7)


crates/prover/src/constraint_framework/expr.rs line 222 at r1 (raw file):

Previously, ohad-starkware (Ohad) wrote…

are you covering 1 * 1 => const(1)?

I think so, it would be caught in the first if let, no?


crates/prover/src/constraint_framework/expr.rs line 226 at r1 (raw file):

            let b = simplify(*b);
            if let (Expr::Const(a), Expr::Const(b)) = (a.clone(), b.clone()) {
                Expr::Const(a - b)

Done.

@Alon-Ti Alon-Ti force-pushed the alont/formal-logup-sums-variables branch from e88e970 to d88f160 Compare November 20, 2024 11:49
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from b9f2ff9 to 70aca12 Compare November 20, 2024 11:49
Copy link
Collaborator

@ohad-starkware ohad-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 2 files reviewed, all discussions resolved (waiting on @shaharsamocha7)


crates/prover/src/constraint_framework/expr.rs line 222 at r1 (raw file):

Previously, Alon-Ti wrote…

I think so, it would be caught in the first if let, no?

right


crates/prover/src/constraint_framework/expr.rs line 356 at r2 (raw file):

            .temp_vars
            .iter()
            .map(|(name, expr)| format!("let {} = {};", name, simplify(expr.clone()).format_expr()))

can you find a way to reduce the syntax?
maybe expr.simplify_and_format()
non blocking

Code quote:

 simplify(expr.clone()).format_expr()))

Copy link
Collaborator

@ohad-starkware ohad-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 0 of 2 files reviewed, all discussions resolved (waiting on @shaharsamocha7)

@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from c86533f to 56185a3 Compare November 24, 2024 16:45
@Alon-Ti Alon-Ti force-pushed the alont/formal-logup-sums-variables branch 2 times, most recently from 6501f2a to 584af24 Compare November 25, 2024 10:18
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from 56185a3 to 34ef1ba Compare November 25, 2024 10:19
@Alon-Ti Alon-Ti force-pushed the alont/formal-logup-sums-variables branch from 584af24 to 1a8cb5c Compare November 25, 2024 11:06
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from 34ef1ba to 8a20339 Compare November 25, 2024 11:06
@Alon-Ti Alon-Ti force-pushed the alont/formal-logup-sums-variables branch from 1a8cb5c to 0b14862 Compare November 25, 2024 15:31
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from 8a20339 to 1d9f08c Compare November 25, 2024 15:31
Copy link
Collaborator

@shaharsamocha7 shaharsamocha7 left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r5, all commit messages.
Reviewable status: 1 of 2 files reviewed, all discussions resolved (waiting on @ohad-starkware)

@Alon-Ti Alon-Ti changed the base branch from alont/formal-logup-sums-variables to graphite-base/894 November 26, 2024 08:27
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from 1d9f08c to b5e6acc Compare November 26, 2024 08:27
@Alon-Ti Alon-Ti changed the base branch from graphite-base/894 to dev November 26, 2024 08:28
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from b5e6acc to 188ba5c Compare November 26, 2024 08:28
Copy link
Collaborator

@shaharsamocha7 shaharsamocha7 left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r5.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @Alon-Ti)


crates/prover/src/constraint_framework/expr.rs line 196 at r5 (raw file):

}

pub fn simplify(expr: Expr) -> Expr {

I think this function should have more tests

Code quote:

pub fn simplify(expr: Expr) -> Expr {

crates/prover/src/constraint_framework/expr.rs line 217 at r5 (raw file):

            } else {
                a + b
            }

I think match statement is more readable
Consider to change

Code quote:

            if let (Expr::Const(a), Expr::Const(b)) = (a.clone(), b.clone()) {
                Expr::Const(a + b)
            } else if a == Expr::zero() {
                b
            } else if b == Expr::zero() {
                a
            } else if let Expr::Neg(a) = a {
                if let Expr::Neg(b) = b {
                    -(*a + *b)
                } else {
                    b - *a
                }
            } else if let Expr::Neg(b) = b {
                a - *b
            } else {
                a + b
            }

crates/prover/src/constraint_framework/expr.rs line 264 at r5 (raw file):

            let a = simplify(*a);
            match a {
                Expr::Neg(b) => *b,

Is this Neg(Neg(a))? can you comment on that?

Code quote:

Expr::Neg(b) => *b,

crates/prover/src/constraint_framework/expr.rs line 264 at r5 (raw file):

            let a = simplify(*a);
            match a {
                Expr::Neg(b) => *b,

What happens if a is a secure column?

Code quote:

            match a {
                Expr::Neg(b) => *b,

crates/prover/src/constraint_framework/expr.rs line 267 at r5 (raw file):

                Expr::Const(c) => Expr::Const(-c),
                Expr::Sub(a, b) => Expr::Sub(b, a),
                _ => -a,

I'm a bit worried of this
Will it always be correct?

Code quote:

_ => -a,

Copy link
Contributor Author

@Alon-Ti Alon-Ti left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @shaharsamocha7)


crates/prover/src/constraint_framework/expr.rs line 196 at r5 (raw file):

Previously, shaharsamocha7 wrote…

I think this function should have more tests

Added TODO


crates/prover/src/constraint_framework/expr.rs line 264 at r5 (raw file):

Previously, shaharsamocha7 wrote…

Is this Neg(Neg(a))? can you comment on that?

Done.


crates/prover/src/constraint_framework/expr.rs line 264 at r5 (raw file):

Previously, shaharsamocha7 wrote…

What happens if a is a secure column?

Neg(SecureColumn(...)). I can simplify Neg(SecureColumn(Neg, Neg, Neg, Neg)) etc, but I don't think we'll have many of these.


crates/prover/src/constraint_framework/expr.rs line 267 at r5 (raw file):

Previously, shaharsamocha7 wrote…

I'm a bit worried of this
Will it always be correct?

This just reconstructs Neg(a) if it can't be simplified. Should I change it to explicitly Expr::Neg(Box::new(a))?

Copy link
Collaborator

@shaharsamocha7 shaharsamocha7 left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: 1 of 2 files reviewed, 3 unresolved discussions (waiting on @Alon-Ti)


crates/prover/src/constraint_framework/expr.rs line 267 at r5 (raw file):

Previously, Alon-Ti wrote…

This just reconstructs Neg(a) if it can't be simplified. Should I change it to explicitly Expr::Neg(Box::new(a))?

I think it is better yes


crates/prover/src/constraint_framework/expr.rs line 210 at r6 (raw file):

                (Expr::Const(M31(0)), _) => b, // 0 + b = b
                (_, Expr::Const(ZERO)) => a,   // a + 0 = a
                // (-a + -b) = -(a + b)

Suggestion:

                (Expr::Const(ZERO), _) => b, // 0 + b = b
                (_, Expr::Const(ZERO)) => a,   // a + 0 = a
                // (-a + -b) = -(a + b)

crates/prover/src/constraint_framework/expr.rs line 211 at r6 (raw file):

                (_, Expr::Const(ZERO)) => a,   // a + 0 = a
                // (-a + -b) = -(a + b)
                (Expr::Neg(minus_a), Expr::Neg(minus_b)) => -(*minus_a + *minus_b),

I think you should open Exprs as a, b and not call them minus

Suggestion:

(Expr::Neg(a), Expr::Neg(b)) => -(*a + *b),

@Alon-Ti Alon-Ti mentioned this pull request Nov 27, 2024
@Alon-Ti Alon-Ti force-pushed the alont/simplify-expr branch from e4c2d1d to d53fec3 Compare November 27, 2024 11:17
Copy link
Contributor Author

@Alon-Ti Alon-Ti left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @shaharsamocha7)


crates/prover/src/constraint_framework/expr.rs line 210 at r6 (raw file):

                (Expr::Const(M31(0)), _) => b, // 0 + b = b
                (_, Expr::Const(ZERO)) => a,   // a + 0 = a
                // (-a + -b) = -(a + b)

Done.

Copy link
Collaborator

@shaharsamocha7 shaharsamocha7 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Alon-Ti)

@Alon-Ti Alon-Ti merged commit b6ea512 into dev Nov 28, 2024
18 of 19 checks passed
Copy link
Contributor Author

Alon-Ti commented Nov 28, 2024

Merge activity

  • Nov 28, 10:24 AM EST: A user merged this pull request with Graphite.

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.

5 participants