Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- KX Community
- :
- Discussion Forums
- :
- kdb+ and q
- :
- explanation of x('[min;+])/: x

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

explanation of x('[min;+])/: x

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2020.09.01 05:40 AM

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2020.09.01 06:48 AM

/: is the each-right operator, you can see the documentation at
https://code.kx.com/q/ref/maps/#each-left-and-each-right

The ' is the compose operator, hence you are composing a function over something.

Finally, we can read the function
x('[min;+])/: x as "find the minimum element of x and add this to all elements in x.

Hope it helps, regards.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2020.09.01 07:08 AM

x {min x+y}/: x

{min x+y}[x;] each x

(min +[x;]@) each x

(math)

r_{i,*} = min_j x_{i,j} + x_{j,*}

(python)

result = []

for r in x:

candidates = []

for i in range(len(r)):

candidates.append([v+r[i] for v in x[i]])

result.append(min(candidates)) # lexographical min

result

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2020.09.01 11:30 AM

I am more interested in understanding the idea behind the original expression, basically '[min;+] part in x('[min;x])/: x, as in why and how it is expanding to "min each x +/: x".

All help appreciated!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2020.09.01 04:27 PM

In this specific case '[min;+] is a function of rank two (matching +), which sums the two inputs and returns the min of the result.

In fact, compositions have a special type in q: https://code.kx.com/q/basics/datatypes/

q)type ('[min;+])

105h

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2020.09.01 07:19 AM

{min each x+/:x}

Could possibly be an implementation of min-plus matrix multiplication? Not sure on that.

Terry

Main Office Contacts

**EMEA**

Tel: +44 (0)28 3025 2242

**AMERICAS**

Tel: +1 (212) 447 6700

**APAC**

Tel: +61 (0)2 9236 5700

Useful Information

Popular Links

Follow Us

KX. All Rights Reserved.

KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.