[Jprogramming] Cool roots

Don & Cathy Kelly dhky at shaw.ca
Thu Dec 13 00:25:17 UTC 2012


Rewrite to make a=1  (i.e get 4 2 3 % 4)

   'b c' =:2 3%4

    (-b)(+,-)%:(*:b=:-:b)-c

_0.25j0.829156 _0.25j_0.829156

    p.3 2 4
┌─┬──────────────────────────────┐
│4│_0.25j0.829156 _0.25j_0.829156│
└─┴──────────────────────────────┘
or , to retain b, c
    'b c'=:(2 4)%3

(- -:b)(+,-)%:(*:-:b)-c

_0.333333j1.10554 _0.333333j_1.10554

    b,c
0.666667 1.33333
    p.4 2 3
┌─┬────────────────────────────────────┐
│3│_0.333333j1.10554 _0.333333j_1.10554│
└─┴────────────────────────────────────┘

  Don


On 12/12/2012 4:10 AM, km wrote:
> Thanks, Linda, I like this.  Was trying to stay close to the Iverson-McDonnell formula.  Kip
>
> Sent from my iPad
>
>
> On Dec 12, 2012, at 2:24 AM, "Linda Alvord" <lindaalvord at verizon.net> wrote:
>
>> Kip, Here are two thoughts:
>>
>>
>>
>>     This uses [: only rather than both [: and @
>>
>>     %~ can be "read" as "into" (it makes a prettier tree!)
>>
>>
>>
>> a =:0 { ]
>>
>>    b =:1 { ]
>>
>>    c =:2 { ]
>>
>>    roots2=:(2*a)%~([:-b)(+,-)[:%:([:*:b)-4*a*c
>>
>>    roots2 1 3 2
>>
>> _1 _2
>>
>>    roots2 1 0 4
>>
>> 0j2 0j_2
>>
>>    5!:4 <'roots2'
>>
>>         ┌─ 2
>>   ┌─────┼─ *
>>   │     └─ a
>>   │
>>   ├─ ~ ─── %
>>   │         ┌─ [:
>> ──┤     ┌───┼─ -
>>   │     │   └─ b
>>   │     │
>>   │     │   ┌─ +
>>   │     ├───┼─ ,
>>   └─────┤   └─ -
>>         │
>>         │   ┌─ [:
>>         │   ├─ %:
>>         │   │        ┌─ [:
>>         └───┤    ┌───┼─ *:
>>             │    │   └─ b
>>             │    ├─ -
>>             └────┤   ┌─ 4
>>                  │   ├─ *
>>                  └───┤    ┌─ a
>>                      └────┼─ *
>>                           └─ c
>>
>>
>>
>> Linda
>>
>>
>>
>> -----Original Message-----
>> From: programming-bounces at forums.jsoftware.com [mailto:programming-bounces at forums.jsoftware.com] On Behalf Of Roger Hui
>> Sent: Wednesday, December 12, 2012 2:23 AM
>> To: Programming forum
>> Subject: Re: [Jprogramming] Cool roots
>>
>>
>>
>> Cool.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Tue, Dec 11, 2012 at 7:54 PM, km < <mailto:km at math.uh.edu> km at math.uh.edu> wrote:
>>
>>
>>
>>> Apologies:
>>>     a =: 0 { ]
>>>     b =: 1 { ]
>>>     c =: 2 { ]
>>>     roots =: ( (- at b) (+ , -) [: %: *:@b - 4 * a * c ) % 2 * a
>>>     roots 1 3 2
>>> _1 _2
>>>     roots 1 0 1
>>> 0j1 0j_1
>>>     roots 1 2 1
>>> _1 _1
>>> Kip Murray
>>> Sent from my iPad
>>> On Dec 11, 2012, at 5:29 PM, Roger Hui < <mailto:rogerhui.canada at gmail.com> rogerhui.canada at gmail.com> wrote:
>>>> There are some cheeky (or is it cheesy?) versions:
>>>> (2*a) %~ (-b) (+,-) %: (b^2) - 4*a*c  NB. Kip Murray
>>>> (2*a) %~ - b (+,-) %: (b^2) - 4*a*c
>>>> (+:a) %~ - b (+,-) %: (*:b) - 4*a*c
>>>> -: a %~ - b (+,-) %: (*:b) - 4*a*c
>>>> On Tue, Dec 11, 2012 at 11:37 AM, km < <mailto:km at math.uh.edu> km at math.uh.edu> wrote:
>>>>> It appears this could be translated into J as the rather cool
>>>>> (2*a) %~ (-b) (+,-) %: (b^2) - 4*a*c
>>>>> Sent from my iPad
>>>>> On Dec 11, 2012, at 12:59 PM, Roger Hui < <mailto:rogerhui.canada at gmail.com> rogerhui.canada at gmail.com>
>>> wrote:
>>>>>> Example from the Iverson and McDonnell *Phrasal
>>>>>> Forms*< <http://www.jsoftware.com/papers/fork.htm> http://www.jsoftware.com/papers/fork.htm>paper (which
>>>>>> introduced fork):
>>>>>> (-b)(+,-)√((b*2)-4×a×c)÷2×a
>>>>>> √ is a postulated APL primitive, spelled %: in J.
>>>>>> On Tue, Dec 11, 2012 at 10:49 AM, km < <mailto:km at math.uh.edu> km at math.uh.edu> wrote:
>>>>>>> What is the coolest way of programming the quadratic formula in
>>>>>>> J?  We
>>>>> are
>>>>>>> finding the roots of polynomial c + x*(b + x*a) without using p.
>>>>>>> .  I
>>>>> offer
>>>>>>>   roots
>>>>>>> 3 : 0
>>>>>>> 'a b c' =. y
>>>>>>> q =. %: (b^2) - 4*a*c
>>>>>>> (2*a) %~ (-b) + q,-q
>>>>>>> )
>>>>>>>   roots 1 3 2
>>>>>>> _1 _2
>>>>>>>   roots 1 0 1
>>>>>>> 0j1 0j_1
>>>>>>>   roots 1 _2 1
>>>>>>> 1 1
>>>>>>> partly as problem definition.  I am looking for cool roots verbs!
>>>>>>> Kip Murray
>>>>>>> Sent from my iPad
>>>>>>> -----------------------------------------------------------------
>>>>>>> ----- For information about J forums see
>>> <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm
>>>>>> ------------------------------------------------------------------
>>>>>> ---- For information about J forums see
>>>>>> <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm
>>>>> -------------------------------------------------------------------
>>>>> --- For information about J forums see
>>>>> <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm
>>>> --------------------------------------------------------------------
>>>> -- For information about J forums see
>>>> <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm
>>> ----------------------------------------------------------------------
>>> For information about J forums see  <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm
>> ----------------------------------------------------------------------
>>
>> For information about J forums see  <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm



More information about the Programming mailing list