Discussion:
[xquery-talk] min max and mix
Ihe Onwuka
2014-02-10 07:14:04 UTC
Permalink
max((<b>8<c>0</c></b>,<a>9</a>)) -> 80

Probably works as designed but it does raise the question of the
utility of min and max in the presence of mixed content (i.e in the
case where you expect 9 because it is > than 8) - or are all bets off
if the content is mixed.

No - it is not an actual use case - I was actually trying to establish
something else but stumbled across this in the process.
Michael Kay
2014-02-10 08:17:13 UTC
Permalink
That's nothing to with max() and min(), but everything to do with mixed content.

The system is designed so that

<number><whole-part>123</whole-part>.<fractional-part>456</fractional-part></number>

has an untyped string value of 123.456

Remember, the M in XML stands for Markup. Markup is an annotation to text that can be removed without changing the meaning.

Michael Kay
Saxonica
Post by Ihe Onwuka
max((<b>8<c>0</c></b>,<a>9</a>)) -> 80
Probably works as designed but it does raise the question of the
utility of min and max in the presence of mixed content (i.e in the
case where you expect 9 because it is > than 8) - or are all bets off
if the content is mixed.
No - it is not an actual use case - I was actually trying to establish
something else but stumbled across this in the process.
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Ihe Onwuka
2014-02-10 08:46:11 UTC
Permalink
Post by Michael Kay
Remember, the M in XML stands for Markup. Markup is an annotation to text that can be removed without changing the meaning.
Cripes. It's not that far fetched that

<b>8<c>2</c><d>3</d><e>3</e></b>

might mean

element b (total 8) consists of sub elements of d , e and f that
contribute 2, 3 and 3 respectively to whoever designed it.
David Lee
2014-02-10 12:05:59 UTC
Permalink
====================================================
Cripes. It's not that far fetched that

<b>8<c>2</c><d>3</d><e>3</e></b>

might mean

element b (total 8) consists of sub elements of d , e and f that contribute 2, 3 and 3 respectively to whoever designed it.
====================================================
Its not far fetched that it also means
8 *c(2) + d(3) + e(4)

Its not far fetched but its not what it *actually* means in XML languages (particularly this comes from the rule of how atomization of XML works).


There is defined default behaviour then then is 'whaterver you want behaviour'. You actually have it both ... you are free
to parse the XML and assign whatever meaning you want.

In general, I submit, one should be careful about presuming what things *might mean* in languages (computer, human, and biological).
It is fun to speculate but one is usually totally wrong.

Now your use case could be *coerced* to mean what you say but it's not the default defined behavior.

It's not farfetched that in C

"a" + "b" + "c" == "abc"

but its not actually true.




_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
Ihe Onwuka
2014-02-10 12:18:37 UTC
Permalink
Post by David Lee
====================================================
Cripes. It's not that far fetched that
<b>8<c>2</c><d>3</d><e>3</e></b>
might mean
element b (total 8) consists of sub elements of d , e and f that contribute 2, 3 and 3 respectively to whoever designed it.
====================================================
Its not far fetched that it also means
8 *c(2) + d(3) + e(4)
Its not far fetched but its not what it *actually* means in XML languages (particularly this comes from the rule of how atomization of XML works).
There is defined default behaviour then then is 'whaterver you want behaviour'. You actually have it both ... you are free
to parse the XML and assign whatever meaning you want.
In general, I submit, one should be careful about presuming what things *might mean* in languages (computer, human, and biological).
It is fun to speculate but one is usually totally wrong.
Now your use case could be *coerced* to mean what you say but it's not the default defined behavior.
It's not farfetched that in C
"a" + "b" + "c" == "abc"
but its not actually true.
Personally I avoid mixed content models wherever possible. So it is
more of an issue for those that don't.

I was just messing about with these functions to see whether they were
robust with respect to stability (that is stability as in a stable
sort).
David Lee
2014-02-10 12:23:10 UTC
Permalink
Personally I avoid mixed content models wherever possible. So it is more of an issue for those that don't.

I was just messing about with these functions to see whether they were robust with respect to stability (that is stability as in a stable sort).
[DAL:] ==============

Even neglecting mixed content ( dont use that for data !)
... functions that expect atomics or lists of atomics generally dont do what you want when you give it *nested* XML.

sum( <a><b>1</b><c>2</c></a> ) == 12

Its nice enough to try to simple content elements but not nested ("complex") elements.

You *do* have to be careful with this. I wouldnt classify it as "stability" but its a rational argument.
Dont be putting stuff in functions that you dont know whats in there ... and expect to get something out that you expect.


----------------------------------------
David A. Lee
***@calldei.com
http://www.xmlsh.org
Ihe Onwuka
2014-02-10 12:36:46 UTC
Permalink
Post by David Lee
Personally I avoid mixed content models wherever possible. So it is more of an issue for those that don't.
I was just messing about with these functions to see whether they were robust with respect to stability (that is stability as in a stable sort).
[DAL:] ==============
Even neglecting mixed content ( dont use that for data !)
... functions that expect atomics or lists of atomics generally dont do what you want when you give it *nested* XML.
sum( <a><b>1</b><c>2</c></a> ) == 12
hmmmm I see.
Post by David Lee
Its nice enough to try to simple content elements but not nested ("complex") elements.
You *do* have to be careful with this. I wouldnt classify it as "stability" but its a rational argument.
Dont be putting stuff in functions that you dont know whats in there ... and expect to get something out that you expect.
The stability thing is not a use case of mine either. Was just
interested to see what min/max would do when confronted with multiple
nodes that evaluated to the same value and to see if I could trace
which one it picked.

There you've dragged the wretched truth out of me.
David Carlisle
2014-02-10 12:45:34 UTC
Permalink
Post by Ihe Onwuka
The stability thing is not a use case of mine either. Was just
interested to see what min/max would do when confronted with
multiple nodes that evaluated to the same value and to see if I could
trace which one it picked.
There you've dragged the wretched truth out of me.
_______________________________________________
This is documented as implementation dependent, so any experiments are
limited in value to that particular implementation version.
Post by Ihe Onwuka
Selects an item from the input sequence $arg whose value is greater
than or equal to the value of every other item in the input sequence.
If there are two or more such items, then the specific item whose
value is returned is ·implementation dependent·.
http://www.w3.org/TR/xpath-functions/#func-max

David
Ihe Onwuka
2014-02-10 12:51:44 UTC
Permalink
Post by David Carlisle
Post by Ihe Onwuka
The stability thing is not a use case of mine either. Was just
interested to see what min/max would do when confronted with
multiple nodes that evaluated to the same value and to see if I could
trace which one it picked.
There you've dragged the wretched truth out of me.
_______________________________________________
This is documented as implementation dependent, so any experiments are
limited in value to that particular implementation version.
Post by Ihe Onwuka
Selects an item from the input sequence $arg whose value is greater
than or equal to the value of every other item in the input sequence.
If there are two or more such items, then the specific item whose
value is returned is ·implementation dependent·.
http://www.w3.org/TR/xpath-functions/#func-max
...and now you have exposed what motivated the experiment.
David Lee
2014-02-10 12:53:35 UTC
Permalink
=======

This is documented as implementation dependent, so any experiments are limited in value to that particular implementation version.
Post by Ihe Onwuka
Selects an item from the input sequence $arg whose value is greater
than or equal to the value of every other item in the input sequence.
If there are two or more such items, then the specific item whose
value is returned is *implementation dependent*.
http://www.w3.org/TR/xpath-functions/#func-max
============
[DAL:]
Even if it were not system dependent there is no defined way to take an atomic value and figure out which node it came from,
so, IMHO, the statement of implementation dependency is only there because its also non-testable ...
even given this ...
max( ( <a>1.0</a> , <b>1.00</b> ) ) => 1

a or b ? good luck.

This is really a fancy way of saying implementations can apply the atomization *before* the comparison and dont have to keep track
of where it all came from.


----------------------------------------
David A. Lee
***@calldei.com
http://www.xmlsh.org
Ihe Onwuka
2014-02-10 12:57:13 UTC
Permalink
Post by David Lee
=======
This is documented as implementation dependent, so any experiments are limited in value to that particular implementation version.
Post by Ihe Onwuka
Selects an item from the input sequence $arg whose value is greater
than or equal to the value of every other item in the input sequence.
If there are two or more such items, then the specific item whose
value is returned is *implementation dependent*.
http://www.w3.org/TR/xpath-functions/#func-max
============
[DAL:]
Even if it were not system dependent there is no defined way to take an atomic value and figure out which node it came from,
so, IMHO, the statement of implementation dependency is only there because its also non-testable ...
even given this ...
max( ( <a>1.0</a> , <b>1.00</b> ) ) => 1
a or b ? good luck.
...again exactly why I was curious... (used to be a tester), your test
case is better than the one I tried.
Michael Kay
2014-02-10 19:04:44 UTC
Permalink
Post by David Lee
Even if it were not system dependent there is no defined way to take an atomic value and figure out which node it came from,
so, IMHO, the statement of implementation dependency is only there because its also non-testable ...
even given this ...
max( ( <a>1.0</a> , <b>1.00</b> ) ) => 1
a or b ? good luck.
min() and max() return an atomized value so you can't tell which node it came from anyway. The implementation-dependency has more to do with mixed floats, doubles, and decimals:

min((1.0, 1.0e0)) = the answer will be equal to one, but it's implementation-dependent whether it's a decimal one or a double one. (IIRC, haven't checked the spec).

Michael Kay
Saxonica

Loading...