Naming convention for speed variables/columns - naming-conventions

I'm importing a large set of speed data and trying to figure out how to best rename the columns without loosing essential descriptive data. I generally use underscores to separate so "SpeedZone 3m/s (Distance) (m)" to "SpeedZone_3m_s_Distance_m)" isn't an issue, but I'm not sure how to address some of the special cases outlined below:
Speed designation "m/s"
Greater than or equal to ">="
Negative numbers "-"
Seconds squared "m/s²"
Sample data. I can write a function to substitute the characters - I'm looking for thoughts on what to rename to such as "m/s" can be changed to "m_per_s". Thanks.
column_names <- c("SpeedZone 3m/s (Distance) (m)",
"SpeedZone >=3m/s (Distance) (m)",
"SpeedBand1 Band1 (1.0-3.0 m/s)(Distance) (m)",
"SpeedBand1 >= Band1 (1.0-3.0 m/s) (Distance) (m)",
"Decel Zone -6 to -5m/s²",
"Accel Zone 5-6m/s²")
~~~

Are you asking how to convert >= into something that works in a C-style identifier? I'd use ge, same as Perl and test.

Related

The set of atomic irrational numbers used to express the character table and corresponding (unitary) representations

I want to calculate the irrational number, expressed by the following formula in gap:
3^(1/7). I've read through the related description here, but still can't figure out the trick. Will numbers like this appear in the computation of the character table and corresponding (unitary) representations?
P.S. Basically, I want to figure out the following question: For the computation of the character table and corresponding (unitary) representations, what is the minimum complete set of atomic irrational numbers used to express the results?
Regards,
HZ
You can't do that with GAP's standard cyclotomic numbers, as seventh roots of 3 are not cyclotomic. Indeed, suppose $r$ is such a root, i.e. a rot of the polynomial $f = x^7-3 \in \mathbb{Q}[x]$. Then $r$ is cyclotomic if and only if the field extension \mathbb{Q}[x] is a subfield of a cyclotomic field. By Kronecker-Weber this is equivalent to that field being an abelian extension, i.e., the Galois group is abelian. One can check that this is not the case here (the Galois group is a semidirect product of C_7 with C_6).
So, $r$ is not cyclotomic.

Converting SQL statement to Regular Expression - can it be done?

I need to convert the below SQL statement into Regular Expression.
CASE WHEN TypeCode >= 400
AND TypeCode < 700
THEN Amt * -1
ELSE Amt
END
Background: I am putting a bank transactions file (BAI2 file) in to a system for transactional matching (matching bank transactions to GL transactions). In order to get these transactions to match, the fields to match on have to be exactly the same. However, in the GL a $500 check may be input as -500 (because the company's cash account is being reduced by $500 for a utility bill), but BAI files store all amounts as positive values. I need to use the transaction type code from the bank to identify whether an amount should be a debit or a credit (in reference to the GL).
I have SQL developers that can do this using SQL, but this tool I'm using to do the BAI data manipulation requires the logic to be input as Regular Expression.
Can anyone assist in applying the appropriate signage (positive or negative) to these amounts for bank transactions? Can this even be done? I'm a new poster so please bear with any ignorance and let me know if I can provide further details/information.
Maybe try this:
^[4-6][0-9]{2}$
This will look for numbers between 400-699 inclusive.
EDIT: Changed \d to [0-9] as \d may include weird characters as well.
I feel your pain...no bank makes it easy.
'\d' means exactly '[0-9]', '\d' is shorter.
Banks have done a good job at fooling the masses that the word 'credit' is good and 'debit' is bad (me thinks that is their intent...).
You can't know if the value should be negative or positive unless you KNOW which direction the money is flowing in.
IF the table has separate columns for INWARDS/RECEIVED funds and OUTWARDS/PAID funds, then you do not need positive and negative indication.
IF, however, there is only ONE column in the table for all AMOUNTS, whether moved INTO or taken OUT FROM the account, then you definitely need SIGNED VALUES (positive/negative indication).
Either "-$nnn" or "($nnn)", with or without the "$".
If you have TWO COLUMN tables (PAID IN and PAID OUT) then just use "$nnn" without SIGNS.
If you have a SINGLE COLUMN table, then you can replace "$" with "-$" using:
$value =~ s/\$/-\$/;
The above is a perl example.
'\$' means "literal SIGIL" (i.e. dollar sign).
To match any value between and including 399-700 use the following regex:
^(399|[4-6]\d\d|700)$
That should match exactly what you want.
So you could do something like (in perl):
if ($TypeCode =~ m/^([4-6]\d\d|399|700)$/) { # if code matches pattern
# -EITHER-
$Amount=~ s/\$/-\$/; # prepend "-" to "$"
# -OR-
$Amount=~ s/\$/-/; # replace "$" with "-"
}
The '^' (carat - start of line or string) and '$' (sigil - end of line or string) surrounding the regex stop it from matching anything with 4 or more digits, like 3399 or 47421.
I moved '[4-6]\d\d' to the front as that will match 300 of 302 possible codes (and, I dunno, it may save a few milliseconds of processing).
'[4-6]' = '[456]', which means the digits from '4' to '6'.
TEST THIS ON SAMPLE DATA FIRST!

Formatting Short Text as Numbers

I've got a column called Amount, with a lot of numbers looking like this:
67000.00000000000000000000
Some of the columns have 2 numbers after the decimal that need to be retained.
Which should amount to $67,000.00
But my problem is, when I format it into currency or numbers, I get MUCH larger numbers than i would like, looking like this:
6.700.000.000.000.000.000.000.000,00
How can I get it into the right format?
Edit: For this scenario, the user was using ACC2013 and the Field Type was Short Text. The method of conversion that succeeded was : CCur(Val(FieldNameHere))
CCur(YourFieldName)
This will convert it to a currency format.
CLng(YourFieldName)
This will convert it to a long integer format. (It will cut off the decimals)
If you're looking for a reference, Microsoft has a few examples and goes into brief detail about some of these conversion functions.
CCur(Replace("67000.00000000000000000000", ".", Format(0, ".")))
You have to replace point symbol to actual decimal separator before conversion. Because you can't know actual seprator, choosen in regional settings, you have to find it out - and such Format() operation does dirty work.

Using SQL - how do I match an exact number of characters?

My task is to validate existing data in an MSSQL database. I've got some SQL experience, but not enough, apparently. We have a zip code field that must be either 5 or 9 digits (US zip). What we are finding in the zip field are embedded spaces and other oddities that will be prevented in the future. I've searched enough to find the references for LIKE that leave me with this "novice approach":
ZIP NOT LIKE '[0-9][0-9][0-9][0-9][0-9]'
AND ZIP NOT LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
Is this really what I must code? Is there nothing similar to...?
ZIP NOT LIKE '[\d]{5}' AND ZIP NOT LIKE '[\d]{9}'
I will loath validating longer fields! I suppose, ultimately, both code sequences will be equally efficient (or should be).
Thanks for your help
Unfortunately, LIKE is not regex-compatible so nothing of the sort \d. Although, combining a length function with a numeric function may provide an acceptable result:
WHERE ISNUMERIC(ZIP) <> 1 OR LEN(ZIP) NOT IN(5,9)
I would however not recommend it because it ISNUMERIC will return 1 for a +, - or valid currency symbol. Especially the minus sign may be prevalent in the data set, so I'd still favor your "novice" approach.
Another approach is to use:
ZIP NOT LIKE '%[^0-9]%' OR LEN(ZIP) NOT IN(5,9)
which will find any row where zip does not contain any character that is not 0-9 (i.e only 0-9 allowed) where the length is not 5 or 9.
There are few ways you could achieve that.
You can replace [0-9] with _ like
ZIP NOT LIKE '_'
USE LEN() so it's like
LEN(ZIP) NOT IN(5,9)
You are looking for LENGTH()
select * from table WHERE length(ZIP)=5;
select * from table WHERE length(ZIP)=9;
To test for non-numeric values you can use ISNUMERIC():
WHERE ISNUMERIC(ZIP) <> 1

can a variable have multiple values

In algebra if I make the statement x + y = 3, the variables I used will hold the values either 2 and 1 or 1 and 2. I know that assignment in programming is not the same thing, but I got to wondering. If I wanted to represent the value of, say, a quantumly weird particle, I would want my variable to have two values at the same time and to have it resolve into one or the other later. Or maybe I'm just dreaming?
Is it possible to say something like i = 3 or 2;?
This is one of the features planned for Perl 6 (junctions), with syntax that should look like my $a = 1|2|3;
If ever implemented, it would work intuitively, like $a==1 being true at the same time as $a==2. Also, for example, $a+1 would give you a value of 2|3|4.
This feature is actually available in Perl5 as well through Perl6::Junction and Quantum::Superpositions modules, but without the syntax sugar (through 'functions' all and any).
At least for comparison (b < any(1,2,3)) it was also available in Microsoft Cω experimental language, however it was not documented anywhere (I just tried it when I was looking at Cω and it just worked).
You can't do this with native types, but there's nothing stopping you from creating a variable object (presuming you are using an OO language) which has a range of values or even a probability density function rather than an actual value.
You will also need to define all the mathematical operators between your variables and your variables and native scalars. Same goes for the equality and assignment operators.
numpy arrays do something similar for vectors and matrices.
That's also the kind of thing you can do in Prolog. You define rules that constraint your variables and then let Prolog resolve them ...
It takes some time to get used to it, but it is wonderful for certain problems once you know how to use it ...
Damien Conways Quantum::Superpositions might do what you want,
https://metacpan.org/pod/Quantum::Superpositions
You might need your crack-pipe however.
What you're asking seems to be how to implement a Fuzzy Logic system. These have been around for some time and you can undoubtedly pick up a library for the common programming languages quite easily.
You could use a struct and handle the operations manualy. Otherwise, no a variable only has 1 value at a time.
A variable is nothing more than an address into memory. That means a variable describes exactly one place in memory (length depending on the type). So as long as we have no "quantum memory" (and we dont have it, and it doesnt look like we will have it in near future), the answer is a NO.
If you want to program and to modell this behaviour, your way would be to use a an array (with length equal to the number of max. multiple values). With this comes the increased runtime, hence the computations must be done on each of the values (e.g. x+y, must compute with 2 different values x1+y1, x2+y2, x1+y2 and x2+y1).
In Perl , you can .
If you use Scalar::Util , you can have a var take 2 values . One if it's used in string context , and another if it's used in a numerical context .