Re: [Info-Ingres] verhoeff function for Ingres

This is a discussion on Re: [Info-Ingres] verhoeff function for Ingres within the Ingres Database forums in Other Databases category; Hi Jim, The c+2 was actually a red-herring. I've sussed the problem causing the differences between the Numerical Recipes verhoeff function and the version described by Wikipedia(ie. the version I've implemented). The Wikipedia description is... The number having a check digit calulated is represented as AnAn-1...A1. Each 'A' being a single digit. A0 will be the check digit. A0 is then calculated as the inverse of F1(A1)*F2(A2)*...Fn(An) The trouble is that mathematical system used in the function is not commutative ie a*b b*a. So getting the ...

Go Back   Database Forum > Other Databases > Ingres Database

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-25-2008, 10:54 AM
Default Re: [Info-Ingres] verhoeff function for Ingres

Hi Jim,

The c+2 was actually a red-herring.

I've sussed the problem causing the differences between the Numerical
Recipes verhoeff function and the version described by Wikipedia(ie. the
version I've implemented).

The Wikipedia description is...
The number having a check digit calulated is represented as AnAn-1...A1.
Each 'A' being a single digit. A0 will be the check digit.

A0 is then calculated as the inverse of F1(A1)*F2(A2)*...Fn(An)

The trouble is that mathematical system used in the function is not
commutative ie a*b <> b*a. So getting the order right is imperative.

The NR version starts from the left (ie Fn(An)) which is why they are
getting different answers.

But I have no idea if one would be superior to the other, so I have
implemented both versions inside the functions....

select
generate_digit('verhoeff', '142857') --- which is the Wiki version
(returns 0)
,generate_digit('verhoeffNR', '142857') -- which is the NR version
(returns 6)

Marty

PS. I just finished adding the 'Luhn' algorithm to the generate_digit()
family.

-----Original Message-----
From: jcelko212-at-earthlink.net [mailto:jcelko212-at-earthlink.net]
Sent: 25 September 2008 14:42
To: Martin Bowes
Subject: RE: [Info-Ingres] verhoeff function for Ingres

There is a version in Pascal in the ACM or maybe the IEEE journals from
years ago. It is much easier to read than the C family versions and
uses
an array for a look-up table. I'll try to find it for you.

--CELKO--
Please include DDL if you want help with SQL. You cannot debug code you
cannot see.


> [Original Message]
> From: Martin Bowes
> To: Ingres and related product discussion forum


> Cc: --CELKO--
> Date: 2008-09-25 07:07:32
> Subject: RE: [Info-Ingres] verhoeff function for Ingres
>
> Hi Jim,
>
> Thanks for the input. Doing that in SQL would have been an interesting
> exercise!
>
> FYI. I've changed the thing to be:
> ** (char ) generate_digit((varchar )scheme, (varchar )string);
> ** This generates the check digit on the string using the
> nominated
> ** scheme(verhoeff, Luhn and Luhn Mod N, etc)
> **
> ** (int1 ) validate_digit((varchar )scheme, (varchar )string);
> ** Validates the string, returning 1 for yes and 0 for no.
>
> In regards to the 'styles' of verhoeff, I've tracked down the source

of
> this to an algorithm in 'Numerical Recipes'. The essential difference
> between that algorithm and the ones described in Wikipedia etc is:
> (Numerical Recipes) k=ij[k][ ip[(c+2) % 10][7 &m++] ];
> (mine) k = d[k][ F[7 & m++][atoi(&c)] ];
>
> For some reason NR is adding 2 to each digit (c), and then modulo 10

to
> get it to fit into their ip[10][8].
>
> I'm in the process of setting up a trial of the NR algorithm against
> mine to see if it actually produces different digits. I imagine it

must.
> In which case, I'll modify my code to accept an input of "verhoeff[N]"
> where N is an offset, and code accordingly.
>
> Marty
>
> -----Original Message-----
> From: info-ingres-bounces-at-kettleriverconsulting.com
> [mailto:info-ingres-bounces-at-kettleriverconsulting.com] On Behalf Of
> --CELKO--
> Sent: 24 September 2008 17:17
> To: info-ingres-at-kettleriverconsulting.com
> Subject: Re: [Info-Ingres] verhoeff function for Ingres
>
> >> What do people think of this?<<

>
> Nice work. You can do this in pure SQL via table look-up, but it is
> awful. I tried it when i wrote THINKING IN SETS. Uggh!
>
> >> Do the function names make sense, seem reasonable to use? <<

>
> Minor nit -- the current convention is "_" name for code
> modules, "computer_verhoeff()" or something might be better.
>
> >> Also, in passing, I have heard that there is more than one verhoeff

> 'style' out there, and that they return different numbers. But I can't
> find a reference to these on wikipedia. Does anyone have any idea
about
> the truth of this multiple style stuff? <<
>
> I would guess "false" because you would need a group that had <= 10
> elements to map to the digits and I think D-5 is the only one in that
> range with the right properties. However, if the number of elements
> is increased, I don't know.
>
> _______________________________________________
> Info-Ingres mailing list
> Info-Ingres-at-kettleriverconsulting.com
> http://www.kettleriverconsulting.com...fo/info-ingres




Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 09:56 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Integrated by bbpixel2009 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.