01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.strategy.termProjection;
12:
13: import java.math.BigInteger;
14:
15: import de.uka.ilkd.key.java.Services;
16: import de.uka.ilkd.key.logic.PosInOccurrence;
17: import de.uka.ilkd.key.logic.Term;
18: import de.uka.ilkd.key.logic.TermBuilder;
19: import de.uka.ilkd.key.proof.Goal;
20: import de.uka.ilkd.key.rule.RuleApp;
21: import de.uka.ilkd.key.rule.metaconstruct.arith.Monomial;
22: import de.uka.ilkd.key.rule.metaconstruct.arith.Polynomial;
23:
24: /**
25: * Given a monomial and a polynomial, this projection computes the gcd of all
26: * numerical coefficients. The constant term of the polynomial is ignored. The
27: * result is guaranteed to be non-negative.
28: */
29: public class CoeffGcdProjection implements ProjectionToTerm {
30:
31: private final ProjectionToTerm monomialLeft;
32: private final ProjectionToTerm polynomialRight;
33:
34: private CoeffGcdProjection(ProjectionToTerm monomialLeft,
35: ProjectionToTerm polynomialRight) {
36: this .monomialLeft = monomialLeft;
37: this .polynomialRight = polynomialRight;
38: }
39:
40: public static ProjectionToTerm create(
41: ProjectionToTerm monomialLeft,
42: ProjectionToTerm polynomialRight) {
43: return new CoeffGcdProjection(monomialLeft, polynomialRight);
44: }
45:
46: public Term toTerm(RuleApp app, PosInOccurrence pos, Goal goal) {
47: final Services services = goal.proof().getServices();
48:
49: final Term monoT = monomialLeft.toTerm(app, pos, goal);
50: final Term polyT = polynomialRight.toTerm(app, pos, goal);
51:
52: final Monomial mono = Monomial.create(monoT, services);
53: final Polynomial poly = Polynomial.create(polyT, services);
54:
55: final BigInteger gcd = mono.getCoefficient().gcd(
56: poly.coeffGcd());
57: return TermBuilder.DF.zTerm(services, gcd.abs().toString());
58: }
59: }
|