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
d7329b8d
Commit
d7329b8d
authored
Mar 21, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added last logarithmic rule.
parent
3cfa07da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
3 deletions
+37
-3
src/rules/logarithmic.py
src/rules/logarithmic.py
+23
-2
tests/test_rules_logarithmic.py
tests/test_rules_logarithmic.py
+14
-1
No files found.
src/rules/logarithmic.py
View file @
d7329b8d
from
itertools
import
combinations
from
itertools
import
combinations
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
OP_LOG
,
E
,
\
from
..node
import
ExpressionNode
as
N
,
ExpressionLeaf
as
L
,
OP_LOG
,
E
,
\
OP_ADD
,
OP_MUL
,
Scope
OP_ADD
,
OP_MUL
,
OP_POW
,
Scope
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..translate
import
_
from
..translate
import
_
...
@@ -65,7 +65,7 @@ def divide_same_base(root, args):
...
@@ -65,7 +65,7 @@ def divide_same_base(root, args):
return
log
(
raised
)
/
log
(
base
)
return
log
(
raised
)
/
log
(
base
)
MESSAGES
[
divide_same_base
]
=
_
(
'Apply log_b(a)
->
log(a) / log(b) on {0}.'
)
MESSAGES
[
divide_same_base
]
=
_
(
'Apply log_b(a)
=
log(a) / log(b) on {0}.'
)
def
match_add_logarithms
(
node
):
def
match_add_logarithms
(
node
):
...
@@ -154,3 +154,24 @@ def subtract_logarithms(root, args):
...
@@ -154,3 +154,24 @@ def subtract_logarithms(root, args):
MESSAGES
[
subtract_logarithms
]
=
_
(
'Apply log(a) - log(b) = log(a / b).'
)
MESSAGES
[
subtract_logarithms
]
=
_
(
'Apply log(a) - log(b) = log(a / b).'
)
def
match_raised_base
(
node
):
"""
g ^ log_g(a) -> a
"""
assert
node
.
is_op
(
OP_POW
)
root
,
exponent
=
node
if
exponent
.
is_op
(
OP_LOG
)
and
exponent
[
1
]
==
root
:
return
[
P
(
node
,
raised_base
,
(
exponent
[
0
],))]
return
[]
def
raised_base
(
root
,
args
):
"""
g ^ log_g(a) -> a
"""
return
args
[
0
]
tests/test_rules_logarithmic.py
View file @
d7329b8d
from
src.rules.logarithmic
import
log
,
ln
,
match_constant_logarithm
,
\
from
src.rules.logarithmic
import
log
,
ln
,
match_constant_logarithm
,
\
logarithm_of_one
,
divide_same_base
,
match_add_logarithms
,
\
logarithm_of_one
,
divide_same_base
,
match_add_logarithms
,
\
add_logarithms
,
expand_negations
,
subtract_logarithms
add_logarithms
,
expand_negations
,
subtract_logarithms
,
\
match_raised_base
,
raised_base
from
src.node
import
Scope
from
src.node
import
Scope
from
src.possibilities
import
Possibility
as
P
from
src.possibilities
import
Possibility
as
P
from
tests.rulestestcase
import
RulesTestCase
,
tree
from
tests.rulestestcase
import
RulesTestCase
,
tree
...
@@ -73,3 +74,15 @@ class TestRulesLogarithmic(RulesTestCase):
...
@@ -73,3 +74,15 @@ class TestRulesLogarithmic(RulesTestCase):
loga
,
logb
=
root
loga
,
logb
=
root
self
.
assertEqual
(
subtract_logarithms
(
root
,
(
Scope
(
root
),
logb
,
loga
)),
self
.
assertEqual
(
subtract_logarithms
(
root
,
(
Scope
(
root
),
logb
,
loga
)),
expect
)
expect
)
def
test_match_raised_base
(
self
):
root
,
a
=
tree
(
'2 ^ log_2(a), a'
)
self
.
assertEqualPos
(
match_raised_base
(
root
),
[
P
(
root
,
raised_base
,
(
a
,))])
root
=
tree
(
'2 ^ log_3(a)'
)
self
.
assertEqualPos
(
match_raised_base
(
root
),
[])
def
test_raised_base
(
self
):
root
,
a
=
tree
(
'2 ^ log_2(a), a'
)
self
.
assertEqual
(
raised_base
(
root
,
(
root
[
1
][
0
],)),
a
)
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