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
63b9dd96
Commit
63b9dd96
authored
Nov 17, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extending exponents is now limited to 1 < exponent < 4
parent
30c29dd5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
src/rules/powers.py
src/rules/powers.py
+12
-5
No files found.
src/rules/powers.py
View file @
63b9dd96
...
@@ -278,16 +278,20 @@ MESSAGES[exponent_to_root] = \
...
@@ -278,16 +278,20 @@ MESSAGES[exponent_to_root] = \
def
match_extend_exponent
(
node
):
def
match_extend_exponent
(
node
):
"""
"""
(a + ... + z)^n -> (a + ... + z)(a + ... + z)^(n - 1) # n > 1
(a + ... + z)^n -> (a + ... + z)(a + ... + z)^(n - 1) # 1 < n < 4
n is maxed at 3 because otherwise evaluations may get out of hand, and high
school expressions do not contain powers higher than 3
"""
"""
assert
node
.
is_op
(
OP_POW
)
assert
node
.
is_op
(
OP_POW
)
left
,
right
=
node
left
,
right
=
node
if
right
.
is_numeric
():
if
right
.
is_numeric
()
and
1
<
right
.
actual_value
()
<
4
:
for
n
in
Scope
(
node
):
for
n
in
Scope
(
node
):
if
n
.
is_op
(
OP_ADD
):
if
n
.
is_op
(
OP_ADD
):
return
[
P
(
node
,
extend_exponent
,
(
left
,
right
))]
return
[
P
(
node
,
extend_exponent
,
(
left
,
right
,
right
.
actual_value
()
-
1
))]
return
[]
return
[]
...
@@ -296,14 +300,17 @@ def extend_exponent(root, args):
...
@@ -296,14 +300,17 @@ def extend_exponent(root, args):
"""
"""
(a + ... + z)^n -> (a + ... + z)(a + ... + z)^(n - 1) # n > 1
(a + ... + z)^n -> (a + ... + z)(a + ... + z)^(n - 1) # n > 1
"""
"""
left
,
right
=
args
left
,
right
,
extended_exp
=
args
if
right
.
value
>
2
:
if
right
.
value
>
2
:
return
left
*
left
**
L
(
right
.
value
-
1
)
return
left
*
left
**
L
(
extended_exp
)
return
left
*
left
return
left
*
left
MESSAGES
[
extend_exponent
]
=
_
(
'Split exponent {2} to exponents `1` and {3}.'
)
def
match_constant_exponent
(
node
):
def
match_constant_exponent
(
node
):
"""
"""
(a + ... + z)^n -> (a + ... + z)(a + ... + z)^(n - 1) # n > 1
(a + ... + z)^n -> (a + ... + z)(a + ... + z)^(n - 1) # n > 1
...
...
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