Post Reply 
Crash when Solve for Integral with 15C
09-04-2017, 02:37 AM (This post was last modified: 09-05-2017 08:19 PM by Gerson W. Barbosa.)
Post: #61
RE: Crash when Solve for Integral with 15C
(09-03-2017 06:47 PM)Gerson W. Barbosa Wrote:  Only the first 22 digits are correct. 600+ terms would be necessary for 100 digits, but a clean 50g will run out of memory after around 380 terms.

EXPANDing inside the loop is slower at first, but becomes faster as the number of terms increases, not to mention a lesser memory requirement. Still, not a recommended method for the task (727 seconds on the emulator).

600

« 0 DUP ROT
FOR n n 3 * 1 + DUP n ! * 6 ROT ^ SWAP / + EXPAND
NEXT →STR "/" " " SREPL DROP "'" " " SREPL DROP OBJ→ SWAP 12 ALOG * SWAP IQUOT →STR DUPDUP SIZE DUP 11 - SWAP SUB "." OVER + SREPL DROP
»

EVAL

=>

59639380918976775196293204202056658471019738405733913
533679285187391995176580099542319971838.280912881192



PS:

A stack-only version hasn't helped, at least on the emulator, mostly due to my clumsy stack handling:

6 600

« DUP2 3 * 1 + DUP UNROT OVER 3 ^ UNROT ^ 4 PICK ! 1 6 PICK
START DUP2 6 PICK * / 7 ROLL + EXPAND 6 ROLLD 5 PICK / UNROT OVER / ROT 5 ROLL 1 - 5 ROLLD 4 ROLL 3 - 4 ROLLD
NEXT 5 DROPN →STR "/" " " SREPL DROP "'" " " SREPL DROP OBJ→ SWAP 12 ALOG * SWAP IQUOT →STR DUPDUP SIZE DUP 11 - SWAP SUB "." OVER + SREPL DROP
»

EVAL

=>

59639380918976775196293204202056658471019738405733913
533679285187391995176580099542319971838.280912881192

(1293 seconds)

PPS:

It's better to sum the terms in ascending order, otherwise the time-consuming expansions of long expressions are done since the beginning. Execution time down to 769 seconds despite more command inside the loop. Stack handling optimization might make it faster than the first version.

6 601

« OVER 3 ^ ROT 1 0 1 1 6 ROLLD 6 ROLLD 6 ROLLD DUP 8 ROLL
START DUP2 6 PICK * / 7 ROLL + EXPAND 6 ROLLD 5 PICK * UNROT OVER * ROT 5 ROLL 1 + 5 ROLLD 4 ROLL 3 + 4 ROLLD
NEXT 5 DROPN →STR "/" " " SREPL DROP "'" " " SREPL DROP OBJ→ SWAP 12 ALOG * SWAP IQUOT →STR DUPDUP SIZE DUP 11 - SWAP SUB "." OVER + SREPL DROP
»

EVAL

=>

59639380918976775196293204202056658471019738405733913
533679285187391995176580099542319971838.280912881192


The arguments are

Y: upper limit of integration
X: number of terms (n-1, in the previous version)

PPPS:

A version using local variables isn't any faster:

6 601

« 0 UNROT OVER 3 ^ ROT 1 DUPDUP → k b d f n
« 1 SWAP
START b d f * / + EXPAND k 'b' STO* 3 'd' STO+ n 'f' STO* 1 'n' STO+
NEXT
» DUP TYPE 28 - NOT SWAP →STR SWAP { "'" SWAP + "/1'" + } IFT "/" " " SREPL DROP "'" " " SREPL DROP OBJ→ SWAP 12 ALOG * SWAP IQUOT →STR "#" + DUPDUP SIZE DUP 12 - SWAP SUB "." OVER + SREPL DROP "#" "" SREPL DROP
»

EVAL

=>

59639380918976775196293204202056658471019738405733913
533679285187391995176580099542319971838.280912881192

786 seconds on the emulator.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Crash when Solve for Integral with 15C - Gerson W. Barbosa - 09-04-2017 02:37 AM



User(s) browsing this thread: 1 Guest(s)