[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

What is the largest n-tuple for which you can define a function which returns n times its argument in Lisp ?

gengyangcai

7/9/2015 3:54:00 PM

The following expression defines a function called double which returns twice its argument:

CL-USER 17 : 8 > (defun double (x) (* x 2))
DOUBLE

Having fed this to Lisp, we can call double in other functions, or from the top level:

CL-USER 18 : 8 > (double 1)
2

CL-USER 18 : 8 > (double 2)
4

CL-USER 18 : 8 > (double 4)
8

I experimented and realised that this works with triple too, I can define a function called triple which returns three times its argument :

CL-USER 21 : 8 > (defun triple (x) (* x 3))
TRIPLE

CL-USER 22 : 8 > (triple 3)
9

CL-USER 23 : 8 > (triple 6)
18

CL-USER 24 : 8 > (triple 1)
3

This works for quadruple too: I can define a function called quadruple which returns four times its argument :

CL-USER 25 : 8 > (defun quadruple (x) (* x 4))
QUADRUPLE

CL-USER 26 : 8 > (quadruple 4)
16

CL-USER 27 : 8 > (quadruple 8)
32

CL-USER 28 : 8 > (quadruple 16)
64

Works for quintuple too ! :

CL-USER 9 : 2 > (defun quintuple (x) (* x 5))
QUINTUPLE

CL-USER 10 : 2 > (quintuple 4)
20

CL-USER 11 : 2 > (quintuple 5)
25

I then tried a far larger n-tuple : centuple and it works as well !

CL-USER 12 : 2 > (defun centuple (x) (* x 100))
CENTUPLE

CL-USER 13 : 2 > (centuple 6)
600

CL-USER 14 : 2 > (centuple 8)
800

I was wondering if there is a limit to this ? What is the largest n-tuple for which you can define a function which returns n times its argument ?

CAI GENGYANG
15 Answers

Kaz Kylheku

7/9/2015 7:58:00 PM

0

On 2015-07-09, CAI GENGYANG <gengyangcai@gmail.com> wrote:
> I was wondering if there is a limit to this ? What is the largest n-tuple for which you can define a function which returns n times its argument ?

This depends on any limit that your implementation imposes on the size
of "bignum" integers. Some are limited only by available memory: a situation
when there is no space to allocate a bignum operand needed by
a calculation.

$ clisp -q
[1]> (expt 10 (expt 10 10))

*** - overflow during multiplication of large numbers
The following restarts are available:
ABORT :R1 Abort main loop

taruss

7/9/2015 9:43:00 PM

0

On Thursday, July 9, 2015 at 8:53:40 AM UTC-7, CAI GENGYANG wrote:
> The following expression defines a function called double which returns twice its argument:
>
> CL-USER 17 : 8 > (defun double (x) (* x 2))
> ...
> I then tried a far larger n-tuple : centuple and it works as well !
>
> CL-USER 12 : 2 > (defun centuple (x) (* x 100))
> CENTUPLE
>
> CL-USER 13 : 2 > (centuple 6)
> 600
>
> I was wondering if there is a limit to this ? What is the largest n-tuple for which you can define a function which returns n times its argument ?
>

In general, you will only be limited by available memory, since Common Lisp has no a priori size limit on integers.

smh

7/10/2015 1:32:00 AM

0

A couple side comments:

The term "N-tuple" refers to an ordered set of N quantities. For example, a position in Cartesian space can be represented as a 3-tuple.

What you are asking about is simple multiplication.

Once during an X3J13 meeting I mentioned a constant named most-positive-bignum. Guy and others appeared to think this concept funny.

If some kind person would take the time to define an implementation of ANSI CL on a Turing machine, there would be no necessary limit on integer range, or float range, or lanbda-arg limits, or even fixnum size or anything else. Unfortunately this implementation would be nonconforming, since the ANS requires these limits to be finitelydefined. Poor planning...

gengyangcai

7/10/2015 5:31:00 AM

0

On Friday, July 10, 2015 at 5:43:04 AM UTC+8, tar...@google.com wrote:
> On Thursday, July 9, 2015 at 8:53:40 AM UTC-7, CAI GENGYANG wrote:
> > The following expression defines a function called double which returns twice its argument:
> >
> > CL-USER 17 : 8 > (defun double (x) (* x 2))
> > ...
> > I then tried a far larger n-tuple : centuple and it works as well !
> >
> > CL-USER 12 : 2 > (defun centuple (x) (* x 100))
> > CENTUPLE
> >
> > CL-USER 13 : 2 > (centuple 6)
> > 600
> >
> > I was wondering if there is a limit to this ? What is the largest n-tuple for which you can define a function which returns n times its argument ?
> >
>
> In general, you will only be limited by available memory, since Common Lisp has no a priori size limit on integers.

This is great, Lisp is a great language , looks very clean and elegant too .... I have finished all the exercises up to page 54 of http://ep.yimg.com/ty/cdn/paulgraham/... , mostly I could run them all successfully with the exception of a few errors like these :

CL-USER 1 > (let ((x 10) (y x))
y)

Error: The variable X is unbound.
1 (continue) Try evaluating X again.
2 Return the value of :X instead.
3 Specify a value to use this time instead of evaluating X.
4 Specify a value to set X to.
5 (abort) Return to level 0.
6 Return to top loop level 0.

Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.

CL-USER 2 : 1 > (count-instances 'a '((a b c) (d a r p a) (d a r) (a a)))

Error: Undefined operator COUNT-INSTANCES in form (COUNT-INSTANCES (QUOTE A) (QUOTE ((A B C) (D A R P A) (D A R) (A A)))).
1 (continue) Try invoking COUNT-INSTANCES again.
2 Return some values from the form (COUNT-INSTANCES (QUOTE A) (QUOTE ((A B C) (D A R P A) (D A R) (A A)))).
3 Try invoking something other than COUNT-INSTANCES with the same arguments.
4 Set the symbol-function of COUNT-INSTANCES to another function.
5 Set the macro-function of COUNT-INSTANCES to another function.
6 (abort) Return to level 1.
7 Return to debug level 1.
8 Return to level 0.
9 Return to top loop level 0.

Gonna take a break and come back later ...

gengyangcai

7/10/2015 5:43:00 AM

0

On Friday, July 10, 2015 at 9:32:13 AM UTC+8, smh wrote:
> A couple side comments:
>
> The term "N-tuple" refers to an ordered set of N quantities. For example, a position in Cartesian space can be represented as a 3-tuple.
>
> What you are asking about is simple multiplication.
>
> Once during an X3J13 meeting I mentioned a constant named most-positive-bignum. Guy and others appeared to think this concept funny.
>
> If some kind person would take the time to define an implementation of ANSI CL on a Turing machine, there would be no necessary limit on integer range, or float range, or lanbda-arg limits, or even fixnum size or anything else. Unfortunately this implementation would be nonconforming, since the ANS requires these limits to be finitelydefined. Poor planning...

Here are some very good articles by Paul Graham on Lisp : http://www.paulgraham.com.... I am currently working through his book ---onlisphttp://ep.yimg.com/ty/cdn/paulgraham/... and am at page 54. I managed to run most of the programs successfully with a few exceptions. Its downloadable online free of charge and really good , but I am still a far way from achieving the "profound enlightenment experience you will have when you finally get it" as he so nicely described in his excellent essay "Beating the Averages" : http://www.paulgraham.co....

Sebastian Christ

7/10/2015 6:29:00 AM

0

>>>>> "CAI" == CAI GENGYANG <gengyangcai@gmail.com> writes:

CAI> CL-USER 1 > (let ((x 10) (y x)) y)

CAI> Error: The variable X is unbound. 1 (continue) Try evaluating
CAI> X again. 2 Return the value of :X instead. 3 Specify a value
CAI> to use this time instead of evaluating X. 4 Specify a value to
CAI> set X to. 5 (abort) Return to level 0. 6 Return to top loop
CAI> level 0.

Use let* instead of let

CAI> CL-USER 2 : 1 > (count-instances 'a '((a b c) (d a r p a) (d a
CAI> r) (a a)))

CAI> Error: Undefined operator COUNT-INSTANCES in form
CAI> (COUNT-INSTANCES (QUOTE A) (QUOTE ((A B C) (D A R P A) (D A R)
CAI> (A A)))). 1 (continue) Try invoking COUNT-INSTANCES again. 2
CAI> Return some values from the form (COUNT-INSTANCES (QUOTE A)
CAI> (QUOTE ((A B C) (D A R P A) (D A R) (A A)))). 3 Try invoking
CAI> something other than COUNT-INSTANCES with the same arguments.
CAI> 4 Set the symbol-function of COUNT-INSTANCES to another
CAI> function. 5 Set the macro-function of COUNT-INSTANCES to
CAI> another function. 6 (abort) Return to level 1. 7 Return to
CAI> debug level 1. 8 Return to level 0. 9 Return to top loop
CAI> level 0.

Have you evaluated the count-instances function?

Best,
Sebastian

Jim Newton

7/10/2015 8:10:00 AM

0

congratulations Pascal, I looks like you have come up with the best every use of format~R.

Pascal J. Bourguignon

7/10/2015 12:51:00 PM

0

smh <shaflich@gmail.com> writes:

> A couple side comments:
>
> The term "N-tuple" refers to an ordered set of N quantities. For
> example, a position in Cartesian space can be represented as a
> 3-tuple.
>
> What you are asking about is simple multiplication.
>
> Once during an X3J13 meeting I mentioned a constant named
> most-positive-bignum. Guy and others appeared to think this concept
> funny.

Yes, this concept if funny.

Either most-positive-bignum doesn't fill more than half the available
memory, or it does.

If it doesn't then (1+ most-positive-bignum) can be computed in the
remaining free memory, and then most-positive-bignum is not the
most positive bignum.

If it does then you won't be able to operate on it since most operations
would produce a big num as big and you won't have the memory to store
it (even (1- most-positive-bignum) won't be storable).


> If some kind person would take the time to define an implementation of
> ANSI CL on a Turing machine, there would be no necessary limit on
> integer range, or float range, or lanbda-arg limits, or even fixnum
> size or anything else. Unfortunately this implementation would be
> nonconforming, since the ANS requires these limits to be
> finitelydefined. Poor planning...

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Pascal J. Bourguignon

7/10/2015 12:52:00 PM

0

CAI GENGYANG <gengyangcai@gmail.com> writes:

> On Friday, July 10, 2015 at 9:32:13 AM UTC+8, smh wrote:
>> A couple side comments:
>>
>> The term "N-tuple" refers to an ordered set of N quantities. For
>> example, a position in Cartesian space can be represented as a
>> 3-tuple.
>>
>> What you are asking about is simple multiplication.
>>
>> Once during an X3J13 meeting I mentioned a constant named
>> most-positive-bignum. Guy and others appeared to think this concept
>> funny.
>>
>> If some kind person would take the time to define an implementation
>> of ANSI CL on a Turing machine, there would be no necessary limit on
>> integer range, or float range, or lanbda-arg limits, or even fixnum
>> size or anything else. Unfortunately this implementation would be
>> nonconforming, since the ANS requires these limits to be
>> finitelydefined. Poor planning...
>
> Here are some very good articles by Paul Graham on Lisp :
> http://www.paulgraham.com.... I am currently working through
> his book ---onlisphttp://ep.yimg.com/ty/cdn/paulgraham/... and
> am at page 54. I managed to run most of the programs successfully with
> a few exceptions. Its downloadable online free of charge and really
> good , but I am still a far way from achieving the "profound
> enlightenment experience you will have when you finally get it" as he
> so nicely described in his excellent essay "Beating the Averages" :
> http://www.paulgraham.co....

Count on needing between two and ten years of lisp learning and
programming before you get it.


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

gengyangcai

7/10/2015 1:50:00 PM

0

On Friday, July 10, 2015 at 8:52:20 PM UTC+8, informatimago wrote:
> CAI GENGYANG <gengyangcai@gmail.com> writes:
>
> > On Friday, July 10, 2015 at 9:32:13 AM UTC+8, smh wrote:
> >> A couple side comments:
> >>
> >> The term "N-tuple" refers to an ordered set of N quantities. For
> >> example, a position in Cartesian space can be represented as a
> >> 3-tuple.
> >>
> >> What you are asking about is simple multiplication.
> >>
> >> Once during an X3J13 meeting I mentioned a constant named
> >> most-positive-bignum. Guy and others appeared to think this concept
> >> funny.
> >>
> >> If some kind person would take the time to define an implementation
> >> of ANSI CL on a Turing machine, there would be no necessary limit on
> >> integer range, or float range, or lanbda-arg limits, or even fixnum
> >> size or anything else. Unfortunately this implementation would be
> >> nonconforming, since the ANS requires these limits to be
> >> finitelydefined. Poor planning...
> >
> > Here are some very good articles by Paul Graham on Lisp :
> > http://www.paulgraham.com.... I am currently working through
> > his book ---onlisphttp://ep.yimg.com/ty/cdn/paulgraham/... and
> > am at page 54. I managed to run most of the programs successfully with
> > a few exceptions. Its downloadable online free of charge and really
> > good , but I am still a far way from achieving the "profound
> > enlightenment experience you will have when you finally get it" as he
> > so nicely described in his excellent essay "Beating the Averages" :
> > http://www.paulgraham.co....
>
> Count on needing between two and ten years of lisp learning and
> programming before you get it.
>
>
> --
> __Pascal Bourguignon__ http://www.informat...
> "The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment." -- Carl Bass CEO Autodesk

Hopefully it doesn't take THAT long !