Kirk Rader  1.0-SNAPSHOT
Public Member Functions | Private Member Functions | Private Attributes | List of all members
us.rader.tt.formula.Identity Class Reference

Identity, i.e. More...

Inheritance diagram for us.rader.tt.formula.Identity:
Inheritance graph

Public Member Functions

 Identity (final Expression factor1, final Expression factor2)
 Initialize factors. More...
 
boolean evaluate (final Map< Expression, Boolean > values)
 see Formula#evaluate More...
 
Set< ExpressiongetNodes ()
 
Set< ExpressiongetTerminalNodes ()
 
void printDigraph (final PrintStream stream, final int indent)
 
Expression replaceVariable (final Variable boundVariable, final Expression factor)
 
void toLaTeX (final PrintStream stream)
 
String toString ()
 
- Public Member Functions inherited from us.rader.tt.formula.Formula
abstract boolean evaluate (Map< Expression, Boolean > values)
 Evaluate this formula according to its truth table assuming the given values for its primitive terms. More...
 
final String toDigraph (final int indent) throws IOException
 
final void toDigraph (final PrintStream stream, final int indent)
 Write this formula's syntax tree as a Graphviz digraph. More...
 
final String toTruthTable (final int indent) throws IOException
 
final void toTruthTable (final PrintStream stream, final int indent) throws IOException
 Print this formula's truth table in LaTeX format to the given output stream. More...
 
- Public Member Functions inherited from us.rader.tt.formula.Expression
final boolean equals (final Object obj)
 Base equality on the string representation of a formula. More...
 
abstract Set< ExpressiongetNodes ()
 
abstract Set< ExpressiongetTerminalNodes ()
 
final int hashCode ()
 Base the hash code on the string representation of a formula. More...
 
abstract Expression replaceVariable (Variable boundVariable, Expression factor)
 Replace boundVariable with factor everywhere in this Expression. More...
 
final String toLaTeX () throws IOException
 
abstract void toLaTeX (PrintStream stream)
 Print the LaTeX representation of this object to the given stream. More...
 

Private Member Functions

Expression replaceFactor (final Variable variable, final Expression oldFactor, final Expression newFactor)
 Return newFactor if oldFactor equals `variable. More...
 

Private Attributes

final Expression factor1
 First Expression. More...
 
final Expression factor2
 Second Expression. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from us.rader.tt.formula.Formula
static Formula parseFormula (final BufferedReader reader) throws IOException
 Parse the next Formula from the given buffered input stream. More...
 
static Formula parseFormula (final InputStream stream) throws IOException
 Parse the next Formula from the given input stream. More...
 
static Formula parseFormula (final String formula) throws IOException
 Parse the the given term. More...
 
- Static Public Member Functions inherited from us.rader.tt.formula.Expression
static Expression parseFactor (final BufferedReader reader) throws IOException
 Parse the next Expression from the given buffered input stream. More...
 
static Expression parseFactor (final InputStream stream) throws IOException
 Parse the next Expression from the given buffered input stream. More...
 
static Expression parseFactor (final String factor) throws IOException
 Parse the next Expression from the given buffered input stream. More...
 
- Protected Member Functions inherited from us.rader.tt.formula.Expression
 Expression ()
 Initialize nodeName. More...
 
- Static Protected Member Functions inherited from us.rader.tt.formula.Expression
static Expression parseVariableBindingOperator (final BufferedReader reader, final Class<? extends VariableBindingOperator > type, final char terminator) throws IOException
 Parse the next VariableBindingOperator or Description from the given buffered input stream. More...
 
static void printIndentation (final PrintStream stream, final int indent)
 Print the specified number of spaces to the given stream. More...
 
static int skipWhitespace (final BufferedReader reader) throws IOException
 Discard white space from the given buffered input stream. More...
 
- Protected Attributes inherited from us.rader.tt.formula.Expression
String nodeName
 Graphviz digraph node name. More...
 
- Static Package Functions inherited from us.rader.tt.formula.Expression
 [static initializer]
 

Detailed Description

Identity, i.e.

factor = factor.

Definition at line 27 of file Identity.java.

Constructor & Destructor Documentation

◆ Identity()

us.rader.tt.formula.Identity.Identity ( final Expression  factor1,
final Expression  factor2 
)

Initialize factors.

Parameters
factor1factor1
factor2factor2

Definition at line 48 of file Identity.java.

References us.rader.tt.formula.Identity.factor1, and us.rader.tt.formula.Identity.factor2.

Referenced by us.rader.tt.formula.Identity.replaceVariable().

48  {
49 
50  this.factor1 = factor1;
51  this.factor2 = factor2;
52 
53  }
final Expression factor1
First Expression.
Definition: Identity.java:32
final Expression factor2
Second Expression.
Definition: Identity.java:37

Member Function Documentation

◆ evaluate()

boolean us.rader.tt.formula.Identity.evaluate ( final Map< Expression, Boolean >  values)

see Formula#evaluate

Definition at line 59 of file Identity.java.

References us.rader.tt.formula.Identity.toString().

59  {
60 
61  final Boolean value = values.get(this);
62 
63  if (value == null) {
64 
65  throw new IllegalArgumentException(String.format("no value specified for %s", toString()));
66 
67  }
68 
69  return value.booleanValue();
70 
71  }

◆ getNodes()

Set<Expression> us.rader.tt.formula.Identity.getNodes ( )
See also
Formula::getNodes

Definition at line 77 of file Identity.java.

References us.rader.tt.formula.Expression.getNodes().

77  {
78 
79  final Set<Expression> nodes = new HashSet<>();
80  nodes.add(this);
81  nodes.addAll(factor1.getNodes());
82  nodes.addAll(factor2.getNodes());
83  return nodes;
84 
85  }
abstract Set< Expression > getNodes()
final Expression factor1
First Expression.
Definition: Identity.java:32
final Expression factor2
Second Expression.
Definition: Identity.java:37

◆ getTerminalNodes()

Set<Expression> us.rader.tt.formula.Identity.getTerminalNodes ( )
See also
Formula::getTerminalNodes

Definition at line 91 of file Identity.java.

91  {
92 
93  final Set<Expression> nodes = new HashSet<>();
94  nodes.add(this);
95  return nodes;
96 
97  }

◆ printDigraph()

void us.rader.tt.formula.Identity.printDigraph ( final PrintStream  stream,
final int  indent 
)
See also
Graphable::printDigraph

Implements us.rader.tt.formula.Graphable.

Definition at line 103 of file Identity.java.

References us.rader.tt.formula.Expression.nodeName, us.rader.tt.formula.Graphable.printDigraph(), and us.rader.tt.formula.Expression.printIndentation().

103  {
104 
105  factor1.printDigraph(stream, indent);
106  factor2.printDigraph(stream, indent);
107  printIndentation(stream, indent);
108  stream.print(nodeName);
109  stream.println(" [ label=\"=\" ]");
110  stream.print(nodeName);
111  stream.print(" -> { ");
112  stream.print(factor1.nodeName);
113  stream.print(' ');
114  stream.print(factor2.nodeName);
115  stream.println(" }");
116 
117  }
void printDigraph(PrintStream stream, int indent)
Print the Graphviz nodes and edges for this object to the given stream.
String nodeName
Graphviz digraph node name.
Definition: Expression.java:90
final Expression factor1
First Expression.
Definition: Identity.java:32
final Expression factor2
Second Expression.
Definition: Identity.java:37
static void printIndentation(final PrintStream stream, final int indent)
Print the specified number of spaces to the given stream.

◆ replaceFactor()

Expression us.rader.tt.formula.Identity.replaceFactor ( final Variable  variable,
final Expression  oldFactor,
final Expression  newFactor 
)
private

Return newFactor if oldFactor equals `variable.

