Exemplo n.º 1
0
 public Generic scalarProduct(JSCLVector vector) {
   Generic a = JSCLInteger.valueOf(0);
   for (int i = 0; i < n; i++) {
     a = a.add(element[i].multiply(vector.element[i]));
   }
   return a;
 }
 public static Generic compute(Generic generic) {
   try {
     return GenericVariable.content(factorize(generic.integerValue()));
   } catch (NotIntegerException e) {
     Factorization f =
         new Factorization(Polynomial.factory(generic.variables(), Monomial.iteratorOrdering, -1));
     f.computeValue(generic);
     return f.getValue();
   }
 }
Exemplo n.º 3
0
 JSCLVector product(int product[][], JSCLVector vector) {
   JSCLVector v = (JSCLVector) newinstance();
   for (int i = 0; i < n; i++) v.element[i] = JSCLInteger.valueOf(0);
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < n; j++) {
       Generic a = element[i].multiply(vector.element[j]);
       int k = Math.abs(product[i][j]) - 1;
       v.element[k] = v.element[k].add(product[i][j] < 0 ? a.negate() : a);
     }
   }
   return v;
 }
Exemplo n.º 4
0
 JSCLVector differential(int product[][], Variable variable[]) {
   JSCLVector v = (JSCLVector) newinstance();
   for (int i = 0; i < n; i++) v.element[i] = JSCLInteger.valueOf(0);
   int l = Clifford.log2e(n);
   for (int i = 1; i <= l; i++) {
     for (int j = 0; j < n; j++) {
       Generic a = element[j].derivative(variable[i - 1]);
       int k = Math.abs(product[i][j]) - 1;
       v.element[k] = v.element[k].add(product[i][j] < 0 ? a.negate() : a);
     }
   }
   return v;
 }
Exemplo n.º 5
0
  /*
   * 有泛型的情况
   * 使得程序具有更好的可读性和安全性
   */
  private static void test1() throws Exception {
    // 代码更具有可读性.
    Generic<String> bc = new Generic();
    String s = "OK";
    File file = new File("e:/1.txt");
    // 问题:在添加元素时,会检查错误,只可以向数组列表中添加指定类的对象.
    bc.add(s);
    // 由于加入的元素不是String类型,故报错.
    // bc.add(file);//error  The method add(String) in the type Generic<String> is not applicable
    // for the arguments (File)

    /*
     * 不用强制转换
     * 擦除get的返回类型后将返回Object类型.编译器自动插入String的强制类型转换.
     * 也就说,编译器把这个方法调用翻译为两条虚拟机指令:
     * 		1.对原始方法get的调用.
     * 		2.将返回的Object类型强制转换为String类型.
     */
    String s1 = bc.get(0);
  }
 void process(Generic generic[]) {
   boolean flag = true;
   for (int i = 0; i < generic.length; i++) {
     Generic s = generic[i];
     Variable va[] = s.variables();
     if (va.length == 1) {
       Variable t = va[0];
       Polynomial p = Polynomial.factory(t).valueOf(s);
       if (p.degree() > 1) {
         flag = false;
         Polynomial r[] = linearize(p, t);
         for (int j = 0; j < r.length; j++) {
           process(
               Basis.compute(Basis.augment(new Generic[] {r[j].genericValue()}, generic), unknown)
                   .elements());
         }
       }
     } else flag = false;
   }
   if (flag) result.add(generic);
 }
 static Generic factorize(JsclInteger integer) {
   Generic n[] = integer.gcdAndNormalize();
   Generic s = n[1];
   Generic a = JsclInteger.valueOf(1);
   Generic p = JsclInteger.valueOf(2);
   while (s.compareTo(JsclInteger.valueOf(1)) > 0) {
     Generic q[] = s.divideAndRemainder(p);
     if (q[0].compareTo(p) < 0) {
       p = s;
       q = s.divideAndRemainder(p);
     }
     if (q[1].signum() == 0) {
       a = a.multiply(expression(p, true));
       s = q[0];
     } else p = p.add(JsclInteger.valueOf(1));
   }
   return a.multiply(n[0]);
 }
 static Generic terminator(Generic generic, Variable var, boolean tail) {
   Generic x = var.expressionValue();
   Generic a = JsclInteger.valueOf(1);
   Iterator it = IntegerDivisor.create(generic.integerValue());
   while (it.hasNext()) {
     Generic s = (Generic) it.next();
     a = a.multiply(x.subtract(s));
     if (!tail) a = a.multiply(x.add(s));
   }
   return a;
 }
 void computeValue(Generic generic) {
   Debug.println("factorization");
   Polynomial n[] = factory.valueOf(generic).gcdAndNormalize();
   Monomial m = n[1].monomialGcd();
   Polynomial s = n[1].divide(m);
   Generic a = JsclInteger.valueOf(1);
   Divisor d[] = new Divisor[2];
   Monomial p[] = new Monomial[2];
   Monomial q[] = new Monomial[2];
   d[1] = new Divisor(s.head().monomial());
   loop:
   while (d[1].hasNext()) {
     p[1] = (Monomial) d[1].next();
     q[1] = d[1].complementary();
     d[0] = new Divisor(s.tail().monomial());
     while (d[0].hasNext()) {
       p[0] = (Monomial) d[0].next();
       q[0] = d[0].complementary();
       if (p[1].compareTo(p[0]) <= 0) continue loop;
       Debug.println(toString(p) + " * " + toString(q) + " = " + s);
       if (ArrayComparator.comparator.compare(q, p) < 0) {
         a = a.multiply(expression(s.genericValue()));
         break loop;
       } else {
         Debug.increment();
         Polynomial r[] = remainder(s, polynomial(s, p), terminator(s));
         Debug.decrement();
         if (r[0].signum() == 0) {
           a = a.multiply(expression(r[1].genericValue()));
           s = r[2];
           d[1].divide();
           d[0].divide();
           continue loop;
         }
       }
     }
   }
   result = a.multiply(n[0].multiply(m).genericValue());
 }
Exemplo n.º 10
0
 public void test_for_SpitFire() {
   Generic<Payload> q = new Generic<Payload>();
   q.setHeader(new Header());
   q.setPayload(new Payload());
   String text = JSON.toJSONString(q, SerializerFeature.WriteClassName);
   System.out.println(text);
   Generic<Payload> o = (Generic<Payload>) JSON.parseObject(text, q.getClass());
   Assert.assertNotNull(o.getPayload());
 }
  public static String crtLogDir(final String Pathname) throws IOException {
    String directoryName = "Log_" + Generic.CreateDateAsString();
    File theDir = new File(Pathname + "\\" + directoryName);
    String FolderPath = null;

    // if the directory does not exist, create it
    if (!theDir.exists()) {
      System.out.println("creating directory: " + directoryName);
      boolean result = false;

      try {
        theDir.mkdir();
        result = true;
      } catch (SecurityException se) {

      }
      if (result) {
        System.out.println("Log DIR created");
      }
    }
    FolderPath = theDir.getCanonicalPath();
    return FolderPath;
  }
Exemplo n.º 12
0
  /**
   * An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.
   *
   * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. This
   * class and the subclasses of this class are used to declare either <b>opaque</b> <tt>public</tt>
   * instance fields of the opaque type {@link js.Var.Member} or the <b>opaque</b> <tt>public</tt>
   * static fields of other <b>opaque</b> types while their constructors are used to define the
   * fields inside <b>opaque</b> classes. Under either circumstance, the field names must be exactly
   * same as the member names, as the <b>opaque</b> fields of <b>opaque</b> types are resolved by
   * re-compilers directly based on the field names.
   *
   * @author <a href="mailto:[email protected]">J.J.Liu (Jianjun Liu)</a> at <a
   *     href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
   * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created in
   *     the target codes. Re-compilers must exit with error on operations accessing that kind of
   *     class objects. Re-compilers must resolve an <b>opaque</b> instance field declared by this
   *     class in {@link js.Var.Member} or its subclasses to the JavaScript identifier:
   *     <pre>q.m</pre>
   *     where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
   *     resolved from the instance of the enclosing member. Re-compilers must resolve an
   *     <b>opaque</b> static field declared by this class in <b>opaque</b> types other than {@link
   *     js.Var.Member} and its subclasses to the JavaScript identifier:
   *     <pre>m</pre>
   *     where <tt>m</tt> is the identifier of the field name. And re-compilers must report error on
   *     the access to <b>opaque</b> fields declared by this class under any other circumstances.
   */
  public static class Member extends JsGlobal.RangeError.Prototype.Member {
    /**
     * Internally constructs a member based on a qualifying member.
     *
     * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> or
     * <b>internal</b> classes or class members.
     *
     * <p>Note that, this constructor is <b>internal</b> but its declaring class is <b>opaque</b>.
     * This constructor is used to define <b>opaque</b> instance fields declared in the declaring
     * class of this constructor itself or its subclasses. Under this circumstance, the field names
     * must be exactly same as the member names, as the <b>opaque</b> instance fields of the
     * <b>opaque</b> type {@link js.Var.Member} or its subclasses are resolved by re-compilers
     * directly to their names appending to the name resolved from the specified qualifying member
     * with a dot in between.
     *
     * @param q A qualifying member
     * @param mid The ID of the member to construct
     * @since 1.0
     * @javascript Re-compilers must report error on the invocation to an <b>internal</b>
     *     constructor.
     */
    public Member(JsObject.Member q, Mid mid) {
      super(q, mid);
    }
    /**
     * Internally constructs a member without a qualifying member.
     *
     * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> or
     * <b>internal</b> classes or class members.
     *
     * <p>Note that, this constructor is <b>internal</b> but its declaring class is <b>opaque</b>.
     * This constructor is used to define <b>opaque</b> static fields, declared in <b>opaque</b>
     * types other than the declaring class of this constructor itself and its subclasses. Under
     * this circumstance, the field names must be exactly same as the member names, as the
     * <b>opaque</b> static fields of <b>opaque</b> types are generally resolved by re-compilers
     * directly to identifiers of their names.
     *
     * @param mid The ID of the member to construct
     * @since 1.0
     * @javascript Re-compilers must report error on the invocation to an <b>internal</b>
     *     constructor.
     */
    public Member(Mid mid) {
      super(mid);
    }
    /**
     * Evaluates the property, represented by the current member instance, of the argument object.
     *
     * @param o The argument object
     * @return The value of the current member based on the object argument.
     * @since 1.0
     * @javascript Re-compilers must convert the instance invocation of this method into the
     *     JavaScript expression:
     *     <pre>o.m</pre>
     *     where <tt>m</tt> is the identifier name resolved from the current member instance of the
     *     invocation.
     */
    @Override
    public JsRangeError with(ObjectLike o) {
      return new JsRangeError(super.with(o));
    }

    /**
     * An <b>opaque</b> instance field defining a sub-member that is named by the name of this
     * field, qualified by the current member instance of the field, and to access the property of
     * the name on an object.
     *
     * <p>The <tt>constructor</tt> property of an object is a reference to the function that was the
     * constructor for that object.
     *
     * <p>A common use of the <tt>constructor</tt> property is to determine the type of unknown
     * objects. Given an unknown value, you can use the {@link js.Js#typeof(Object)} operation to
     * determine whether it is a primitive value or an object. If it is an object, you can use the
     * <tt>constructor</tt> property to determine what type of object it is.
     *
     * <p>Note, however, that while this technique works for the objects built into core JavaScript,
     * it is not guaranteed to work with host objects such as the <tt>window</tt> object of
     * client-side JavaScript. The default implementation of the <tt>toString()</tt> method provides
     * another way to determine the type of an unknown object.
     *
     * @since 1.0
     * @javascript Re-compilers must resolve the member of this instance field to the identifier of
     *     the field name appending to the identifier resolved from its qualifying member with a dot
     *     in between.
     */
    public final JsFunction.Member<JsRangeError> constructor =
        new JsFunction.Member<JsRangeError>(
            this, Members.constructor, Generic.get(JsRangeError.class));
  }
Exemplo n.º 13
0
/**
 * An <b>opaque</b> class representing JavaScript <tt>RangeError</tt>.
 *
 * <p>An instance of the this class is thrown when a numeric value is not in its legal range. For
 * example, setting the length of an array to a negative number causes a <tt>RangeError</tt> to be
 * thrown.
 *
 * <p>In JS, to throw a value or object as a <tt>RuntimeException</tt>, see {@link
 * js.Js#err(Object)}.
 *
 * @author <a href="mailto:[email protected]">J.J.Liu (Jianjun Liu)</a> at <a
 *     href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
 * @see js.Js#err(Object)
 * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be generated
 *     into the target codes. Re-compilers must exit with error on the operations of accessing that
 *     kind of class objects. The <tt>checkcast</tt> operation to the class literal of this
 *     interface must be ignored and <tt>instanceof</tt> to it always <tt>true</tt>.
 */
public class JsRangeError extends JsGlobal.RangeError.Prototype {
  /**
   * An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.
   *
   * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. This
   * class and the subclasses of this class are used to declare either <b>opaque</b> <tt>public</tt>
   * instance fields of the opaque type {@link js.Var.Member} or the <b>opaque</b> <tt>public</tt>
   * static fields of other <b>opaque</b> types while their constructors are used to define the
   * fields inside <b>opaque</b> classes. Under either circumstance, the field names must be exactly
   * same as the member names, as the <b>opaque</b> fields of <b>opaque</b> types are resolved by
   * re-compilers directly based on the field names.
   *
   * @author <a href="mailto:[email protected]">J.J.Liu (Jianjun Liu)</a> at <a
   *     href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
   * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created in
   *     the target codes. Re-compilers must exit with error on operations accessing that kind of
   *     class objects. Re-compilers must resolve an <b>opaque</b> instance field declared by this
   *     class in {@link js.Var.Member} or its subclasses to the JavaScript identifier:
   *     <pre>q.m</pre>
   *     where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
   *     resolved from the instance of the enclosing member. Re-compilers must resolve an
   *     <b>opaque</b> static field declared by this class in <b>opaque</b> types other than {@link
   *     js.Var.Member} and its subclasses to the JavaScript identifier:
   *     <pre>m</pre>
   *     where <tt>m</tt> is the identifier of the field name. And re-compilers must report error on
   *     the access to <b>opaque</b> fields declared by this class under any other circumstances.
   */
  public static class Member extends JsGlobal.RangeError.Prototype.Member {
    /**
     * Internally constructs a member based on a qualifying member.
     *
     * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> or
     * <b>internal</b> classes or class members.
     *
     * <p>Note that, this constructor is <b>internal</b> but its declaring class is <b>opaque</b>.
     * This constructor is used to define <b>opaque</b> instance fields declared in the declaring
     * class of this constructor itself or its subclasses. Under this circumstance, the field names
     * must be exactly same as the member names, as the <b>opaque</b> instance fields of the
     * <b>opaque</b> type {@link js.Var.Member} or its subclasses are resolved by re-compilers
     * directly to their names appending to the name resolved from the specified qualifying member
     * with a dot in between.
     *
     * @param q A qualifying member
     * @param mid The ID of the member to construct
     * @since 1.0
     * @javascript Re-compilers must report error on the invocation to an <b>internal</b>
     *     constructor.
     */
    public Member(JsObject.Member q, Mid mid) {
      super(q, mid);
    }
    /**
     * Internally constructs a member without a qualifying member.
     *
     * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> or
     * <b>internal</b> classes or class members.
     *
     * <p>Note that, this constructor is <b>internal</b> but its declaring class is <b>opaque</b>.
     * This constructor is used to define <b>opaque</b> static fields, declared in <b>opaque</b>
     * types other than the declaring class of this constructor itself and its subclasses. Under
     * this circumstance, the field names must be exactly same as the member names, as the
     * <b>opaque</b> static fields of <b>opaque</b> types are generally resolved by re-compilers
     * directly to identifiers of their names.
     *
     * @param mid The ID of the member to construct
     * @since 1.0
     * @javascript Re-compilers must report error on the invocation to an <b>internal</b>
     *     constructor.
     */
    public Member(Mid mid) {
      super(mid);
    }
    /**
     * Evaluates the property, represented by the current member instance, of the argument object.
     *
     * @param o The argument object
     * @return The value of the current member based on the object argument.
     * @since 1.0
     * @javascript Re-compilers must convert the instance invocation of this method into the
     *     JavaScript expression:
     *     <pre>o.m</pre>
     *     where <tt>m</tt> is the identifier name resolved from the current member instance of the
     *     invocation.
     */
    @Override
    public JsRangeError with(ObjectLike o) {
      return new JsRangeError(super.with(o));
    }

    /**
     * An <b>opaque</b> instance field defining a sub-member that is named by the name of this
     * field, qualified by the current member instance of the field, and to access the property of
     * the name on an object.
     *
     * <p>The <tt>constructor</tt> property of an object is a reference to the function that was the
     * constructor for that object.
     *
     * <p>A common use of the <tt>constructor</tt> property is to determine the type of unknown
     * objects. Given an unknown value, you can use the {@link js.Js#typeof(Object)} operation to
     * determine whether it is a primitive value or an object. If it is an object, you can use the
     * <tt>constructor</tt> property to determine what type of object it is.
     *
     * <p>Note, however, that while this technique works for the objects built into core JavaScript,
     * it is not guaranteed to work with host objects such as the <tt>window</tt> object of
     * client-side JavaScript. The default implementation of the <tt>toString()</tt> method provides
     * another way to determine the type of an unknown object.
     *
     * @since 1.0
     * @javascript Re-compilers must resolve the member of this instance field to the identifier of
     *     the field name appending to the identifier resolved from its qualifying member with a dot
     *     in between.
     */
    public final JsFunction.Member<JsRangeError> constructor =
        new JsFunction.Member<JsRangeError>(
            this, Members.constructor, Generic.get(JsRangeError.class));
  }

  /**
   * Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it with the
   * wrapping constructor.
   *
   * @param var The argument of an <b>opaque</b> object.
   * @since 1.0
   * @javascript Re-compilers must ignore the construction operation of this constructor, that is,
   *     replacing it with its only argument.
   */
  public JsRangeError(JsObject var) {
    super(var);
  }

  /**
   * An <b>opaque</b> static field defining a member that is named by the field name without a
   * qualifying member and to access the property of the name on an object.
   *
   * <p>The <tt>constructor</tt> property of an object is a reference to the function that was the
   * constructor for that object.
   *
   * <p>A common use of the <tt>constructor</tt> property is to determine the type of unknown
   * objects. Given an unknown value, you can use the {@link js.Js#typeof(Object)} operation to
   * determine whether it is a primitive value or an object. If it is an object, you can use the
   * <tt>constructor</tt> property to determine what type of object it is.
   *
   * <p>Note, however, that while this technique works for the objects built into core JavaScript,
   * it is not guaranteed to work with host objects such as the <tt>window</tt> object of
   * client-side JavaScript. The default implementation of the <tt>toString()</tt> method provides
   * another way to determine the type of an unknown object.
   *
   * @since 1.0
   * @javascript Re-compilers must resolve the member of this static field to the identifier of the
   *     field name.
   */
  public static final JsFunction.Member<JsRangeError> constructor =
      new JsFunction.Member<JsRangeError>(Members.constructor, Generic.get(JsRangeError.class));

  /**
   * Returns the primitive value associated with the current instance, if there is one. This
   * invocation simply returns the instance itself for the current instance is an object and there
   * is no primitive value for it.
   *
   * @return The current object itself.
   * @since 1.0
   * @javascript Re-compilers must convert the instance invocation of this method directly into a
   *     JavaScript invocation on its current object instance without changing the method name, but
   *     expanding variable arguments, if any, into comma-separated values.
   */
  @Override
  public JsRangeError valueOf() {
    return new JsRangeError((JsObject) var().valueOf());
  }
}
Exemplo n.º 14
0
 public Generic divergence(Variable variable[]) {
   Generic a = JSCLInteger.valueOf(0);
   for (int i = 0; i < n; i++) a = a.add(element[i].derivative(variable[i]));
   return a;
 }
Exemplo n.º 15
0
 static IntegerDivisor create(JsclInteger integer) {
   Generic a = Factorization.factorize(integer);
   return new IntegerDivisor(a, a.variables(), Monomial.iteratorOrdering);
 }
Exemplo n.º 16
0
 static Generic expression(Generic generic, boolean integer) {
   if (generic.compareTo(JsclInteger.valueOf(1)) == 0) return generic;
   else return GenericVariable.valueOf(generic, integer).expressionValue();
 }