Method: makeTransitive(PExp, PExp, AVariableExp, ATypeDefinition)

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.pog.obligation;
25:
26: import org.overture.ast.analysis.AnalysisException;
27: import org.overture.ast.definitions.ATypeDefinition;
28: import org.overture.ast.expressions.*;
29: import org.overture.ast.factory.AstExpressionFactory;
30: import org.overture.ast.factory.AstFactory;
31: import org.overture.ast.types.ABooleanBasicType;
32: import org.overture.pog.pub.IPOContextStack;
33: import org.overture.pog.pub.IPogAssistantFactory;
34: import org.overture.pog.pub.POType;
35:
36: import java.util.List;
37: import java.util.Vector;
38:
39: public class StrictOrderRelationObligation extends ProofObligation
40: {
41:         private static final long serialVersionUID = -3771203462569628826L;
42:
43:         public StrictOrderRelationObligation(ATypeDefinition node,
44:                         IPOContextStack question, IPogAssistantFactory af)
45:                         throws AnalysisException
46:         {
47:                 super(node, POType.STRICT_ORDER, question, node.getLocation(), af);
48:
49:                 AVariableExp xExp = getVarExp(getUnique("x"));
50:                 AVariableExp yExp = getVarExp(getUnique("y"));
51:                 AVariableExp zExp = getVarExp(getUnique("z"));
52:
53:                 AForAllExp forallExp1 = makeRelContext(node,xExp);
54:                 forallExp1.setPredicate(makeIrreflexive(xExp,node));
55:
56:                 AForAllExp forallExp2 = makeRelContext(node, xExp, yExp, zExp);
57:                 forallExp2.setPredicate(makeTransitive(xExp,yExp,zExp,node));
58:
59:                 PExp andExp = makeAnd(forallExp1,forallExp2);
60:                 valuetree.setPredicate(andExp);
61:         }
62:
63:         private PExp makeIrreflexive(PExp var, ATypeDefinition node){
64:                 ANotUnaryExp notExp = new ANotUnaryExp();
65:                 notExp.setType(new ABooleanBasicType());
66:                 PExp applyExp = makeLessWithApply(var, var, node);
67:                 notExp.setExp(applyExp);
68:                 return notExp;
69:         }
70:
71:         private PExp makeLessWithApply(PExp l, PExp r, ATypeDefinition node){
72:                 List<PExp> args = new Vector<>();
73:                 args.add(l.clone());
74:                 args.add(r.clone());
75:                 PExp root = AstFactory.newAVariableExp(node.getName().getOrdName(node.getLocation()).clone());
76:                 return AstFactory.newAApplyExp(root,args);
77:         }
78:
79:         private PExp makeTransitive(PExp x, PExp y, AVariableExp z,
80:                         ATypeDefinition node){
81:                 PExp lessXYExp = makeLessWithApply(x,y,node);
82:                 PExp lessYZExp = makeLessWithApply(y,z,node);
83:                 PExp lessXZExp = makeLessWithApply(x,z,node);
84:                 AAndBooleanBinaryExp andExp = AstExpressionFactory.newAAndBooleanBinaryExp(lessXYExp,lessYZExp);
85:                 AImpliesBooleanBinaryExp impExp = AstExpressionFactory.newAImpliesBooleanBinaryExp(andExp,lessXZExp);
86:                 return impExp;
87:         }
88:
89: }