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

poly: improvements, tests and examples #208

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

PottierLoic
Copy link
Contributor

@PottierLoic PottierLoic commented Jul 15, 2024

This PR fix eval and sorted_3_ function, they returned wrong results.

The new eval function is now faster and return the correct result:

C:\Users\loicp\Documents\GitHub\vsl\poly>v run .
time for 10000 old eval: 219.500us
old_eval returned value: 53.0
time for 10000 new eval: 126.700us
new_eval returned value: 56.0

I'll add tests for the others functions soon and I can fill some examples to resolve this : #106

Summary by CodeRabbit

  • New Features

    • Added detailed examples for polynomial operations, including addition, subtraction, multiplication, and division.
    • Introduced new test functions to validate polynomial operations and derivatives.
    • Implemented a module for constructing and balancing companion matrices from polynomials.
  • Bug Fixes

    • Corrected the sorting logic to ensure accurate results in polynomial evaluations.
  • Improvements

    • Enhanced the polynomial evaluation function for better efficiency and clarity.
    • Updated test scenarios for improved coverage and accuracy, including adjustments to expected results.

Copy link

coderabbitai bot commented Jul 15, 2024

Walkthrough

The recent updates refine polynomial evaluation and manipulation in the poly/poly.v file, specifically enhancing the eval, sorted_3_, and divide functions. The poly_test.v file has seen significant improvements with new test cases and updated assertions, while a new main.v file demonstrates basic polynomial operations such as addition, subtraction, multiplication, and division. These changes collectively enhance the functionality and testing framework for polynomial mathematics.

Changes

Files Change Summary
poly/poly.v Major updates to the eval, sorted_3_, balance_companion_matrix, and divide functions for enhanced functionality and clarity.
poly/poly_test.v Improvements to test functions with updated calculations, assertions, and multiple new test additions for comprehensive coverage.
examples/poly_operations/main.v New file implementing polynomial operations: addition, subtraction, multiplication, and division.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Main
    participant Poly as vsl.poly
    
    User ->> Main: Run poly_operations example
    Main ->> Poly: Call add, subtract, multiply, divide functions
    Poly -->> Main: Return results
    Main -->> User: Display results
Loading

Possibly related PRs

Poem

In the code where numbers play,
Polynomials dance and sway.
With functions crisp and tests so bright,
Math in V takes joyful flight.
A rabbit's hop, a cheerful tune,
Together we explore this boon!
🐇✨

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d0b4fd5 and 6ebfb97.

