Skip to content

Fraction Reduction rule#24

Open
justindujardin wants to merge 17 commits into
masterfrom
feat/fraction-reduction
Open

Fraction Reduction rule#24
justindujardin wants to merge 17 commits into
masterfrom
feat/fraction-reduction

Conversation

@justindujardin

@justindujardin justindujardin commented Feb 24, 2025

Copy link
Copy Markdown
Member

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

@netlify

netlify Bot commented Feb 24, 2025

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Feb 24, 2025

Copy link
Copy Markdown

Codecov Report

❌ 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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@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