001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2011, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.kernel.se.dto.module;
017
018 import org.qedeq.base.utility.EqualsUtility;
019 import org.qedeq.kernel.se.base.list.Element;
020 import org.qedeq.kernel.se.base.module.Universal;
021
022
023 /**
024 * Usage of rule for universal generalization.
025 *
026 * Rule of universal generalization.
027 * <pre>
028 * A -> B(x)
029 * -------------------
030 * A -> forall x B(x)
031 * </pre>
032 *
033 * @author Michael Meyling
034 */
035 public class UniversalVo implements Universal {
036
037 /** Reference to previously proven formula. */
038 private String reference;
039
040 /** Subject variable that we will quantify about. */
041 private Element subjectVariable;
042
043 /**
044 * Constructs an reason.
045 *
046 * @param reference Reference to a valid formula.
047 * @param subjectVariable Subject variable that we will quantify about.
048 */
049
050 public UniversalVo(final String reference, final Element subjectVariable) {
051 this.reference = reference;
052 this.subjectVariable = subjectVariable;
053 }
054
055 /**
056 * Default constructor.
057 */
058 public UniversalVo() {
059 // nothing to do
060 }
061
062 public Universal getUniversal() {
063 return this;
064 }
065
066 public String getReference() {
067 return reference;
068 }
069
070 /**
071 * Set formula reference.
072 *
073 * @param reference Reference to formula.
074 */
075 public void setReference(final String reference) {
076 this.reference = reference;
077 }
078
079 public String[] getReferences() {
080 if (reference == null || reference.length() == 0) {
081 return new String[] {};
082 } else {
083 return new String[] {reference };
084 }
085 }
086
087 public Element getSubjectVariable() {
088 return subjectVariable;
089 }
090
091 /**
092 * Set quantification subject variable.
093 *
094 * @param subjectVariable Set free subject variable.
095 */
096 public void setSubjectVariable(final Element subjectVariable) {
097 this.subjectVariable = subjectVariable;
098 }
099
100 public String getName() {
101 return "Universal";
102 }
103
104 public boolean equals(final Object obj) {
105 if (!(obj instanceof UniversalVo)) {
106 return false;
107 }
108 final UniversalVo other = (UniversalVo) obj;
109 return EqualsUtility.equals(reference, other.reference)
110 && EqualsUtility.equals(subjectVariable, other.subjectVariable);
111 }
112
113 public int hashCode() {
114 return (reference != null ? reference.hashCode() : 0)
115 ^ (subjectVariable != null ? 2 ^ subjectVariable.hashCode() : 0);
116 }
117
118 public String toString() {
119 StringBuffer result = new StringBuffer();
120 result.append("SubstFree");
121 if (reference != null || subjectVariable != null) {
122 result.append(" (");
123 boolean w = false;
124 if (reference != null) {
125 result.append(reference);
126 w = true;
127 }
128 if (subjectVariable != null) {
129 if (w) {
130 result.append(", ");
131 }
132 result.append(subjectVariable);
133 w = true;
134 }
135 result.append(")");
136 }
137 return result.toString();
138 }
139
140 }
|