473,378 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

boyer expression

281 100+
Kindly please someone who knows about this below expression share some info with me..

(x2 = x1 + s) & ( y2 = y1) & (f (x1, y1) > -1) => f(x1, y1) = f(x2, y2)[/i]

What does the relation mean? Are the left expr and right equal?
Thank you in advance..
May 16 '07 #1
11 1383
JosAH
11,448 Expert 8TB
Kindly please someone who knows about this below expression share some info with me..

(x2 = x1 + s) & ( y2 = y1) & (f (x1, y1) > -1) => f(x1, y1) = f(x2, y2)[/i]

What does the relation mean? Are the left expr and right equal?
Thank you in advance..
It's just a conditional relation: A => B reads as "if A is true then B is true".
In your example A is "(x2 = x1+s) & (y2 = y1) & f(x1, y1) > -1)" which
reads as three and clauses: "a and b and c". Similar reasoning applies
the the expression B at the right side of the arrow.

The entire expression depends on the value of 's' and the definition of the
function 'f' of course. Without know those definitions the entire relation is
meaningless.

kind regards,

Jos
May 16 '07 #2
shana07
281 100+
It's just a conditional relation: A => B reads as "if A is true then B is true".
In your example A is "(x2 = x1+s) & (y2 = y1) & f(x1, y1) > -1)" which
reads as three and clauses: "a and b and c". Similar reasoning applies
the the expression B at the right side of the arrow.

The entire expression depends on the value of 's' and the definition of the
function 'f' of course. Without know those definitions the entire relation is
meaningless.

kind regards,

Jos
Thank you very much Jos...first time look at the expr I was really clueless.
When you put 'if A is true then B is true' it's really simple to understand.
So, 'f' here could be any calculation functions such as division (/) or string search algorithm - boyer?

One last expr need to consult you...

(x3 = x1 + x2) & (y1 = y2 = y3) & (f (x,1, y1) = -1) => f(x3, y3) <= f(x2,y2) +len(x1)

From my understanding, the relation shows relation with lenght of string x1.
Any other means .....? Thank you again...
May 16 '07 #3
JosAH
11,448 Expert 8TB
Thank you very much Jos...first time look at the expr I was really clueless.
When you put 'if A is true then B is true' it's really simple to understand.
So, 'f' here could be any calculation functions such as division (/) or string search algorithm - boyer?

One last expr need to consult you...

(x3 = x1 + x2) & (y1 = y2 = y3) & (f (x,1, y1) = -1) => f(x3, y3) <= f(x2,y2) +len(x1)

From my understanding, the relation shows relation with lenght of string x1.
Any other means .....? Thank you again...
What article are you reading? I'm sure that there's some explaining text around
those darn formulas. My guess is that indeed x1, x2, x3 and y1, y2 and y3
are strings, '+' is the string concatenation operator and I think (just a guess) that
'f' is the failure function used in the Boyer Moore string matching algorithm.

kind regards,

Jos
May 16 '07 #4
shana07
281 100+
What article are you reading? I'm sure that there's some explaining text around
those darn formulas. My guess is that indeed x1, x2, x3 and y1, y2 and y3
are strings, '+' is the string concatenation operator and I think (just a guess) that
'f' is the failure function used in the Boyer Moore string matching algorithm.

kind regards,

Jos
Brilliant guess.. Yes, I am reading Boyer Program article. Since you've mentioned about Boyer Moore algorithm..kindly please take a look at this below code ...(it's an open source)
How to get it started...please advise me Jos. Thanks

Expand|Select|Wrap|Line Numbers
  1. public static void main( String[] args)
  2.       {
  3.       if ( DEBUGGING )
  4.          {
  5.          System.out.println(Boyer.indexOf("dogcatwombat","cat"));
  6.          System.out.println("dogcatwombat".indexOf("cat"));
  7.  
  8.          System.out.println(Boyer.indexOf("crtcamccmcarogcatwombat","cat"));
  9.          System.out.println("crtcamccmcarogcatwombat".indexOf("cat"));
  10.  
  11.          System.out.println(Boyer.indexOf("dogcatwombat",""));
  12.          System.out.println("dogcatwombat".indexOf(""));
  13.  
  14.          System.out.println(Boyer.indexOf("",""));
  15.          System.out.println("".indexOf(""));
  16.  
  17.          System.out.println(Boyer.indexOf("","abcde"));
  18.          System.out.println("".indexOf("abcde"));
  19.  
  20.          System.out.println(Boyer.indexOf("dogcatwombat","cow"));
  21.          System.out.println("dogcatwombat".indexOf("cow"));
  22.  
  23.          String s = "create table foo (created_date datetime default sysdate not null)";
  24.          System.out.println(s.indexOf("create", 10));
  25.          System.out.println(Boyer.indexOf(s, "create", 10));
  26.  
  27.          try
  28.             {
  29.  
  30.             // O P E N
  31.             // Any file of sample characters
  32.             File f = new File ("C:/temp/temp.txt");
  33.             int size = (int) f.length();
  34.             FileReader fr;
  35.             fr = new FileReader(f);
  36.  
  37.             // R E A D
  38.             char[] ca = new char[size];
  39.             int charsRead = fr.read(ca);
  40.             s = new String(ca);
  41.  
  42.             long start;
  43.             long stop;
  44.             int result = 0;
  45.  
  46.             start = System.currentTimeMillis();
  47.             for ( int i=0; i<1000; i++ )
  48.                {
  49.                // Need to make different so optimiser will actually do
  50.                // the work repeatedly.
  51.                // search for strings like "efficiency9" that probably won't be there.
  52.                result = Boyer.indexOf(ca,"efficiency"+i%10);
  53.                }
  54.             System.out.println("Boyer.indexOf(char[]): " + result);
  55.             stop = System.currentTimeMillis();
  56.             System.out.println("Elapsed:"
  57.                                + (stop-start));
  58.  
  59.             // benchmark Boyer.indexOf
  60.             start = System.currentTimeMillis();
  61.             for ( int i=0; i<1000; i++ )
  62.                {
  63.                // Need to make different so optimiser will actually do
  64.                // the work repeatedly.
  65.                result = Boyer.indexOf(s,"efficiency"+i%10);
  66.                }
  67.             System.out.println("Boyer.indexOf(String): " + result);
  68.             stop = System.currentTimeMillis();
  69.             System.out.println("Elapsed:"
  70.                                + (stop-start));
  71.  
  72.             // Benchmark String.indexOf
  73.             start = System.currentTimeMillis();
  74.             for ( int i=0; i<1000; i++ )
  75.                {
  76.                result = s.indexOf("efficiency"+i%10);
  77.                }
  78.             System.out.println("String.indexOf: " + result);
  79.             stop = System.currentTimeMillis();
  80.             System.out.println("Elapsed:"
  81.                                + (stop-start));
  82.  
  83.             // C L O S E
  84.             fr.close();
  85.  
  86.             }
  87.          catch ( IOException e )
  88.             {
  89.             return;
  90.             }
  91.  
  92.          } // end if debugging
  93.       } // end main
  94.    } // end class Boyer
May 16 '07 #5
JosAH
11,448 Expert 8TB
Brilliant guess.. Yes, I am reading Boyer Program article. Since you've mentioned about Boyer Moore algorithm..kindly please take a look at this below code ...(it's an open source)
How to get it started...please advise me Jos. Thanks
That is the last part of a Boyer class and it seems to exercise the algorithm a
bit by timing its performance. The entire test suite is not compiled if a boolean
DEBUGGING variable has not been set to true.

Don't try to scrape pieces of code from the internet; better read those articles
first until you understand the theory behind it all. To me it seems that you
also have to read up on the Java language itself too (no insult intended).

kind regards,

Jos
May 16 '07 #6
shana07
281 100+
That is the last part of a Boyer class and it seems to exercise the algorithm a
bit by timing its performance. The entire test suite is not compiled if a boolean
DEBUGGING variable has not been set to true.

Don't try to scrape pieces of code from the internet; better read those articles
first until you understand the theory behind it all. To me it seems that you
also have to read up on the Java language itself too (no insult intended).

kind regards,

Jos
Thank you Jos..Really appreciate your effort to answer my Qs. Never mind..please don't give up to give any comment to me...as a java student I learn new thing everyday and I'm learning a lot about java from this forum...indeed.
May 16 '07 #7
JosAH
11,448 Expert 8TB
The Boyer-Moore algorithm is not a trivial algorithm, nor is the Knuth-Morris-Pratt
algorithm which is a variation on the same theme. Both are clever algorithms for
finding a substring somewhere in a string in O(n) where n is the length of the
string to be scanned. Can't you start with something simpler, easier to comprehend?

