Ejemplo n.º 1
0
 /*
  * We use a very hacky way to avoid recomputing proof when the input is not
  * changed. To achieve that, we create a fingerprint of the current input.
  * The fingerprint function should eventually be improved. Here we assume
  * that the input objects are always in the same order (that seems sensible)
  * and the obtained algebraic description changes iff the object does. This
  * may not be the case if rounding/precision is not as presumed.
  */
 private static String fingerprint(GeoElement statement) {
   return Prover.getTextFormat(statement);
 }
Ejemplo n.º 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);
  }