Even if spreadsheets are streets behind (unhip), I think people still want to 
make calculations, and J is both quicker than any other language, and much 
quicker than spreadsheets.  A key benefit to powerful one liners is 
interactively obtaining answers.

The way I would enhance the original example would be to enhance it to daily 
interest and more specific payment schedules.  It is relatively easy concept, 
that would seem intimidating to code at the same time:

toDailyint =: ^&365 inv

   (^&365 inv) 1.05
1.00013

looks right, and didn't even need to know the math to find it.  other language 
problems. 

  1.000131 ^ 365
1.04859

could point out the extended precision option x:@(^&365 inv) if there is a need 
to get it right, but the above is probably the number the bank/lender would use.

Lets say you want to make payments every 2 weeks.

   28$ 1,~ 13 # 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1

shows payments for 28 days.

3650 $  1,~ 13 # 0  NB. payment days for 10 years.

0 0 0 , 3650 $  1,~ 13 # 0  NB. if payments start 2 weeks from 3 days from now. 
(then 2 weeks thereafter)


biweekly =. 40 * 3650 $  1,~ 13 # 0  NB.  $40 payments biweekly for 10 years.


 ] endofyearmarks =: <: 365 * >: i.10  NB. will be used for 
display/classification and bonus payments.
364 729 1094 1459 1824 2189 2554 2919 3284 3649  NB. <: used to compensate for 
0 start.


yearly =. 100 endofyearmarks} 3650 $ 0  NB. pay $100 at end of each year.

100 (endofyearmarks - 30)} 3650 $ 0  NB. would set payment date 30 days prior 
to end of each year.


payments =. biweekly + yearly  NB. add lists of payments like a spreadsheet 
would.  Reason to calculate separately and sum is that payments might occur on 
same days.  Cool feature of J, that drew me into the language.  When I was 
learning it, I called these "noun collisions"... smashing together data 
structures into 1.

   (0,endofyearmarks) { ([-~(toDailyint 1.05)*])/\. 10000,~|.payments
1630.09 2663.44 3647.23 4584.05 5476.11 6325.57 7134.43 7904.64 8638.04 9336.39 
10001.3

One issue with the above, is that payments is a compound noun without any major 
benefits to it being so.  The advantage of single powerful lines is that we 
don't have to recompute nouns for instance if we modified biweekly or yearly, 
or added a new payment stream.  To balance that and readability, a better 
version of the statement is:

   (0,endofyearmarks) { ([-~(toDailyint 1.05)*])/\. 10000,~|. biweekly + yearly
1630.09 2663.44 3647.23 4584.05 5476.11 6325.57 7134.43 7904.64 8638.04 9336.39 
10001.3

Darn.... I was hoping to have the loan paid off in 10 years.
There needs to be a modification to find the day that a 0 balance is reached, 
but a cool reshaping feature is available

      (0,endofyearmarks) { ([-~(toDailyint 1.05)*])/\. 10000,~|. (12*365) $ 
biweekly + yearly
_590.933 546.808 1630.31 2663.44 3647.23 4584.05 5476.11 6325.57 7134.43 
7904.64 8638.04

shows results at the end of years 2 to 12, and tells us that full repayment is 
made sometime in year 11.  To find exact date:

   (1 i:~ 0>:])  ([-~(toDailyint 1.05)*])/\. 10000,~|. (12*365) $ biweekly + 
yearly
170

170 days before end of year 12.

To me, there would be major struggles in accomplishing this in another 
language, and a spreadsheet probably doesn't have enough rows.

A good punch line is to show J performance by extending the example to a $23100 
loan paid over 100 years... by simple modification to edit history

   (0,endofyearmarks) {  ([-~(toDailyint 1.05)*])/\. 23100,~|. (100*365) $ 
biweekly + yearly
_4164.15 _2855.63 _1609.02 _421.909 708.536 1785.02 2810.1 3786.23 4715.75 
5600.86 6443.7

I found 23100 by trial and error, by adjusting it until the last 10 years 
crossed the 0 point, but it shows off J's speed in calculating through 40000+ 
rows instantly, and everything else that happens on that line.  Never mind the 
pain of copy pasting 40000 rows in a spreadsheet, updating the starting loan 
value would bring it to its knees.



----- Original Message -----
From: Brian Schott <schott.br...@gmail.com>
To: Programming forum <programm...@jsoftware.com>
Cc: 
Sent: Friday, February 21, 2014 6:51:02 PM
Subject: Re: [Jprogramming] J in 5 minutes

Don,

My intent was not to make the essay a financial tutorial, but to highlight
the beauty and uniqueness of J code, so some of those details seem
inappropriate. I need another introductory sentence/statement or else I
need to change the example.

Thanks for you help,



On Fri, Feb 21, 2014 at 4:51 PM, Don Guinn <dongu...@gmail.com> wrote:

> I'm confused! I assume that the annual payment against the $10000 loan is
> $1000. Which means that the value of the loan must be more than $7000 as
> only $3000 has been paid against it. Yet the line which should be the value
> of the loan after three years shows $3711.05.
>
> I think the description of the problem needs to include the amount of
> payment and if the payments are annual or whatever. Also, it would help to
> reference the formula used, such as a link to a web page deriving that
> formula rather than seeing it in J without an explanation.
>
> And I couldn't view the video either.
>
>
>
-- 
(B=)
----------------------------------------------------------------------
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