Live data from Hacker News

A regular expression to check for prime numbers (2007)

noulakaz.net

101–102 of 102 posts

Re: A regular expression to check for prime numbers (2007)

#101
post #99
post #96

Earlier quoted context omitted.

When we deal with algorithms involving numbers, we are interested in actual numbers, not in their numeral representation. It would be absurd to compare unary and binary addition relative to the same numeral length. We are ultimately interested in numbers, not numerals. Adding one million to one million is simply much faster for binary addition than for unary addition, even if unary addition has better complexity rela…

> It would be absurd to compare unary and binary addition relative to the same numeral length. Why? The Turing machine has no concept of numeric values, it only knows about the length of whatever the input is. > Adding one million to one million is simply much faster for binary addition than for unary addition, even if unary addition has better complexity relative to its own encoding than binary addition has to its e…

> Why? The Turing machine has no concept of numeric values, it only knows about the length of whatever the input is.

That's irrelevant. We are interested in addition, or multiplication, or whatever, which is an operation between numbers (values), and it can be faster or slower depending on which numerals (encoding) are used.

> But the complexity relative to the numerical value is not even well-defined, since it _depends_ on the choice of the encoding.

Yes it depends on the encoding, no it is of course well-defined. You can measure two different algorithms which use two different encodings, relative to the same thing, the value.

> complexity is _always_ measured relative to the length of the input

That's simply not true. There is even a Wikipedia article about it. Even if it calls it "pseudo".

> But _the numeral is not the input_, its _encoding_ is

A numeral is an encoding of a number.

Re: A regular expression to check for prime numbers (2007)

#102
post #91
post #64

Earlier quoted context omitted.

If you want something with an actual regular expression, have a look at https://codegolf.stackexchange.com/questions/3503/hard-code-... which is a code golf for regular expressions to test divisibility by 7.

Very cool! The top answer has a 12,731 character regular expression that matches base 10 numbers that are divisible by 7. (There is an answer with only 105 characters, but that uses .NET "regular expressions" which have some pretty gnarly extensions and are definitely not regular languages). The regex itself is generated from a relatively simple DFA based on mod 7 arithmetic on digits using a program (JFLAP apparentl…

I'm the guy who wrote the original implementation that the question mentions. I have no clue who 'Charles' who asked the question is, or how he found my toy implementation.
Post reply on HN