Package tools

Class MiscTools

Object
MiscTools

public class MiscTools
extends Object
The MiscTools class contains miscellaneous methods.
  • Method Details

    • factorial

      public static long factorial​(int n)
      Returns n factorial (n!)
      Parameters:
      n - the number
      Returns:
      n!
    • gcd

      public static int gcd​(int a, int b)
      Computes the GCD of the inputs. It is preferred to input a > b, but this is not explicitly necessary.
      Parameters:
      a - the first input
      b - the second input
      Returns:
      the GCD of the inputs
    • findClassValue

      public static int findClassValue​(GeneralFunction function)
      Returns the location of a GeneralFunction in its class-based sort order (see GeneralFunction.sortOrder)
      Parameters:
      function - the function whose location in the class order is to be found
      Returns:
      location in GeneralFunction.sortOrder
    • stripConstantsOfSum

      public static List<Pair<Double,​GeneralFunction>> stripConstantsOfSum​(Sum sum)
      Returns a list of the elements in this Sum with the constants stripped as a pair. Ex: x^2+2sin(x) becomes [<1.0, x^2>, <2.0, sin(x)>]
      Parameters:
      sum - the sum whose constants should be stripped
      Returns:
      the list of pairs as specified above
    • toFirstNonTrivial

      public static GeneralFunction toFirstNonTrivial​(GeneralFunction function)
      Executes CommutativeFunction.simplifyTrivialElement() until the function is not a CommutativeFunction or has a argument count greater than one. Ex: (((2*x))) becomes 2*x
      Parameters:
      function - the function to be simplified
      Returns:
      the function with all layers removed
    • printWithSleep

      public static void printWithSleep​(String message)
      Prints a message, sleeping for Settings.defaultSleep between newlines, but not at the end
      Parameters:
      message - the message to print
    • printWithSleep

      public static void printWithSleep​(String message, double time)
      Prints a message, sleeping for time seconds between newlines, but not at the end
      Parameters:
      message - the message to print
      time - amount of seconds to sleep
    • printWithSleep

      public static void printWithSleep​(String message, boolean sleepAtEnd)
      Prints a message, sleeping for Settings.defaultSleep between newlines, then sleeps that same amount at the end if sleepAtEnd is true.
      Parameters:
      message - the message to print
      sleepAtEnd - denotes whether the message should end with a sleep()
    • sleep

      public static void sleep()
      Sleeps for Settings.defaultSleep seconds
    • sleep

      public static void sleep​(double seconds)
      Sleeps for seconds seconds
      Parameters:
      seconds - the amount of seconds to sleep for
    • minimalSimplify

      public static GeneralFunction minimalSimplify​(GeneralFunction function)
      Simplifies the input without executing any of the optional simplifications steps enabled and disabled in Settings
      Parameters:
      function - the function to be minimally simplified
      Returns:
      the minimally simplified version of the function