Skip to content

Commit

Permalink
- Extended the Number liouville_sum method to accept an additional …
Browse files Browse the repository at this point in the history
…argument.

When an additional argument is given, the returned result is:

	Sum_{k=a..b} liouville(k)

Example:

	say liouville_sum(10**9, 10**10)   #=> -90809
  • Loading branch information
trizen committed May 5, 2022
1 parent b8b5e20 commit 360f402
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
10 changes: 8 additions & 2 deletions lib/Sidef/Types/Number/Number.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10945,9 +10945,15 @@ package Sidef::Types::Number::Number {
}

sub liouville_sum {
my ($n) = @_;
my ($from, $to) = @_;

$n = _any2mpz($$n) // goto &nan;
if (defined($to)) {
_valid(\$to);
return ZERO if $to->lt($from);
return $to->liouville_sum->sub($from->dec->liouville_sum);
}

my $n = _any2mpz($$from) // goto &nan;
Math::GMPz::Rmpz_sgn($n) > 0 or return ZERO;

state $liouville_table = {
Expand Down
17 changes: 13 additions & 4 deletions lib/Sidef/Types/Number/Number.pod
Original file line number Diff line number Diff line change
Expand Up @@ -4335,12 +4335,21 @@ Equivalent to:

=head2 liouville_sum

n.liouville_sum
liouville_sum(n)
liouville_sum(a,b)

Computes partial sums of the Liouville lambda function.
Computes partial sums of the Liouville lambda function:

say liouville_sum(10**9) #=> -25216
say liouville_sum(10**10) #=> -116026
Sum_{k=1..n} liouville(k)

When an additional argument is given, the returned result is:

Sum_{k=a..b} liouville(k)

Example:

say liouville_sum(10**9) #=> -25216
say liouville_sum(10**9, 10**10) #=> -90809

=cut

Expand Down
7 changes: 6 additions & 1 deletion utils/find_class_typos.pl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
}

while ($content =~ /\b(Sidef(::\w+)+)/g) {
push @{$invokants{$1}}, $_;
my $name = $1;
push @{$invokants{$name}}, $_;

if ($name =~ /^(.+)::/) { # handle function calls
push @{$invokants{$1}}, $_;
}
}
},

Expand Down

0 comments on commit 360f402

Please sign in to comment.