Skip to content

Commit 106b244

Browse files
author
trizen
committed
new file: Math/harmonic_prime_powers.sf
1 parent 1606357 commit 106b244

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

Math/harmonic_prime_powers.sf

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/ruby
2+
3+
# Daniel "Trizen" Șuteu
4+
# Date: 25 October 2017
5+
# https://github.com/trizen
6+
7+
# Harmonic sum of prime powers <= n, defined as:
8+
#
9+
# Sum_{p <= n} (Sum_{1 <= k <= floor(log(n)/log(p))} 1/p^k)
10+
#
11+
# where p runs over the prime number <= n.
12+
13+
# This is equivalent with:
14+
# Sum_{p <= n} (p^(floor(log(n)/log(p))) - 1) / (p^(floor(log(n)/log(p))) * (p-1))
15+
16+
# See also:
17+
# https://oeis.org/A294208
18+
19+
func g((0), _) { 1 }
20+
func f((0), _) { 0 }
21+
22+
func g(k,n) is cached {
23+
var p = prime(k)
24+
p**n.ilog(p) * (p-1) * g(k-1, n)
25+
}
26+
27+
func f(k,n) is cached {
28+
var p = prime(k)
29+
(p**n.ilog(p) * (p-1) * f(k-1, n)) + ((p**n.ilog(p) - 1) * g(k-1, n))
30+
}
31+
32+
for n in (0..100) {
33+
34+
var a = f(prime_count(n), n)
35+
var b = g(prime_count(n), n)
36+
var r = a/b
37+
38+
say ("#{a}/#{b} = #{r.as_frac}")
39+
}
40+
41+
__END__
42+
0/1 = 0/1
43+
1/2 = 1/2
44+
10/12 = 5/6
45+
26/24 = 13/12
46+
616/480 = 77/60
47+
28752/20160 = 599/420
48+
62544/40320 = 1303/840
49+
201072/120960 = 4189/2520
50+
23327520/13305600 = 48599/27720
51+
3798760320/2075673600 = 659507/360360
52+
7856979840/4151347200 = 1364059/720720
53+
2203520071680/1129166438400 = 23909723/12252240
54+
773928860405760/386174921932800 = 466536977/232792560
55+
400103851647836160/195404510497996800 = 10963143031/5354228880
56+
2039600160338780160/977022552489984000 = 55886560931/26771144400
57+
6227358542404116480/2931067657469952000 = 170634254393/80313433200
58+
5138685030841301237760/2380026937865601024000 = 5028706810597/2329089562800
59+
4850377886818378181836800/2213425052215008952320000 = 158219000691307/72201776446800
60+
9839094839400194423193600/4426850104430017904640000 = 320950612410539/144403552893600
61+
13265040929840539616260915200/5896564339100783848980480000 = 12019576212083543/5342931457063200
62+
21990529698502516324627120128000/9670365516125285512327987200000 = 498145556152488463/219060189739591200
63+
40121051987172806473794354413568000/17464680122122265635264344883200000 = 21639319104296595109/9419588158802421600
64+
87545089681885231815565554106761216000/37758638424028338303441513637478400000 = 1026467586060742391723/442720643463713815200
65+
618209718976629242466593380695539712000/264310468968198368124090595462348800000 = 7248518908634298715661/3099044504245996706400
66+
1717530129885936507380384068160949583872000/728439652476354702549993681094233292800000 = 387270546661863828636433/164249358725037825439200
67+
5919637604313303301003573914750235006992384000/2492720490774085792126078376704466327961600000 = 23013211611775003714988747/9690712164777231700912800
68+
21815436861233135229200645230588128105269821440000/9123356996233153999181446858738346760339456000000 = 1413496620483052458315226367/591133442051411133755680800
69+
43915978628598556520875710675511829546800250880000/18246713992466307998362893717476693520678912000000 = 2845466161030211514560317759/1182266884102822267511361600
70+
195400740619165593263204343592466772028315517583360000/80686969274686013968760716018681938748442148864000000 = 191828499673126993743052651453/79211881234889091923261227200
71+
976789768726481019495938837775867592693119072809779200000/401014237295189489424740758612849235579757479854080000000 = 13699035358026905647679999480363/5624043567677125526551547131200
72+
5162880049511637881709235865970085212156776385237693235200000/2107730831223515956416437427269135582207205314113044480000000 = 1005653624703641237807191509197699/410555180440430163438262940577600
73+
31978069869926146871692793525434657652722218100335483184742400000/12987837381999305323438087426832413457560799145564580085760000000 = 79857191532028087950206392167195821/32433859254793982911622772305630400
74+
96415240623926563034464976406927395678817054269360693261107200000/38963512145997915970314262280497240372682397436693740257280000000 = 240772828642558115069568168068462663/97301577764381948734868316916891200
75+
659397135682416017122134398932548628700588827947077765036192563200000/265185663665661816093958869081064217976476396954137596191047680000000 = 20081446355096705499509026266599292229/8076030954443701744994070304101969600
76+
5187734705067260485916824992918854511164941623413477164228272350822400000/2076934117829463343647885862642894955191763140944805653368285429760000000 = 1795324756558050491201297408031438977981/718766754945489455304472257065075294400
77+
48507571248897958125847671376874091123666345658757000696017027532115148800000/19340410505227962656049113152930637822745698368478030244165473921925120000000 = 174865268141076387101830320836114656158557/69720375229712477164533808935312303556800

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ A simple collection of Sidef scripts.
8787
* [Generalized fibonacci closed-form 2](./Math/generalized_fibonacci_closed-form_2.sf)
8888
* [Harmonic numbers from powers](./Math/harmonic_numbers_from_powers.sf)
8989
* [Harmonic numbers from powers simple](./Math/harmonic_numbers_from_powers_simple.sf)
90+
* [Harmonic prime powers](./Math/harmonic_prime_powers.sf)
9091
* [Haversine formula](./Math/haversine_formula.sf)
9192
* [Inverse of factorial](./Math/inverse_of_factorial.sf)
9293
* [Invmod of coprime factorials](./Math/invmod_of_coprime_factorials.sf)

0 commit comments

Comments
 (0)