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
fa6beda1
Commit
fa6beda1
authored
Jan 09, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added pretty printing of possibilities with 'add_exponents' as usage example.
parent
ae1b35f7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
6 deletions
+23
-6
src/possibilities.py
src/possibilities.py
+12
-1
src/rules/numerics.py
src/rules/numerics.py
+1
-1
src/rules/poly.py
src/rules/poly.py
+2
-3
src/rules/powers.py
src/rules/powers.py
+8
-1
No files found.
src/possibilities.py
View file @
fa6beda1
# Each rule will append its hint message to the following dictionary. The
# function pointer to the apply function of the rule is used as key. The
# corresponding value is a string, which will be used to produce the hint
# message. The string will be processed using string.format().
MESSAGES
=
{}
class
Possibility
(
object
):
class
Possibility
(
object
):
def
__init__
(
self
,
root
,
handler
,
args
):
def
__init__
(
self
,
root
,
handler
,
args
):
self
.
root
=
root
self
.
root
=
root
...
@@ -5,11 +12,15 @@ class Possibility(object):
...
@@ -5,11 +12,15 @@ class Possibility(object):
self
.
args
=
args
self
.
args
=
args
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
handler
in
MESSAGES
:
return
MESSAGES
[
self
.
handler
].
format
(
self
.
root
,
*
self
.
args
)
return
'<Possibility root="%s" handler=%s args=%s>'
\
return
'<Possibility root="%s" handler=%s args=%s>'
\
%
(
self
.
root
,
self
.
handler
.
func_name
,
self
.
args
)
%
(
self
.
root
,
self
.
handler
.
func_name
,
self
.
args
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
str
(
self
)
return
'<Possibility root="%s" handler=%s args=%s>'
\
%
(
self
.
root
,
self
.
handler
.
func_name
,
self
.
args
)
# TODO: Add unit tests
# TODO: Add unit tests
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
...
...
src/rules/numerics.py
View file @
fa6beda1
from
..node
import
ExpressionLeaf
as
Leaf
,
OP_DIV
,
OP_MUL
from
..node
import
ExpressionLeaf
as
Leaf
,
OP_DIV
,
OP_MUL
from
..possibilities
import
Possibility
as
P
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
.utils
import
nary_node
from
.utils
import
nary_node
...
...
src/rules/poly.py
View file @
fa6beda1
from
itertools
import
combinations
from
itertools
import
combinations
from
..node
import
ExpressionNode
as
Node
,
ExpressionLeaf
as
Leaf
,
\
from
..node
import
ExpressionNode
as
Node
,
OP_ADD
,
OP_MUL
OP_ADD
,
OP_MUL
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..possibilities
import
Possibility
as
P
from
.utils
import
nary_node
from
.utils
import
nary_node
from
.numerics
import
add_numerics
from
.numerics
import
add_numerics
...
...
src/rules/powers.py
View file @
fa6beda1
...
@@ -2,8 +2,9 @@ from itertools import combinations
...
@@ -2,8 +2,9 @@ from itertools import combinations
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
\
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
\
OP_NEG
,
OP_MUL
,
OP_DIV
,
OP_POW
OP_NEG
,
OP_MUL
,
OP_DIV
,
OP_POW
from
..possibilities
import
Possibility
as
P
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
.utils
import
nary_node
from
.utils
import
nary_node
from
..translate
import
_
def
match_add_exponents
(
node
):
def
match_add_exponents
(
node
):
...
@@ -137,6 +138,12 @@ def add_exponents(root, args):
...
@@ -137,6 +138,12 @@ def add_exponents(root, args):
return
nary_node
(
'*'
,
scope
)
return
nary_node
(
'*'
,
scope
)
#MESSAGES[add_exponents] = _('Add the exponents of {1[0]} and {1[1]}, which'
# ' will reduce to {1[0][0]}^({1[0][1]} + {1[1][1]}).')
MESSAGES
[
add_exponents
]
=
_
(
'Add the exponents of {1} and {2}, which'
' will reduce to {1[0]}^({1[1]} + {2[1]}).'
)
def
subtract_exponents
(
root
,
args
):
def
subtract_exponents
(
root
,
args
):
"""
"""
a^p / a^q -> a^(p - q)
a^p / a^q -> a^(p - q)
...
...
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