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
68a227a2
Commit
68a227a2
authored
Jun 13, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sqrt(a) no longer supports an additional argument for n (n=2 by default).
parent
bc8b6611
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
26 deletions
+23
-26
src/rules/powers.py
src/rules/powers.py
+12
-8
src/rules/sqrt.py
src/rules/sqrt.py
+1
-1
tests/test_rules_powers.py
tests/test_rules_powers.py
+10
-17
No files found.
src/rules/powers.py
View file @
68a227a2
...
...
@@ -249,27 +249,31 @@ MESSAGES[remove_negative_root] = _('{0[1]} is an odd number, so apply the ' \
def
match_exponent_to_root
(
node
):
"""
a^(1 /
m) -> sqrt(a, m
)
a^(n /
m) -> sqrt(a^n, m
)
a^(1 /
2) -> sqrt(a
)
a^(n /
2) -> sqrt(a^n
)
"""
assert
node
.
is_op
(
OP_POW
)
left
,
right
=
node
if
right
.
is_op
(
OP_DIV
):
return
[
P
(
node
,
exponent_to_root
,
(
left
,)
+
tuple
(
right
)
)]
if
right
.
is_op
(
OP_DIV
)
and
right
[
1
]
==
2
:
return
[
P
(
node
,
exponent_to_root
)]
return
[]
def
exponent_to_root
(
root
,
args
):
"""
a^(1 /
m) -> sqrt(a, m
)
a^(n /
m) -> sqrt(a^n, m
)
a^(1 /
2) -> sqrt(a
)
a^(n /
2) -> sqrt(a^n
)
"""
a
,
n
,
m
=
args
a
,
(
n
,
_
)
=
root
return
N
(
OP_SQRT
,
a
if
n
==
1
else
a
**
n
,
m
)
return
N
(
OP_SQRT
,
a
if
n
==
1
else
a
**
n
)
MESSAGES
[
exponent_to_root
]
=
\
_
(
'Rewrite power with exponent {0[1]} to a square root.'
)
def
match_extend_exponent
(
node
):
...
...
src/rules/sqrt.py
View file @
68a227a2
...
...
@@ -88,7 +88,7 @@ def quadrant_sqrt(root, args):
MESSAGES
[
quadrant_sqrt
]
=
\
_
(
'The
square root of a quadrant
reduces to the raised root.'
)
_
(
'The
root of a
reduces to the raised root.'
)
def
constant_sqrt
(
root
,
args
):
...
...
tests/test_rules_powers.py
View file @
68a227a2
...
...
@@ -140,17 +140,13 @@ class TestRulesPowers(RulesTestCase):
P
(
root
,
remove_negative_root
)])
def
test_match_exponent_to_root
(
self
):
a
,
n
,
m
,
l1
=
tree
(
'a,n,m,1'
)
root
=
tree
(
'a ^ (1 / 2)'
)
self
.
assertEqualPos
(
match_exponent_to_root
(
root
),
[
P
(
root
,
exponent_to_root
)])
root
=
a
**
(
n
/
m
)
possibilities
=
match_exponent_to_root
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
exponent_to_root
,
(
a
,
n
,
m
))])
root
=
a
**
(
l1
/
m
)
possibilities
=
match_exponent_to_root
(
root
)
self
.
assertEqualPos
(
possibilities
,
[
P
(
root
,
exponent_to_root
,
(
a
,
1
,
m
))])
root
=
tree
(
'a ^ (n / 2)'
)
self
.
assertEqualPos
(
match_exponent_to_root
(
root
),
[
P
(
root
,
exponent_to_root
)])
def
test_add_exponents
(
self
):
a
,
p
,
q
=
tree
(
'a,p,q'
)
...
...
@@ -198,14 +194,11 @@ class TestRulesPowers(RulesTestCase):
self
.
assertEqualNodes
(
remove_negative_root
(
root
,
()),
expect
)
def
test_exponent_to_root
(
self
):
a
,
n
,
m
,
l1
=
tree
(
'a,n,m,1'
)
root
=
a
**
(
n
/
m
)
self
.
assertEqualNodes
(
exponent_to_root
(
root
,
(
a
,
n
,
m
)),
N
(
'sqrt'
,
a
**
n
,
m
))
root
,
expect
=
tree
(
'a ^ (1 / 2), sqrt(a)'
)
self
.
assertEqualNodes
(
exponent_to_root
(
root
,
()),
expect
)
self
.
assertEqualNodes
(
exponent_to_root
(
root
,
(
a
,
l1
,
m
)),
N
(
'sqrt'
,
a
,
m
)
)
root
,
expect
=
tree
(
'a ^ (n / 2), sqrt(a ^ n)'
)
self
.
assertEqualNodes
(
exponent_to_root
(
root
,
()),
expect
)
def
test_match_constant_exponent
(
self
):
a0
,
a1
,
a2
=
tree
(
'a ^ 0, a ^ 1, a ^ 2'
)
...
...
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