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
63ab861b
Commit
63ab861b
authored
Feb 20, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented {match_,}multiply_one functions.
parent
e115283e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
2 deletions
+38
-2
src/rules/__init__.py
src/rules/__init__.py
+2
-2
src/rules/numerics.py
src/rules/numerics.py
+36
-0
No files found.
src/rules/__init__.py
View file @
63ab861b
...
@@ -6,7 +6,7 @@ from .powers import match_add_exponents, match_subtract_exponents, \
...
@@ -6,7 +6,7 @@ from .powers import match_add_exponents, match_subtract_exponents, \
match_remove_negative_exponent
,
match_exponent_to_root
,
\
match_remove_negative_exponent
,
match_exponent_to_root
,
\
match_extend_exponent
,
match_constant_exponent
match_extend_exponent
,
match_constant_exponent
from
.numerics
import
match_add_numerics
,
match_divide_numerics
,
\
from
.numerics
import
match_add_numerics
,
match_divide_numerics
,
\
match_multiply_numerics
,
match_multiply_zero
match_multiply_numerics
,
match_multiply_zero
,
match_multiply_one
from
.fractions
import
match_constant_division
,
match_add_constant_fractions
,
\
from
.fractions
import
match_constant_division
,
match_add_constant_fractions
,
\
match_expand_and_add_fractions
match_expand_and_add_fractions
from
.negation
import
match_negated_factor
,
match_negate_polynome
,
\
from
.negation
import
match_negated_factor
,
match_negate_polynome
,
\
...
@@ -17,7 +17,7 @@ RULES = {
...
@@ -17,7 +17,7 @@ RULES = {
match_combine_groups
],
match_combine_groups
],
OP_MUL
:
[
match_multiply_numerics
,
match_expand
,
match_add_exponents
,
OP_MUL
:
[
match_multiply_numerics
,
match_expand
,
match_add_exponents
,
match_expand_and_add_fractions
,
match_multiply_zero
,
match_expand_and_add_fractions
,
match_multiply_zero
,
match_negated_factor
],
match_negated_factor
,
match_multiply_one
],
OP_DIV
:
[
match_subtract_exponents
,
match_divide_numerics
,
OP_DIV
:
[
match_subtract_exponents
,
match_divide_numerics
,
match_constant_division
,
match_negated_division
],
match_constant_division
,
match_negated_division
],
OP_POW
:
[
match_multiply_exponents
,
match_duplicate_exponent
,
OP_POW
:
[
match_multiply_exponents
,
match_duplicate_exponent
,
...
...
src/rules/numerics.py
View file @
63ab861b
...
@@ -155,6 +155,42 @@ def multiply_zero(root, args):
...
@@ -155,6 +155,42 @@ def multiply_zero(root, args):
MESSAGES
[
multiply_zero
]
=
_
(
'Multiplication with zero yields zero.'
)
MESSAGES
[
multiply_zero
]
=
_
(
'Multiplication with zero yields zero.'
)
def
match_multiply_one
(
node
):
"""
a * 1 -> a
1 * a -> a
-1 * a -> -a
1 * -a -> -a
-1 * -a -> a
"""
assert
node
.
is_op
(
OP_MUL
)
left
,
right
=
node
if
left
.
value
==
1
:
return
[
P
(
node
,
multiply_one
,
(
right
,
left
))]
if
right
.
value
==
1
:
return
[
P
(
node
,
multiply_one
,
(
left
,
right
))]
return
[]
def
multiply_one
(
root
,
args
):
"""
a * 1 -> a
1 * a -> a
-1 * a -> -a
1 * -a -> -a
-1 * -a -> a
"""
a
,
one
=
args
return
a
.
negate
(
one
.
negated
+
root
.
negated
)
MESSAGES
[
multiply_one
]
=
_
(
'Multiplication with one yields the multiplicant.'
)
def
match_multiply_numerics
(
node
):
def
match_multiply_numerics
(
node
):
"""
"""
3 * 2 -> 6
3 * 2 -> 6
...
...
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