Proposal : List of regular expressions for numeric syntax on different HP calculators
06-07-2019, 05:25 PM
Post: #1
 Jonathan Busby Member Posts: 81 Joined: Nov 2014
Proposal : List of regular expressions for numeric syntax on different HP calculators
I'm interested in the syntax of what the user can enter as a number in various HP calculators. For the HP48 series, I think the regular expression is :

((([+-]?[0-9]+(\.)?[0-9]*)|([+-]?[0-9]*(\.)?[0-9]+))([eE](([+-]?[0-9]+(\.)?[0-9]*)|([+-]?[0-9]*(\.)?[0-9]+)))?)

which is quite convoluted. Here's a short Perl script that presents it in a more understandable way :

Code:
#!/usr/bin/perl $a = "([+-]?[0-9]+(\\.)?[0-9]*)";$b = "([+-]?[0-9]*(\\.)?[0-9]+)"; $c = "($a|$b)";$d = "($c([eE]$c)?)"; while(<STDIN>) {     /$d/; print$1; }

I'm interested in how the regular expressions used to match the user entered number formats differ in different HP Calculators. Perhaps we could compile a list of the different regular expressions

Regards,

Jonathan
06-07-2019, 05:44 PM
Post: #2
 Jonathan Busby Member Posts: 81 Joined: Nov 2014
RE: Proposal : List of regular expressions for numeric syntax on different HP calculators
I fear though, that because most of the numeric representations are very general, there will only be minor variations. So, maybe not a very interesting proposal after all :/

Regards,

Jonathan
06-07-2019, 06:26 PM
Post: #3
 Jonathan Busby Member Posts: 81 Joined: Nov 2014
Proposal : List of regular expressions for numeric syntax on different HP calculators
(06-07-2019 05:25 PM)Jonathan Busby Wrote:  For the HP48 series, I think the regular expression is :

((([+-]?[0-9]+(\.)?[0-9]*)|([+-]?[0-9]*(\.)?[0-9]+))([eE](([+-]?[0-9]+(\.)?[0-9]*)|([+-]?[0-9]*(\.)?[0-9]+)))?)

I think the above might be incorrect because it allows a trailing decimal separator ( eg. 9.e9 ), but that can be fixed. Also, the decimal separator is just "." as including "," would be redundant for the purposes of explaining the regular expression.

Regards,

Jonathan
06-07-2019, 06:55 PM
Post: #4
 Albert Chan Senior Member Posts: 635 Joined: Jul 2018
RE: Proposal : regular expressions for numeric syntax on different HP calculators
(06-07-2019 05:25 PM)Jonathan Busby Wrote:  For the HP48 series, I think the regular expression is :

((([+-]?[0-9]+(\.)?[0-9]*)|([+-]?[0-9]*(\.)?[0-9]+))([eE](([+-]?[0-9]+(\.)?[0-9]*)|([+-]?[0-9]*(\.)?[0-9]+)))?)

Hi, Jonathan:

I only have a HP-12C, but I don't think decimal points allowed on the exponent field.
06-07-2019, 07:24 PM
Post: #5
 Jonathan Busby Member Posts: 81 Joined: Nov 2014
Proposal : List of regular expressions for numeric syntax on different HP calculators
(06-07-2019 06:55 PM)Albert Chan Wrote:
(06-07-2019 05:25 PM)Jonathan Busby Wrote:  For the HP48 series, I think the regular expression is :

((([+-]?[0-9]+(\.)?[0-9]*)|([+-]?[0-9]*(\.)?[0-9]+))([eE](([+-]?[0-9]+(\.)?[0-9]*)|([+-]?[0-9]*(\.)?[0-9]+)))?)

Hi, Jonathan:

I only have a HP-12C, but I don't think decimal points allowed on the exponent field.

You are indeed correct! The regular expression should then be :

((([+-]?[0-9]+(\.)?[0-9]*)|([+-]?[0-9]*(\.)?[0-9]+))([eE][0-9]+)?)

Regards,

Jonathan
06-07-2019, 08:01 PM
Post: #6
 Jonathan Busby Member Posts: 81 Joined: Nov 2014
Proposal : List of regular expressions for numeric syntax on different HP calculators
I've been notified that the above regular expression is incorrect. It seems I took out the optional sign after the exponent. Here is the corrected version :

((([+-]?[0-9]+(\.)?[0-9]*)|([+-]?[0-9]*(\.)?[0-9]+))([eE][+-]?[0-9]+)?)

Regards,

Jonathan
06-07-2019, 09:00 PM
Post: #7
 JoJo1973 Junior Member Posts: 47 Joined: Apr 2016
RE: Proposal : List of regular expressions for numeric syntax on different HP calculators
Has anybody ever attacked the problem from the other side: given an adequately long list of strings, compute a regular expression matching all of them.

Of course the strings must have a trait-d'union and not purely random, e.g. number representation by a calc, coordinates, plate licenses...
06-08-2019, 05:44 AM
Post: #8
 Paul Dale Senior Member Posts: 1,474 Joined: Dec 2013
RE: Proposal : List of regular expressions for numeric syntax on different HP calculators
Are you interested in the resulting number format or the user's entry sequence? It looks like the final result but one never knows.

You've missed the finite number of digits that can be entered, the expressions posted so far allow any number of digits which simply isn't possible on a calculator.

No calculator that I'm aware of allows a leading plus sign. Minus or nothing both for the mantissa and exponent.

If you are following the user's key sequence, then e.g. the +/- key can be pressed at any time and as many times desired.

Regular expressions for reals are tricky

Pauli
06-08-2019, 05:50 AM
Post: #9
 Paul Dale Senior Member Posts: 1,474 Joined: Dec 2013
RE: Proposal : List of regular expressions for numeric syntax on different HP calculators
(06-07-2019 09:00 PM)JoJo1973 Wrote:  Has anybody ever attacked the problem from the other side: given an adequately long list of strings, compute a regular expression matching all of them.

List all of the strings as the expression: string_1|string_2|...|string_n. A state minimisation is usually done as part of the finite automata construction. Immediate optimal matcher.

Well almost. Strictly, for a series of constant strings like this an entirely different algorithm based on a many in parallel Boyer-Moore style approach is used instead.

Pauli
06-08-2019, 07:57 AM
Post: #10
 Paul Dale Senior Member Posts: 1,474 Joined: Dec 2013
RE: Proposal : List of regular expressions for numeric syntax on different HP calculators
On the HP 41 series the sequence 'E3' is possibly (synthetically). It's value is 1000. From the keyboard, it works normally.

I don't have a calculator to check if '.' is legal alone but I suspect it would be.

In key sequences, a leading '+/-' doesn't start number entry....

Pauli
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)