[Question]
  [
Based on [Practical Golf - US States](https://codegolf.stackexchange.com/questions/38499/practical-golf-us-states)
Your task is to find the abbreviation (symbol) of an element given the element name, up to and including ununoctium (118). Use the periodic table on [Wikipedia](https://en.wikipedia.org/w/index.php?title=Periodic_table_(large_version)&oldid=627552839).
Thanks to squeamish ossifrage, you can find a full list of elements to abbreviations at <http://pastebin.com/DNZMWmuf>.
You may not use any external resources. In addition, you may not use any built-in data specifically about the elements of the periodic table. Standard loopholes apply.
**Input**
Input may be from stdin, file, `prompt`, `input` etc.
Input Format:
All of the following are valid inputs:
```
Carbon
carbon
CARBON
cArBOn
```
Essentially, the element name - case insensitive.
You do not have to handle misspellings or any invalid element name. Invalid input is undefined behavior.
**Output**:
The symbol for the element. The first character **must** be capitalized and the rest
**must** be lowercase.
Example output: `C`
Test cases:
```
Carbon -> C
NiTROGen -> N
Sodium -> Na
Gold -> Au
Silver -> Ag
Tin -> Sn
```
There are many more elements than states, so I expect it to be harder to find a general rule for these.
This is code golf. Shortest code wins!
  
[Answer]
# C, 452
A good hash function helps. There may be better ones. (Improvements suggested by [@ugoren](https://codegolf.stackexchange.com/users/3544/) et al.)
```
h;main(c){char*p="Sn)Cu&V$U#Mo#Rf#Sg&Cs#Y+FTa%Rb)S'Nd#GaK&Mg'Zr$PtPm%ReUuo#SmDy(Ac$Lu%W&CaRa(Cf)EuB#Ds%Md$Uus*NpIn$H&YbIr*BeEs*Tc#I(FlRuC#ThSrBh/NaCoLrKr&Nb$CePb$Ne'Am)At*PdLa#Tl%HgMt,CrTbBk$Rh&Rn4TeZn$HfAg%Fm)Xe$AlScFePo$As'HeO#LvN&DbGe#Ho&Mn$Cd+Ni$Rg$HsBr$AuSi#Pr&Uup#Se*Ti#Tm$Er$Sb&PPu&Cm$GdBa'Cn&UutLiFr#Ar#Bi#NoOs%Pa4Cl";while((c=getchar())>64)h=(h+c%32+74)*311%441;while(h)if(*p<65?h-=*p++-34,0:1)for(h--;*++p>96;);do putchar(*p++);while(*p>96);}
```
Ungolfed with comments:
```
int h;
main(c) {
  
  /* Hashed element symbols. Characters #$% etc. are used as padding: */
  char *p="Sn)Cu&V$U#Mo#Rf#Sg&Cs#Y+FTa%Rb)S'Nd#GaK&Mg'Zr$PtPm%ReUuo#SmDy(Ac$Lu%W&C"
          "aRa(Cf)EuB#Ds%Md$Uus*NpIn$H&YbIr*BeEs*Tc#I(FlRuC#ThSrBh/NaCoLrKr&Nb$CeP"
          "b$Ne'Am)At*PdLa#Tl%HgMt,CrTbBk$Rh&Rn4TeZn$HfAg%Fm)Xe$AlScFePo$As'HeO#Lv"
          "N&DbGe#Ho&Mn$Cd+Ni$Rg$HsBr$AuSi#Pr&Uup#Se*Ti#Tm$Er$Sb&PPu&Cm$GdBa'Cn&Uu"
          "tLiFr#Ar#Bi#NoOs%Pa4Cl";
  
  /* This hash function gives a unique result for each element: */
  while((c=getchar())>64) h=(h+c%32+74)*311%441;
  
  /* Find the corresponding position in the hashed data */
  while(h) {
    if(*p<65?h-=*p++-34,0:1) {      /* Step over an abbreviation */
      for(h--;*++p>96;);            /* Skip padding */
    }
  }
  
  /* Output first uppercase character and all following lowercase characters: */
  do {
    putchar(*p++);
  } while(*p>96);
}
```
I used brute force to find this hash; This was the only one with a hash size of ≤512 that had no collisions. I didn't check alternative spellings though, and there might be better functions with different algorithms (e.g. using XOR instead of addition).
The hash function maps text strings to values from 0 to 440. "Tin" hashes to zero, so "Sn" is at the start of the table. The next 7 positions are empty. To keep the code compact, this is indicated by the ASCII value 34+7=41 (")"). Next comes "Copper" (8), four empty cells (34+4=38="&"), and "Vanadium" (13). After calculating a hash, the program steps through the table, subtracting 1 for every capital letter followed by 0 or more lowercase letters, and subtracting (ASCII VALUE)-34 for every non-alphabet character. When the value reaches zero, we have found the correct result.
[Answer]
# CJam, ~~337~~ ~~297~~ ~~293~~ ~~232~~ ~~220~~ ~~201~~ 200 bytes
```
leu:E2f^3b2+4%_"53N5903CVCT4":i3/=~Ef+b\%]53b"gØâ^ÃP·^À4Î¾^ß^E5^W^Ma{áª^B¤±´oòæ»^XÊQÑ»4Å¾DÙÝòÙ 0^ÝþKa6^Ó£,Ûkû¥¡ùh^E"256b7b6a/0a3**<)5md@5a/,(" ¬^GH/N¿·%^U^RU1²Bd
òë^Ð¼~í^ÌéáU"256b25b'Af+2/='J-'Q/"UU"*\)_5=)*E%2<?(\el
```
The above code uses caret notation, since it contains control characters.
At the cost of 24 additional bytes (for a total of 224), those characters can be avoided.
```
leu:E2f^3b2+4%_"53N5903CVCT4":i3/=~Ef+b\%]53b
"' NwEvKv6e8@]jO4G)=b{L!v@hFQ/oCN)*|BRxvNRL+LO7NI(pLs4[d87$Q%8R\t+' M5JU"
{32f-95b}:B~7b6a/0a3**<)5md@5a/,(
"&y.$h*z^t\rQPUc]l8F h$=18C^r|vD~S"
B25b'Af+2/='J-'Q/"UU"*\)_5=)*E%2<?(\el
```
You can try this code in the [CJam interpreter](http://cjam.aditsu.net/).
### Test cases
```
$ base64 -d > elements.cjam <<< bGV1OkUyZl4zYjIrNCVfIjUzTjU5MDNDVkNUNCI6aTMvPX5FZitiXCVdNTNiImfY4oNQt4A0zr6fBTUXDWF74aoCpLG0b/LmuxjKUdG7NMW+RNnd8tmgMJ3+S2E2k6Ms22v7paH5aAUiMjU2YjdiNmEvMGEzKio8KTVtZEA1YS8sKCIgrAdIL06/tyUVElUxskJkCvLrkLx+7Yzp4VUiMjU2YjI1YidBZisyLz0nSi0nUS8iVVUiKlwpXzU9KSpFJTI8PyhcZWw=
$ cksum elements.cjam 
952664534 200 elements.cjam
$ for e in Carbon NiTROGen Sodium Gold Silver Tin; do LANG=en_US cjam elements.cjam <<< $e; echo; done
C                                                                                                       
N                                                                                                       
Na                                                                                                      
Au                                                                                                      
Ag                                                                                                      
Sn
```
### How it works
The first step is to read the element name from STDIN and apply a rather elaborated hash function, which maps all element names in the range **[0, 225]**:
```
l eu :E          " Read a line from STDIN, convert to uppercase and save in E.            ";
2 f^             " XOR each character code with 2.                                        ";
3 b              " Convert to integer; consider the resulting array a base 3 number.      ";
2 + 4 %          " Add 2 and take the result modulo 4. Result: R                          ";
"53N5903CVCT4":i " Push [53 51 78 53 57 48 51 67 86 67 84 52].                            ";
3 / =            " Retrieve the chunk of length 3 that corresponds to R. Result: C        ";
~ E f+           " Add C[2] to all character codes of E.                                  ";
b                " Convert to integer; consider the resulting array a base C[1] number.   ";
\ %              " Take the integer modulo C[0]. Result: M                                ";
] 53 b           " Push H := 53 * R + M.                                                  ";
```
Many element symbols are formed by the first and second, first and third, first and fourth, first and fifth or first and tenth (which is just the first) character of the element's English name. We are going to represent these elements by numbers from 0 to 4 respectively. All remaining elements (represented by 5) will require a lookup table. 
The resulting table can be pushed as follows:
```
"gØâ^ÃP·^À4Î¾^ß^E5^W^Ma{áª^B¤±´oòæ»^XÊQÑ»4Å¾DÙÝòÙ 0^ÝþKa6^Ó£,Ûkû¥¡ùh^E"256b7b6a/0a3**
```
The array of character codes gets converted from base 256 to base 7 and 6's are replaced by runs of three 0's.
This is the decision table D:
```
[4 0 0 0 1 0 0 0 0 0 0 3 0 2 0 1 0 0 0 0 0 0 0 0 4 1 1 0 0 0 0 2 0 4 0 5 2 0 0 3 4 0 0 0 0 4 0 1 0 0 3 1 0 0 2 1 1 1 0 0 0 1 0 5 5 0 0 2 0 0 0 5 5 0 0 0 5 0 3 0 0 0 0 5 0 0 0 0 0 0 0 0 5 2 3 0 1 0 5 0 4 0 0 0 0 4 0 5 0 0 0 0 0 5 0 0 0 2 5 1 4 1 5 0 0 0 5 0 0 5 1 1 0 0 0 0 0 0 2 0 5 0 0 0 3 1 0 2 0 0 0 2 0 0 0 5 0 0 0 0 1 0 0 0 0 0 4 0 2 2 5 2 0 0 5 1 0 0 0 0 4 0 5 0 0 3 5 0 0 5 0 1 0 0 0 2 0 0 0 0 0 5 0 4 0 0 0 0 0 0 0 0 3 0 4 0 0 1 2 2 0 0 0 0 0]
```
The necessary action for the element with hash **1**, e.g., corresponds to the first element of the this array. Array elements that do not correspond to any element's hash are also zero, which allows the **(0 0 0) ↦ 6** compression.
Now, we interpret D for hash H.
```
< ) 5 md     " Push D[:H-1] (D[H-1] / 5) (D[H-1] % 5).                                    ";
@ 5a / , (   " Count the number of 5's in D[:H-1] (by splitting at [5]). Result: I        ";
```
Next, we push the lookup table. If we append **j** to single-character symbols and replace **Uu** with **Q**, each symbol will be exactly two characters long. It can be pushed as follows:
```
" ¬^GH/N¿·%^U^RU1²Bd
òë^Ð¼~í^ÌéáU"256b25b'Af+2/
```
The array of character codes gets converted from base 256 to base 25, the character code of **A** gets added to all digits (casting to Character in the process) and the result is split into chunks of length two.
This is the lookup table L:
```
["QP" "YB" "PD" "SN" "QO" "QT" "QS" "SB" "KJ" "TM" "FE" "PB" "AU" "WJ" "CN" "SG" "RF" "CM" "CU" "HG" "NA" "RG" "AG"]
```
Now, we proceed to compute potential element names.
```
=                " Push L[I].                                                             ";
'J - 'Q / "UU" * " Remove J's and replace Q's with runs of two U's.                       ";
\ ) _ 5 = ) *    " Push S := (D[H-1] % 5 + 1) * ((D[H-1] % 5 + 1 == 5) + 1).              ";
E %              " Push every Sth character of E.                                         ";
2 <              " Discard all but the first two characters.                              ";
```
The stack now contains
```
B M N
```
where **B** is the Boolean **D[H-1] / 5**, **M** is the name retrieved from the lookup table an **N** is the element name formed by selecting characters from E.
We're almost done:
```
?                " If B, push M; else, push N.                                            ";
( \              " Extract the first character from the string.                           ";
el               " Convert the rest to lowercase.                                         ";
```
[Answer]
# JavaScript ES6, 690 ~~708~~ bytes
```
for(n=prompt()[l='toLowerCase'](i=0);!(c='HHeLiBeBCNFNeNaMgAlSiPSClArKCaScTiVCrMnFeCoNiCuZnGaGeAsSeBrKrRbSrYZrNbMoTcRuRhPdAgCdInSnSbTeIXeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaWReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaUNpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnUutFlUupLvUusUuo'.match(x=/[A-Z][a-z]*/g)['HyHeLitBeryBorCarNitFluNeonSoMagAlSiliPhSuChlArgPotCalcScTitVChrManIroCobNicCoppZinGalGeArsSelBrKRubStYttrZirNioMoTecRuthenRhoPaSilvCadInTinAnTelIoXCaeBaLanCePraNeodPromSaEuGadTerDyHoErThuYtteLuHafTaTuRheOsIriPlaGoMerThaLeBiPolAsRadoFrRadiAcThoProtUrNepPluAmCuBerkCaliEiFeMenNoLawRutherDuSeaBohHasMeiDaRoCopeUnuntFleUnunpLivUnunsUnuno'.match(x).map(a=>a[l]()).indexOf(n.slice(0,i++))]);)
alert(c)
```
The first array holds the symbols, and the second array holds the minimum letters necessary to tell which element is being referred to. Thanks to core1024 and edc65 for helping shorten it. Test at <http://jsfiddle.net/xjdev4m6/2/>. Slightly more readable:
```
n=prompt().toLowerCase()
e='HyHeLitBeryBorCarNitFluNeonSoMagAlSiliPhSuChlArgPotCalcScTitVChrManIroCobNicCoppZinGalGeArsSelBrKRubStYttrZirNioMoTecRuthenRhoPaSilvCadInTinAnTelIoXCaeBaLanCePraNeodPromSaEuGadTerDyHoErThuYtteLuHafTaTuRheOsIriPlaGoMerThaLeBiPolAsRadoFrRadiAcThoProtUrNepPluAmCuBerkCaliEiFeMenNoLawRutherDuSeaBohHasMeiDaRoCopeUnuntFleUnunpLivUnunsUnuno'.match(x=/[A-Z][a-z]*/g).map(a=>a.toLowerCase())
s='HHeLiBeBCNFNeNaMgAlSiPSClArKCaScTiVCrMnFeCoNiCuZnGaGeAsSeBrKrRbSrYZrNbMoTcRuRhPdAgCdInSnSbTeIXeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaWReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaUNpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnUutFlUupLvUusUuo'.match(x)
for(i=0;i<7;i++){
  if(c=s[e.indexOf(n.slice(0,i))]){
    alert(c,i=8) // i=8 breaks out of the loop so the result is only alerted once
  }
}
```
[Answer]
**Ruby 1.9+, 565 471 447  444**
A one-liner. Because nothing is "impossible to do with regexes"...  
(Just saved 94 chars by adding another regex) ((and 24 by simplifying them))
```
p"VAlAmA.sArAcAnt|SbA.tBaB..kBeBiB.hBrBDyD.+sD.bE..sErEuF..mFrFlu|[[email protected]](/cdn-cgi/l/email-protection)|AuH.fH.sHeHoHInIro|FeIrIKrL.vL.+rLaLiLuL|PbM.gMoM.+dM.nM.+tM|HgC.+sC.dC.+fCeCar|[[email protected]](/cdn-cgi/l/email-protection)|CmCop|CuCoC.rC.lN.+dN.+pNeN..bNit|[[email protected]](/cdn-cgi/l/email-protection)|PdP...aPrP.uP..tPot|KPoPR.*n$RaR.+gR.eRhR.+bR.+fRuS.mScS.+gSeS..v|AgSiSo|NaS.rSTaT.cT.+bTeThu|TmT..lThTin|SnTiTu|WU.u.oU.u.pU.u.sU.u.tUXeY.+bYZ.nZ.r"
.split(/(?<!\|)(?=[A-Z])/).find{|r|/^#{r}/i.match *$*}.gsub /.*\||\W/,''
```
*(newline after string added for "readability", remove for test)*
usage: `ruby periodic.rb aluminum` $>
Explanation:  
[Splitting the string on leading capitals](https://stackoverflow.com/q/26260767/10396) returns an array of regex to match against element names. The only alphabetic characters allowed in each are those from the abbreviation\*. They are ordered such that the first match found when comparing to the command line argument `*$*` is the correct one. The trailing gsub strips out the non-alpha characters before printing.
\*Odd abbreviations like "Fe" for "Iron" are handled by a `|` element: "Iro|Fe". The first choice is what is actually matched; the gsub then removes all characters up to the '|', leaving the actual abbreviation. 
Test framework (requires [@squeamish's list](http://pastebin.com/DNZMWmuf): downloaded as 'table.txt' in the working directory).
```
def testfunc(name) 
  #replace with however you call your code
  return `ruby1.9.3 periodic2.rb #{name}`.chomp()
end
elements= File.new('table.txt').readlines.map{|s|s.chomp}
elements.each{|l|
  a,n=l.split(' ')
  r = testfunc(n)
  print "#{n} => #{a} "
  if r!=a then
    print ("FAIL: gave #{r}\n")
    exit
  else 
    print("\tOK\n")
  end
}
print("PASS: #{elements.size} elements matched\n")
```
[Answer]
## Ruby, 1068 bytes
```
require"zlib"
require"base64"
$><<eval(Zlib::Inflate.inflate(Base64.decode64"eJwlU8tu2zAQ/Bee+QW6CLYTx0FiR7CdtsmNkmhJCEUKfKQViv57Z9YnE+vd2ZnZ0d+1j2Go6oO2bipzpQ5W6SmPU6nU66S0jatzldqiGmLwVb3VJrZ87NAmoyf9Zx0sKm/alRCnqt5riw514lAvqCejtBm8TZU6Dgp984SGjcMuN3WhUhfsGkNaxqpudHG3Eqv6okdHPLVDXxwIuYmAzCalqn7RxnWkuQN2Z3yPxktH8sbjeQWg8QbV+oceY5iJE1kbDICOHpBE3JNka1zG3wHT3ZeF3hOmw7LYiGpB1XeV+sSIcY4rnwydmQn0hPmYLFduEqpOnhdWg4jcYmlclwyRL3iWdiLTc6s07PNYe0E15wjc+kNPsSOrT9Sm0HLXCZ3BrW0P0iBou9FbyIPSkkfYrs6F1vXsPY9C0aC36entNxVs4LjpZ/EKVX8/ybOnLqzHr8/TzCO0FODgvbreb4dV9bO2npx+oWSTzO6g1ER5bnlZn0eDvIgr9wbqN8kCtIEUG/qVKejFFQvRzYyx2fC6FzxLDAuej4VMg8PzqSeYOHAFrTUtEWAPK80QKQeYwf+B+4gVY5HLXGeaicFKfbS0yGaAvRL35mXsJnwNjnwF3+KHlKv6p4aV4iCIp1lQ3yAyTuLrMxY4k2lXk8kABm8KCXY06wCDR0YDmIiqFf+xfUpzgdYtw+QCc9GAdMqGnDZZtPKAzKLxHYp7JvR+nzNjjZVs7XjhKPpGWpgN8tgYGWNu3rVdcuEnt/DjykRtwG/GOdC5EYfvh5nJWjK+/WJYphts3d2YhZQRrMck0eauPXt9z95jz6/EUuEJEszvyOS9xnsIYcH5xmiLhQ9MkWkDqhcYE0YhvmU0U5ITcMWUGeMjTYgzTqAeUA3W5wFgHMPHhxU7prP4DLD3gmZnY/gGNSflxbIMzROCDnWv31JOUk7yDh3fQf37D7D/kWs="))[gets.downcase[1..5].to_sym]
```
Input via STDIN.
The shortest unique substrings of the element names are from the second to the sixth character (or the end of the name if its too short). So I'm simply getting those and looking them up in a hash. I also compressed the hash because that saves another 200 bytes. Here is what the hash itself looks like:
```
{ydrog:?H,elium:"He",ithiu:"Li",eryll:"Be",oron:?B,arbon:?C,itrog:?N,xygen:?O,luori:?F,eon:"Ne",
 odium:"Na",agnes:"Mg",lumin:"Al",ilico:"Si",hosph:?P,ulfur:?S,hlori:"Cl",rgon:"Ar",otass:?K,
 alciu:"Ca",candi:"Sc",itani:"Ti",anadi:?V,hromi:"Cr",angan:"Mn",ron:"Fe",obalt:"Co",ickel:"Ni",
 opper:"Cu",inc:"Zn",alliu:"Ga",erman:"Ge",rseni:"As",eleni:"Se",romin:"Br",rypto:"Kr",ubidi:"Rb",
 tront:"Sr",ttriu:?Y,ircon:"Zr",iobiu:"Nb",olybd:"Mo",echne:"Tc",uthen:"Ru",hodiu:"Rh",allad:"Pd",
 ilver:"Ag",admiu:"Cd",ndium:"In",in:"Sn",ntimo:"Sb",ellur:"Te",odine:?I,enon:"Xe",esium:"Cs",
 arium:"Ba",antha:"La",erium:"Ce",raseo:"Pr",eodym:"Nd",romet:"Pm",amari:"Sm",uropi:"Eu",
 adoli:"Gd",erbiu:"Tb",yspro:"Dy",olmiu:"Ho",rbium:"Er",huliu:"Tm",tterb:"Yb",uteti:"Lu",
 afniu:"Hf",antal:"Ta",ungst:?W,heniu:"Re",smium:"Os",ridiu:"Ir",latin:"Pt",old:"Au",ercur:"Hg",
 halli:"Tl",ead:"Pb",ismut:"Bi",oloni:"Po",stati:"At",adon:"Rn",ranci:"Fr",adium:"Ra",ctini:"Ac",
 horiu:"Th",rotac:"Pa",raniu:?U,eptun:"Np",luton:"Pu",meric:"Am",urium:"Cm",erkel:"Bk",alifo:"Cf",
 inste:"Es",ermiu:"Fm",endel:"Md",obeli:"No",awren:"Lr",uther:"Rf",ubniu:"Db",eabor:"Sg",
 ohriu:"Bh",assiu:"Hs",eitne:"Mt",armst:"Ds",oentg:"Rg",opern:"Cn",nuntr:"Uut",lerov:"Fl",
 nunpe:"Uup",iverm:"Lv",nunse:"Uus",nunoc:"Uuo"}
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 298 bytes
```
s=>(i=`23>3c9@94=4E33:3Q0I3:9[020G0O3@74M9=4A6@4;7J5H96?9K0L723E4343A4R40A0T9D3J5H4?4?3J329>9P9;359:0B9^3=95h6:9<6M0~D0@0N3<3;0:9@4<4<6H3I3`.replace(/\D/g,s=>"2".repeat(Buffer(s)[0]-56))[h=parseInt(s,36)*184%901])-9?s[0]+[s[i-1]]:`Ag,Fe,Hg,,W,Sn,K,Cu,Pb,,Sb,Au,,Na`.split`,`[h%418%48%15]||'Uu'+s[4]
```
[Try it online!](https://tio.run/##RVXbcts2EH3PV2g845HU0A5t0kpoW7apm6VYklVJzk1VxxAJkUxIgAOAbjWTyRd0pi99bP@j35Mf6Ce4IHehvEiD5WJx9pyDxWfyRGQgklwdMR7S5237WbavGkn78dS5cgLvxnPbbt9xzp2f7ZFz7q3sU/vWvnduXrsTr@36rRv34vXbs6HXuvbu7PHrU6fvOq7ju3PX9u2l13P0R/favXbeOqfelTfzLpwz79zueL86be8sbp17l62J/a1n39hT59K5sM@9G/fSvWwNnZHzeCxonpKANl790nsVWRrawelBGaRENTrFdktFQzZX9vrorNVsruJ2ToSkI6Ya0nJazZ9O3riHnn2ybh5511KnvVzJVXJ0sl6fP/qRNaDWMLKs99aCWXdWt7BmG8tabCy/sKwpeTyWeZqoR@txFR@6J28O3TeHJ2frr1/rD0X9pVy56@eL1YvVwXAXCh5RdmAdDA/Wlg7QNCmyckmr9ThRMQTGSRXoULFLMacDOR0ueFmhU626RGyqZbdaThNlTphWgfvfd7C8r5aDtOAiYVQHBrCBVrunUHvBQzhrSqr1hESMSghNoirkp0WWMAj5KexK0iSoyiwA9SzmMo@5KKSOzSCnSLeFKFMAdpwaHF0o4ouoKuELKMEVkXjyHXaaBrDuArhFQBjCXQRVZJkogtCWgOQdYQRz3uHBgmdYRmCPLCK6yxLLhFWhETA8AFK6fENSVW7gyHHwhaYlSQl@z3NattYtqvWnhAV69Qlq3RKj3y3AvqUiMyhvKfYuKUvKTb6E1mhKMWWBqpewK746APtO7HJVwbyDwLzYJNjqfANVtBeYwjKQ9FEpAYGPiFVo5SDySWB7fIMmgDITnu42IWXgAuBgSYOYUay9DBCAig3qOVAxj42h5jHIqtkwgsxC456nij4/Qp1DIxAkjIzKI4YqV1aDha8bzDjblZENQkvTAptcAnkjjaLiblQtP1BWEfcB9SXG4l1gv0NwewcUGxOmYgL9jyHUpZjShRozQSTl4Q6Rz4S5XPvQNMREnlFzyWcZMEAyc@ICIv1C8Bwi/QJtFPLU3LvbEDsVqNQSWu/tZC44NtPbwYjhKSIYgnR9s6kPIJdxgQZdZsYj@8IfofC4UEbsMeAZki2CGW6hjCaJpFAHOFoWLJKqGj7v0Q17ewBr9xKh3Uu8d8bBI5wCKVEJED9TwANPw9IrgGJCRVCIUvxhhM3sr9sS5sqYknLDDBrpJDLTNi21xVHFU@P/GfDjS1UeWtrFhzPnmvuyizlYbiAIw0k0ECYB@4LO/UDtRyROJj0NEVZsfKDIj7QZbHwQZjI8oIFyVWBkmiMlhdojBhb8TLsREfmgYdfcgG5m3pEv5q3pfDHzNNlygaW6oGI/YVoyg6oPsgz0xMJ@M6SdhXpCPeHDAG6c8o05Ycrx3vwmqKFqLH4MCaHPNYzBub1ig2f2cHZRsuEiwlsR4csXm4sZownNEzGUCCxRzFzNCajXIyLTkobo3x5kzjllKtr7MTKTnGpCzDMDcj@wgpmh@VAofEap4Nj@IN2n5dSM24cixwddz7bMaD9@2qdKraxJlfsoD/ZBTeGL9YtjzVSfBHGjsWIko1ZN7rLNullrX9X03JY8pccpjxrlt@OchH0WNk7cZu1lrf7tqlbX/w1BZa1d21YpzaZJqnLgW7uqWbuu1f/798/vf/@lf@u181r9@z9/1JvN5vP/ "JavaScript (Node.js) – Try It Online")
## How?
### Element groups
We split the elements into 3 groups:
* **Group 1**: 12 elements whose symbol is the first letter of their name, such as `Carbon -> C`.
* **Group 2**: 91 elements whose symbol is the first letter of their name, followed by the \$n\$-th letter (0-indexed) with \$1\le n \le6\$. Examples: `Helium -> He` (\$n=1\$), `Zirconium -> Zr` (\$n=2\$).
* **Group 3**: 15 elements that do not belong to the other groups, such as `Iron -> Fe`.
This means that all elements can be encoded with a single digit: we use \$0\$ for group 1, \$n+1\$ for group 2 and \$9\$ for group 3. (Obviously, we'll need some extra data for group 3. More on that later.)
It is worth noting that 44 symbols simply consist of the first two letters of the element name. That's almost 50% of group 2. These ones will be encoded with a `"2"`, so that's the padding character that we want to use in our lookup string.
### Hash function, lookup string and compression
We apply the following hash function (found by brute-force) on the input string:
```
h = parseInt(s, 36) * 184 % 901
```
The corresponding lookup string is \$899\$ characters long, which is pretty big.
But, by design, we have many runs of consecutive \$2\$'s in there. Our compression strategy is to replace each run of \$2\$'s of length \$2\le n\le70\$ with the character whose ASCII code is \$n+56\$ (that's the range going from `":"` to `"~"`).
The compressed string is only \$132\$ characters long.
You can see the decompression process here:
[Try it online!](https://tio.run/##hc7NTsJQEAXgPU9xw6ZtFJh0piVz20JBjIDiX3QFGmq5FExtSW9rogtfvda4wo27ycz5Juc1eo90XOwPZSfLN6qutQjE2sYBxhwyBXSOKPEOZih5CTZcwA2GfVpwQCM3JK8/d6bsDvkSrvo2nhMSjuieYAQPPMHmSEMa4hxtHvAte@iwhDE/Y8DOzpXsuwv4mkAI1@ijB5JD8sl3pzjDtdeqmi66W6hDGsXK7K0mveRUNAUHom23f/YqKs1xtd2qwtTWEp5ERziuZXmtVpxnOk9VN80T0zjL3w6F0lpthN5/KiGkMMRJ8zpVWVLumtEQLx@l0kZDj@RjFh/bX1n9L1fZsS2LfZbIv7HK8ur6Gw "JavaScript (Node.js) – Try It Online")
### Decoding
Groups 1 and 2 are decoded the same way:
```
s[0] + [s[i - 1]]
```
(NB: For group 1, `s[-1]` is undefined and `[undefined]` is coerced to an empty string.)
For group 3, we use another hash function and another lookup string (also found by brute-force):
```
`Ag,Fe,Hg,,W,Sn,K,Cu,Pb,,Sb,Au,,Na`.split`,`[h % 418 % 48 % 15]
```
There are 4 remaining superheavy elements that are not included above. Because they are referred to by their temporary names and thanks to the [systematic nomenclature](https://en.wikipedia.org/wiki/Systematic_element_name), we can build the symbols for these ones by concatenating `"Uu"` with the fifth letter of their name:
```
    v
Unun**t**rium   -> Uut
Unun**p**entium -> Uup
Unun**s**eptium -> Uus
Unun**o**ctium  -> Uuo
    ^
```
Hence the last part of the code:
```
|| 'Uu' + s[4]
```
[Answer]
# Python - ~~652 649~~ 637
My hash table is based on the combination of every second and every third character of the uppercase name:
```
import re
def f(s,c='S<8F0FCE;2.ACR;J@W$;BI8>GD*?GnHQ<K>&T\(51IAg/Y?S2=169.,325(F(98?>?=^97DUCITX;SJ`0C<P9iLP/G4B,A(-A?(3QLLZ;81D(.4F;L8GaVP[=\=cOX3U,LQl6:E9/OXdSe(4,TSV/=FN98?K.18Q>R$+<GG[IS-4?;4H;T/IMq9<LXMYH4HG<>>KTT,>IIEM,[Nf<,:Z60(A9fImZTMRTcM?[lVg^qC}',e='HHeLiBeBCNOFNeNaMgAlSiPSClArKCaScTiVCrMnFeCoNiCuZnGaGeAsSeBrKrRbSrYZrNbMoTcRuRhPdAgCdInSnSbTeIXeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaWReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaUNpPuAmCmBkCfEsFmMdNoLrRfDbSgBhHsMtDsRgCnUutFlUupLvUusUuo'):
 U=s.upper();X=lambda x:chr(32+sum(ord(u)-65for u in x))
 return re.findall('[A-Z][a-z]*',e)[zip(c[::2],c[1::2]).index((X(U[1::3]),X(U[:-1:2])))]
```
Here is the corresponding generator:
```
table = '''
H     Hydrogen
He    Helium
...
Uuo   Ununoctium
'''
table = map(lambda l: l.split(), table.split('\n')[1:-1])
abbr = []
for name in map(str.upper, zip(*table)[1]):
    abbr.append(chr(32+sum(ord(u)-65 for u in name[1::3]))+
                chr(32+sum(ord(u)-65 for u in name[:-1:2])))
print 'c=' + ''.join(abbr)
print 'e=' + ''.join(zip(*table)[0])
print 'Unique' if len(table) == len(set(abbr)) else 'Duplicates'
```
There's probably room for improvements, especially compressing the two long strings.
Tested with:
```
for short, name in table:
    if f(name) != short:
        print "Wrong result!"
```
[Answer]
# CJam, ~~462 449 434 401 391 384~~ 382
With help from Dennis.
## Code
Nested ternary ifs are ***probably*** not the right way to do this in CJam.
```
rel_"ruthen"#!"Ru"{_"tel"#!"Te"{__5{\_ceu\@=+_}:U~"PdYbRgCmCn"{\#)!}:X~{;__4U"RnPaCfDs"X{;_3U"NbCsNdPmTbPtTlBkEsFmMdLrMt"X{;2U"MgClCrMnZnAsRbSrZrTcCdSmGdHfReAtNpPuDbBhHsLv"X{;__"sili"#{;__ceu\1=@2=++"SodIroCopSilTinAntThuGolMerLeaTunPotRutSeaHydBorCarNitOxyFluPhoSulVanYttIodUra"\#3d/m[)"_NaFeCuAgSnSbTmAuHgPbWKRfSgHBCNOFPSVYIU"S%\=_"_"={;_1U"Un"={;4="Uu"\+}*}*}"Si"?}*}*}*}*}?}?]W=
```
With indents:
```
rel
_"ruthen"#!"Ru"
{
_"tel"#!"Te"
{
  __5{\_ceu\@=+_}:U~
  "PdYbRgCmCn"{\#)!}:X~
  {
   ;__4U
   "RnPaCfDs"X
   {
    ;_3U
    "NbCsNdPmTbPtTlBkEsFmMdLrMt"X
    {
     ;2U
     "MgClCrMnZnAsRbSrZrTcCdSmGdHfReAtNpPuDbBhHsLv"X
     {
       ;__"sili"#
       {
        ;__ceu\1=@2=++"SodIroCopSilTinAntThuGolMerLeaTunPotRutSeaHydBorCarNitOxyFluPhoSulVanYttIodUra"\#3d/m[)"_ Na Fe Cu Ag Sn Sb Tm Au Hg Pb W K Rf Sg H B C N O F P S V Y I U"S%\=_"_"=
        {;_1U"Un"={;4="Uu"\+}*}*
       }
      "Si"?
     }*
    }*
   }*
  }*
 }?
}?
]W=
```
Many of the symbols are just the first two letters of the element's name. These are handled in the second-deepest layer of nested if statements. Many others are the first and third letter, or the first and fourth letter - these are handled in successive outer layers. Symbols where only the first letter appears, and complete irregulars, are handled in the fifth and third deepest layers respectively.
There are a few where it gets confused (`TelLurium` vs `ThaLlium`, or `SILicon` vs `SILver`, or `RUThenium` vs `RUTherfordium`). These are handled separately.
A lot of golfing could be done here, mostly by reusing code blocks and improving handling of irregulars.
[Answer]
# PHP, 507 485 476 466 characters
Usage: enter the element name as GET parameter '0' - elements.php?0=carbon
Algorithm: Run through the data string, pulling out substring,abbreviation code pairs. If the substring matches the start of the element passed in, use the abbreviation code to determine what to output: If the code starts with a letter, output it as a string. If it is a number N, output the first letter of the element + the Nth letter. The Unun elements are special-cased with the code '|'. If no substring is found that matches the name passed in, output the first two characters of the name as the abbreviation.
Readable Code:
```
<?
$l=ucfirst(strtolower($_GET[0]));
for(
  $m[3]="AnSbArs2As2Berk3Boh2BoBCad2Cae3Cali4CarCChl2Ch2Cope5CopCuCu5Da4Du2Ei3Fe3FluFGad2GoAuHaf2Ha2HyHIo0IroFeLaw3LePbLiv2Mag2Man2Mei3Men3MeHgNeod3Nep2Nio3NiNOxOPa5PhPPla3Plu2PotKProm3Pro4Rado4Rhe2Roe5Rub2Ruther6Sa2Sea6SilvAgSoNaSt2SuSTec2Ter3Tha3Thu6TinSnTuWUn|UUVVYtte5YYZin2Z2";
  preg_match('/(.[a-z]*)(.[a-z]*)(.*)/',$m[3],$m)
;)
    if(strstr($l,$m[1]))
        echo($x=$m[2][0])>'@'?$x>'{'?"Uu$l[4]":$m[2]:$l[0].$l[$x],die;
echo$l[0],$l[1];
```
Condensed:
```
<?$l=ucfirst(strtolower($_GET[0]));for($m[3]="AnSbArs2As2Berk3Boh2BoBCad2Cae3Cali4CarCChl2Ch2Cope5CopCuCu5Da4Du2Ei3Fe3FluFGad2GoAuHaf2Ha2HyHIo0IroFeLaw3LePbLiv2Mag2Man2Mei3Men3MeHgNeod3Nep2Nio3NiNOxOPa5PhPPla3Plu2PotKProm3Pro4Rado4Rhe2Roe5Rub2Ruther6Sa2Sea6SilvAgSoNaSt2SuSTec2Ter3Tha3Thu6TinSnTuWUn|UUVVYtte5YYZin2Z2";preg_match('/(.[a-z]*)(.[a-z]*)(.*)/',$m[3],$m);)if(strstr($l,$m[1]))echo($x=$m[2][0])>'@'?$x>'{'?"Uu$l[4]":$m[2]:$l[0].$l[$x],die;echo$l[0],$l[1];
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~121~~ ~~117~~ ~~112~~ ~~110~~ 109 bytes
```
•S²c¾rƒã∞Øø”.ÑSZl›¹'•2в°T•2nZιć‹ε˜Órv†„₃}Z$+àFQ$•7в1.•®DÝ∍ÌoƵižÒƵaŒ•2ô.;.;6ÝIS¬ì:slƵ{ö•X»²ÄµÕΛεĀδkM•9ävy%}èÙ™
```
[Try it online!](https://tio.run/##AcgAN/9vc2FiaWX//@KAolPCsmPCvnLGksOj4oiew5jDuOKAnS7DkVNabOKAusK5J@KAojLQssKwVOKAojJuWs65xIfigLnOtcucw5NyduKAoOKAnuKCg31aJCvDoEZRJOKAojfQsjEu4oCiwq5Ew53iiI3DjG/GtWnFvsOSxrVhxZLigKIyw7QuOy47NsOdSVPCrMOsOnNsxrV7w7bigKJYwrvCssOEwrXDlc6bzrXEgM60a03igKI5w6R2eSV9w6jDmeKEov//Z29MZA "05AB1E – Try It Online") or [validate all test cases](https://tio.run/##TVRBaxNBFP4rJSge1IIeFC1YkrRpi2kbkyga8TC7O80OnZ0JszPRRQpBC/agByuCopVSPXgQkWDEKvSwU3MRgr9h/0id7O687WnfzLx973vf997jIXIIPulH86WZizdmSvPRSTI4aMVDNz4S4139Mdn5oN/on8lgb1a/bHVoMvgVH54zPpf/DeNv7anBOpPD42fJ4HAy@vtevxL9ZLCfDD4kT55udc6c1/u1W2eM29V/w0uz5ht/XdB7yc4L/ZyPR@TPkd4dj9Cf3Wkg/X12bnbuit6LWvEX/eV6SMejx/qHebob/46Hejse6deTd5PR8WDyfXPV3F/Tn/rR2S39Wb9Ntg9OLpzcLy1HnuBdzEoXZkrLmBIVTK06kX5uVrCIqL2vcMFT1yoSTmatEQkB1h9FuVWjigvCcOqBM88W9/Iwq6jLcJgfylQFhOWHFqHEzdwbPg97PhcqTB8U3VAiTe1TCF0W3dyZSxTaiFVEXRvPRcxmbROJbJ47iCF7X/UFDwAZ6yKDLY2@YovlDqIyK9bdxDS76/VwiqdDmDv9LiGgaQmLAFKVRYgZSV1amGJ7XZkmzaq4KaKezFI1lUMsrpYhlsn8cE9KkZsdIgxF@WGNcMdi5zRyPMzyarHrM2x/byrpQ@qmD0o0DGggwpDfz2qqIs8ysnKKvxRi2WAKOIuyJJQqi2vFRM0KuotZzhyoXEHWrY6Y9FGOsortdUOgEHMvsnnXTh8ahiwMLdlCAURbVIL3LO3I4xRaqY2FZWYhCnuCWyjLnNq4i@DS9hUtqC5@rSsJJC6jDQhuikA0txXrhjLr@2bB8noIFArQtEGRJHntS5x6qW5YuEpkfPpFE9UxSp8rJAyMelmXUxC@HMppqJTvpik8GzuBmG39JuhadmXBipmoglSJTj3dFtCza7gnFQPMShZpA6OYTVEF7c2W2ITtYeaPbHBhf1kkzNADaWpmOGzHYuaZkejbrNwpNhB6KHBRy7R9hYlpS1pQDqwMjBwuurChfAFywUZYxUQyaLUFJALDngfDwTGTXRDOjDY24F2YMB@qr1EseB/mLXThUCdmdALgto2Z2SJhrs96ulNCo9GD/w).
[Answer]
## JavaScript (1100)
Naive implementation shining in its simplicity. Unique sub string from the start of the name is simply mapped to symbol.
```
e={hy:"H",he:"He",lit:"Li",bery:"Be",bor:"B",car:"C",nit:"N",ox:"O",flu:"F",neon:"Ne",so:"Na",mag:"Mg",al:"Al",sili:"Si",ph:"P",su:"S",chl:"Cl",arg:"Ar",pot:"K",calc:"Ca",sc:"Sc",tit:"Ti",v:"V",chr:"Cr",man:"Mn",iro:"Fe",cob:"Co",nic:"Ni",copp:"Cu",zin:"Zn",gal:"Ga",ge:"Ge",ars:"As",sel:"Se",br:"Br",k:"Kr",rub:"Rb",st:"Sr",yttr:"Y",zir:"Zr",nio:"Nb",mo:"Mo",tec:"Tc",ruthen:"Ru",rho:"Rh",pa:"Pd",silv:"Ag",cad:"Cd",in:"In",tin:"Sn",an:"Sb",tel:"Te",io:"I",x:"Xe",cae:"Cs",ba:"Ba",lan:"La",ce:"Ce",pra:"Pr",neod:"Nd",prom:"Pm",sa:"Sm",eu:"Eu",gad:"Gd",ter:"Tb",dy:"Dy",ho:"Ho",er:"Er",thu:"Tm",ytte:"Yb",lu:"Lu",haf:"Hf",ta:"Ta",tu:"W",rhe:"Re",os:"Os",iri:"Ir",pla:"Pt",go:"Au",mer:"Hg",tha:"Tl",le:"Pb",bi:"Bi",pol:"Po",as:"At",rado:"Rn",fr:"Fr",radi:"Ra",ac:"Ac",tho:"Th",prot:"Pa",ur:"U",nep:"Np",plu:"Pu",am:"Am",cu:"Cm",berk:"Bk",cali:"Cf",ei:"Es",fe:"Fm",men:"Md",no:"No",law:"Lr",ruther:"Rf",du:"Db",sea:"Sg",boh:"Bh",has:"Hs",mei:"Mt",da:"Ds",ro:"Rg",cope:"Cn",ununt:"Uut",fle:"Fl",ununp:"Uup",liv:"Lv",ununs:"Uus",ununo:"Uuo"}
n=prompt().toLowerCase()
for(i in e)n.indexOf(i)?i:alert(e[i])
```
[Answer]
## Golfscript - 1052 821
```
{.91<32*+}%:x;'H
He
Li
Be
B
C
N
F
Ne
Na
Mg
Al
Si
P
S
Cl
Ar
K
Ca
Sc
Ti
V
Cr
Mn
Fe
Co
Ni
Cu
Zn
Ga
Ge
As
Se
Br
Kr
Rb
Sr
Y
Zr
Nb
Mo
Tc
Ru
Rh
Pd
Ag
Cd
In
Sn
Sb
Te
I
Xe
Cs
Ba
La
Ce
Pr
Nd
Pm
Sm
Eu
Gd
Tb
Dy
Ho
Er
Tm
Yb
Lu
Hf
Ta
W
Re
Os
Ir
Pt
Au
Hg
Tl
Pb
Bi
Po
At
Rn
Fr
Ra
Ac
Th
Pa
U
Np
Pu
Am
Cm
Bk
Cf
Es
Fm
Md
No
Lr
Rf
Db
Sg
Bh
Hs
Mt
Ds
Rg
Cn
Uut
Fl
Uup
Lv
Uus'n/'hy
he
lit
bery
bor
car
nit
flu
neon
so
mag
al
sili
ph
su
chl
arg
pot
calc
sc
tit
v
chr
man
iro
cob
nic
copp
zin
gal
ge
ars
sel
br
k
rub
st
yttr
zir
nio
mo
tec
ruthen
rho
pa
silv
cad
in
tin
an
tel
io
x
cae
ba
lan
ce
pra
neod
prom
sa
eu
gad
ter
dy
ho
er
thu
ytte
lu
haf
ta
tu
rhe
os
iri
pla
go
mer
tha
le
bi
pol
as
rado
fr
radi
ac
tho
prot
ur
nep
plu
am
cu
berk
cali
ei
fe
men
no
law
ruther
du
sea
boh
has
mei
da
ro
cope
ununt
fle
ununp
liv
ununs
ununo'n/[{x\?)}/]1?=
```
Explanation:
```
{        }%                              Map these ops to the input string:
 .91<32*+                                   Add 32 if less than 91 (convert to lowercase, in essence)
           :x;                           Store to x.
              '...'  '...'               The first array is the symbols, the second is the names.
                                         (stripped down to the minimum necessary)
                   n/     n/             Convert them to arrays.
                             {    }/     For each element in the name array...
                              x\?)          ...return 1 if the element is found in the input.
                            [       ]    Gather every element in an array...
                                     1?  Find the 1 in the array (the only element name match)...
                                       = ...then return that symbol in the symbol array.
                               (implied) Print.
```
[Answer]
# Haskell, 920 817 807 776 Chars
After working far too long creating a system of rules for what characters of an elements name are included in its symbol, and a bit of tinkering, I managed to write a script that translates element to symbol easily. Iron was a problem for me, because I could sample certain characters from GOld, SilVer, TiN, LEad, SoDium, MerCury, ANtimony, PotaSsium, and TUngsten, converting them to an unused periodic symbol (I chose whichever sampling made it simplest to integrate them into the existing rules), and then translating after symbolic conversion; Iron, however, was a problem, because Ir, Io, and In are all used already. This was initially 920 characters, but I realized that the final pattern match (the largest) didn't need to be there, as it either let things drop through (which it didn't) or matched all of them; therefore, I replaced it with a catch-all wildcard. After that, I further golfed from 817 to 808 by abbreviating some patterns using wild-cards in such a way that they were still unique to that element name (e.g. the only element with a 'w' in its name is Lawrencium, so "\*w" matches that in 1 less character than "Law").
Here is my code. I tested it for all of the elements, and I coded it so that it automatically converted its input to titlecase, so no issues with case sensitivity.
## EDIT 1
I further reduced it to 776 characters by replacing the case expression in t with a pattern match (this makes sense because the case expression was testing the raw operand as opposed to an expression in terms of the operand), removing unnecessary parentheses, and re-expressing `e` as a newline-delimited string instead of a list of strings, and later splitting it in the main function. Because these changes are purely golfing, I have left the human-readable version unchanged.
```
import Data.Char
m _[]=True;m[]_=False;m k@(c:s)x@(y:z)=case y of{']'->m s x;'['->let(i,(_:j))=break(==']')z in(c`elem`i)&&m s j;'?'->m s z;'*'->null z||m k z||m s z||m s x;_->c==y&&m s z};p(a:t)(x:y)=case a of{'.'->x:p t y;'_'->p t y;_->a:p t y};p[]_=[];e="Iro\nUn\nCu Pa Ro Y*e\nR*r\n*pp\nCop Rado\nSea Thu\nCali Da P*ot Tha\nA*s Boh ?ub Ch [CG]ad [HM]a Liv Nep Plu Rhe S[ato] Tec Tin Z\nB*k Cae [ES]i *w Nio [FM]e N*d Pro Pla Ter\nBor Car Flu Hy Io Nit Ox Ph Su [UVY]\n*";s="Fe ._._. .____. .f .u .n ._____. .___. ._. .__. . ..";t"Sv"="Ag";t"Sd"="Na";t"Go"="Au";t"Le"="Pb";t"Mc"="Hg";t"An"="Sb";t"Ps"="K";t"Tu"="W";t"Tn"="Sn";t x=x;main=interact$unlines.map(\(a:b)->let y=toUpper a:map toLower b in t$p(snd.head.filter(any(m y).fst)$zip(map words$lines e)$words s)y).lines
```
Human-Readable Version (newlines, spacing, verbose names, comments: 2311 Chars) 
```
import Data.Char
-- Test against search-pattern strings
match _ [] = True
match [] _ = False
match k@(c:s) x@(y:z) = case y of
']' -> match s x
'[' -> let (i,(_:j)) = break (==']') z in (c `elem` i) && match s j
'?' -> match s z
'*' -> null z || match k z || match s z || match s x
 _  -> c == y && match s z
-- Write according to name-pattern string
pattern (a:t) (x:y) = case a of
'.' -> x : (pattern t y)
'_' -> (pattern t y)
 _  -> a : (pattern t y)
pattern [] _ = []
-- Search-Patterns for the elements
elements=["Iro", -- Iron -> Fe
      "Un", -- UnUn-Blank-ium (1,3,5)
      "Cu Pa Ro Y*e", -- CuriuM PallaDium RoentGenium YtterBium (1,6)
      "R*r", -- Rutherfordium (1,f)
      "*pp", -- Copper (1,u)
      "Cop Rado", -- Copernicium Radon (1,n)
      "Sea Thu", -- SeaborGium ThuliuM (1,7)
      "Cali Da P*ot Tha", -- CaliFornium DarmStadtium ProtActinium PotaSsium (1,5)
      {- AsTatine ArSenic BoHrium DuBnium RuBidium ChLorine ChRome CaDmium
      GaDolinium HaFnium HaSsium MaNganese MaGnesium LiVermorium NePtunium
      PlUtonium RhEnium SaMarium StRontium SoDium TeChnetium TiN ZiNc
      ZiRconium (1,3) -}
      "A*s Boh ?ub Ch [CG]ad [HM]a Liv Nep Plu Rhe S[ato] Tec Tin Z", 
      {- BerKelium CaeSium EinSteinum SilIcon SilVer LawRencium NioBium
      FerMium MenDelevium MeiTnerium MerCury NeoDymium ProMethium PlaTinum
      TerBium (1,4) -}
      "B*k Cae [ES]i *w Nio [FM]e N*d Pro Pl Ter",
      {- Boron Carbon Fluorine Hydrogen Nitrogen Oxygen Phosphorous Sulphur
      Uranium Vanadium Yttrium (1) -}
      "Bor Car Flu Hy Io Nit Ox Ph Su [UVY]",
      "*"] -- Everything else (1,2)
-- respective naming patterns for searches
symbol = "Fe ._._. .____. .f .u .n ._____. .___. ._. .__. . .."
-- Translate fake symbols
translate x = case x of
"Sv" -> "Ag" -- SilVer
"Sd" -> "Na" -- SoDium
"Go" -> "Au" -- GOld
"Le" -> "Pb" -- LEad
"Mc" -> "Hg" -- MerCury
"An" -> "Sb" -- ANtimony
"Ps" -> "K" -- PotaSsium
"Tu" -> "W" -- TUngsten
"Tn" -> "Sn" -- TiN
  _  -> x  -- Keep everything else the same
main = interact $ unlines . map (\(a:b) -> let y = (toUpper a) : (map toLower b) in t $ p (snd.head.filter (any (m y) . fst) $ zip (map words e) $ words s) $ y) . lines
```
If anyone is interested in an explanation for any part of this, feel free to ask.
[Answer]
## C# (826)
not the greatest but I thought I'd try it with the handicap of c#.
```
using System;class P{static string s="HyHHe1Li1Be1BoBCaCNitNOxOFlFNe1SoNaMaMgAl1Sil1PhPSuSChClAr1PotKCal1Sc1Tit1VaVChrCrManMnIrFeCo1Ni1CopCuZiZnGa1Ge1ArsAsSe1Br1Kr1RuRbStSrYtYZirZrNioNbMo1TecTcRut1Rh1PaPdSiAgCadCdIn1TiSnAnSbTel1IoIXe1CaeCsBa1La1Ce1Pra1NeoNdPrPmSaSmEu1GadGdTeTbDy1Ho1Er1ThTmYttYbLu1HaHfTa1TuWRheReOs1Iri1PlPtGoAuMeHgThaTlLePbBi1Po1AsAtRaRnFr1Rad1Ac1Tho1ProPaUrUNepNpPluPuAm1CuCmBerBkCaliCfEiEsFeFmMenMdNo1LawLrRuthRfDuDbSeaSgBohBhHasHsMeiMtDaDsRoRgCopeCnUnUutFle1UnuUupLivLvUnunUus",n,t,k;static void Main(){var d=new System.Collections.Specialized.StringDictionary();while(s!=""){k=g;d[k]=g;if(d[k]=="1")d[k]=k.Substring(0,2);};t=Console.ReadLine();while(t!=""&!d.ContainsKey(t))t=t.Remove(t.Length-1);Console.Write(d[t]);}static string g{get{n="";do n+=s[0];while((s=s.Remove(0,1))!=""&&s[0]>96);return n;}}}
```
So I wrote a program to turn the full name of elements (e.g. carbon) in to the smallest but still unique string possible and did this for all elements with respect to all the other unique strings. I then serialized that in to a big ugly string where capital letters denote the start of "chunks", with chunks alternating between being keys and values. Like KeyValueKey2Value2 etc.
This script desterilizes that big string and cuts a character off the end of the inputted string until it finds it in the dictionary made from the big string.
(I should add my knowledge of C# isn't amazing and the original submission I made was just using things I knew but I've subsequently had some tricks pointed out to me by others.)
[Answer]
JavaScript (E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$="Yb
Let$="Lu
Hni$="Hf
Tta$="Ta
Tgs$="W
Rni$="Re
Oiu$="Os
Idi$="Ir
Pti$="Pt
Gd$="Au
Mcu$="Hg
Tll$="Tl
Ld$="Pb
Bmu$="Bi
Pon$="Po
Aat$="At
Ron$="Rn
Fnc$="Fr
Riu$="Ra
Ain$="Ac
Tri$="Th
Pta$="Pa
Uni$="U
Ntu$="Np
Pto$="Pu
Ari$="Am
Ciu$="Cm
Bke$="Bk
Cif$="Cf
Est$="Es
Fmi$="Fm
Mde$="Md
Nel$="No
Lre$="Lr
Dni$="Db
Sbo$="Sg
Bri$="Bh
Hsi$="Hs
Mtn$="Mt
Dms$="Ds
Rnt$="Rg
Cer$="Cn
Unt$="Uut
Fro$="Fl
Unp$="Uup
Ler$="Lv
Uns$="Uus
Uno$="Uuo
S$=VAR(E$[0]+MID$(E$,3,2))IF"Cm"==S$*!VAL(".1"+E$[1])THEN S$="Ce
IF LEN(E$)>12THEN S$="Rf
?S$
```
I chose 3 characters which were mostly unique (the 0th, 2nd, and 3rd), which leaves 2 special cases: Cerium/Curium are both "Ciu", and Ruthenium/Rutherfordium are both "Rhe". For Ciu, I check if the second character of the name is "e" or "E", and for "Rhe", I check the length of the name.
`VAR(name)` returns the variable with that name. Variable names are case insensitive.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~291~~ ~~286~~ 276 bytes
```
.*
$u
Pot
K
op
u
Iro
Fe
Silv
Ag
Tin
Sn
0L`.*f|[RS].*g|[CGP]a.*d|(As|Ch|G|Law|Ma|Me.|Pla?|Prot?|Rado|St|Tha|Unun|Zi).|Flu|N[ei]o?[bdpt]|[ACEH].*s|[BDLRST].[bcehmv]|..+r[bkmn]s?|[CT]h?u.*m|..
\B.*\B
T`l``[FHKNOSVY][at-y]|Cb|Bo|Io|Ph|Ur
So
Na
An
Sb
Tu
W
Go
Au
Mc
Hg
Le
Pb
U.
U$l
```
[Try it online!](https://tio.run/##PVTtbuM4DPzP59gDdnM44@4JAsdtkqJJGsTJftRrILLNWkJlyZCl7gbQu3cpyb1fYmhpyBkOY9AKxf57/@vz5vqeLeCTg6O28Ah6BAcPRsMaoRTyDfIezkJBqeDf3TVbvPjqVNbZovdVsTnWLFt0/nM@@YL7jd@xX37P/B4zf5Rs6Y9G26U/sU770vozZ/6inPLP4kvm19L5Q4Wi1suq6UZb@yov7rcEPflqdbc7lec6q5oW@fBW@yz721TN66DqaUmVzzVfumwxUB5@rrLFzxXA@Sqv12q9fTw8lV9/1BWz/9xqXzR@pf2D9kfuLwZKDQcGOfFp4OzgG2w05A72LWx72CEcG7hkcPkk39@3t87oHhVwlMINsBOWh3OF5iZjptFGKyiYaehQwqbrT79v4SB@2giFoJC@TroLL/asVziFKJduECpEpLJo6cqR62nk2rgJSidH7gwUXCaM3PR0Y9SWTfF1wWQb37ZMReCzsCyifWWKxUzBjR5STdUzqophrNSubpi0cBDtK0r6NY5o4FmoFjYs0dqgGRJYbiZUooUSJcbEKmBSP4/mNloCO7lGxGolkVc2RD@sNeF8FoZYheggdBMb0fLWdKhCu9hyhfH@yVmewE88iXSkPhKHYEDqrmBdZPLwwVXRBK0YtLoRkpQuFnyg19Tad1RxKEnmFYvfdkxZzkLlAmPiaNiEurtF3MP/ERl2wDTmkg3p7b0zeoy6kI9lmtkZTaR0d5tGo2OlrZYR4j59OXMnZznmuztnE@Mte0kg1BSTIXCqnyx55jQr8TQlviaJS7tE2xo60LKDPZrWGWLO53ntkHWwEtNAStIWy6R6PtnwCiGsH9nRMBUtc0rS5q2dqZDlZuqWfSQvJhnggKN1KvXg7Aw8kIQRqkjC00K8phUhW4oXbeK1e6GIU4Jbk6OiA1B1ZKW3CK2bea/YL4Nzb8ELhhBii3euSQuCjDatj6U0N0nCtAd7FFalid4xMxDlLplKo7J9EpMsjtRSLBD@fpI91xKNfvvIjZjMuxPktyEJEvIT8f@IdRvCPw "Retina – Try It Online")
[Verification script](https://tio.run/##PVXLbuM4ELzzK7y5JMEOFrvYW4AcbPmJ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vBBP8p901/3xiRouWnLCKowVmGte/a/psW85AT35/4QzrAbvsq7t/sX21T23hz@/b3O3owsAPrBro/vP7PXd@@K1Xev72rH5WtzeCfOzWI4XJX/om3runw8l0NzM8DwtwVwegPpX77ATBO5gZSe1Pc3uKhPQ6KN/v@x32J/7AHDVYOwkyeN5NsNxlff@P9t8H1bL2DkT67/fqaY@1i2WLDqpHK1Eqt1RSrESsRixC7D@tObVSOTYbtpR6wprCbsI/UE9YOVg22C7YKdgk2CPYG9gWWBPYClgEWAFQfUg95Vy9QcQg31Br6DEWGCEN5IbaQWOgq1BQyCulUC0gklBFyCBGE7kHtoG4QNEgYZAtSBXGCIkGDIDyQG2gMZAVSAv1Q3yET0AYoAmQA1AflwXNwG5wGkUFeEBY8BTfBSLAQ1FN70AuMAonAG7AFBAEjQAHgHkAHuAFnoBeQBUiBTMARAATggLAEKcAoIQdYSeBIcPgF "Python 3 – Try It Online") (Python)
## Explanation
```
.*
$u
```
Convert the first letter of the input to uppercase and the rest to lowercase.
```
0L`.*f|[RS].*g|[CGP]a.*d|(As|Ch|G|Law|Ma|Me.|Pla?|Prot?|Rado|St|Tha|Unun|Zi).|Flu|N[ei]o?[bdpt]|[ACEH].*s|[BDLRST].[bcehmv]|..+r[bkmn]s?|[CT]h?u.*m|..
```
Truncate each element name, ending with the intended second letter. The default case `..` matches the first two letters of the element name.
```
\B.*\B
```
Keep only the first and last letter.
```
T`l``[FHKNOSVY][at-y]|Cb|Bo|Io|Ph|Ur
```
Remove the lowercase letters from the single-letter abbreviations.
```
U.
U$l
```
Insert the `u` for the elements that require it.
---
The rest of the program deals with various special-case replacements. Some of these occur before the main regex because those elements share their first two letters with another.
[Answer]
# T-SQL, ~~900 894~~ 676 bytes
```
SELECT ISNULL((SELECT LEFT(value,3)FROM
STRING_SPLIT('Sb An-As Ars-At Ast-Bk Berk-Bh Boh-B  Bor-Cd Cad-Cs Cae-Cf Cali-C  Car-Cl Chl-Cr Chr-Cn Cope-Cu Copp-Cm Cu-Ds Da-Db Du-Es Ei-Fm Fe-F  Flu-Gd Gad-Au Go-Hf Haf-Hs Has-H  Hy-I  Io-Fe Iro-Lr Law-Pb Le-Lv Liv-Mg Mag-Mn Man-Mt Mei-Md Men-Hg Mer-Nd Neod-Np Nep-Nb Nio-N  Nit-O  Ox-Pd Pa-P  Ph-Pt Pla-Pu Plu-K  Pot-Pm Prom-Pa Prot-Rn Rado-Re Rhe-Rg Ro-Rb Rub-Rf Ruther-Sm Sa-Sg Sea-Ag Silv-Na So-Sr St-S  Su-Tc Tec-Tb Ter-Tl Tha-Tm Thu-Sn Tin-W  Tu-UuoUnuno-UupUnunp-UusUnuns-UutUnunt-U  Ur-V  V-Yb Ytte-Y  Yttr-Zn Zin-Zr Zir'
    ,'-')m,t WHERE e LIKE SUBSTRING(value,4,9)+'%'),
(SELECT UPPER(LEFT(e,1))+LOWER(SUBSTRING(e,2,1))FROM t))
```
Returns are for readability only, the second line is one very long string.
`STRING_SPLIT` is supported in SQL 2016 and higher.
Input is taken via a pre-existing table **t** with varchar field **e**, [per our IO standards](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/5341#5341). Output is padded with spaces to 3 characters; the rules were unclear on whether that was ok. If necessary, I can add a `TRIM`.
The input table is joined with a table generated with a list of all element symbols (padded to 3 characters) with the shortest unique prefix for each element name (`X` is sufficient for *Xenon*, but *Rutherfordium* requires `Ruther` to distinguish it from *Ruthenium*).
**EDIT 1**: Saved 218 characters by removing the 44 entries from the list whose symbol is the first two letters of their name; the `ISNULL` function is used to see if the first query fails to return a row, and if so, generates the symbol (properly cased) from the input element name.
]