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
d7329b8d
Commit
d7329b8d
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added last logarithmic rule.
parent
3cfa07da
No related branches found
Branches containing commit
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
+23
-2
23 additions, 2 deletions
src/rules/logarithmic.py
tests/test_rules_logarithmic.py
+14
-1
14 additions, 1 deletion
tests/test_rules_logarithmic.py
with
37 additions
and
3 deletions
src/rules/logarithmic.py
+
23
−
2
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
]
This diff is collapsed.
Click to expand it.
tests/test_rules_logarithmic.py
+
14
−
1
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
)
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