Check for truth in a predicate : Java


/**
  * Checks for truth in a predicate.
  * http://www.victorbyte.net/
  * Returns boolean value 
  */
       
    public static boolean forEachPredicate(double [] set_S)
    {
        for(double x:set_S)
            if(!(Math.pow(x,2.0) >= x))   //predicate
                return false;
            return true;
    }

    public static boolean negateForEachPredicate(double [] set_S)
    {
        return !forEachPredicate(set_S);
    }

    public static boolean thereExistsPredicate(double [] set_S)
    {
        for(double x:set_S)
            if (( x + 1 ) > x)   // predicate
                return true;
            return false;
    }

    public static boolean negateThereExistsPredicate(double [] set_S)
    {
        return !thereExistsPredicate(set_S);
    }

    public static boolean uniquePredicate(double [] set_S)
    {
        int unique = 0;

        for(double x:set_S)
            if (( x + 1 ) > x)  //predicate
                unique++;

        return unique == 1;
    }
 
This entry was posted in Code samples and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *