Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write exponent in racket?

Using (x^4) or (^ x 4) giving an error message. Is there some functions for exponent than simply using (* x x x x)?

like image 406
Yamin Momo Avatar asked Jan 18 '26 15:01

Yamin Momo


2 Answers

Use the primitive function expt (see reference):

(expt x 4)    ;  = x⁴
like image 90
Renzo Avatar answered Jan 20 '26 05:01

Renzo


If you forget expt, you can use:

(for/product ((i 4))  x)

It's easier than writing (* x x x x) for larger values.

like image 37
rnso Avatar answered Jan 20 '26 06:01

rnso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!