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
- :
- Re: not getting the desired behavior

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

not getting the desired behavior

Options

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

2020.12.17 06:32 AM

for a sample input: x:-1 2 3 4 -1 6 7 8 9 -1

why does this work -> 0 (min+)\x, and this doesn't (min+\)x?

Thanks.

6 REPLIES 6

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

2020.12.17 11:23 PM

@see http://www.catb.org/~esr/faqs/smart-questions.html

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

2020.12.18 06:07 AM

So, the question is:

For sample input, x::-1 2 3 4 -1 6 7 8 9 -1, I am expecting same output for both the following expressions,

1) 0 (min+)\x

output -> -1 2 3 4 -1 6 7 8 9 -1

2) (min+\)x

output -> -1

Why is the output for 2) not the same as 1)? Where is the thought process going wrong?

Thanks,

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

2020.12.24 10:31 AM

the first example uses the 'do' syntax: https://code.kx.com/q/ref/accumulators/#do

so you are running the function (min+) (which is a curiosity to me) zero times. the result is thus the same as the input.

the second example runs (min+\) which is the same as 'min sums' on your input. the result is thus -1

i think the question is, what did you expect to happen and why do you think they should produce the same output?

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

2020.12.24 11:55 AM

It's not 'min sums x' but 'min x'

It appears the interpreter doesn't like the composition & 'sums' is not evaluated

q)(min+\)x

-1

q)min(+\)x

-1

q)(max+\)x

9

q)max(+\)x

37

q)((::)+\)x

-1 2 3 4 -1 6 7 8 9 -1

q)

q)parse"(min+\\)x"

((\;+);min)

`x

q)x:20000000#x

q)\ts (+\)x

83 268435648

q)\ts (min+\)x

17 848

q)\ts min x

18 512

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

2020.12.24 01:02 PM

as your 'parse' reveals, it is actually 'sums min':

q)0N!parse "sums min";

(+\;min)

(+\;min)

and since sums on an atom returns the original atom, the result is 'min':

q)sums min

min

min

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

2020.12.24 01:17 PM

Why I expected the sample output was:

for a diadic function, f, eg, +, "(f\)x" and "0 f\ x" should be result in same output. What I realized is, (min+\) is not same as (min+)\, since it would be evaluated right to left, so (+\), and then joining it with min would result in different kind of composition, as pointed by Jason in parse result.

PS: Still thinking why its translating to sums min? Is it bug?

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.