public boolean runTest(IEnv env) { try { TermSystem general = TermWare.getInstance().getRoot().resolveSystem("general"); Term t = TermWare.getInstance().getTermFactory().createParsedTerm("neq(p(x),p(x))"); Term r = general.reduce(t); if (!(r.isBoolean() && r.getBoolean() == false)) { System.out.println("r1=" + TermHelper.termToString(r)); return false; } t = TermWare.getInstance().getTermFactory().createParsedTerm("neq(p(\"x\"),p(\"x\"))"); r = general.reduce(t); if (r.isBoolean()) { if (r.getBoolean() == false) { return true; } else { return false; } } else { System.out.println("r2=" + TermHelper.termToString(r)); return false; } } catch (TermWareException ex) { ex.printStackTrace(); return false; } }
public static Term static_transform(Term t, TermSystem system, TransformationContext ctx) throws TermWareException { if (t.getArity() != 2) { throw new AssertException("logical_and must have arity 2"); } LogHelper.log(system, LogicalAndTransformer.class, "LogicalAnd, t=", t); Term frs = t.getSubtermAt(0); Term snd = t.getSubtermAt(1); Term retval = t; if (frs.isBoolean() && snd.isBoolean()) { ctx.setChanged(true); retval = system.getInstance().getTermFactory().createBoolean(frs.getBoolean() && snd.getBoolean()); } else if (frs.isBoolean()) { if (frs.getBoolean()) { // true && y -> y ctx.setChanged(true); retval = snd; } else { // false && y -> false ctx.setChanged(true); retval = frs; } } else if (snd.isBoolean()) { if (snd.getBoolean()) { // x && true -> x ctx.setChanged(true); retval = frs; } else { // x && false -> x ctx.setChanged(true); retval = snd; } } LogHelper.log(system, LogicalAndTransformer.class, "return ", retval); return retval; }