--Alt-Boundary-6156.32940475
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body
Am 16 Feb 2006 um 21:56 hat Mario Rodriguez geschrieben:
Hello Mario,
I am using Windows-Maxima 5.9.2 with GCL.
Are you able to calculate n_sum_1(1000000,0);
without compilation?
My interest is concentrated on the compilation behaviour. What does clisp do, when you
compile n-sum-1?
Is there a tail recursive optimization?
If I compile Lisp code with GCL, there is a tail recursive optimization.
I would like to have it under Maxima as well.
The problem seems to be, that the translated function is wrapped with the additional
SIMPLIFY . After this the compiler is not able to recognize the function as tail recursive.
(PROGN
(DEFPROP $N_SUM_1 T TRANSLATED)
(ADD2LNC '$N_SUM_1 $PROPS)
(DEFMTRFUN ($N_SUM_1 $ANY MDEFINE NIL NIL) ($N $RES)
(DECLARE (SPECIAL $RES $N))
(COND
((LIKE $N 0) $RES)
(T ;(SIMPLIFY
(MFUNCTION-CALL $N_SUM_1 (ADD* $N -1) (ADD* $N $RES))))));)
The translation is done by Maxima. So I expect, that you have the same code and I
expect, that clisp will not optimize too.
The optimization is a conceptual thing. Will Maxima generally miss this or is there a
way to realize it?
Volker
> Hallo Volker,
>
>
>
> >
> > (C1) n_sum_1(n,res):=
> > if n=0 then res
> > else n_sum_1(n-1,n+res)$
> > (C2) n_sum_1(1000,0); ---> Bind stack overflow.
> >
>
> I don't see any problems here:
>
> Maxima 5.9.2.19cvs http://maxima.sourceforge.net
> Using Lisp CLISP ()
> Distributed under the GNU Public License. See the file COPYING.
> Dedicated to the memory of William Schelter.
> This is a development version of Maxima. The function bug_report()
> provides bug reporting information.
> (%i1) n_sum_1(n,res):=
> if n=0 then res
> else n_sum_1(n-1,n+res)$
> (%i2) n_sum_1(1000,0);
> (%o2) 500500
>
>
>
> could that be a GCL specific problem?
>
> By the way, which Maxima version are you running?
>
> Bis bald.
> --
> Mario Rodriguez Riotorto
> www.biomates.net
>
--Alt-Boundary-6156.32940475
Content-type: text/html; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body
<?xml version="1.0" ?><html>
<head>
<title></title>
</head>
<body>
<div align="left"><font face="Arial"><span style="font-size:10pt">Am 16 Feb 2006 um 21:56 hat Mario Rodriguez geschrieben: </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Hello Mario, </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">I am using Windows-Maxima 5.9.2 with GCL. </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Are you able to calculate </span></font><font face="Arial" color="#7f0000"><span style="font-size:10pt">n_sum_1(1000000,0);  </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">without compilation? </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">My interest is concentrated on the compilation behaviour. What does clisp do, when you
compile n-sum-1? </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Is there a tail recursive optimization? </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">If I compile Lisp code with GCL, there is a tail recursive optimization. </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">I would like to have it under Maxima as well.  </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">The problem seems to be, that the translated function is wrapped with the additional  </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">SIMPLIFY . After this the compiler is not able to recognize the function as tail recursive. </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">(PROGN </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">  (DEFPROP $N_SUM_1 T TRANSLATED) </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">  (ADD2LNC '$N_SUM_1 $PROPS) </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">  (DEFMTRFUN ($N_SUM_1 $ANY MDEFINE NIL NIL) ($N $RES) </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">      (DECLARE (SPECIAL $RES $N)) </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">      (COND </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">        ((LIKE $N 0) $RES) </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">        (T ;(SIMPLIFY </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">               (MFUNCTION-CALL $N_SUM_1
(ADD* $N -1) (ADD* $N $RES))))));) </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">The translation is done by Maxima. So I expect, that you have the same code and I
expect, that clisp will not optimize too. </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">The optimization is a conceptual thing. Will Maxima generally miss this or is there a
way to realize it? </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Volker </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Hallo Volker, </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> >  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (C1) n_sum_1(n,res):= </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> >   if n=0 then res </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> >   else n_sum_1(n-1,n+res)$ </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > (C2) n_sum_1(1000,0);       --->  Bind
stack overflow. </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> >  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> I don't see any problems here: </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Maxima 5.9.2.19cvs </span></font><font face="Arial" color="#008000"><span style="font-size:10pt"><u>http://maxima.sourceforge.net</u></span></font><font
face="Arial" color="#7f0000"><span style="font-size:10pt"> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Using Lisp CLISP () </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Distributed under the GNU Public License. See the file COPYING. </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Dedicated to the memory of William Schelter. </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> This is a development version of Maxima. The function bug_report() </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> provides bug reporting information. </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> (%i1) n_sum_1(n,res):= </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>   if n=0 then res </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>   else n_sum_1(n-1,n+res)$ </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> (%i2) n_sum_1(1000,0); </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> (%o2)                              
500500 </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> could that be a GCL specific problem? </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> By the way, which Maxima version are you running? </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Bis bald. </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> --  </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Mario Rodriguez Riotorto </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> www.biomates.net </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">>  </span></font></div>
<div align="left"><br/></div>
<div align="left"></div>
</body>
</html>
--Alt-Boundary-6156.32940475--