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

Fraction Reduction rule #24

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Conversation

justindujardin
Copy link
Member

@justindujardin justindujardin commented Feb 24, 2025

Add support for reducing fractions, layout.render_tree_to_text utility, and improved error reporting.

should probably update the poly simplify generation function to include fractions.

render_tree_to_text

from mathy_core import ExpressionParser
from mathy_core.layout import render_tree_to_text

parser = ExpressionParser()
expression = parser.parse("4x + 2x = 6x")
print(render_tree_to_text(expression))

                 =          
              ╱      ╲      
         +              *   
       ╱     ╲         ╱  ╲ 
   *           *     6     x
  ╱  ╲        ╱  ╲          
4     x     2     x         

Used for debugging fraction reduction rule errors, generally enriches test assertions:

E       ValueError: 
E       
E         unknown env: Expression value changed
E         
E               IN: (3x^2) / 6x = 6.0
E       
E               
E                /         
E              ╱     ╲     
E          *           *   
E         ╱  ╲        ╱  ╲ 
E       3     ^     6     x
E            ╱  ╲          
E          x     2         
E       
E               OUT: 1 / 2x = 0.041666666666666664
E       
E               
E          /      
E         ╱  ╲    
E       1     *   
E            ╱  ╲ 
E          2     x
E       
E               ERROR: 6.0 != 0.041666666666666664
E               
E       
E         Traceback:
E         ├─ test_rules_fraction_reduction in /home/user/mathy_core/tests/test_rules.py:63
E         ├─── run_rule_tests in /home/user/mathy_core/mathy_core/testing.py:108
E         └───── compare_expression_string_values in /home/user/mathy_core/mathy_core/util.py:41

Copy link

netlify bot commented Feb 24, 2025

Deploy Preview for friendly-daifuku-ae17d2 canceled.

Name Link
🔨 Latest commit 6080631
🔍 Latest deploy log https://app.netlify.com/sites/friendly-daifuku-ae17d2/deploys/67bcdd6900da5900088a1d03

Copy link

codecov bot commented Feb 24, 2025

Codecov Report

Attention: Patch coverage is 90.98712% with 21 lines in your changes missing coverage. Please review.

Project coverage is 88.89%. Comparing base (8f09702) to head (6080631).

Files with missing lines Patch % Lines
mathy_core/util.py 84.53% 15 Missing ⚠️
mathy_core/layout.py 91.80% 5 Missing ⚠️
mathy_core/problems.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #24      +/-   ##
==========================================
+ Coverage   88.73%   88.89%   +0.16%     
==========================================
  Files          22       23       +1     
  Lines        2556     2729     +173     
==========================================
+ Hits         2268     2426     +158     
- Misses        288      303      +15     

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

@justindujardin justindujardin added documentation Improvements or additions to documentation enhancement New feature or request rules PRs related to implementing rules labels Feb 24, 2025
@justindujardin justindujardin changed the title WIP: Fraction Reduction rule Fraction Reduction rule Feb 24, 2025
…ault

BREAKING CHANGE: prior to this ConstantsSimplify would by default evaluate any fractions it found, yielding a single constant value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request rules PRs related to implementing rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant