Comparing arraies

Discussion in 'Javascript' started by Archos, Jan 26, 2012.

  1. No, I have not.
    And now look up "function" there, stupid.
    That is a reference (a doubtful one at that), but not a proof for your
    statement. In fact, it happens to confirm what I have said (although
    citations are lacking).

    Troll away.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jan 30, 2012
    #21
    1. Advertisements

  2. An operator is not necessarily a function in the strict mathematical
    sense. It COULD be a function. For example:

    y^2 + 3x = 6

    Is not a function, but a relation. Since this is JavaScript we are
    talking about and not a Logic Language, Functional language, nor a
    Proof assistant, it is generally understood that a "function" really
    means "procedure" with potential side-effects.
     
    Michael Haufe (TNO), Jan 30, 2012
    #22
    1. Advertisements

  3. But every relation can be re-defined as a function from the inputs to
    the set {true, false}. This is what C, etc, do with the == 'relation' :
    it's a function that returns a boolean value.

    Surely most descriptions of procedures say that they are functions with
    no return value (void functions in C terminology).


    John
     
    John G Harris, Jan 31, 2012
    #23
  4. Not every relation is a predicate, but I think I understand what you
    are trying to say.

    This is where Mathematicians and Physicists tend to get sloppy. When
    it comes to the hand-manipulation of symbols, Math is more an
    impressionistic language than a rigorous one. Generally you'll notice
    that the common practice is to treat single element sets and the
    single element of that set as the same thing, where clearly they are
    not and do not share the same operations:

    sqrt 9 != sqrt {9}

    One cannot take the sqrt of a set. sqrt is not defined in the Algebra
    of Sets.

    So while we could step back and just say every function is simply:

    f : Set -> Set

    That lacks an enormous amount of expressiveness.
    But they MIGHT return a value. They could also launch the missiles as
    a side-effect. They may not return the same value twice when called
    twice. They could also throw exceptions, or a number of other things.
    Regardless of whether the word "function" is used as its name or as
    part of the description, they clearly are not the same "function" that
    has been used mathematically or in PLs with better foundations. In
    most PLs the word "function" is more impressionistic than something of
    substance.
     
    Michael Haufe (TNO), Jan 31, 2012
    #24
  5. ***Plonkity plonk***

    I could have said Troll! or Newbie! or Idiot! as Thomas would do, but I
    said silly; it's more polite.

    "We are discussing the syntax of ECMAScript" says otherwise.

    I look up 'function' in Foldoc and find it says what it ought to say.
    What point are you trying to make?

    'Proof'? Who said 'proof'? You must be hoping to get the job of
    propaganda minister. What I said was that here are two sources that
    agree with me.

    Again you'll have to explain. What I see are almost the same words I
    used.

    Silly Thomas.


    John
     
    John G Harris, Jan 31, 2012
    #25
  6. I'll say it in more detail. The main, or only, part of a relation is
    represented by a set of tuples, each with the same number of elements.
    The elements in a tuple are the arguments or operands, whichever you
    prefer to say. If a tuple is in the set then the relation is true for
    those elements, if not then it's false. There is obviously a function
    from tuples to bool that gives the same answer.

    Professional mathematicians are usually rigorous, but they have an
    annoying habit of switching to shorthand notation without saying so. I
    suspect it's because they do it to students and expect them to work it
    out for themselves, and provide the full gruesome working just once,
    yawn, yawn.

    I think this is more often something computer scientists do.

    You should also use the partial function symbol, something like |-> .
    Functions defined for all sets are very dangerous. (They can't be
    represented by sets for a start).

    To put it crudely, a procedure doesn't have a return statement, so it
    can't 'return' a value.

    If you want to describe side effects then you have to say that the
    function is from system state to system state. The input state includes
    places to hold the arguments, and places holding anything else that
    affects the result. The output state includes a place to hold the
    result, if any, and places holding the consequences of side effects,
    including the effects of an exception.

    Defining just the arguments and result is only a part of the complete
    description, but an important part of course.

    As for launching missiles when your sqrt function goes wrong, the output
    state simply has more empty missile silos.


    John
     
    John G Harris, Jan 31, 2012
    #26
  7. In comp.lang.javascript message <>,
    Mon, 30 Jan 2012 19:03:23, Thomas 'PointedEars' Lahn
    Plonking someone and continuing to reply to their article is unusually
    childish, even for you.
     
    Dr J R Stockton, Jan 31, 2012
    #27

  8. A relation can be redefined using multiple functions, and you can
    place those functions into a set. You can then define a function from
    that set to the set of booleans. This does not make the latter
    function the same as the original relation.

    Based on what do you come to this conclusion?
    I suggest glancing at Axiomatic Set Theory then.
    Since procedures can branch, and can branch back to the caller, it is
    possible to "return". There are versions of SQL with "return"
    statements in procedures for example.
    That is one possible method, but neither the 'function' of JavaScript
    or any other language you've mentioned do this. To repeat what has
    been said earlier: it does not matter what word is used in the
    language, 'function' is not a true function in the mathematical sense,
    nor can all of the operators of the language.

    And since the language doesn't represent this in its syntax or
    semantics, such "functions" are still not.
     
    Michael Haufe (TNO), Feb 1, 2012
    #28
  9. I don't know why you think it's so complicated. You have a function
    that, given (2, 3) returns true if 2 < 3, false if not, and the same
    rule for all other pairs of numbers. That's all.

    When you do
    var a = 2 < 3;
    the language is using the functional version of < (with extra rules for
    NaN and other peculiar values).

    It's my impression based on reading books, articles, and papers.

    Which do you prefer : ZF or VNB? What I said is true in both.

    (Hint: Russel's paradox).

    The definition of procedure and function varies from language to
    language. In Pascal they are keywords. A procedure must not have a
    return value, a function must. In C and relatives it's common to use
    procedure for functions that do not return a value (void functions).

    An ECMAScript function cannot be flagged as void, but if it doesn't
    return a value or always returns undefined then we can call it a
    procedure if we wish. But if it causes arguments then we mustn't use the
    word.

    Have a look at ECMA 262 v5.1, section 15.9.5.27 where it defines a Date
    object's setTime method. The method has side effects. The method's
    definition describes the changes to the system state outside the return
    value.

    In what way is this not mathematical?

    It does in C++. It's called 'undefined behaviour'. It's what happens if
    you break a rule that the compiler can't catch. E.g if you break a
    precondition.


    John
     
    John G Harris, Feb 1, 2012
    #29
  10. I have to disagree here. That the outcome of a programmatic function, given
    the same arguments in the same order, is not necessarily the same always,
    and there may be side-effects, is what distinguishes it from a programmatic
    operator.

    With such a programmatic operator, by definition the outcome must be the
    same given the same operand(s) in the same order (or the operator becomes
    ambiguous and useless). It is therefore an non-injective *mathematical*
    function of the operands, from the sets that the operands may belong to, to
    the set of the result type. But it is _not_ a function in the *syntax* of
    any programming language, not even C++, because you *need to* tell the two
    kinds apart to make sense of the syntax, i. e. to parse the program.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Feb 1, 2012
    #30
  11. First off, I need to correct an error:

    "...nor can all of the operators of the language."

    s/can/are

    Second, I'm not certain what you're disagreeing with exactly. Perhaps
    I was ambiguous on something.
     
    Michael Haufe (TNO), Feb 1, 2012
    #31
  12. I am disagreeing with you when you say that (all) operators in a programming
    language ("programmatic operator(s)") are not true functions in the
    mathematical sense (are not "mathematical function(s)"). I think they are,
    because of the reasons I named above.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Feb 1, 2012
    #32
  13. Ah, I see. I am specifically referring to JavaScript though and this
    is what I am trying to say with that sentence:

    let "x" represent a particular operator

    let P(x) represent the claim "x is a function"

    ¬(∀x P(x))

    which is equivalent to:

    ∃x ¬P(x)

    I am not trying to say:

    (∀x ¬P(x))

    I hope that is clearer (and of course I hope Google Groups doesn't
    mangle the quantifiers when I hit submit...).

    But now the burden of proof is on me to prove that there exists an
    operator which is not a function. Luckily for me and my laziness, this
    work has already been done:

    <https://drj11.wordpress.com/2008/07/11/javascript-using-numbers-as-
    table-keys-considered-harmful/>

    So I think x + "" would qualify if x is one of the values mentioned
    in the link.

    (I took a glance at the 5.1 spec and that note is still there.)
     
    Michael Haufe (TNO), Feb 2, 2012
    #33
  14. If you misread what I've written then you are bound to be confused.

    I still can't work out how you turned "inputs" into multiple functions.
    Do you think I'm a fanatical exponent of currying and was describing a
    cascade of curried functions?

    Only when misinterpreting it.

    There must be hundreds of text books that explain that Russell's paradox
    hasn't been a paradox since the 1920's, but that the name persists.

    The better books then go on to prove the theorem that replaces the
    paradox, then prove that no function that is defined for *all* sets can
    be represented, aka modelled, by a set or sets.

    As I said. Such functions are dangerous and only for use by the very
    cautious.

    But not at the point where you started this sub-thread.

    You didn't make it very clear that you were arguing that the definition
    of 'procedure' is arbitrary.

    Referential transparency, if you're using the same definition as in
    Wikipedia, is certainly convenient for automatic theorem provers, but
    doesn't stop you proving things about Date objects.

    Nor does lack of it stop you writing correct code.

    Ah, I see what it's all about. You are a language snob. You think that a
    pure functional language is the only kind that is first class and
    suitable for use by gentlemen.

    You feel that languages used to control petrol pumps and implement sat
    navs are working class and should be sneered at and are only fit for
    common people.

    Cobblers.

    And another thought. How come Turing machines are modelled as a function
    from system state to system state? Does that mean they are not
    mathematical?


    John
     
    John G Harris, Feb 2, 2012
    #34
  15. Your statement is clear now, as Google Groups positive-surprisingly kept the
    Unicode characters intact.
    While the argument on number representation in the referred article might be
    solid, a disturbing (but unfortunately common) amount of inaccuracies,
    misnomers and misconceptions with regard to its environment can be found
    there. This includes, but might not be limited to:

    | […] in JavaScript all tables (associative arrays) are indexed by strings,
    | and nothing else."

    There are _no_ (built-in) "associative arrays" or "tables" in JavaScript
    (the programming language). There are *objects* (as required by ES 5.1,
    section 8.6, and corresponding sections of earlier Editions, of which
    JavaScript is stated by the respective vendor [see below] to be an
    implementation of). [How ECMAScript objects are to be implemented in a
    programming language is _not_ specified.]

    Objects are _not_ "indexed by string". Objects *have properties* with
    String-type names, where with Array instances some property names with
    numeric representation are special (ES 5.1, 15.4). [That particular
    misconception might be a direct result of David Flanagan's listing `['…`]'
    as "Array/index operator" in his "JavaScript: The Definitive Reference"
    (IIRC).]

    | […] when you go a[0] = thing, isn’t that indexing the table `a' with the
    | number 0? Well, yes and no.

    | So with (small) integer keys there are few possible problems.

    `a[0]' is _not_ accessing a "table `a' with the number `0'" or by "integer
    key". It is accessing a *property* of an *object* by the numeric
    representation of its *property name*. Likewise, a["0"] is accessing the
    property with the name "0" (for short: "the '0' property") of the object
    *referred to* by the `a' property of the next matching object in the scope
    chain (and potentially by other properties of other objects).

    | Given the importance of arrays in JavaScript, […]

    | When converting numbers to strings JavaScript requires that the
    | parsimonious printing rule is applied.

    | In principle a JavaScript implementation could make a different choice
    | each time it performed the conversion.

    | It would of course be insanity for an implementation to do that, but it’s
    | still a loophole in the specification, and it should be closed.

    The terms JavaScript and ECMAScript are used interchangeably there. But
    JavaScript (1.1+) is (merely) *an implementation of* ECMAScript, originally
    by (Brendan Eich of) the Netscape Communications Corporation, and later the
    Mozilla Organization (Mozilla.org).

    The article is speaking about "JavaScript implementations". However, there
    are, in a manner of speaking, AFAIK only two production-quality JavaScript
    implementations: SpiderMonkey (with improvements TraceMonkey and
    JägerMonkey), and Rhino [1, 2]. [There is also a test implementation of
    what was then called "JavaScript 2.0", itself an implementation of
    Netscape's (Waldemar Horwat's) proposal for ECMAScript Edition 4, called
    Epimetheus (as in Greek mythology) [2], see also [3].]

    All other implementations that this concerns are *ECMAScript*
    implementations. This is important because "varying between
    implementations" with regard to the ECMAScript Language Specification means,
    of course, "varying between *ECMAScript* implementations".

    I will look into said argument later, but this needed pointing out right
    now.


    PointedEars
    ___________
    [1] <https://developer.mozilla.org/en/JavaScript>
    [2] <https://developer.mozilla.org/en/JavaScript_Language_Resources>
    [3] "Google Tech Talk – Changes to JavaScript, Part 1: EcmaScript 5", with
    Mark Miller, Waldemar Horwat, and Mike Samuel.
    <>
     
    Thomas 'PointedEars' Lahn, Feb 2, 2012
    #35
  16. I meant "JavaScript: The Definitive Guide" as mentioned in the FAQ. The
    relevant section of the Sixth(?) Edition of that book has been reviewed
    here (by mere chance) by Richard Cornford and criticised accordingly, while
    David Flanagan (by rare appearance here) was not convinced in the following
    discussion that this listing could be positively harmful. I might be able
    to find the Message-ID later if anyone is interested.
     
    Thomas 'PointedEars' Lahn, Feb 3, 2012
    #36
  17. That's not a good example. That's just a case of a function being partly
    specified by the manufacturer, who might regard it as a commercial
    secret.

    The example you are looking for is the function that returns the current
    time. It returns different values at different times, so lacks any
    Referential transparency.

    John
     
    John G Harris, Feb 4, 2012
    #37
  18. You can't be serious...
    The example I was looking for is a JavaScript "operator" that is not
    R.T.
     
    Michael Haufe (TNO), Feb 5, 2012
    #38
  19. In comp.lang.javascript message <830F0FF37FB96852AD0
    8924D9443D28E23ED5CD>, Sat, 4 Feb 2012 10:34:56, John G Harris
    I know of a constructor which does that; but is it a function? Of
    course, it can be put into an undoubted function. If one's code is
    quick enough, it can return the same result repeatedly at slightly
    different times.

    Math.random() will almost always return a different result for every
    call, until after 2^n calls, where n is not necessarily as large as
    should be hoped for.

    function AllDiff() { return +new Date() + String(Math.random()) }

    should never repeat itself, unless Math.random is either unexpectedly
    good or bad, or the computer is prodigiously fast.
     
    Dr J R Stockton, Feb 5, 2012
    #39
  20. <snip>

    I was thinking of
    (new Date()).getTime()
    which is a function call, but of a function with an unusual name.

    John
     
    John G Harris, Feb 6, 2012
    #40
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.