Otherwise, return oldFactor.

Parameters
variableThe bound variable being replaced.
oldFactorThe current Expression being considered for replacement.
newFactorThe new Expression in the replacement.
Returns
oldFactor or newFactor.

Definition at line 169 of file Identity.java.

References us.rader.tt.formula.Expression.equals().

Referenced by us.rader.tt.formula.Identity.replaceVariable().

169  {
170 
171  if (oldFactor instanceof Variable && oldFactor.equals(variable)) {
172 
173  return newFactor;
174 
175  }
176 
177  return oldFactor;
178 
179  }

◆ replaceVariable()

Expression us.rader.tt.formula.Identity.replaceVariable ( final Variable  boundVariable,
final Expression  factor 
)
See also
Expression::replaceVariable

Definition at line 123 of file Identity.java.

References us.rader.tt.formula.Identity.Identity(), and us.rader.tt.formula.Identity.replaceFactor().

123  {
124 
125  return new Identity(replaceFactor(boundVariable, factor1, factor),
126  replaceFactor(boundVariable, factor2, factor));
127 
128  }
Expression replaceFactor(final Variable variable, final Expression oldFactor, final Expression newFactor)
Return newFactor if oldFactor equals `variable.
Definition: Identity.java:169
Identity(final Expression factor1, final Expression factor2)
Initialize factors.
Definition: Identity.java:48
final Expression factor1
First Expression.
Definition: Identity.java:32
final Expression factor2
Second Expression.
Definition: Identity.java:37

◆ toLaTeX()

void us.rader.tt.formula.Identity.toLaTeX ( final PrintStream  stream)
See also
Expression::toLaTeX

Definition at line 134 of file Identity.java.

References us.rader.tt.formula.Expression.toLaTeX().

134  {
135 
136  factor1.toLaTeX(stream);
137  stream.print(" = ");
138  factor2.toLaTeX(stream);
139 
140  }
final Expression factor1
First Expression.
Definition: Identity.java:32
final Expression factor2
Second Expression.
Definition: Identity.java:37

◆ toString()

String us.rader.tt.formula.Identity.toString ( )
See also
Object::toString

Definition at line 146 of file Identity.java.

Referenced by us.rader.tt.formula.Identity.evaluate().

146  {
147 
148  return factor1.toString() + "=" + factor2.toString();
149 
150  }
final Expression factor1
First Expression.
Definition: Identity.java:32
final Expression factor2
Second Expression.
Definition: Identity.java:37

Member Data Documentation

◆ factor1

final Expression us.rader.tt.formula.Identity.factor1
private

First Expression.

Definition at line 32 of file Identity.java.

Referenced by us.rader.tt.formula.Identity.Identity().

◆ factor2

final Expression us.rader.tt.formula.Identity.factor2
private

Second Expression.

Definition at line 37 of file Identity.java.

Referenced by us.rader.tt.formula.Identity.Identity().


The documentation for this class was generated from the following file: