KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Five easy pieces #4: Little Six

  • Five easy pieces #4: Little Six

    Posted by SJT on March 29, 2022 at 12:00 am

    Golden age or not, England under Elizabeth I was a very minor European power. Keen to be part of the cultural mainstream, its poets imitated Italian forms such as the sonnet. And a tricky French form Italians called the sestina the little six. Philip Sidney wrote a clever but vapid double sestina what a show-off.

    Not heard of it? Me neither, until I stumbled across Marilyn Hackers arresting Untoward Occurrence at Embassy Poetry Reading.

    Took me a while to see its structure or even that it had one. You will be quicker. Heres the challenge. Given a list of six words, return a template for a sestina.

     

    q)sest string`pleased`read`poetry`death`seasons`subjects

    “pleased” “read” “poetry” “death” “seasons” “subjects” “” “subjects” .. .. “pleased” “” “pleased read” “poetry death” “seasons subjects”

     

    Single expression, please. Usual rules no control words. Hint: iterate with the Scan form of Converge.

     

    SJT replied 2 months, 2 weeks ago 3 Members · 5 Replies
  • 5 Replies
  • rolf

    Member
    June 4, 2022 at 12:00 am

    i think this is what you are after

    q)f:{abs(til[x]div 2)-x#(x-1),0} 
    
    q)f each 2*1+til 5 
    
    1 0 
    3 0 2 1 
    5 0 4 1 3 2 
    7 0 6 1 5 2 4 3 
    9 0 8 1 7 2 6 3 5 4

    i cannot claim authorship

  • SJT

    Member
    March 19, 2024 at 10:55 am

    Nice!

    Interesting that you have used bracket notation for the Do iteration; that is, {x[5 0 4 1 3 2]}[5;i] rather than 5 {x[5 0 4 1 3 2]}i. I dont think it does anything for you here, but it means you could get a unary {x[5 0 4 1 3 2]}[5;] to use in a composition.

    Now

    1. Can you do the shuffle without a lambda?
    2. Try using cut for the envoi
  • SJT

    Member
    March 19, 2024 at 10:55 am

    Very nice! Especially the use of Converge. Your expression makes it clear that the permutation returns to the original order and that the envoi has the order of the original.

    Further thoughts: if you use Do with a left argument of 6, you can then use Apply At @ to apply " "sv'2 cut to the last item. This expression emphasises that the permutation returns the envoi to the original order.

     

    sest1:{1_raze” “,/:@[;6;” “sv’2 cut]6 @[;5 0 4 1 3 2]x}

     

    Getting down to a single reference to the argument introduces the possibility of writing the function as a composition, which eliminates the tiny overhead of a lambda. Here we can use the bracket notation you introduced earlier for Do.

     

    sest2:1_ raze ” “,/: @[;6;” “sv’2 cut] @[;5 0 4 1 3 2][6;] @

     

    Above spaces clarify the structure a composition of five unaries:

    1. 1_
    2. raze
    3. " ",/:
    4. @[;6;" "sv'2 cut]
    5. @[;5 0 4 1 3 2][6;]

    If you’ve read this far, test your understanding!

    When projecting a binary function f onto its first argument (e.g. 6) we can elide the semicolon and write either f[6;] or f[6]. Why can we not do that here why does @[;5 0 4 1 3 2][6] not work?

    Lastly, can 5 0 4 1 3 2 become a function of the stanza length assuming an even number of lines? That would support new forms, such as an octrina (I just made that word up) or a quatrina.

  • cathan

    Member
    March 19, 2024 at 11:01 am

    How about:

    sest:{[i] stanza:raze ,:[;” “]{x[5 0 4 1 3 2]}[5;i]; envoi:” “sv’ (i[0 1]; i[2 3]; i[4 5]); stanza,envoi}

  • cathan

    Member
    March 19, 2024 at 11:01 am

    Hmm, perhaps this is more what you had in mind…

     

    sest:{(raze @[;5 0 4 1 3 2][x],:” “),” “sv’ 2 cut x}

     

    Edit: Whoops, meant to reply to above.

     

Log in to reply.