开发者

J How to get equation to multiply by itself?

开发者 https://www.devze.com 2023-02-12 21:53 出处:网络
How do I get this equation to开发者_高级运维 multiply by itself? */-.%~.q:36 other than repeating the number 36 again. It\'s Euler\'s Totient Function by the way.

How do I get this equation to开发者_高级运维 multiply by itself?

*/-.%~.q:36

other than repeating the number 36 again. It's Euler's Totient Function by the way.

J How to get equation to multiply by itself?

I'm lacking the last step of multiplying this by itself.

Yes, I know they already have the code for this function at jsoftware. But I'm trying to break down the codes and learn.

Sorry to ask such simple questions. It's really hard to find help for J on Google.


The most direct way to use the value again is to include the value again.

   */ 36, -. % ~. q: 36
12

A name can be used for the value.

   */ y, -. % ~. q: y=. 36
12

A verb can be defined. The name is local within it.

   etf=: verb : '*/ y, -. % ~. q: y'
   etf 36
12

The same verb can be phrased in tacit form. In this form the parameter is implied, not named. Here the key to using the parameter value twice is the hook created within parentheses.

   etfT=: */ @ ( , -. @ % @ ~. @ q: )
   etfT 36
12


Short answer

y * (f y)

is

(* f) y

Longer answer

You have a case of

y f (g (y))

where f is the dyad * and g is the function that you already had: */-.%~.q:. Now, y f (g(y)) transforms simply to the "train" (f g) y (as you can see at the manual). Using Cap [:* to parenthesize g:

g =: [: */ [: -. [: % [: ~. q:

we finally have:

phi =: * g
phi 36
12

or

(* [: */ [: -. [: % [: ~. q:) 36
12

* You can use Atop and At to construct function g but Cap is usually clearer for trains.


Ok this what I came up with.

(* */@:-.@:%@~.@q:)36


After I played around with this function trying to find out how it works and researching and the like (I only have a second year Calculus background), I looked back at an old tab for the primes function p: and found that J has built in Euler's totient function 5&p: .

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号