Hi,
I am looking for multifactorial function in the source code but unable to.Help me out...
It should be like
a=42
k=3
sage: a.multifactorial(k)
On Friday, 30 October 2015 05:38:56 UTC, prateek sharma wrote:
It should be like
a=42
k=3
sage: a.multifactorial(k)
I told you to display the source code for this function, as this is what you asked, no?
def multifactorial(self, int k):
r"""
Computes the k-th factorial `n!^{(k)}`
of self. For k=1
this is the standard factorial,
and for k greater than one it is
the product of every k-th terms
down from self to k. The recursive
definition is used to extend this
function to the negative
integers.
EXAMPLES::
sage:
5.multifactorial(1)
120
sage:
5.multifactorial(2)
15
sage:
23.multifactorial(2)
316234143225
sage: prod([1..23,
step=2])
316234143225
sage:
(-29).multifactorial(7)
1/2640
"""
if k <= 0:
raise ValueError,
"multifactorial only defined for positive values of k"
if not
mpz_fits_sint_p(self.value):
raise ValueError, "multifactorial
not implemented for n >= 2^32.\nThis is probably OK, since the answer would
have billions of digits."
cdef int n =
mpz_get_si(self.value)
# base case
if 0 < n < k:
return one
# easy to calculate
elif n % k == 0:
factorial =
Integer(n/k).factorial()
if k == 2:
return factorial <<
(n/k)
else:
return factorial *
Integer(k)**(n/k)
# negative base case
elif -k < n < 0:
return one / (self+k)
# reflection case
elif n < -k:
if (n/k) % 2:
sign = -one
else:
sign = one
return sign /
Integer(-k-n).multifactorial(k)
# compute the actual product, optimizing the
number of large
# multiplications
cdef int i,j
# we need (at most)
log_2(#factors) concurrent sub-products
cdef int prod_count =
<int>ceil_c(log_c(n/k+1)/log_c(2))
cdef mpz_t* sub_prods =
<mpz_t*>check_allocarray(prod_count, sizeof(mpz_t))
for i from 0 <= i <
prod_count:
mpz_init(sub_prods[i])
sig_on()
cdef residue = n % k
cdef int tip = 0
for i from 1 <= i <=
n//k:
mpz_set_ui(sub_prods[tip], k*i +
residue)
# for the i-th terms we use
the bits of i to calculate how many
# times we need to multiply
"up" the stack of sub-products
for j from 0 <= j <
32:
if i & (1 <<
j):
break
tip -= 1
mpz_mul(sub_prods[tip],
sub_prods[tip], sub_prods[tip+1])
tip += 1
cdef int last = tip-1
for tip from last > tip >=
0:
mpz_mul(sub_prods[tip],
sub_prods[tip], sub_prods[tip+1])
sig_off()
cdef Integer z =
PY_NEW(Integer)
mpz_swap(z.value,
sub_prods[0])
for i from 0 <= i <
prod_count:
mpz_clear(sub_prods[i])
sage_free(sub_prods)
return z
From the given code for
sage:5.multifactorial(3)
5
But the result should be 10.
I have submitted a patch to the issue #5415.
Please review.
--
You received this message because you are subscribed to a topic in the Google Groups "sage-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-devel/XIEZaUziPh4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-devel+...@googlegroups.com.
To post to this group, send email to sage-...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.
Can you please summarize me what I basically need to do?
Can you tell me how can I create a branch .When I do git-trac-checkout 5415
It says "Newly created local branch: t/5415/problems_with_multifactorial_"
I have made my changes on git.
How can I commit those changes on trac.
On Wednesday, December 9, 2015 at 5:13:58 AM UTC-8, prateek sharma wrote:Can you tell me how can I create a branch .When I do git-trac-checkout 5415
It says "Newly created local branch: t/5415/problems_with_multifactorial_"
Doesn't the system just tell you that you have now succeeded in creating a (local) branch?
No . The system just says "Newly created local branch..." and processing keeps on going.I have to forcefully stop the programme.
On Wednesday, December 9, 2015 at 10:21:17 AM UTC-8, prateek sharma wrote:No . The system just says "Newly created local branch..." and processing keeps on going.I have to forcefully stop the programme.
It works for me (it does take some time to finish, however. I don't know what it's doing. I'd imagine that any of: speed of local disk access, processor speed, internet speed might affect how long this should take. I'd imagine that if you are not up-to-date on the local develop, it might have quite a bit of downloading to do from trac (I assume that pulling a ticket with a non-existant branch will just pull "develop" on trac.)
--
You received this message because you are subscribed to a topic in the Google Groups "sage-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-devel/XIEZaUziPh4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-devel+...@googlegroups.com.
I had pushed my branch on trac but I am unable to see any commit on trac.Can anybody tell me why?
| Do not allow creation of ticket titled "help" |
How can I change doctest to check my changes made.?