Files selected for processing (3)
  • examples/poly_operations/main.v (1 hunks)
  • poly/poly.v (4 hunks)
  • poly/poly_test.v (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • examples/poly_operations/main.v
Additional comments not posted (11)
poly/poly_test.v (7)

5-7: LGTM!

The test case has been updated with the correct expected value. The changes look good.


9-14: Great addition!

The new test case for eval_derivs function looks good. It enhances the test coverage of polynomial operations by validating the derivative evaluation.


16-21: Great addition!

The new test case for solve_quadratic function looks good. It enhances the test coverage of polynomial operations by validating the roots of a quadratic equation.


31-37: LGTM!

The test case for sorted_3_ function looks good. The assertions correctly verify the order of the sorted elements.

The past review comment is no longer valid as the assertions have been updated correctly.


39-46: Great addition!

The new test case for companion_matrix function looks good. It enhances the test coverage of polynomial operations by validating the construction of a companion matrix from polynomial coefficients.


48-56: Great addition!

The new test case for balance_companion_matrix function looks good. It enhances the test coverage of polynomial operations by validating the balancing of the companion matrix.


81-91: LGTM!

The changes in the test_divide function look good. The test cases correctly verify the quotient and remainder of polynomial division.

The past review comment regarding the remainder value is no longer valid as the user has verified the result using an online solver.

poly/poly.v (4)

18-22: LGTM!

The changes to the eval function improve its clarity and performance. Initializing ans to zero and using a decrementing index i to traverse the coefficients in reverse order is a cleaner and more efficient approach compared to the previous implementation.


149-155: LGTM!

The changes to the sorted_3_ function improve its readability. The revised order of variable assignments during the sorting process makes the logic clearer and easier to follow.


218-228: LGTM!

The changes to the balance_companion_matrix function improve its readability. Replacing references to poly.radix and poly.radix2 with radix and radix2, respectively, makes the code cleaner and easier to understand.


293-320: LGTM!

The changes to the divide function improve its robustness. The additional checks for empty input polynomials prevent division by an empty polynomial and handle cases where the dividend is empty. This ensures that the function behaves correctly in all scenarios.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7fd1d43 and 4c41c75.

Files selected for processing (2)
  • poly/poly.v (2 hunks)
  • poly/poly_test.v (3 hunks)
Additional comments not posted (4)
poly/poly_test.v (2)

5-9: Ensure test_eval reflects the updated eval logic.

The comments and assertions in test_eval seem to align with the updated eval function logic. The test case appears to correctly validate the expected outcome based on the new loop structure and initialization of ans to 0.0.


39-44: Review the updated test_multiply for correctness.

The test_multiply function has been updated with new calculations and assertions. Ensure that the expected results in the assertion match the expected polynomial multiplication output. This test case should be verified to ensure it accurately reflects the changes in the multiply function.

poly/poly.v (2)

13-17: Approved changes in eval function.

The updated eval function initializes ans to 0.0 and correctly iterates through the coefficients in reverse order, ensuring that each coefficient is correctly factored into the result. This change aligns with the performance improvements noted in the PR description.


136-142: Verify the logic of sorted_3_ function.

The sorted_3_ function has been updated to ensure correct sorting by adjusting the conditional checks and variable assignments. It's crucial to verify that this function now correctly sorts any three values.

Verification successful

Verify the logic of sorted_3_ function.

The sorted_3_ function is implemented in poly/poly.v and is tested in poly/poly_test.v. The test case in poly/poly_test.v verifies the sorting logic. Please ensure that the test case comprehensively covers different scenarios to confirm the correctness of the function.

  • Location of sorted_3_ function implementation:

    • poly/poly.v: fn sorted_3_(x_ f64, y_ f64, z_ f64) (f64, f64, f64) {
  • Location of test case:

    • poly/poly_test.v: fn test_sorted_3_() {
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the logic of the sorted_3_ function by checking its usage and ensuring it sorts correctly.

# Test: Search for the sorted_3_ function usage. Expect: Only occurances of the new signature.
rg --type v -A 5 $'sorted_3_'

Length of output: 54


Script:

#!/bin/bash
# Description: Verify the logic of the sorted_3_ function by checking its usage and ensuring it sorts correctly.

# Test: Search for the sorted_3_ function usage in all .v files.
rg 'sorted_3_' --glob '*.v' -A 5

Length of output: 820

poly/poly_test.v Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4c41c75 and e736526.

Files selected for processing (2)
  • poly/poly.v (2 hunks)
  • poly/poly_test.v (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • poly/poly.v
  • poly/poly_test.v

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
examples/poly_eval/README.md (1)

3-3: Add missing article for grammatical correctness.

Consider adding "a" before "polynomial" to improve the grammatical correctness of the sentence.

- This example demonstrates the usage of the V Scientific Library for evaluating polynomial at given value of x.
+ This example demonstrates the usage of the V Scientific Library for evaluating a polynomial at a given value of x.
Tools
LanguageTool

[uncategorized] ~3-~3: You might be missing the article “a” here.
Context: ...ic Library for evaluating polynomial at given value of x. ## Instructions 1. Ensure...

(AI_EN_LECTOR_MISSING_DETERMINER_A)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e736526 and 6e57a00.

Files selected for processing (4)
  • examples/poly_eval/README.md (1 hunks)
  • examples/poly_eval/main.v (1 hunks)
  • examples/poly_operations/README.md (1 hunks)
  • examples/poly_operations/main.v (1 hunks)
Files skipped from review due to trivial changes (2)
  • examples/poly_eval/main.v
  • examples/poly_operations/README.md
Additional context used
LanguageTool
examples/poly_eval/README.md

[uncategorized] ~3-~3: You might be missing the article “a” here.
Context: ...ic Library for evaluating polynomial at given value of x. ## Instructions 1. Ensure...

(AI_EN_LECTOR_MISSING_DETERMINER_A)

Additional comments not posted (2)
examples/poly_eval/README.md (1)

1-17: Review of README content.

The README provides clear instructions on how to run the polynomial evaluation example using the V Scientific Library. The steps are well-documented and include links to necessary resources.

Tools
LanguageTool

[uncategorized] ~3-~3: You might be missing the article “a” here.
Context: ...ic Library for evaluating polynomial at given value of x. ## Instructions 1. Ensure...

(AI_EN_LECTOR_MISSING_DETERMINER_A)

examples/poly_operations/main.v (1)

1-23: Review of polynomial operations example.

The example demonstrates polynomial operations using the VSL effectively. The code is clean and well-commented, providing clear insights into the operations being performed.

examples/poly_operations/main.v Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6e57a00 and cc2d76c.

Files selected for processing (3)
  • examples/poly_operations/main.v (1 hunks)
  • poly/poly.v (3 hunks)
  • poly/poly_test.v (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • examples/poly_operations/main.v
  • poly/poly_test.v
Additional comments not posted (2)
poly/poly.v (2)

13-17: Refactored eval function: Correctness and Performance

The refactoring of the eval function from a forward iteration to a reverse iteration approach is a significant improvement. This change not only corrects the previously incorrect results but also enhances performance, as demonstrated in the PR description. The use of a reverse iteration aligns well with the Horner's method for polynomial evaluation, which is known for its efficiency.


136-142: Refactored sorted_3_ function: Logic and Efficiency

The changes to the sorted_3_ function's logic, where the sequence of comparisons and swaps has been adjusted, are critical for ensuring the correct sorting of the three values. The new sequence of swaps ensures that the smallest value is correctly placed first, followed by the second smallest, and then the largest, which is a more logical and efficient approach than the previous one.

However, it's important to verify that this new logic indeed sorts the values correctly in all scenarios.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cc2d76c and 9277af1.

Files selected for processing (3)
  • examples/poly_operations/main.v (1 hunks)
  • poly/poly.v (4 hunks)
  • poly/poly_test.v (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • examples/poly_operations/main.v
  • poly/poly_test.v
Additional comments not posted (2)
poly/poly.v (2)

13-17: Approved changes in eval function.

The changes optimize polynomial evaluation using a decrementing loop, which is a typical implementation of Horner's method for evaluating polynomials efficiently. The transformation is correctly implemented.

However, ensure that the function handles cases where the coefficients array might be empty, as indicated by the initial panic check.

Verification successful

Approved changes in eval function.

The changes optimize polynomial evaluation using a decrementing loop, which is a typical implementation of Horner's method for evaluating polynomials efficiently. The transformation is correctly implemented.

Additionally, the function includes a panic condition to handle cases where the coefficients array might be empty, ensuring robust error handling.

  • Verified the handling of empty coefficients with the panic condition at the start of the function.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify handling of empty coefficients in `eval` function.

# Test: Search for the panic condition when coefficients are empty. Expect: Proper handling of empty input.
rg --type v -A 5 $'if c.len == 0'

Length of output: 60


Script:

#!/bin/bash
# Description: Verify handling of empty coefficients in `eval` function.

# Test: Search for the panic condition when coefficients are empty. Expect: Proper handling of empty input.
rg -A 5 'if c.len == 0'

Length of output: 205


136-142: Approved changes in sorted_3_ function.

The updated logic in sorted_3_ function ensures correct sorting of three values using a simple and effective conditional structure, akin to a bubble sort for three elements. The changes are correctly implemented to ensure that values are sorted in ascending order.

However, verify that the sorting logic always results in the correct order by comparing against a variety of test cases.

@PottierLoic
Copy link
Contributor Author

I have a problem with the solve_cubic function, I don't understand why it has only 3 parameters, a cubic polynomial should be written as $ax^3+bx^2+cx+d$, with a, b, c and d as parameters.

@PottierLoic PottierLoic changed the title poly: fix eval and sorted_3_ + fix tests poly: poly improvements, tests and examples Jul 19, 2024
@PottierLoic PottierLoic changed the title poly: poly improvements, tests and examples poly: improvements, tests and examples Jul 19, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
examples/poly_eval/main.v (1)

5-10: Ensure consistent types in the coefficients list.

The coefficients list should use consistent types for better readability and to avoid potential issues.

-	coef := [4.0, 5, 2]
+	coef := [4.0, 5.0, 2.0]
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9277af1 and 9695393.

Files selected for processing (2)
  • examples/poly_eval/main.v (1 hunks)
  • poly/poly_test.v (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • poly/poly_test.v
Additional comments not posted (2)
examples/poly_eval/main.v (2)

1-4: LGTM!

The module declaration and import statement are correct.


12-16: LGTM!

The example correctly evaluates the polynomial derivatives.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9695393 and eae3bf6.

Files selected for processing (3)
  • examples/poly_matrix/README.md (1 hunks)
  • examples/poly_matrix/main.v (1 hunks)
  • poly/poly_test.v (2 hunks)
Files skipped from review due to trivial changes (1)
  • examples/poly_matrix/README.md
Additional comments not posted (14)
examples/poly_matrix/main.v (4)

1-4: LGTM!

The module declaration and import statement are correct and necessary.


5-8: LGTM!

The main function and polynomial coefficients are correctly defined.


9-19: LGTM!

The companion matrix calculation and printing are correct and follow the mathematical definition.


21-26: LGTM!

The balancing matrix calculation and printing are correct and follow the mathematical definition.

poly/poly_test.v (10)

5-10: LGTM!

The test case for the eval function is correct and verifies the expected output.


12-17: LGTM!

The test case for the eval_derivs function is correct and verifies the expected output.


19-24: LGTM!

The test case for the solve_quadratic function is correct and verifies the expected output.


Line range hint 26-31:
LGTM!

The test case for the swap_ function is correct and verifies the expected output.


34-40: LGTM!

The test case for the sorted_3_ function is correct and verifies the expected output.


42-49: LGTM!

The test case for the companion_matrix function is correct and verifies the expected output.


51-58: LGTM!

The test case for the balance_companion_matrix function is correct and verifies the expected output.


61-64: LGTM!

The test case for the add function is correct and verifies the expected output.


67-70: LGTM!

The test case for the subtract function is correct and verifies the expected output.


73-76: LGTM!

The test case for the multiply function is correct and verifies the expected output.

poly/poly_test.v Outdated Show resolved Hide resolved
@PottierLoic
Copy link
Contributor Author

Sorry for the noise in the 2 previous commit messages, I confused my 2 PR...

@PottierLoic
Copy link
Contributor Author

I have a problem with the solve_cubic function, I don't understand why it has only 3 parameters, a cubic polynomial should be written as a x 3 + b x 2 + c x + d , with a, b, c and d as parameters.

I read something about normalized cubic polynomials where 𝑎 is equal to 1. Is that what the function is supposed to take as parameters?

@ulises-jeremias can you explain me the goal behind this ?

Merging with @suleyman-kaya changes
removed println and useless math import in poly_test.v
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
examples/poly_operations/main.v (1)

5-33: Great examples of polynomial operations!

The main function provides clear examples of using the polynomial operations from the V Scientific Library, including addition, subtraction, multiplication, and division. This is a valuable addition to the codebase.

A few suggestions for improvement:

  1. Address the TODO comment regarding fixing the division operation. Ensure that the division example produces the expected results.
  2. Consider enhancing the print statements to provide more context about each operation. For example:
    println('Addition of ${poly_1} and ${poly_2}:')
    println('Result: ${result_add}')
    This will make the output more informative and easier to understand.

Overall, great work on demonstrating the usage of polynomial operations!

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eae3bf6 and 2f05eb1.

Files selected for processing (3)
  • examples/poly_operations/main.v (1 hunks)
  • poly/poly.v (2 hunks)
  • poly/poly_test.v (4 hunks)
Additional comments not posted (9)
poly/poly_test.v (7)

5-7: Verify the updated expected result.

The expected result for the polynomial evaluation has been updated from 53 to 56. It's crucial to ensure that this change aligns with the modifications made to the eval function's implementation.

Please double-check the coefficients and the evaluation logic to confirm that the new expected result of 56 is indeed correct. If necessary, provide additional test cases to cover different scenarios and boundary conditions.


9-14: LGTM!

The addition of the test_eval_derivs function is a valuable contribution to the test suite. It verifies the correctness of the eval_derivs function, which evaluates the derivatives of a polynomial at a given point.

The test case is well-structured and covers the expected behavior. Great job on enhancing the test coverage for polynomial operations!


16-21: LGTM!

The addition of the test_solve_quadratic function is a great contribution to the test suite. It verifies the correctness of the solve_quadratic function, which finds the roots of a quadratic equation.

The test case is well-structured and covers the expected behavior. It's great to see the test coverage expanding to include different types of polynomial equations!


31-37: LGTM!

The updated test_sorted_3_ function now includes assertions to verify the expected order of the sorted values. The assertions cover all three sorted positions, ensuring that the values are indeed sorted in ascending order.

The test case is well-structured and provides comprehensive coverage of the sorted_3_ function's behavior. Great job on enhancing the test suite!


39-46: LGTM!

The addition of the test_companion_matrix function is a valuable contribution to the test suite. It verifies the correctness of the companion_matrix function, which constructs a companion matrix from polynomial coefficients.

The test case is well-structured and covers the expected behavior. It's great to see the test coverage expanding to include matrix-related operations!


48-56: LGTM!

The addition of the test_balance_companion_matrix function is a great contribution to the test suite. It verifies the correctness of the balance_companion_matrix function, which balances a companion matrix to improve numerical stability.

The test case is well-structured and covers the expected behavior. It's excellent to see the test coverage expanding to include matrix balancing operations!


Line range hint 58-91: LGTM!

The removal of print statements from the test_add, test_subtract, test_multiply, and test_divide functions is a positive change. It helps to keep the test output clean and focused on the assertions.

By relying solely on assertions to verify the expected behavior, the test functions become more maintainable and less prone to errors caused by manual inspection of printed output.

Great job on improving the test suite's clarity and reliability!

poly/poly.v (2)

18-22: Verify the updated polynomial evaluation logic.

The changes made to the eval function modify the way polynomial evaluation is performed. The new implementation initializes ans to zero and uses a decrementing index i to traverse the coefficients in reverse.

While the updated logic appears to be correct, it's important to verify the following:

  1. Ensure that the changes do not introduce any unintended side effects or bugs.
  2. Confirm that the updated implementation produces the same results as the previous version for various test cases.
  3. Assess the performance impact of the changes, if any, to ensure that the evaluation remains efficient.

Please provide additional test cases and benchmarks to validate the correctness and performance of the updated eval function.


149-156: Verify the updated sorting logic.

The changes made to the sorted_3_ function modify the order in which the variables are compared and swapped during the sorting process. The updated conditions ensure that the variables are sorted in ascending order.

While the new implementation appears to be correct, it's important to verify the following:

  1. Ensure that the changes do not introduce any unintended side effects or bugs.
  2. Confirm that the updated implementation produces the expected sorted order for various test cases, including edge cases and different input combinations.

Please provide additional test cases to validate the correctness of the updated sorted_3_ function and ensure that it handles all possible scenarios correctly.

@PottierLoic
Copy link
Contributor Author

@suleyman-kaya
I noticed an issue in the divide function
It might be my mistake,but the result of the following code:

poly_dividend := [2.0, -4.0, -4.0, 1.0] // 2 - 4x - 4x^2 + x^3
poly_divisor := [-2.0, 1.0] // -2 + x
quotient, remainder := poly.divide(poly_dividend, poly_divisor)

should be :
Division quotient: [1.0, -2.0, -8.0]
Division remainder: [-14.0]

When I reverse the order of the parameters, I get the correct result.
So I believe the comment above the divide function should be updated:

...
// Input: a = [a_0, ..., a_n], b = [b_0, ..., b_m]
...
pub fn divide(a []f64, b []f64) ([]f64, []f64) {

Alternatively, we could modify the function so that it accepts the parameters in the order specified in the comment.
(It would be more consistent since all the functions in the poly module take the lower degree coefficient first, with divide being the only exception.)

Copy link
Contributor

@suleyman-kaya suleyman-kaya left a comment

Choose a reason for hiding this comment

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

Thank you for efforts, all seems good! I regret that I am unable to make the necessary changes in the near future, and therefore, I must kindly request your assistance in this matter. Please feel free to employ any method you deem appropriate to resolve this issue.

@PottierLoic
Copy link
Contributor Author

No problem, I'll take a look when I have some time. You couldn't catch it with test_poly because the test is done with a symmetric polynomial:

a := [1.0, 2.0, 1.0]
b := [1.0, 1.0]

Reversing the two lists wouldn't change anything, which is why it passed :)

Copy link
Contributor

@suleyman-kaya suleyman-kaya left a comment

Choose a reason for hiding this comment

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

All seems great! Thank you for your efforts Loïc!

@PottierLoic
Copy link
Contributor Author

@ulises-jeremias could you take a look please ?

Also, a v fmt -w . would change A LOT of files.. I did it on the files I modified, but there are a lot of others and I don't understand why.

@larpon
Copy link
Contributor

larpon commented Sep 13, 2024

@ulises-jeremias could you take a look please ?

Also, a v fmt -w . would change A LOT of files.. I did it on the files I modified, but there are a lot of others and I don't understand why.

vfmt has changed in a few places recently and maintainers hasn't had time to update the code base it seems.

@PottierLoic
Copy link
Contributor Author

PottierLoic commented Sep 15, 2024

Oh ok I guess i can fmt everything in that case ?

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