Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: $a++ allowed by $a-- is not ! why?

by kabel (Chaplain)
on Sep 01, 2003 at 16:35 UTC ( #288160=note: print w/ replies, xml ) Need Help??


in reply to Re: $a++ allowed by $a-- is not ! why?
in thread $a++ allowed by $a-- is not ! why?

sorry, i did not mean that permutation ;) it was just meant to be a visual description of the commutitativity law.

Modern algebra would say that although ++ is one-to-one, it is not onto.
why? it is a mapping from N to N (if i understand you correctly).
-- OTOH (as it is currently defined) is theoretically a permutation over the set of all finite numbers ...
the association is not clear to me. why do you think -- is a permutation? (what is a permutation for you?).

i think we make too much fuss about nothing. perhaps we should continue this by mail?


Comment on Re: Re: $a++ allowed by $a-- is not ! why?
Replies are listed 'Best First'.
Re: $a++ allowed by $a-- is not ! why?
by jonadab (Parson) on Sep 01, 2003 at 18:33 UTC
    Modern algebra would say that although ++ is one-to-one, it is not onto.
    why? it is a mapping from N to N (if i understand you correctly).

    Given a function F from set S to set T, F is said to be one-to-one if F(s) is equal to a unique t in T for all s in S, and F is said to be onto if for all t in T there exists exactly one s in S such that F(s)=t. In our case both S and T are the same set, the set of all finite numbers and alphanumeric strings. (I believe (Inf)++ is also defined, but that can be considered a special case.)

    ++ as it is defined in Perl is one-to-one because each possible number or alphanumeric string has a unique successor, but it is not onto because it is not true that each number or alphanumeric string has a unique predecessor.

    why do you think -- is a permutation?

    Because, its domain and range are the same set (specifically, the set of all finite numbers; again, (Inf)-- is also defined but can be considered a special case, a polymorphism if you will) and it is both one-to-one and onto.

    You can also consider ++ to be a permutation over the set of all finite numbers, if you consider the string magic to be a polymorphism, but ++ is definitely not a permutation over the set of alphanumeric strings, because it is not onto.


    $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
      Your definitions of one-to-one and onto are somewhat incorrect.

      One-to-one (aka injective) means that F(s) = F(s') only happens if s=s'. In other words no more than one value will map to a given target.

      Onto (aka surjective) means that for each t in the target space T there is an s such that F(s)=t.

      The necessity that F(s) not have 2 values (which you gave as a definition of being one-to-one) is required for F to be a function. The requirement of "exactly one" that you stated for onto is wrong.

      Furthermore any function F that is one-to-one has a unique local inverse function G from its image in T back to S such that G(F(s)) is s for all s in S. For G to truly be the inverse of F, you also need F(G(t)) to be t for all t in T, which requires that F be onto.

      Therefore any function which is one-to-one and onto is called invertible (because it has an inverse function).

      And the entire discussion about strings comes down to this. The ++ operation is not onto the set of alphanumeric strings, and therefore does not have an inverse from the set of all strings. Therefore there is no natural way to define a general -- operator for strings, so none has been defined.

      (Exercise for the interested reader - search the archives of p5p for past discussions of the -- operator on strings. I know that it has been discussed extensively there, and am just too lazy to search for it.)

        One-to-one means that F(s) = F(s') only happens if s=s'.

        Onto means that for each t in the target space T there is an s such that F(s)=t.

        The necessity that F(s) not have 2 values is required for F to be a function.

        I knew I should check. (It's been far too long since I dealt with them separately... mostly what matters is whether a given function is a permutation or not.) Anyway, my point that ++ is not onto and therefore not reversible is still valid, even though I mixed up one-to-one pretty badly.


        $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
        (Exercise for the interested reader - search the archives of p5p for past discussions of the -- operator on strings. I know that it has been discussed extensively there, and am just too lazy to search for it.)
        thanks. i think i found the starting point into it. further pointers welcome! :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://288160]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2015-07-29 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls