Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102564188
hash_derivative.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Feb 22, 01:14
Size
1 KB
Mime Type
text/x-python
Expires
Mon, Feb 24, 01:14 (2 d)
Engine
blob
Format
Raw Data
Handle
24364694
Attached To
R6746 RationalROMPy
hash_derivative.py
View Options
# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
from
scipy.special
import
binom
from
rrompy.utilities.base.types
import
List
__all__
=
[
'hashDerivativeToIdx'
,
'hashIdxToDerivative'
]
def
shellCount
(
shell
:
int
,
dim
:
int
)
->
int
:
return
int
(
binom
(
shell
+
dim
,
dim
))
def
hashDerivativeToIdx
(
derIdx
:
List
[
int
])
->
int
:
dim
=
len
(
derIdx
)
if
dim
==
0
:
return
0
derMag
=
sum
(
derIdx
)
base
=
shellCount
(
derMag
-
1
,
dim
)
if
derMag
==
derIdx
[
0
]:
return
base
return
base
+
hashDerivativeToIdx
(
derIdx
[
1
:])
def
hashIdxToDerivative
(
n
:
int
,
dim
:
int
)
->
List
[
int
]:
if
n
==
0
:
return
[
0
]
*
dim
shell
=
0
shellOld
=
-
1
shellNew
=
1
while
shellNew
<=
n
:
shell
+=
1
shellOld
=
shellNew
shellNew
=
shellCount
(
shell
,
dim
)
rest
=
hashIdxToDerivative
(
n
-
shellOld
,
dim
-
1
)
return
[
shell
-
sum
(
rest
)]
+
rest
Event Timeline
Log In to Comment