kind regards,

Jos
May 16 '07 #8
shana07
281 100+
The Boyer-Moore algorithm is not a trivial algorithm, nor is the Knuth-Morris-Pratt
algorithm which is a variation on the same theme. Both are clever algorithms for
finding a substring somewhere in a string in O(n) where n is the length of the
string to be scanned. Can't you start with something simpler, easier to comprehend?

kind regards,

Jos
Jos, I shall try....
It's just happened that I need to study the Boyer program that is given to us..
May 16 '07 #9
JosAH
11,448 Expert 8TB
Jos, I shall try....
It's just happened that I need to study the Boyer program that is given to us..
Ah, ok, if it's a "given thing" I suppose you do have to study it. Try to understand
that failure function first then. Don't think about coding anything yet. Those
pattern matching algorithms have two phases:

1) construct the failure function given a pattern.
2) match a string for a pattern using that failure function.

A failure function is just an aray containing index values; the length of the array
is as long as the pattern to be found and every entry in that array tells what
part of the pattern has been matched if the current character in the pattern didn't
match against a character in the string.

kind regards,

Jos
May 16 '07 #10
shana07
281 100+
Ah, ok, if it's a "given thing" I suppose you do have to study it. Try to understand
that failure function first then. Don't think about coding anything yet. Those
pattern matching algorithms have two phases:

1) construct the failure function given a pattern.
2) match a string for a pattern using that failure function.

A failure function is just an aray containing index values; the length of the array
is as long as the pattern to be found and every entry in that array tells what
part of the pattern has been matched if the current character in the pattern didn't
match against a character in the string.

kind regards,

Jos
You mean this function?
Expand|Select|Wrap|Line Numbers
  1.   /**
  2.   * Calculate how many chars you can skip
  3.   * to the right if you find a mismatch.
  4.   * It depends on what character is at
  5.   * the end of the word when you find a mismatch.
  6.   * We must match the pattern, char by char, right to left.
  7.   * Only called after degenerate cases,
  8.   * (e.g. null, zero-length and 1-length Pattern) are eliminated.
  9.   */
  10.    private final void analysePattern ()
  11.       {
  12.       if ( pattern.equals(prevPattern) )
  13.          {
  14.          return;
  15.          }
  16.       // get pattern in fast-to-access charArray form
  17.       patternArray = pattern.toCharArray();
  18.       // Calculate how many slots we can skip to the right
  19.       // depending on which char is at the end of the word
  20.       // when we find a match.
  21.       // Recycle old array if possible.
  22.       if ( skip == null ) skip = new int [256];
  23.       for ( int i=0; i<256; i++ )
  24.          {
  25.          skip[i] = lenPat;
  26.          } // end for
  27.  
  28.       for ( int i=0; i<lenPat-1; i++ )
  29.          {
  30.          // The following line is the key to the whole algorithm.
  31.          // It also deals with repeating letters in the pattern.
  32.          // It works conservatively, considering only the last
  33.          // instance of repeating letter.
  34.          // We exclude the last letter of the pattern, because we are
  35.          // only concerned with what to do on a mismatch.
  36.          skip[patternArray[i] & 0xff] = lenPat-i-1;
  37.          } // end for
  38.       prevPattern = pattern;
  39.       } // end analysePattern
May 16 '07 #11
JosAH
11,448 Expert 8TB
You mean this function?
Yup, that function. It sets up the failure function.

kind regards,

Jos
May 16 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
22
by: Tony Johansson | last post by:
Hello Experts! I'm reading i a book about C++ and they mention infix with telling what it is. I hope you out there can do so. Many thanks! //Tony
2
by: Mike Turco | last post by:
I like using the expression builder for a lot of different things but it isn't always available when I want to use it, for example in the code window, or in all of the control properties. I am...
14
by: John Temples | last post by:
Given this code: extern volatile unsigned char v; int main(void) { v; return 0; }
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
4
by: gurdz | last post by:
Hey everyone, I am looking for futher explanation on the boyer - moore algorithm. Can someone please provide me with some links. Thank you. kind regards, Gurdip
28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.