Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
trs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
trs
Commits
4e488c46
Commit
4e488c46
authored
12 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Fixed an exception that occured when using a non-numeric logarithmic base
parent
eb08c96e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/rules/logarithmic.py
+5
-3
5 additions, 3 deletions
src/rules/logarithmic.py
tests/test_rules_logarithmic.py
+9
-1
9 additions, 1 deletion
tests/test_rules_logarithmic.py
with
14 additions
and
4 deletions
src/rules/logarithmic.py
+
5
−
3
View file @
4e488c46
...
@@ -253,10 +253,12 @@ def match_factor_out_exponent(node):
...
@@ -253,10 +253,12 @@ def match_factor_out_exponent(node):
p
.
append
(
P
(
node
,
factor_out_exponent
))
p
.
append
(
P
(
node
,
factor_out_exponent
))
elif
exp
.
is_numeric
()
and
not
exp
.
negated
:
elif
exp
.
is_numeric
()
and
not
exp
.
negated
:
b
,
a
=
exp
.
value
,
base
.
value
b
,
a
=
exp
.
value
,
base
.
value
y
=
int
(
round
(
math
.
log
(
b
,
a
)))
if
b
==
a
**
y
:
if
not
isinstance
(
a
,
str
)
and
not
isinstance
(
b
,
str
):
p
.
append
(
P
(
node
,
make_raised_base
,
(
y
,)))
y
=
int
(
round
(
math
.
log
(
b
,
a
)))
if
b
==
a
**
y
:
p
.
append
(
P
(
node
,
make_raised_base
,
(
y
,)))
return
p
return
p
...
...
This diff is collapsed.
Click to expand it.
tests/test_rules_logarithmic.py
+
9
−
1
View file @
4e488c46
...
@@ -11,7 +11,8 @@
...
@@ -11,7 +11,8 @@
# details.
# details.
#
#
# You should have received a copy of the GNU Affero General Public License
# You should have received a copy of the GNU Affero General Public License
# along with TRS. If not, see <http://www.gnu.org/licenses/>.
import
math
from
src.rules.logarithmic
import
log
,
match_constant_logarithm
,
\
from
src.rules.logarithmic
import
log
,
match_constant_logarithm
,
\
base_equals_raised
,
logarithm_of_one
,
divide_same_base
,
\
base_equals_raised
,
logarithm_of_one
,
divide_same_base
,
\
match_add_logarithms
,
add_logarithms
,
expand_negations
,
\
match_add_logarithms
,
add_logarithms
,
expand_negations
,
\
...
@@ -176,6 +177,13 @@ class TestRulesLogarithmic(RulesTestCase):
...
@@ -176,6 +177,13 @@ class TestRulesLogarithmic(RulesTestCase):
root
=
tree
(
'
log(99)
'
)
root
=
tree
(
'
log(99)
'
)
self
.
assertEqualPos
(
match_factor_out_exponent
(
root
),
[])
self
.
assertEqualPos
(
match_factor_out_exponent
(
root
),
[])
def
test_match_factor_out_exponent_make_raised_base_string
(
self
):
root
=
tree
(
'
log_a(2)
'
)
self
.
assertEqualPos
(
match_factor_out_exponent
(
root
),
[])
root
=
tree
(
'
log_e(%s)
'
%
(
math
.
e
**
2
))
self
.
assertEqualPos
(
match_factor_out_exponent
(
root
),
[])
def
test_split_negative_exponent
(
self
):
def
test_split_negative_exponent
(
self
):
root
,
expect
=
tree
(
'
log(a ^ -b), log((a ^ b) ^ -1)
'
)
root
,
expect
=
tree
(
'
log(a ^ -b), log((a ^ b) ^ -1)
'
)
self
.
assertEqual
(
split_negative_exponent
(
root
,
()),
expect
)
self
.
assertEqual
(
split_negative_exponent
(
root
,
()),
expect
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment