Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Your aim is high and to the right.


comp / comp.lang.lisp / Math operation abstraction

SubjectAuthor
* Math operation abstractionDaniel Cerqueira
+- Re: Math operation abstractionB. Pym
+- Re: Math operation abstractionSpiros Bousbouras
`- Re: Math operation abstractionSpiros Bousbouras

1
Subject: Math operation abstraction
From: Daniel Cerqueira
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 27 May 2024 22:29 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: dan.list@lispclub.com (Daniel Cerqueira)
Newsgroups: comp.lang.lisp
Subject: Math operation abstraction
Date: Mon, 27 May 2024 23:29:56 +0100
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <87fru251nf.fsf@lispclub.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 28 May 2024 00:29:59 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="04013055fa4dd42dc81955d154213b07";
logging-data="268119"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qprwOWINlyTFLHQKZFKk7OheokcjNr7A="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:WhnMIHDtgSny4M5qYWZLNaRx9gg=
sha1:vYH6hX7+T7hQg5niR9zDcU2MBWg=
View all headers

Hi.

I have this function

```
(defun muo (func a b)
(cond
((eq b 1) a)
(t (funcall func a (muo func a (1- b))))))
```

Which I can use for obtaining the multiplication operation using the
addition. As an example:

* (muo #'+ 5 2)
10

and "muo #'+" means "use the multiplication".

Now if I want the exponentiation I have to do:

* (muo #'(lambda (a b) (muo #'+ a b)) 5 2)
25

This creates the exponentiation.

I would like to obtain the exponentiation using "(muo #'+ 5 2 2)"
instead, being the last argument ("2") the number of times the operation
is applied. In the case of exponentiation, it applies the multiplication
2 times, resulting in the exponentiation math operation.

I am hoping I am explaining this concept well enough.

Basically, "muo #'+" creates the addition twice, which is the
multiplication, and "muo #'+ a b 2" should create the multiplication
twice, which is the exponentiation. If I use "muo #'+ a b 3" it should
create the exponentiation twice, which is the exponentiation of the
exponentiation.

I need help in making this code modification. Seeing code is what I
want. If you can write the code and explain it, better.

Subject: Re: Math operation abstraction
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 27 May 2024 23:54 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Math operation abstraction
Date: Mon, 27 May 2024 23:54:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <v336g2$8ti9$1@dont-email.me>
References: <87fru251nf.fsf@lispclub.com>
Injection-Date: Tue, 28 May 2024 01:54:43 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f602e386ecaccd5eca901d418dfe446e";
logging-data="292425"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eNBzrGnUXJRa0M39NUVtJ"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:d9AA+ogNfMN02uPt6uVK2/OBLhk=
View all headers

On 5/27/2024, Daniel Cerqueira wrote:

> * (muo #'(lambda (a b) (muo #'+ a b)) 5 2)

Pascal Bourguignon wrote:

> > #'(lambda (letter)
> > (add-counter letters letter))
> > word))
> > (read-words infile)))
>
> (function (lambda ...)) is a pleonasm. lambda is a macro that
> already expands to (function (lambda ...)).

Subject: Re: Math operation abstraction
From: Spiros Bousbouras
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Tue, 28 May 2024 21:10 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: Math operation abstraction
Date: Tue, 28 May 2024 21:10:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <OEX3U1SVrO3XtgFC3@bongo-ra.co>
References: <87fru251nf.fsf@lispclub.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 28 May 2024 23:10:11 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="882506c66873f2cd903eecd927d35b9d";
logging-data="819841"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eZpBRHMOV0AtcqDzkb+mj"
Cancel-Lock: sha1:tG5TeJHuYsg6MzFBCxActyCIPvs=
X-Organisation: Weyland-Yutani
In-Reply-To: <87fru251nf.fsf@lispclub.com>
X-Server-Commands: nowebcancel
View all headers

On Mon, 27 May 2024 23:29:56 +0100
Daniel Cerqueira <dan.list@lispclub.com> wrote:
> Hi.
>
> I have this function
>
> ```
> (defun muo (func a b)
> (cond
> ((eq b 1) a)
> (t (funcall func a (muo func a (1- b))))))
> ```
>
> Which I can use for obtaining the multiplication operation using the
> addition. As an example:
>
> * (muo #'+ 5 2)
> 10
>
> and "muo #'+" means "use the multiplication".
>
> Now if I want the exponentiation I have to do:
>
> * (muo #'(lambda (a b) (muo #'+ a b)) 5 2)
> 25
>
> This creates the exponentiation.
>
> I would like to obtain the exponentiation using "(muo #'+ 5 2 2)"
> instead, being the last argument ("2") the number of times the operation
> is applied. In the case of exponentiation, it applies the multiplication
> 2 times, resulting in the exponentiation math operation.
>
> I am hoping I am explaining this concept well enough.
>
> Basically, "muo #'+" creates the addition twice, which is the
> multiplication, and "muo #'+ a b 2" should create the multiplication
> twice, which is the exponentiation. If I use "muo #'+ a b 3" it should
> create the exponentiation twice, which is the exponentiation of the
> exponentiation.
>
> I need help in making this code modification. Seeing code is what I
> want. If you can write the code and explain it, better.

You don't give a precise definition but perhaps the following gives you
what you want or at least a starting point :

(defun muo-aux (func a b)
(cond
((eql b 1) a)
(t (funcall func a (muo-aux func a (1- b))))))

(defun muo (func a b repeats)
(cond
((eql repeats 1)
(muo-aux func a b))
((< 1 repeats)
(muo-aux (lambda (x y) (muo func x y (1- repeats))) a b))))

--
vlaho.ninja/menu

Subject: Re: Math operation abstraction
From: Spiros Bousbouras
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Tue, 28 May 2024 21:17 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.lisp
Subject: Re: Math operation abstraction
Date: Tue, 28 May 2024 21:17:55 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <3uApLYr=HDq1P0ITS@bongo-ra.co>
References: <87fru251nf.fsf@lispclub.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 28 May 2024 23:17:56 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="882506c66873f2cd903eecd927d35b9d";
logging-data="821778"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/OgzY9WVqVkSrANls15xfs"
Cancel-Lock: sha1:k5YKWcmYFfOTaaBNS+ITGyMGexU=
X-Organisation: Weyland-Yutani
In-Reply-To: <87fru251nf.fsf@lispclub.com>
X-Server-Commands: nowebcancel
View all headers

On Mon, 27 May 2024 23:29:56 +0100
Daniel Cerqueira <dan.list@lispclub.com> wrote:
> Hi.
>
> I have this function
>
> ```
> (defun muo (func a b)
> (cond
> ((eq b 1) a)
> (t (funcall func a (muo func a (1- b))))))

By the way , I don't think that in Common Lisp it is guaranteed that
(eq 1 1) returns T so it's best to use EQL to compare numbers.

1

rocksolid light 0.9.8
clearnet tor