// Sun's ecliptic longitude
 protected static double lambda0(double t) {
   double M = 357.528 + 35999.050 * Times.T0(t);
   double lambda = 280.460 + 36000.772 * Times.T0(t);
   return lambda
       + (1.915 - 0.0048 * Times.T0(t)) * Math.sin(Math.toRadians(M))
       + 0.020 * Math.sin(Math.toRadians(2 * M));
 }
 @Override
 public void visit(Times timesExp) {
   System.out.print("(");
   if (timesExp.getLHS() != null) timesExp.getLHS().accept(this);
   System.out.print(" * ");
   if (timesExp.getRHS() != null) timesExp.getRHS().accept(this);
   System.out.print(")");
 }
  public final void testMultiplicationBetweenIntegersSimplification() {
    Times times = new Times();
    times.left = new Number(5);
    times.left.type = IntegerType.instance;
    times.right = new Number(2);
    times.right.type = IntegerType.instance;

    expressionSimplificationTester(times, Number.class, IntegerType.instance, 10, true);
  }
  private static RealMatrix S2(double t) {
    double Omega = 73.6667 + 0.013958 * (Times.MJD(t) + 3242) / 365.25;
    double theta0 =
        Math.atan(
            Math.toRadians(
                Math.cos(Math.toRadians(7.25)) * Math.tan(Math.toRadians(lambda0(t) - Omega))));
    double angle1 = (lambda0(t) - Omega);

    angle1 = angle1 % 360.0;
    theta0 = theta0 % 360.0;

    if (angle1 < 0.0) angle1 += 360.0;
    if (theta0 < 0.0) theta0 += 360.0;
    if (angle1 < 180.0) {
      if (theta0 < 180.0) theta0 += 180.0;
    }
    if (angle1 > 180.0) {
      if (theta0 > 180.0) theta0 -= 180.0;
    }

    RealMatrix A = RotationMatrix(theta0, new Vector3D(0, 0, 1));
    RealMatrix B = RotationMatrix(7.25, new Vector3D(1, 0, 0));
    RealMatrix C = RotationMatrix(Omega, new Vector3D(0, 0, 1));
    RealMatrix S2 = A.preMultiply(B).preMultiply(C);
    return S2;
  }
 /*Transformation matrices*/
 private static RealMatrix P(double t) {
   double t0 = Times.T0(t);
   double zA = 0.64062 * t0 + 0.00030 * Math.pow(t0, 2);
   double thetaA = 0.55675 * t0 + 0.00012 * Math.pow(t0, 2);
   double zetaA = 0.64062 * t0 + 0.00008 * Math.pow(t0, 2);
   RealMatrix A = RotationMatrix(zA, new Vector3D(0, 0, 1));
   RealMatrix B = RotationMatrix(thetaA, new Vector3D(0, 1, 0));
   RealMatrix C = RotationMatrix(zetaA, new Vector3D(0, 0, 1));
   return A.preMultiply(B).preMultiply(C);
 }
  private void multiplyWithOne(boolean oneOnLeft) {
    Times t = new Times();
    t.type = IntegerType.instance;
    IdExpression id = new IdExpression("mult");
    id.type = IntegerType.instance;
    if (oneOnLeft) {
      t.left = new Number(1);
      t.right = id;
    } else {
      t.right = new Number(1);
      t.left = id;
    }

    IdExpression idExp =
        (IdExpression)
            expressionSimplificationTester(t, IdExpression.class, IntegerType.instance, 0, false);

    assertEquals(idExp.id, id.id);
  }
 private void multiplyToGetZero(boolean zeroOnLeft) {
   Times t = new Times();
   t.type = IntegerType.instance;
   Number n = (Number) operationWithZero(t, Number.class, zeroOnLeft, false);
   assertEquals(n.id, 0);
 }
 public final void testSideEffectZeroTimesExp() {
   Times t = new Times();
   t.type = IntegerType.instance;
   operationWithZero(t, Times.class, true, true);
 }
  public static void main(final String[] args) {
    String CLASSPATH = null;
    String outputDirName = null;
    String lookIn = null;

    // Parse the command line
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-trace")) {
        BloatBenchmark.TRACE = true;
        PersistentBloatContext.DB_COMMIT = true;

      } else if (args[i].equals("-calleeSize")) {
        if (++i >= args.length) {
          BloatBenchmark.err.println("** No callee size specified");
          BloatBenchmark.usage();
        }

        try {
          BloatBenchmark.CALLEE_SIZE = Integer.parseInt(args[i]);

        } catch (final NumberFormatException ex33) {
          BloatBenchmark.err.println("** Bad number: " + args[i]);
          BloatBenchmark.usage();
        }

      } else if (args[i].startsWith("-classpath")) {
        if (++i >= args.length) {
          BloatBenchmark.err.println("** No classpath specified");
          BloatBenchmark.usage();
        }

        // If there is more than one -classpath append it to the
        // current one. That way the CLASSPATH reflects the order in
        // which the options came on the command line.
        if (CLASSPATH == null) {
          CLASSPATH = args[i];

        } else {
          CLASSPATH += File.pathSeparator + args[i];
        }

      } else if (args[i].equals("-no-stack-alloc")) {
        Main.STACK_ALLOC = false;

      } else if (args[i].equals("-peel-loops")) {
        if (++i >= args.length) {
          BloatBenchmark.usage();
        }

        final String n = args[i];

        if (n.equals("all")) {
          FlowGraph.PEEL_LOOPS_LEVEL = FlowGraph.PEEL_ALL_LOOPS;

        } else {
          try {
            FlowGraph.PEEL_LOOPS_LEVEL = Integer.parseInt(n);

            if (FlowGraph.PEEL_LOOPS_LEVEL < 0) {
              BloatBenchmark.usage();
            }
          } catch (final NumberFormatException ex) {
            BloatBenchmark.usage();
          }
        }
      } else if (args[i].equals("-no-color")) {
        Liveness.UNIQUE = true;

      } else if (args[i].equals("-no-dce")) {
        Main.DCE = false;

      } else if (args[i].equals("-no-prop")) {
        Main.PROP = false;

      } else if (args[i].equals("-no-pre")) {
        Main.PRE = false;

      } else if (args[i].equals("-no-check")) {
        BloatBenchmark.CHECK = false;

      } else if (args[i].equals("-depth")) {
        if (++i >= args.length) {
          BloatBenchmark.err.println("** No depth specified");
          BloatBenchmark.usage();
        }

        try {
          BloatBenchmark.DEPTH = Integer.parseInt(args[i]);

        } catch (final NumberFormatException ex33) {
          BloatBenchmark.err.println("** Bad number: " + args[i]);
          BloatBenchmark.usage();
        }

      } else if (args[i].equals("-inline")) {
        // Inline calls to static methods
        BloatBenchmark.INLINE = true;

      } else if (args[i].equals("-intra")) {
        BloatBenchmark.INTRA = true;

      } else if (args[i].equals("-lookIn")) {
        if (++i >= args.length) {
          BloatBenchmark.err.println("** No directory specified");
          BloatBenchmark.usage();
        }

        if (lookIn != null) {
          lookIn += File.pathSeparator + args[i];

        } else {
          lookIn = args[i];
        }

      } else if (args[i].equals("-morph")) {
        if (++i >= args.length) {
          BloatBenchmark.err.println("** No morphosity specified");
          BloatBenchmark.usage();
        }

        try {
          BloatBenchmark.MORPH = Integer.parseInt(args[i]);

        } catch (final NumberFormatException ex33) {
          BloatBenchmark.err.println("** Bad number: " + args[i]);
          BloatBenchmark.usage();
        }

      } else if (args[i].equals("-noinline")) {
        // Don't perform inlining, just specialize
        BloatBenchmark.INLINE = false;

      } else if (args[i].equals("-peephole")) {
        // Perform peephole optimizations when doing interprocedural
        // stuff
        BloatBenchmark.PEEPHOLE = true;

      } else if (args[i].equals("-size")) {
        if (++i >= args.length) {
          BloatBenchmark.err.println("** No size specified");
          BloatBenchmark.usage();
        }

        try {
          BloatBenchmark.SIZE = Integer.parseInt(args[i]);

        } catch (final NumberFormatException ex33) {
          BloatBenchmark.err.println("** Bad number: " + args[i]);
          BloatBenchmark.usage();
        }

      } else if (args[i].equals("-specialize")) {
        // Specialize virtual method call sites
        BloatBenchmark.SPECIALIZE = true;

      } else if (args[i].equals("-stats")) {
        if (++i >= args.length) {
          BloatBenchmark.err.println("** No stats file specified");
          BloatBenchmark.usage();
        }

        BloatBenchmark.statsFile = args[i];

      } else if (args[i].equals("-sun")) {
        // Optimize sun packages
        BloatBenchmark.SUN = true;

      } else if (args[i].equals("-times")) {
        BloatBenchmark.TIMES = true;

        if (++i >= args.length) {
          BloatBenchmark.err.println("** No times file specified");
          BloatBenchmark.usage();
        }

        BloatBenchmark.timesFile = args[i];

      } else if (args[i].equals("-no-verify")) {
        BloatBenchmark.VERIFY = false;

      } else if (args[i].equals("-no-opt-stack")) {
        CodeGenerator.OPT_STACK = false;

      } else if (args[i].equals("-no-stack-vars")) {
        Tree.USE_STACK = false;

      } else if (args[i].equals("-skip")) {
        if (++i >= args.length) {
          BloatBenchmark.usage();
        }

        String pkg = args[i];

        // Account for class file name on command line
        if (pkg.endsWith(".class")) {
          pkg = pkg.substring(0, pkg.lastIndexOf('.'));
        }

        BloatBenchmark.SKIP.add(pkg.replace('.', '/'));

      } else if (args[i].equals("-1.1")) {
        // There are some classes that we don't want to be pre-live.
        // They don't exist in JDK1.1.
        BloatBenchmark.USE1_1 = true;
        CallGraph.USE1_2 = false;

      } else if (args[i].equals("-1.2")) {
        CallGraph.USE1_2 = true;

        if (lookIn != null) {
          lookIn += File.separator + "1.2";
        }

      } else if (args[i].startsWith("-")) {
        BloatBenchmark.err.println("** Unrecognized option: " + args[i]);
        BloatBenchmark.usage();

      } else if (i == args.length - 1) {
        outputDirName = args[i];

      } else {
        BloatBenchmark.CLASSES.add(args[i]);
      }
    }

    if (BloatBenchmark.CLASSES.isEmpty()) {
      BloatBenchmark.err.println("** No classes specified");
      BloatBenchmark.usage();
    }

    if (outputDirName == null) {
      BloatBenchmark.err.println("** No output directory specified");
      BloatBenchmark.usage();
    }

    // Make sure the options the user entered make sense
    if (BloatBenchmark.CHECK) {
      BloatBenchmark.checkOptions();
    }

    if (BloatBenchmark.USE1_1) {
      // Don't generate stats for 1.1
      BloatBenchmark.statsFile = null;
    }

    if (lookIn != null) {
      CLASSPATH = lookIn + File.pathSeparator + CLASSPATH;
    }

    final StringBuffer sb = new StringBuffer();
    for (int i = 0; i < args.length; i++) {
      sb.append(args[i] + " ");
    }
    BloatBenchmark.tr("BLOATing with command line: " + sb);

    BloatContext context = null;

    float systemStart = 0.0F;
    float systemDelta = 0.0F;
    float systemEnd = 0.0F;
    float systemTotal = 0.0F;

    float userStart = 0.0F;
    float userDelta = 0.0F;
    float userEnd = 0.0F;
    float userTotal = 0.0F;

    PrintWriter times = null;

    if (BloatBenchmark.TIMES) {
      try {
        times = new PrintWriter(new FileWriter(BloatBenchmark.timesFile), true);

      } catch (final IOException ex) {
        times = new PrintWriter(System.out, true);
      }
    }

    if (BloatBenchmark.INTRA) {
      BloatBenchmark.tr("Intraprocedural BLOAT");

      // First compute the roots of the call graph. Figure out which
      // methods are live.
      context = BloatBenchmark.makeContext(CLASSPATH, null);
      final Collection liveMethods = BloatBenchmark.liveMethods(BloatBenchmark.CLASSES, context);

      // Run intraprocedural BLOAT on the live methods.
      BloatBenchmark.tr(liveMethods.size() + " live methods");
      context = BloatBenchmark.makeContext(CLASSPATH, outputDirName);
      BloatBenchmark.intraBloat(liveMethods, context);

    } else {
      BloatBenchmark.tr("Interprocedural BLOAT");

      if (BloatBenchmark.TIMES) {
        Times.snapshot();
        systemStart = Times.systemTime();
        userStart = Times.userTime();
      }

      // Do the interprocedural BLOATing
      context = BloatBenchmark.makeContext(CLASSPATH, outputDirName);
      BloatBenchmark.liveMethods(BloatBenchmark.CLASSES, context);

      if (BloatBenchmark.TIMES) {
        // Take a measurement
        Times.snapshot();

        systemEnd = Times.systemTime();
        userEnd = Times.userTime();

        systemDelta = systemEnd - systemStart;
        userDelta = userEnd - userStart;

        systemStart = systemEnd;
        userStart = userEnd;

        systemTotal += systemDelta;
        userTotal += userDelta;

        times.println("Call graph construction");
        times.println("  User: "******"  System: " + systemDelta);
      }

      if (BloatBenchmark.SPECIALIZE) {
        BloatBenchmark.specialize(context);
      }

      if (BloatBenchmark.TIMES) {
        // Take a measurement
        Times.snapshot();

        systemEnd = Times.systemTime();
        userEnd = Times.userTime();

        systemDelta = systemEnd - systemStart;
        userDelta = userEnd - userStart;

        systemStart = systemEnd;
        userStart = userEnd;

        systemTotal += systemDelta;
        userTotal += userDelta;

        times.println("Call site specialization");
        times.println("  User: "******"  System: " + systemDelta);
      }

      if (BloatBenchmark.INLINE) {
        BloatBenchmark.inline(context);
      }

      if (BloatBenchmark.TIMES) {
        // Take a measurement
        Times.snapshot();

        systemEnd = Times.systemTime();
        userEnd = Times.userTime();

        systemDelta = systemEnd - systemStart;
        userDelta = userEnd - userStart;

        systemStart = systemEnd;
        userStart = userEnd;

        systemTotal += systemDelta;
        userTotal += userDelta;

        times.println("Method inlining");
        times.println("  User: "******"  System: " + systemDelta);
      }

      if (BloatBenchmark.PEEPHOLE) {
        BloatBenchmark.peephole(context);
      }
    }

    // Commit dirty data
    BloatBenchmark.tr("Committing dirty methods");
    context.commitDirty();

    if (BloatBenchmark.TIMES) {
      // Take a measurement
      Times.snapshot();

      systemEnd = Times.systemTime();
      userEnd = Times.userTime();

      systemDelta = systemEnd - systemStart;
      userDelta = userEnd - userStart;

      systemStart = systemEnd;
      userStart = userEnd;

      systemTotal += systemDelta;
      userTotal += userDelta;

      times.println("Committal");
      times.println("  User: "******"  System: " + systemDelta);
    }

    if (BloatBenchmark.TIMES) {
      times.println("Total");
      times.println("  User: "******"  System: " + systemTotal);
    }

    if (BloatBenchmark.statsFile != null) {
      final InlineStats stats = context.getInlineStats();
      PrintWriter statsOut = null;
      try {
        statsOut = new PrintWriter(new FileWriter(BloatBenchmark.statsFile), true);

      } catch (final IOException ex) {
        statsOut = new PrintWriter(System.out, true);
      }

      stats.printSummary(statsOut);
    }

    BloatBenchmark.tr("Finished");
  }
 // obliquity of the ecliptic
 protected static double epsilon(double t) {
   return 23.439 - 0.013 * Times.T0(t);
 }
 private static RealMatrix T1(double t) {
   double theta = 100.461 + 36000.770 * Times.T0(t) + 360.0 * (Times.H(t) / 24.0);
   RealMatrix T1 = RotationMatrix(theta, new Vector3D(0, 0, 1));
   return T1;
 }