Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

265 views
Skip to first unread message

CAI GENGYANG

unread,
Jul 9, 2015, 11:53:40 AM7/9/15
to
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

Pascal J. Bourguignon

unread,
Jul 9, 2015, 12:16:30 PM7/9/15
to
CAI GENGYANG <gengy...@gmail.com> writes:

> 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 ?

No limit!


(defmacro define-multiplicator (n)
`(defun ,(intern (substitute-if-not #\- (function alpha-char-p)
(format nil "~:@(~R-UPLE~)" n))) (x)
(* x ,n)))

(pprint (macroexpand-1 '(define-multiplicator #.most-positive-fixnum)))

(defun one-quintillion-one-hundred-fifty-two-quadrillion-nine-hundred-twenty-one-trillion-five-hundred-four-billion-six-hundred-six-million-eight-hundred-forty-six-thousand-nine-hundred-seventy-five-uple (x)
(* x 1152921504606846975))

(one-quintillion-one-hundred-fifty-two-quadrillion-nine-hundred-twenty-one-trillion-five-hundred-four-billion-six-hundred-six-million-eight-hundred-forty-six-thousand-nine-hundred-seventy-five-uple 2)
--> 2305843009213693950



(pprint (macroexpand-1 '(define-multiplicator #.(* (random 1000000) most-positive-fixnum))))

(defun eight-hundred-twenty-five-sextillion-three-hundred-eight-quintillion-four-hundred-eighty-two-quadrillion-seven-hundred-seventy-nine-trillion-two-hundred-sixty-nine-billion-nine-hundred-forty-five-million-four-hundred-thirty-thousand-nine-hundred-seventy-five-uple (x)
(* x 825308482779269945430975))


(eight-hundred-twenty-five-sextillion-three-hundred-eight-quintillion-four-hundred-eighty-two-quadrillion-seven-hundred-seventy-nine-trillion-two-hundred-sixty-nine-billion-nine-hundred-forty-five-million-four-hundred-thirty-thousand-nine-hundred-seventy-five-uple 1/975)
846470238747969174801


--
__Pascal Bourguignon__ http://www.informatimago.com/
“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

CAI GENGYANG

unread,
Jul 9, 2015, 2:54:16 PM7/9/15
to
Great !

Kaz Kylheku

unread,
Jul 9, 2015, 3:58:23 PM7/9/15
to
On 2015-07-09, CAI GENGYANG <gengy...@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

tar...@google.com

unread,
Jul 9, 2015, 5:43:04 PM7/9/15
to
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

unread,
Jul 9, 2015, 9:32:13 PM7/9/15
to
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...
Message has been deleted
Message has been deleted

Sebastian Christ

unread,
Jul 10, 2015, 2:29:19 AM7/10/15
to
>>>>> "CAI" == CAI GENGYANG <gengy...@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

unread,
Jul 10, 2015, 4:09:44 AM7/10/15
to
congratulations Pascal, I looks like you have come up with the best every use of format~R.

Pascal J. Bourguignon

unread,
Jul 10, 2015, 8:51:21 AM7/10/15
to
smh <shaf...@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 J. Bourguignon

unread,
Jul 10, 2015, 8:52:20 AM7/10/15
to
CAI GENGYANG <gengy...@gmail.com> writes:
> Here are some very good articles by Paul Graham on Lisp :
> http://www.paulgraham.com/lisp.html. I am currently working through
> his book ---onlisphttp://ep.yimg.com/ty/cdn/paulgraham/onlisp.pdf 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.com/avg.html.

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

CAI GENGYANG

unread,
Jul 10, 2015, 9:50:28 AM7/10/15
to
Hopefully it doesn't take THAT long !

Pascal J. Bourguignon

unread,
Jul 10, 2015, 10:03:17 AM7/10/15
to
CAI GENGYANG <gengy...@gmail.com> writes:

> On Friday, July 10, 2015 at 8:52:20 PM UTC+8, informatimago wrote:
>> Count on needing between two and ten years of lisp learning and
>> programming before you get it.
>
> Hopefully it doesn't take THAT long !

It may even be worse, because I think you can really get it only if you
have suffered thousands pains for years in the hell of other programming
languages, so you should add ten to twenty years trying other
programming languages first…

CAI GENGYANG

unread,
Jul 10, 2015, 10:08:20 AM7/10/15
to
On Friday, July 10, 2015 at 10:03:17 PM UTC+8, informatimago wrote:
> CAI GENGYANG <gengy...@gmail.com> writes:
>
> > On Friday, July 10, 2015 at 8:52:20 PM UTC+8, informatimago wrote:
> >> Count on needing between two and ten years of lisp learning and
> >> programming before you get it.
> >
> > Hopefully it doesn't take THAT long !
>
> It may even be worse, because I think you can really get it only if you
> have suffered thousands pains for years in the hell of other programming
> languages, so you should add ten to twenty years trying other
> programming languages first...
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
> "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

Last paragraph of this essay by PG : http://www.paulgraham.com/raq.html.

I want to start a startup, but I don't know how to program. How long will it take to learn?

I would guess a smart person can learn to hack sufficiently well in 6 months to a year. The best way to do it would be to find some startup to hire you in an initially menial capacity, and start learning to program on the side. Then gradually work your way up from answering phones through system administration to actual software design. There is always so much to do in a startup that people won't be too picky about your paper qualifications, if you can solve problems for them without screwing up.

Barry Margolin

unread,
Jul 10, 2015, 10:27:56 AM7/10/15
to
In article <f8ec179c-61c6-4a88...@googlegroups.com>,
CAI GENGYANG <gengy...@gmail.com> wrote:

> On Friday, July 10, 2015 at 10:03:17 PM UTC+8, informatimago wrote:
> > CAI GENGYANG <gengy...@gmail.com> writes:
> >
> > > On Friday, July 10, 2015 at 8:52:20 PM UTC+8, informatimago wrote:
> > >> Count on needing between two and ten years of lisp learning and
> > >> programming before you get it.
> > >
> > > Hopefully it doesn't take THAT long !
> >
> > It may even be worse, because I think you can really get it only if you
> > have suffered thousands pains for years in the hell of other programming
> > languages, so you should add ten to twenty years trying other
> > programming languages first...
> >
> > --
> > __Pascal Bourguignon__ http://www.informatimago.com/
> > "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
>
> Last paragraph of this essay by PG : http://www.paulgraham.com/raq.html.
>
> I want to start a startup, but I don't know how to program. How long will it
> take to learn?

Last night I saw a question on Stack Overflow by someone who was trying
to write an operating system in C. He was having trouble implementing a
function to convert an integer to a string. He didn't know that in C you
can't return a local array from a function.

What do newbie programmers not understand about "You need to learn to
walk before you can run"?

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Matthew Carter

unread,
Jul 10, 2015, 11:01:17 AM7/10/15
to
Until you understand it, it's all magic.

Reminds me of a time a family member wanted a custom website
(interactive) which was about 20 hours of work for me (having about 10
years of experience).

He said, "I hate to bug you with this, if I had more time I'd slap it
together in an hour or so" (he had no programming experience).

Regarding time to learn, I started learning Common Lisp about 3 years
ago (having had 7 years of other programming) and felt it took me about
~4 months to really feel comfortable with it (I'm by no means an expert,
but if I get a project in mind, can achieve it relatively pain free via
CL now).

--
Matthew Carter (m...@ahungry.com)
http://ahungry.com

Kaz Kylheku

unread,
Jul 10, 2015, 11:46:26 AM7/10/15
to
On 2015-07-10, smh <shaf...@gmail.com> wrote:
> A couple side comments:
>
> The term "N-tuple" refers to an ordered set of N quantities.

I almost wrote the same reply yesterday, but then I thought
about it a litle bit.

"N-tuple" is derived "double (a.k.a. pair), triple, quadruple, pentuple ...".

Those words refer to ordered combinations, as you note above.

But they are also verbs: to double, to triple, to quadruple, ...

Therfore, N-tuple should be eligible for use as a verb also: as in,
to multiply by N.

Example sentence:

"ACME's earnings have, like, N-tupled over the same quarter last year, dude!"

> For example, a position in Cartesian space can be represented as a 3-tuple.

That's a silly way of saying triple, like 2-tuple is a silly way of saying
pair.

However, a wrapped scalar could be a 1-tuple. :)
0 new messages