symbol.priority || insert.arg[0].symbol.rightparen) {
expr=new Expr(symbol, [expr,insert.arg[0]], symbol.priority);
insert.arg[0]=expr;
} else {
expr=new Expr(symbol, [expr,insert.arg[0].arg[0]], symbol.priority);
insert.arg[0].arg[0]=expr;
}
expr=right;
}
return [expr,str];
}
function parse(str) {
var temp = str2expr(str);
if (temp[1].slice(0,5)=="Error") document.write(""+temp[1]+"
");
else if (temp[1].slice(0,5)!="") document.write("
Parse Leftover: "+temp[1]+"
");
//still have to check arities of expressions
return temp[0];
}
function outputList(li) {
for (var i=0; i
");
add(proofattempt,proof[proof.length-1]);
var l=proof.length;
//document.write(space(n)+seq2str(s)+" "+reason+"
");
if (s.left.length==1 && equalTerms(s.left[0],s.right)) return true; //Id
if (s.left.length==0 && s.right.symbol==unit) return true; // 1-right
if (s.right.symbol==topp) return true; // T-right
if (s.right.symbol==under) // \-right
if (isProvable(under.output+"-r",
n, new Seq(concat([s.right.arg[0]],s.left),s.right.arg[1]))) return true;
else {proof = proof.slice(0,l); return false;}
if (s.right.symbol==over) // /-right
if (isProvable(over.output+"-r",
n, new Seq(concat(s.left,[s.right.arg[1]]),s.right.arg[0]))) return true;
else {proof = proof.slice(0,l); return false;}
if (s.right.symbol==meet) // meet-right
if (isProvable(meet.output+"-r1", n+1, new Seq(s.left,s.right.arg[0]))
&& isProvable(meet.output+"-r2", n+1, new Seq(s.left,s.right.arg[1])))
return true;
else {proof = proof.slice(0,l); return false;}
for (var i=0; il",
n, new Seq(concat(s.left.slice(0,i),s.left.slice(i+1)),s.right))) return true;
else {proof = proof.slice(0,l); return false;}
if (s.left[i].symbol==zero) // 0-left
return true;
if (s.left[i].symbol==times) // *-left
if (isProvable(times.output+"-l",
n, new Seq(s.left.slice(0,i).concat(s.left[i].arg,s.left.slice(i+1)), s.right)))
return true;
else {proof = proof.slice(0,l); return false;}
if (s.left[i].symbol==meet) // meet-left
if (isProvable(meet.output+"-l1",
n, new Seq(modify(s.left,i,s.left[i].arg[0]),s.right))) return true;
else {
proof = proof.slice(0,l);
if (isProvable(meet.output+"-l2",
n, new Seq(modify(s.left,i,s.left[i].arg[1]),s.right))) return true;
else proof = proof.slice(0,l); // try other rules before returning false
}
if (s.left[i].symbol==join) // join-left
if (isProvable(join.output+"-l1",
n+1, new Seq(modify(s.left,i,s.left[i].arg[0]),s.right))
&& isProvable(join.output+"-l2",
n+1, new Seq(modify(s.left,i,s.left[i].arg[1]),s.right))) return true;
else {proof = proof.slice(0,l);} // return false;}
if (s.left[i].symbol==under) {// \-left
for (var j=0; j<=i; j=j+1) // sigma=s.left[j..i-1], gamma=s.left[0..j-1]
if (isProvable(under.output+"-l1",
n+1, new Seq(s.left.slice(j,i),s.left[i].arg[0]))
&& isProvable(under.output+"-l2", n+1, new Seq(concat(s.left.slice(0,j),
modify(s.left.slice(i),0,s.left[i].arg[1])),s.right))) return true;
else proof = proof.slice(0,l);
// return false;
}
if (s.left[i].symbol==over) {// /-left
for (var j=i; jl1",
n+1, new Seq(s.left.slice(i+1,j+1),s.left[i].arg[1]))
&& isProvable(over.output+"-l2",
n+1, new Seq(concat(modify(s.left.slice(0,i+1),i,s.left[i].arg[0]),
s.left.slice(j+1)),s.right))) return true;
else proof = proof.slice(0,l);
// return false;
}
}
if (s.right.symbol==join) // join-right
if (isProvable(join.output+"-r1", n, new Seq(s.left,s.right.arg[0])))
return true;
else {
proof = proof.slice(0,l);
if (isProvable(join.output+"-r2", n, new Seq(s.left,s.right.arg[1])))
return true;
else {proof = proof.slice(0,l); return false;}
}
if (s.right.symbol==times) { // *-right
for (var i=0; i<=s.left.length; i=i+1)
if (isProvable(times.output+"-r1", n+1, new Seq(s.left.slice(0,i),s.right.arg[0]))
&& isProvable(times.output+"-r2", n+1, new Seq(s.left.slice(i),s.right.arg[1])))
return true;
else proof = proof.slice(0,l);
return false;
}
proof = proof.slice(0,l);
return false;
}
function showProof(s) {
proof=[];
proofattempt=[];
if (isProvable("",0,s))
document.write(proof.join("")+"true
");
else
document.write(proofattempt.join("")+"false
");
}
function pr2str(s) {
proof=[];
proofattempt=[];
if (isProvable("",0,s))
return proof.join("")+"true
";
else
return proofattempt.join("")+"false
";
}
function b(a1,sym,a2) {
return new Expr(sym,[a1,a2]);
}
function eq2leq(eqn){
return b(eqn.arg[0],leq,eqn.arg[1]);
}
function eq2geq(eqn){
return b(eqn.arg[1],leq,eqn.arg[0]);
}
function leq2seq(le){
return new Seq([le.arg[0]],le.arg[1]);
}
//**************************************
// Part 3. Administering the RL quiz
//generate inequations for quiz
inequations=[];
for (var i=0; i<5; i=i+1)
add(inequations,b(randomTerm(2),leq,randomTerm(2)));
function correct(win, score, st) {
win.document.write("Correct, "+st+", 1 point.");
return score+1;
}
function wrong(win, score, st) {
win.document.write("Wrong, "+st+", -1 point.");
return score-1;
}
function comment(win, st) {
win.document.write(""+st+"");
}
function check(frm) { //analyse the radio buttons and output results
win=open("", "resultWindow", "height=450,width=750,menubar=yes,resizable=yes,scrollbars=yes");
win.document.open();
var score=0;
win.document.write("Quiz Results");
win.document.write(""+
"Results for your personalised Quiz 1
");
for (var i=0; i");
}
win.document.write(""+
"Your Score is "+score+"/"+inequations.length+"
");
if (score<1) comment(win,"Guessing will get you nowhere :-)");
else if (scoreClick the X in the top right '+
'hand corner to close this window');
win.document.write('Here are the Gentzen sequent proofs and proof attempts '+
'for the above inequalities:');
for (var i=0; i"+(i+1)+". "+e2s(inequations[i])+""+
pr2str(leq2seq(inequations[i])));
// showProof(win, leq2seq(inequations[i]));
}
win.document.write("");
win.document.close();
}