Function Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • d0ugg
    New Member
    • Jan 2007
    • 41

    Function Program

    Hello,

    I need to write a Function program that will check if a function is valid or not and also if the function is onto as well.
    Kind of getting started right now, so any ideas will be great.

    Thank you!
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Originally posted by d0ugg
    Hello,

    I need to write a Function program that will check if a function is valid or not and also if the function is onto as well.
    Kind of getting started right now, so any ideas will be great.

    Thank you!
    In what form will the function, which should be checked, be given to the checker function and what type of functions should they be? Should the syntax be checked or the result? Can the functions have side effects and if so, should those be checked too? We'll need some more information, to be able to help you.

    Greetings,
    Nepomuk

    Comment

    • d0ugg
      New Member
      • Jan 2007
      • 41

      #3
      Hi,

      Thanks for the quick answer.

      For example,

      Given the function f, from {1 2 3 4 5}, to itself. Than I have to check if it is a one-to-one function and also if it is a onto function.
      The program will test the following functions:
      f(1) = 4
      f(2) = 3
      f(3) = 1
      f(5) = 2

      Thank you

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        Originally posted by d0ugg
        Hi,

        Thanks for the quick answer.

        For example,

        Given the function f, from {1 2 3 4 5}, to itself. Than I have to check if it is a one-to-one function and also if it is a onto function.
        The program will test the following functions:
        f(1) = 4
        f(2) = 3
        f(3) = 1
        f(5) = 2

        Thank you
        OK, you're talking about a mathematical function f: X -> Y, where X = {1,2,3,4,5} and you want to know, if its injective and/or surjective?

        I guess, it depends. If you only have relatively small sets (X and Y), you could use a for-loop to check every single value, create a set from the results and check, if the elements are equal or whatever you want to know. If however you have a big set (e.g. a set with infinite elements), you'll have to somehow code a method, which will prove or disprove that the given function is one-to-one/onto.

        I guess, these sites will help:
        Proving Functions are One-to-One
        Proving Functions are Onto
        Thank's to Google for those. :-)

        Greetings,
        Nepomuk

        Comment

        • d0ugg
          New Member
          • Jan 2007
          • 41

          #5
          Okay,

          I like the idea of the for loop.

          Thank you,

          Doug

          Comment

          • d0ugg
            New Member
            • Jan 2007
            • 41

            #6
            Hey,

            So I started the code, and I'm getting 2 errors from the compile that I can't figure it out..
            The errors are in those lines
            Code:
            if (testA == 1 || testA == 2 || testA== 3 || testA == 4 || testA == 5)
            		{
            			if(testB == 2 || testB == 3 || testB = 4 || testB == 5)
            			{
            				if(testC == 3 || testC == 4 || testC == 5)
            				{
            					if(testD== 4 || testD ==5)
            					{
            						if(testE ==5)
                                                            {
            	System.out.print("\nThat's really good");
                                                           }
            					}
            				}
            			}				
            		}
            Well I guess I can't do that, the compile says:

            function.java:5 5: operator || cannot be applied to boolean,int
            if(testB == 2 || testB == 3 || testB = 4 || testB == 5)


            Any ideas?

            Thank you,

            Doug

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by d0ugg
              Hey,

              So I started the code, and I'm getting 2 errors from the compile that I can't figure it out..
              The errors are in those lines
              Code:
              if (testA == 1 || testA == 2 || testA== 3 || testA == 4 || testA == 5)
              		{
              			if(testB == 2 || testB == 3 || testB = 4 || testB == 5)
              			{
              				if(testC == 3 || testC == 4 || testC == 5)
              				{
              					if(testD== 4 || testD ==5)
              					{
              						if(testE ==5)
                                                              {
              	System.out.print("\nThat's really good");
                                                             }
              					}
              				}
              			}				
              		}
              Well I guess I can't do that, the compile says:

              function.java:5 5: operator || cannot be applied to boolean,int
              if(testB == 2 || testB == 3 || testB = 4 || testB == 5)


              Any ideas?

              Thank you,

              Doug
              Ever heard of a switch?

              Comment

              • Nepomuk
                Recognized Expert Specialist
                • Aug 2007
                • 3111

                #8
                Originally posted by d0ugg
                Hey,

                So I started the code, and I'm getting 2 errors from the compile that I can't figure it out..
                The errors are in those lines
                Code:
                if (testA == 1 || testA == 2 || testA== 3 || testA == 4 || testA == 5)
                		{
                			if(testB == 2 || testB == 3 || testB = 4 || testB == 5)
                			{
                				if(testC == 3 || testC == 4 || testC == 5)
                				{
                					if(testD== 4 || testD ==5)
                					{
                						if(testE ==5)
                                                                {
                	System.out.print("\nThat's really good");
                                                               }
                					}
                				}
                			}				
                		}
                Well I guess I can't do that, the compile says:

                function.java:5 5: operator || cannot be applied to boolean,int
                if(testB == 2 || testB == 3 || testB = 4 || testB == 5)


                Any ideas?

                Thank you,

                Doug
                You've left out a "=":

                function.java:5 5: operator || cannot be applied to boolean,int
                if(testB == 2 || testB == 3 || testB = 4 || testB == 5)

                But as r035198x said, use switch for that part - it will be much easier.

                Greetings,
                Nepomuk

                Comment

                Working...