June;

Would this be just too simple....

   +/35{.(20#0.9),(40#0.8),(500#0.75)
30

David

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of June Kim
Sent: Sunday, May 07, 2006 9:54 AM
To: Programming forum
Subject: [Jprogramming] APL thinking


Hello,

I read Roy A. Sykes, Jr.'s Whizbang! article in APL Quote Quad vol 27, no 2.
The title is APL thinking. I found it quite instructive even though I know
close to nothing about APL syntax.

I have a few questions on it.

The problem that the article solves through is computing the total cost of
some heating oil using the following rate structure:

First 20 gallons ... 90c per gallon
Next  40 gallons ... 80c per gallon
Remainder        ... 75c per gallon

For example,

c=: 20 40
p=: 0.9 0.8 0.75
q=: 35

and then the total cost is 30

I have translated the first apl solution into J : +/p* 0>.(c,q)<. q - 0,+/\c

The article continues to expand q as a vector.

Firstly, it replaces +/p* with "inner product". I suppose that is, p (+/
.*)~ And then it replaces (c,q) part with something more complexed. It gives
two possibilities: ((($q),$c)$c),q  or >(<c), each q

In the former possibility, I just replaced the original rho function with
J's shape($), and it doesn't work. I had to figure out ((($q),$c)$c),"1 0 q

Am I doing it right? I suppose APL's concatenation quite different from J's.

Now the article continues the task and replaces "q -" part with outer
product, and I think it could be translated into J as "q -/"

I wonder now. Is it necessary to do all this stuff in J as well? Wouldn't
simply applying rank adverb to verbs work? Doesn't APL have rank operator?
Any advantages of doing this replacement(inner, outer, and etc) to get a
differnt rank verb in J?

Finally, the article looks toward making a verb and handling arguments. In
order to avoid taking several arguments boxed into one, it makes a new
concept, price schedule.

   PriceSched=:0 20 40 80 ,: 0.9 0.8 0.75 0.7

And a verb named OILPRICE is dyadic with PriceSched as x arg and Gallons as
y arg.

I might instead do,

   +/ p * c bucket q

Overall, the article is very nice for learning problem solving mind in
APL(or J).

June
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to