Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
trs
Commits
4eeb4ba8
Commit
4eeb4ba8
authored
Jan 23, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added possibilities to fraction rules.
parent
bfd41939
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
src/rules/fractions.py
src/rules/fractions.py
+18
-2
tests/test_rules_fractions.py
tests/test_rules_fractions.py
+2
-2
No files found.
src/rules/fractions.py
View file @
4eeb4ba8
...
@@ -28,11 +28,11 @@ def match_constant_division(node):
...
@@ -28,11 +28,11 @@ def match_constant_division(node):
# 0 / a
# 0 / a
if
nominator
==
0
:
if
nominator
==
0
:
p
.
append
(
P
(
node
,
division_of_zero
))
p
.
append
(
P
(
node
,
division_of_zero
,
(
denominator
,)
))
# a / a
# a / a
if
nominator
==
denominator
:
if
nominator
==
denominator
:
p
.
append
(
P
(
node
,
division_by_self
))
p
.
append
(
P
(
node
,
division_by_self
,
(
nominator
,)
))
return
p
return
p
...
@@ -44,6 +44,9 @@ def division_by_one(root, args):
...
@@ -44,6 +44,9 @@ def division_by_one(root, args):
return
args
[
0
]
return
args
[
0
]
MESSAGES
[
division_by_one
]
=
_
(
'Division of {1} by 1 reduces to {1}.'
)
def
division_of_zero
(
root
,
args
):
def
division_of_zero
(
root
,
args
):
"""
"""
0 / a -> 0
0 / a -> 0
...
@@ -51,6 +54,9 @@ def division_of_zero(root, args):
...
@@ -51,6 +54,9 @@ def division_of_zero(root, args):
return
L
(
0
)
return
L
(
0
)
MESSAGES
[
division_of_zero
]
=
_
(
'Division of 0 by {1} reduces to 0.'
)
def
division_by_self
(
root
,
args
):
def
division_by_self
(
root
,
args
):
"""
"""
a / a -> 1
a / a -> 1
...
@@ -58,6 +64,9 @@ def division_by_self(root, args):
...
@@ -58,6 +64,9 @@ def division_by_self(root, args):
return
L
(
1
)
return
L
(
1
)
MESSAGES
[
division_by_self
]
=
_
(
'Division of {1} by {1} reduces to 1.'
)
def
match_add_constant_fractions
(
node
):
def
match_add_constant_fractions
(
node
):
"""
"""
1 / 2 + 3 / 4 -> 2 / 4 + 3 / 4 # Equalize denominators
1 / 2 + 3 / 4 -> 2 / 4 + 3 / 4 # Equalize denominators
...
@@ -118,6 +127,10 @@ def equalize_denominators(root, args):
...
@@ -118,6 +127,10 @@ def equalize_denominators(root, args):
return
nary_node
(
'+'
,
scope
)
return
nary_node
(
'+'
,
scope
)
MESSAGES
[
equalize_denominators
]
=
_
(
'Equalize the denominators of division'
' of {1} by {2}.'
)
def
add_nominators
(
root
,
args
):
def
add_nominators
(
root
,
args
):
"""
"""
a / b + c / b -> (a + c) / b
a / b + c / b -> (a + c) / b
...
@@ -145,6 +158,9 @@ def add_nominators(root, args):
...
@@ -145,6 +158,9 @@ def add_nominators(root, args):
return
nary_node
(
'+'
,
scope
)
return
nary_node
(
'+'
,
scope
)
MESSAGES
[
add_nominators
]
=
_
(
'Add nominators of the division of {1} by {2}.'
)
def
match_expand_and_add_fractions
(
node
):
def
match_expand_and_add_fractions
(
node
):
"""
"""
a * b / c + d * b / c -> (a + d) * (b / c)
a * b / c + d * b / c -> (a + d) * (b / c)
...
...
tests/test_rules_fractions.py
View file @
4eeb4ba8
...
@@ -21,11 +21,11 @@ class TestRulesFractions(RulesTestCase):
...
@@ -21,11 +21,11 @@ class TestRulesFractions(RulesTestCase):
root
=
zero
/
a
root
=
zero
/
a
possibilities
=
match_constant_division
(
root
)
possibilities
=
match_constant_division
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
division_of_zero
)])
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
division_of_zero
,
(
a
,)
)])
root
=
a
/
a
root
=
a
/
a
possibilities
=
match_constant_division
(
root
)
possibilities
=
match_constant_division
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
division_by_self
)])
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
division_by_self
,
(
a
,)
)])
def
test_division_by_one
(
self
):
def
test_division_by_one
(
self
):
a
=
tree
(
'a'
)
a
=
tree
(
'a'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment