Out of memory with simple calc?Why does XML:Simple complain that “No element found”?How to print a Perl 2-dimensional array?Why is Perl's IO:Compress::Adapter::Deflate running out of memory?Perl factorial subroutine not taking command line argumentshelp calling a sub routine from a perl module and printing to logfileWhy aren't my push and pop methods working?Resolving Out of Memory error when executing Perl scriptPerl - parsing huge *.gz file in WindowsComputing system memory in use in PerlLoading Perl modules into memory for Nginx, to make faster?

Why would the Apollo Lunar Module pressure dump (to space?) valve have a bacterial filter?

Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?

Why not notify faculty candidates of the position being filled?

Anti-cheating: should there be a limit to a number of toilet breaks per game per player?

How many oliphaunts died in all of the Lord of the Rings battles?

Can I change the license of a forked project to the MIT if the license of the parent project has changed from the GPL to the MIT?

What container to use to store developer concentrate?

ECDSA: Why is SigningKey shorter than VerifyingKey

Why would anyone ever invest in a cash-only etf?

How can Paypal know my card is being used in another account?

An easy decision when to use a spline or a polynomial

What steps would an amateur scientist have to take in order to get a scientific breakthrough published?

Why did House of Representatives need to condemn Trumps Tweets?

Why was Sauron preparing for war instead of trying to find the ring?

List of visa access for each country

Does Wolfram Mathworld make a mistake describing a discrete probability distribution with a probability density function?

Move the outer key inward in an association

Reset-ItemField failing silently

Could the rotation of a black hole cause other planets to rotate?

What is "aligned sequences" and "consensus sequence" in the context of sequence logo? How to compute these?

(3 of 11: Akari) What is Pyramid Cult's Favorite Car?

What is the most efficient way to write 'for' loops in Matlab?

How to access HTML input values from Twig and vice versa

Are the named pipe created by `mknod` and the FIFO created by `mkfifo` equivalent?



Out of memory with simple calc?


Why does XML:Simple complain that “No element found”?How to print a Perl 2-dimensional array?Why is Perl's IO:Compress::Adapter::Deflate running out of memory?Perl factorial subroutine not taking command line argumentshelp calling a sub routine from a perl module and printing to logfileWhy aren't my push and pop methods working?Resolving Out of Memory error when executing Perl scriptPerl - parsing huge *.gz file in WindowsComputing system memory in use in PerlLoading Perl modules into memory for Nginx, to make faster?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm getting out of memory with a very simple calc.



I'm try to calc ow many topologies a binary tree might has given a number n of samples



So I simple try perl -E 'sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1) sub top my ($n) = @_; $t = fac(2 * $n - 5) / (2 ** ($n - 3) * fac($n - 3) ) say top(3)'
Also, a other version of same math:



#!/usr/bin/env perl

use warnings;
use strict;
#use features;

sub factorial
my ($n) = @_;
$n == 1 ? 1 : $n * factorial($n -1)


sub topologies
my ($n) = @_;
my $a = (2 * $n) - 5;
my $a_f = factorial($a);
my $b = $n -3;
my $b_f = factorial($b);
my $c = 2 ** $b;
my $q = $c * $b_f;
my $t = $a_f / $q;
return $t;


print "Enter number of taxas: ";
my $input = <STDIN>;
my $ntop = topologies();

print $ntop, "n";


And when I try even for a sample size 3. I got out of memory in a computer with 4GB of ram and 4GB of cache. The same to a 128GB or ram server.



I do not need this calc, I was just try for fun.
But I cannot figure out why I'm getting this out of memory message.



EDIT: I just get it when the sample is equal or smaller than 3










share|improve this question

















  • 2





    Hint: what happens when $n <= 0 in the factorial sub?

    – mob
    Mar 26 at 19:45












  • @mob actually is expected never have $n < 1 anyway if $n == 0 it will return 0, and of course follows the same logic of any mathematical operation. Decreasing to lower than 0 the result should away return 0. Anyway I understand that is better use $n <= 1 in sub fac routine. So: sub fac my ($n) = @_; $n <= 1 ? 1 : $n * fac($n -1)

    – Aureliano Guedes
    Mar 26 at 22:15












  • Note: If you're using a 32-bit build of Perl, the maximum amount of memory the process can use is 2-3 GiB (depending on the OS), regardless of how much RAM the machine has.

    – ikegami
    Mar 27 at 0:06

















1















I'm getting out of memory with a very simple calc.



I'm try to calc ow many topologies a binary tree might has given a number n of samples



So I simple try perl -E 'sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1) sub top my ($n) = @_; $t = fac(2 * $n - 5) / (2 ** ($n - 3) * fac($n - 3) ) say top(3)'
Also, a other version of same math:



#!/usr/bin/env perl

use warnings;
use strict;
#use features;

sub factorial
my ($n) = @_;
$n == 1 ? 1 : $n * factorial($n -1)


sub topologies
my ($n) = @_;
my $a = (2 * $n) - 5;
my $a_f = factorial($a);
my $b = $n -3;
my $b_f = factorial($b);
my $c = 2 ** $b;
my $q = $c * $b_f;
my $t = $a_f / $q;
return $t;


print "Enter number of taxas: ";
my $input = <STDIN>;
my $ntop = topologies();

print $ntop, "n";


And when I try even for a sample size 3. I got out of memory in a computer with 4GB of ram and 4GB of cache. The same to a 128GB or ram server.



I do not need this calc, I was just try for fun.
But I cannot figure out why I'm getting this out of memory message.



EDIT: I just get it when the sample is equal or smaller than 3










share|improve this question

















  • 2





    Hint: what happens when $n <= 0 in the factorial sub?

    – mob
    Mar 26 at 19:45












  • @mob actually is expected never have $n < 1 anyway if $n == 0 it will return 0, and of course follows the same logic of any mathematical operation. Decreasing to lower than 0 the result should away return 0. Anyway I understand that is better use $n <= 1 in sub fac routine. So: sub fac my ($n) = @_; $n <= 1 ? 1 : $n * fac($n -1)

    – Aureliano Guedes
    Mar 26 at 22:15












  • Note: If you're using a 32-bit build of Perl, the maximum amount of memory the process can use is 2-3 GiB (depending on the OS), regardless of how much RAM the machine has.

    – ikegami
    Mar 27 at 0:06













1












1








1








I'm getting out of memory with a very simple calc.



I'm try to calc ow many topologies a binary tree might has given a number n of samples



So I simple try perl -E 'sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1) sub top my ($n) = @_; $t = fac(2 * $n - 5) / (2 ** ($n - 3) * fac($n - 3) ) say top(3)'
Also, a other version of same math:



#!/usr/bin/env perl

use warnings;
use strict;
#use features;

sub factorial
my ($n) = @_;
$n == 1 ? 1 : $n * factorial($n -1)


sub topologies
my ($n) = @_;
my $a = (2 * $n) - 5;
my $a_f = factorial($a);
my $b = $n -3;
my $b_f = factorial($b);
my $c = 2 ** $b;
my $q = $c * $b_f;
my $t = $a_f / $q;
return $t;


print "Enter number of taxas: ";
my $input = <STDIN>;
my $ntop = topologies();

print $ntop, "n";


And when I try even for a sample size 3. I got out of memory in a computer with 4GB of ram and 4GB of cache. The same to a 128GB or ram server.



I do not need this calc, I was just try for fun.
But I cannot figure out why I'm getting this out of memory message.



EDIT: I just get it when the sample is equal or smaller than 3










share|improve this question














I'm getting out of memory with a very simple calc.



I'm try to calc ow many topologies a binary tree might has given a number n of samples



So I simple try perl -E 'sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1) sub top my ($n) = @_; $t = fac(2 * $n - 5) / (2 ** ($n - 3) * fac($n - 3) ) say top(3)'
Also, a other version of same math:



#!/usr/bin/env perl

use warnings;
use strict;
#use features;

sub factorial
my ($n) = @_;
$n == 1 ? 1 : $n * factorial($n -1)


sub topologies
my ($n) = @_;
my $a = (2 * $n) - 5;
my $a_f = factorial($a);
my $b = $n -3;
my $b_f = factorial($b);
my $c = 2 ** $b;
my $q = $c * $b_f;
my $t = $a_f / $q;
return $t;


print "Enter number of taxas: ";
my $input = <STDIN>;
my $ntop = topologies();

print $ntop, "n";


And when I try even for a sample size 3. I got out of memory in a computer with 4GB of ram and 4GB of cache. The same to a 128GB or ram server.



I do not need this calc, I was just try for fun.
But I cannot figure out why I'm getting this out of memory message.



EDIT: I just get it when the sample is equal or smaller than 3







perl






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 19:38









Aureliano GuedesAureliano Guedes

14013 bronze badges




14013 bronze badges







  • 2





    Hint: what happens when $n <= 0 in the factorial sub?

    – mob
    Mar 26 at 19:45












  • @mob actually is expected never have $n < 1 anyway if $n == 0 it will return 0, and of course follows the same logic of any mathematical operation. Decreasing to lower than 0 the result should away return 0. Anyway I understand that is better use $n <= 1 in sub fac routine. So: sub fac my ($n) = @_; $n <= 1 ? 1 : $n * fac($n -1)

    – Aureliano Guedes
    Mar 26 at 22:15












  • Note: If you're using a 32-bit build of Perl, the maximum amount of memory the process can use is 2-3 GiB (depending on the OS), regardless of how much RAM the machine has.

    – ikegami
    Mar 27 at 0:06












  • 2





    Hint: what happens when $n <= 0 in the factorial sub?

    – mob
    Mar 26 at 19:45












  • @mob actually is expected never have $n < 1 anyway if $n == 0 it will return 0, and of course follows the same logic of any mathematical operation. Decreasing to lower than 0 the result should away return 0. Anyway I understand that is better use $n <= 1 in sub fac routine. So: sub fac my ($n) = @_; $n <= 1 ? 1 : $n * fac($n -1)

    – Aureliano Guedes
    Mar 26 at 22:15












  • Note: If you're using a 32-bit build of Perl, the maximum amount of memory the process can use is 2-3 GiB (depending on the OS), regardless of how much RAM the machine has.

    – ikegami
    Mar 27 at 0:06







2




2





Hint: what happens when $n <= 0 in the factorial sub?

– mob
Mar 26 at 19:45






Hint: what happens when $n <= 0 in the factorial sub?

– mob
Mar 26 at 19:45














@mob actually is expected never have $n < 1 anyway if $n == 0 it will return 0, and of course follows the same logic of any mathematical operation. Decreasing to lower than 0 the result should away return 0. Anyway I understand that is better use $n <= 1 in sub fac routine. So: sub fac my ($n) = @_; $n <= 1 ? 1 : $n * fac($n -1)

– Aureliano Guedes
Mar 26 at 22:15






@mob actually is expected never have $n < 1 anyway if $n == 0 it will return 0, and of course follows the same logic of any mathematical operation. Decreasing to lower than 0 the result should away return 0. Anyway I understand that is better use $n <= 1 in sub fac routine. So: sub fac my ($n) = @_; $n <= 1 ? 1 : $n * fac($n -1)

– Aureliano Guedes
Mar 26 at 22:15














Note: If you're using a 32-bit build of Perl, the maximum amount of memory the process can use is 2-3 GiB (depending on the OS), regardless of how much RAM the machine has.

– ikegami
Mar 27 at 0:06





Note: If you're using a 32-bit build of Perl, the maximum amount of memory the process can use is 2-3 GiB (depending on the OS), regardless of how much RAM the machine has.

– ikegami
Mar 27 at 0:06












1 Answer
1






active

oldest

votes


















6














With $n = 3 your toplogies(3) will call factorial(1) and factorial(0). The latter one is improperly implemented and tries to create the factorial by calling factorial(-1) which then calls factorial(-2) which then calls factorial(-3) ..., i.e. an endless recursion where each step allocates more memory. This endless recursion will result therefore in the out of memory. Similar things happen with $n<3.






share|improve this answer

























  • Thanks. So it was bad implemented, better do sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1).

    – Aureliano Guedes
    Mar 26 at 22:19










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365062%2fout-of-memory-with-simple-calc%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














With $n = 3 your toplogies(3) will call factorial(1) and factorial(0). The latter one is improperly implemented and tries to create the factorial by calling factorial(-1) which then calls factorial(-2) which then calls factorial(-3) ..., i.e. an endless recursion where each step allocates more memory. This endless recursion will result therefore in the out of memory. Similar things happen with $n<3.






share|improve this answer

























  • Thanks. So it was bad implemented, better do sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1).

    – Aureliano Guedes
    Mar 26 at 22:19















6














With $n = 3 your toplogies(3) will call factorial(1) and factorial(0). The latter one is improperly implemented and tries to create the factorial by calling factorial(-1) which then calls factorial(-2) which then calls factorial(-3) ..., i.e. an endless recursion where each step allocates more memory. This endless recursion will result therefore in the out of memory. Similar things happen with $n<3.






share|improve this answer

























  • Thanks. So it was bad implemented, better do sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1).

    – Aureliano Guedes
    Mar 26 at 22:19













6












6








6







With $n = 3 your toplogies(3) will call factorial(1) and factorial(0). The latter one is improperly implemented and tries to create the factorial by calling factorial(-1) which then calls factorial(-2) which then calls factorial(-3) ..., i.e. an endless recursion where each step allocates more memory. This endless recursion will result therefore in the out of memory. Similar things happen with $n<3.






share|improve this answer















With $n = 3 your toplogies(3) will call factorial(1) and factorial(0). The latter one is improperly implemented and tries to create the factorial by calling factorial(-1) which then calls factorial(-2) which then calls factorial(-3) ..., i.e. an endless recursion where each step allocates more memory. This endless recursion will result therefore in the out of memory. Similar things happen with $n<3.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 26 at 20:18

























answered Mar 26 at 19:49









Steffen UllrichSteffen Ullrich

66.1k3 gold badges67 silver badges109 bronze badges




66.1k3 gold badges67 silver badges109 bronze badges












  • Thanks. So it was bad implemented, better do sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1).

    – Aureliano Guedes
    Mar 26 at 22:19

















  • Thanks. So it was bad implemented, better do sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1).

    – Aureliano Guedes
    Mar 26 at 22:19
















Thanks. So it was bad implemented, better do sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1).

– Aureliano Guedes
Mar 26 at 22:19





Thanks. So it was bad implemented, better do sub fac my ($n) = @_; $n == 1 ? 1 : $n * fac($n -1).

– Aureliano Guedes
Mar 26 at 22:19








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55365062%2fout-of-memory-with-simple-calc%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해