Wikipedia:Reference desk/Archives/Computing/2022 June 6

= June 6 =

Theory of computation
Write down the regular expression for a language in which each word begins with an 'a' and ends with 'b' ? 5 marks question — Preceding unsigned comment added by 2409:4054:40C:9398:0:0:CE8:A0B0 (talk) 05:52, 6 June 2022 (UTC)


 * - gadfium 06:21, 6 June 2022 (UTC)
 * I doubt we will receive these 5 marks if we obey. Also, my tariff for a Theory-of-computation question starts at 5000 marks. --Lambiam 21:34, 6 June 2022 (UTC)
 * See Regular expression.
 * Here's a handy online regex tester if you need one.
 * Words in a language are made of alphabetic characters. Notice the table at Regular expression, specifically expression on the row "alphabetic characters" under the column ASCII. That expression will match any one alphabetic character.
 * Putting a star * after an expression which matches one character turns it into an expression which matches any number of times, that is, zero or more times. So now you know enough to make a regex which matches words. It won't distinguish between words, it will just match all of them (but not the spaces).
 * [Aa] matches the letter a, upper or lower case, and [Bb] does the same for b.
 * Stick these things together in some order to possibly win yourself 5 marks, unless they want a more complicated answer which includes spaces and punctuation, in which case the syntax will be useful.  Card Zero  (talk) 02:04, 7 June 2022 (UTC)
 * One reason we can't do the OP's homework for them is that we don't know the syntax of the r.e. language they have been taught. --Lambiam 06:36, 7 June 2022 (UTC)
 * In formal language theory, which this question may be about, an alphabet is any non-empty set of symbols, so the reference to the alphabetic character class may be out of place. --Lambiam 06:46, 7 June 2022 (UTC)
 * Additionally, if the answer is meant to be applied to natural language, a 'word' may also be a sequence of letters and digits, too (for example, 'A4' or 'V16'). It may even allow some punctuation (like, say, 'light-year' or 'AK-47'). Then one needs a specific definition what a 'word' is and what can be a word separator. --CiaPan (talk) 15:27, 7 June 2022 (UTC)
 * An excellent way to define what a 'word' is, is by giving an r.e. for it. :) --Lambiam 20:15, 7 June 2022 (UTC)}