Is "ox"
equal to "ox"
?
Yes. The first letters are the same, and the tails of each string are the same.
In this case,
x
is 'o' and X
is "x".
y
is 'o' and Y
is "x".
The big letters can stand for a string that is one letter long.
Here are the rules for string equality.
The symbol x
stands for a single character,
as does y
.
The symbol X
stands for a string of characters,
as does Y
.
The symbol +
stands for concatenation.
1. equals( "", "" ) = true 2. equals( "", X ) = false if X is not the empty string 3. equals( X, "" ) = false if X is not the empty string 4. equals( x+X, y+Y ) = false if x != y 5. equals( x+X, y+Y ) = true if x == y and equals( X, Y )
Here is an example:
equals( "rat", "rat" ) = equals( "at", "at") // rule 5 equals( "at", "at" ) = equals( "t", "t") // rule 5 equals( "t", "t" ) = equals( "", "") // rule 5 equals( "", "" ) = true // rule 1
For another example,
equals( "rat", "ra" ) = equals( "at", "a") // rule 5 equals( "at", "a" ) = equals( "t", "") // rule 5 equals( "t", "" ) = false // rule 3
And yet another example,
equals( "rAt", "rat" ) = equals( "At", "at") // rule 5 equals( "At", "at" ) = false // rule 4
In the rules for string equality, which rules are the base cases?