Пример #1
0
  @Override
  public final void compute() {

    String testType;
    if (tail.getTextString().equals("<")) {
      testType = "left";
    } else if (tail.getTextString().equals(">")) {
      testType = "right";
    } else if (StringUtil.isNotEqual(tail.getTextString())) {
      testType = "two";
    } else {
      result.setUndefined();
      return;
    }

    double n1 = n.getDouble();
    double phat1 = proportion.getDouble();
    double n2 = n_2.getDouble();
    double phat2 = proportion2.getDouble();

    double x1 = phat1 * n1;
    double x2 = phat2 * n2;
    double phatTotal = (x1 + x2) / (n1 + n2);
    se = Math.sqrt(phatTotal * (1 - phatTotal) * (1 / n1 + 1 / n2));
    double testStatistic = (phat1 - phat2) / se;

    NormalDistributionImpl normalDist = new NormalDistributionImpl(0, 1);
    double P = 0;
    try {
      P = normalDist.cumulativeProbability(testStatistic);
    } catch (Exception e) {
      result.setUndefined();
      return;
    }

    if ("right".equals(testType)) {
      P = 1 - P;
    } else if ("two".equals(testType)) {
      if (testStatistic < 0) {
        P = 2 * P;
      } else {
        P = 2 * (1 - P);
      }
    }

    // put these results into the output list
    result.clear();
    result.addNumber(P, null);
    result.addNumber(testStatistic, null);
  }
Пример #2
0
  /** Heavy computation of the proof. */
  public final void initialCompute() {

    // Create and initialize the prover
    Prover p = UtilFactory.getPrototype().newProver();
    ProverSettings proverSettings = ProverSettings.get();
    if ("OpenGeoProver".equalsIgnoreCase(proverSettings.proverEngine)) {
      if ("Wu".equalsIgnoreCase(proverSettings.proverMethod))
        p.setProverEngine(ProverEngine.OPENGEOPROVER_WU);
      else if ("Area".equalsIgnoreCase(proverSettings.proverMethod))
        p.setProverEngine(ProverEngine.OPENGEOPROVER_AREA);
    } else if ("Botana".equalsIgnoreCase(proverSettings.proverEngine))
      p.setProverEngine(ProverEngine.BOTANAS_PROVER);
    else if ("Recio".equalsIgnoreCase(proverSettings.proverEngine))
      p.setProverEngine(ProverEngine.RECIOS_PROVER);
    else if ("PureSymbolic".equalsIgnoreCase(proverSettings.proverEngine))
      p.setProverEngine(ProverEngine.PURE_SYMBOLIC_PROVER);
    else if ("Auto".equalsIgnoreCase(proverSettings.proverEngine))
      p.setProverEngine(ProverEngine.AUTO);
    p.setTimeout(proverSettings.proverTimeout);
    p.setConstruction(cons);
    p.setStatement(root);
    // Compute extra NDG's:
    p.setReturnExtraNDGs(true);

    // Adding benchmarking:
    double startTime = cons.getApplication().getMillisecondTime();
    p.compute(); // the computation of the proof
    int elapsedTime = (int) (cons.getApplication().getMillisecondTime() - startTime);
    /*
     * Don't remove this. It is needed for automated testing. (String match
     * is assumed.)
     */
    Log.debug("Benchmarking: " + elapsedTime + " ms");

    ProofResult proofresult = p.getProofResult();
    ExtendedBoolean result = p.getYesNoAnswer();

    Log.debug("STATEMENT IS " + proofresult + " (yes/no: " + result + ")");

    if (proofresult == ProofResult.PROCESSING) {
      list.setUndefined();
      return;
    }

    list.setDefined(true);
    list.clear();

    if (!ExtendedBoolean.UNKNOWN.equals(result)) {
      Boolean unreadable = null;

      if (proofresult == ProofResult.TRUE_NDG_UNREADABLE) {
        unreadable = true;
      }
      if (proofresult == ProofResult.TRUE) {
        unreadable = false;
      }

      GeoBoolean answer = new GeoBoolean(cons);
      answer.setValue(result.boolVal());
      list.add(answer);
      if (result.boolVal()) {
        HashSet<NDGCondition> ndgresult = p.getNDGConditions();
        GeoList ndgConditionsList = new GeoList(cons);
        ndgConditionsList.clear();
        ndgConditionsList.setDrawAsComboBox(true);
        Iterator<NDGCondition> it = ndgresult.iterator();
        TreeSet<GeoText> sortedSet = new TreeSet<GeoText>(GeoText.getComparator());

        // Collecting the set of NDG conditions.
        // The OGP data collector may left some unreadable conditions
        // so we make sure if the condition is readable.
        while (!unreadable && it.hasNext()) {
          GeoText ndgConditionText = new GeoText(cons);
          NDGCondition ndgc = it.next();
          // Do not print unnecessary conditions:
          if (ndgc.getReadability() > 0) {
            ndgc.rewrite(cons);
            String s = null;

            if (relTool) {
              String cond = ndgc.getCondition();
              if ("AreParallel".equals(cond)) {
                // non-parallism in 2D means intersecting
                // FIXME: this is not true for 3D
                s =
                    RelationNumerical.intersectString(
                        ndgc.getGeos()[0], ndgc.getGeos()[1], true, getLoc());
              } else if ("AreCollinear".equals(cond)) {
                s =
                    RelationNumerical.triangleNonDegenerateString(
                        (GeoPoint) ndgc.getGeos()[0],
                        (GeoPoint) ndgc.getGeos()[1],
                        (GeoPoint) ndgc.getGeos()[2],
                        getLoc());
              } else if ("AreEqual".equals(cond)) {
                s =
                    RelationNumerical.equalityString(
                        ndgc.getGeos()[0], ndgc.getGeos()[1], false, getLoc());
              } else if ("ArePerpendicular".equals(cond)) {
                s =
                    RelationNumerical.perpendicularString(
                        (GeoLine) ndgc.getGeos()[0], (GeoLine) ndgc.getGeos()[1], false, getLoc());
              } else if ("AreCongruent".equals(cond)) {
                s =
                    RelationNumerical.congruentSegmentString(
                        ndgc.getGeos()[0], ndgc.getGeos()[1], false, getLoc());
              }
            }
            if (s == null || !relTool) {
              GeoElement[] geos = ndgc.getGeos();
              if (geos == null) { // formula with quantities
                s = ndgc.getCondition();
              } else {
                s = getLoc().getCommand(ndgc.getCondition());
                s += "[";
                for (int i = 0; i < ndgc.getGeos().length; ++i) {
                  if (i > 0) {
                    s += ',';
                  }
                  /*
                   * There can be a case when the underlying
                   * prover sends such objects which cannot be
                   * understood by GeoGebra. In this case we
                   * use the "Objects" word. In this case we
                   * normally return ProveResult.UNKNOWN to
                   * not confuse the student, but for sure, we
                   * still do the check here as well.
                   */
                  GeoElement geo = ndgc.getGeos()[i];
                  if (geo != null) s += ndgc.getGeos()[i].getLabelSimple();
                  else s += "...";
                }
                s += "]";
                if (relTool) {
                  s = getLoc().getPlain("not") + " " + s;
                }
              }
            }

            ndgConditionText.setTextString(s);
            ndgConditionText.setLabelVisible(false);
            ndgConditionText.setEuclidianVisible(false);
            sortedSet.add(ndgConditionText);
          }
          // For alphabetically ordering, we need a sorted set here:
        }
        // Copy the sorted list into the output:
        Iterator<GeoText> it2 = sortedSet.iterator();
        while (it2.hasNext()) {
          ndgConditionsList.add(it2.next());
        }

        if (unreadable) {
          GeoText ndgConditionText = new GeoText(cons);
          String cond = "...";
          ndgConditionText.setTextString(cond);
          ndgConditionText.setLabelVisible(false);
          ndgConditionText.setEuclidianVisible(false);
          sortedSet.add(ndgConditionText);
          ndgConditionsList.add(ndgConditionText);
        }

        // Put this list to the final output (if non-empty):
        if (ndgConditionsList.size() > 0) list.add(ndgConditionsList);
      }
    }

    /*
     * Don't remove this. It is needed for testing the web platform. (String
     * match is assumed.)
     */
    Log.debug("OUTPUT for ProveDetails: " + list);
  }