text:
Latin Word Judgment
Because I can't concentrate on any task for more than about 5 seconds, I often find myself breaking up words into a sub-strings, each of which is a different length and doesn't contain any repeated characters. For example, the word "pasta" might be broken up in "past" & "a", "pas" & "ta", or "pa" & "sta" and you get the picture.
However, because remembering all the combinations is hard, I generally only select one, and I like to select the nicest one. We consider the nicest way to be that which has the lowest "score". Your task will be, given a word, to print its score, given the following complicated rules.
Scoring
Description of how to score a word:

A word is a string of Latin characters, capital letters should be replaced with 2 of the same lowercase letter (so "Box" becomes "bbox")
A segment is a contiguous (strict) substring of a word, and must not contain any character twice ("her", "re", "h" are all valid segments of "Here" ("hhere"), but "hh" and "ere" are not)
A segmentation is a set of segments of different lengths which, when joined, form the original word ("tre" and "e" makes "tree"), and that cannot be further segmented within the segmentation (i.e. "ba" has a single segmentation, "ba"; and "alp" & "habet" is not a valid segmentation of "alphabet", because either of these could be further segmented (e.g. into "a" & "lp" & "habet", which is now a valid segmentation ("habet" can't be segmented without forming a segment of length 2 or 1))).
The score of a segmentation is the sum of the scores of each distinct character that appears in the original word (once capitals have been replaced)
The scoring of characters is explained below
The score of a word is the score of its nicest possible segmentation (that with the lowest score)

If no valid segmentations exist for a word (for example, "Brass" ("bbrass"), which can't be segmented because the first "b" and last "s" would have to be in their own segments, which would result in two segments of the same length), then you should output the text "evil", otherwise you should output the score of the word.
Character scoring
The scoring of characters is based on how many times the character appears, and the weightings of the segments it appears in. The weightings of the segments depends on the lengths of the segment, and the lowest common multiple of the lengths of all the segments in the segmentation.
segment weighting = lowest common multiple of lengths segments / length of segment

Consider the word "olive", which could be segmented as "ol" & "ive", and visualised as 2 boxes of the same area, one of "ol" with weight 3, and one of "ive" with weight 2 (LCM of 6).
ol
ol ive
ol ive

This is meant to depict the two boxes, one made from 3 "ol"s, and one made from 2 "ive"s. Alternativly, it might be "o" & "live" (LCM of 4)
o
o
o
o live

The score of each character is then the sum of the weights of the segments in which it appears, multiplied by the number of times it appears after replacing capitals (so if it appears twice, you are charged double for each time you have to say it).
character score = character count * sum(segment weights in which character appears)

Scoring example
We take the word "fall", it can only be segmented into "fal" and "l". The lowest common multiple of 3 and 1 is 3, so "fal" has weight 1, and "l" has weight 3.
    l
    l
fal l

Going through each character...

"f" appears once, and is in the segment "fal" with weight 1, so has score 1*1 = 1
"a" also appears only once, has sum of weights of 1, so has score 1*1 = 1
"l" appears twice, and appears in "fal" (weight 1) and "l" (weight 3), so has score 2*(1+3) = 8

The sum of these is 10 (the score of the segmentation, and of the word, as this is the nicest segmentation). Here is this in the same format as the examples below:
fall = fal l
2*1 [fa] + 2*(1+3) [ll] = 10

Example Scorings
These examples of scorings may or may not help:
class -> clas s
3*1 [cla] + 2*(4+1) [ss] = 13

fish -> fis h
3*1 [fis] + 1*3 [h] = 6

eye -> e ye
1*1 [y] + 2*(1+2) [ee] = 7

treasure -> treas u re
3*2 [tas] + 2*2*(2+5) [rree] + 1*10 [u] = 44

Wolf -> w wolf
3*1 [olf] + 2*(1+4) = 13

book
evil

"book" is an evil word, so doesn't have a score.
Note that "treasure" can be segmented in a number of ways, but the segmentation shown benefits from having the more frequent letters ("r" and "e") in the longer segments, so they don't have as much weight. The segmentation "t" & "re" & "asure" would give the same result, while "treas" & "ur" & "e" would suffer, with "e" having a score of 2*(1+10+2) = 24 on its own. This observation is really the spirit of the whole exercise. An example of an incorrect score of "treasure" (incorrect because it's not derived from the score of the nicest segmentation (that with the lowest score)):
treasure = treas ur e
3*2 [tas] + 2*(2+5) [rr] + 1*5 [u] + 2*[2+10] = 49

Input
A single string containing only latin characters of either case ("horse", "Horse", and "hOrSe" are all valid inputs) which can be accepted either by STDIN, Command-line argument, function argument, or otherwise if your language of choice doesn't support any of the aforementioned.
Output
You must output either the score of the word, which is a single positive integer greater than 0, or "evil" if no segmentation exists. Output should be to STDOUT or the return argument of a function, unless your language of choice supports neither of these, in which case do something sportsmanly.
Examples
I do not expect you to print all this stuff, all I want is the score of the word, or the output "evil", for example (input followed by output)
eye
7

Eel
evil

a
1

Establishments
595

antidisestablishmentarianism
8557

I'm not concerned about performance, if you can score just about any 15letter word (after replacing capitals) in under a minute on a sensible (intentionally left vague) machine, that's good enough for me.
This is code-golf, may the shortest code win.
Thanks to PeterTaylor, MartinBüttner, and SP3000 for their help with this challenge

If you can't concentrate on any task for longer than 5 seconds, writing out this challenge must have taken you forever!

Mathematica, 373 bytes
If[l=Length;a=Accumulate[l/@#]&;u=Unequal;e=Select;{}==(m=(g=#;Tr[#2Flatten[ConstantArray[#,LCM@@l/@g/l@#]&/@g]~Count~#&@@@Tally@c])&/@e[p=e[c~Internal`PartitionRagged~#&/@Join@@Permutations/@IntegerPartitions[l[c=Characters[s=StringReplace[#,c:"A"~CharacterRange~"Z":>(d=ToLowerCase@c)<>d]]]],u@@l/@#&&And@@u@@@#&],FreeQ[p,l_List/;#!=l&&SubsetQ[a@l,a@#]]&]),"evil",Min@m]&

This is quite long... and also rather naive. It defines an unnamed function that takes the string and returns score. It takes about 1 second to handle "Establishments", so it's well within the time limit. I've got a slightly shorter version that uses Combinatorica`SetPartitions, but it already takes a minute for "Establishme".
Here is a version with whitespace:
If[
  l = Length;
  a = Accumulate[l /@ #] &;
  u = Unequal;
  e = Select;
  {} == (
    m = (
      g = #;
      Tr[
        #2 Flatten[
          ConstantArray[
            #,
            LCM @@ l /@ g/l@#
          ] & /@ g
        ]~Count~# & @@@ Tally@c
      ]
    ) & /@ e[
      p = e[
        c~Internal`PartitionRagged~# & /@ Join @@ Permutations /@ IntegerPartitions[
          l[
            c = Characters[
              s = StringReplace[
                #,
                c : "A"~CharacterRange~"Z" :> (d = ToLowerCase@c) <> d
              ]
            ]
          ]
        ],
        u @@ l /@ # && And @@ u @@@ # &
      ],
      FreeQ[p, l_List /; # != l && SubsetQ[a@l, a@#]] &
    ]
  ),
  "evil",
  Min@m
] &

I might add a more detailed explanation later. This code uses the second solution from this answer to get all the partitions and this solution to make sure they are all maximally segmented.

Java 8, 1510 1485 bytes
This is way too long. Combinatorics are never easy in java. It definitely can be shortened quite a bit. Call with a(string). This uses an exponential memory and time algorithm; so don't expect it to work for long inputs. It takes about half a second to process Establishments. It crashes with an out of memory error for antidisestablishmentarianism.
import java.util.*;import java.util.stream.*;void a(String a){a=a.replaceAll("\\p{Upper}","$0$0").toLowerCase();List<List<String>>b=b(a),c;b.removeIf(d->d.stream().anyMatch(e->e.matches(".*(.).*\\1.*")));b.removeIf(d->{for(String e:d)for(String f:d)if(e!=f&e.length()==f.length())return 1>0;return 1<0;});c=new ArrayList(b);for(List<String>d:b)for(List<String>e:b){if(d==e)continue;int f=0,g=0;List h=new ArrayList(),i=new ArrayList();for(String j:d)h.add(f+=j.length());for(String k:e)i.add(g+=k.length());if(i.containsAll(h))c.remove(d);else if(h.containsAll(i))c.remove(e);}b=c;int d=-1;for(List e:b)d=d<0?c(e):Math.min(c(e),d);System.out.println(d<0?"evil":d);}int c(List<String>a){List<Integer>b=a.stream().map(c->c.length()).collect(Collectors.toList()),d;int e=d(b.toArray(new Integer[0])),f=0,g=0,h;d=b.stream().map(A->e/A).collect(Collectors.toList());Map<Character,Integer>i=new HashMap(),j=new HashMap();for(;g<a.size();g++){h=d.get(g);String k=a.get(g);for(char l:k.toCharArray()){i.put(l,i.getOrDefault(l,0)+1);j.put(l,j.getOrDefault(l,0)+h);}}for(char k:i.keySet())f+=i.get(k)*j.get(k);return f;}int d(Integer...a){int b=a.length,c,d,e;if(b<2)return a[0];if(b>2)return d(a[b-1],d(Arrays.copyOf(a,b-1)));c=a[0];d=a[1];for(;d>0;d=c%d,c=e)e=d;return a[0]*a[1]/c;}List b(String a){List<List>b=new ArrayList(),c;for(int i=0;++i<a.length();b.addAll(c)){String d=a.substring(0,i),e=a.substring(i);c=b(e);for(List f:c)f.add(0,d);}b.add(new ArrayList(Arrays.asList(a)));return b;}

Try here
Indented with explanation:
void a(String a){
    a = a.replaceAll("\\p{Upper}", "$0$0").toLowerCase();                //Replace all uppercase letters with two lowercase letters

    List<List<String>> b = b(a), c;                                      //Generate partitions
    b.removeIf(d -> d.stream().anyMatch(e -> e.matches(".*(.).*\\1.*")));//Remove partitions that contains duplicate letters

    b.removeIf(d -> {                                                    //Remove partitions that have equal length parts
        for (String e : d)
            for (String f : d)
                if (e != f & e.length() == f.length())
                    return 1 > 0;
        return 1 < 0;
    });

    c = new ArrayList(b);                                                //Remove partitions that can be partitioned further
    for (List<String> d : b)                                             //Uses Martin's technique
        for (List<String> e : b){
            if (d == e)
                continue;
            int f = 0, g = 0;
            List h = new ArrayList(), i = new ArrayList();
            for (String j : d)
                h.add(f += j.length());
            for (String k : e)
                i.add(g += k.length());
            if (i.containsAll(h))
                c.remove(d);
            else if (h.containsAll(i))
                c.remove(e);
        }

    b = c;

    int d = -1;
    for (List e : b)
        d = d < 0 ? c(e) : Math.min(c(e), d);                            //Find nicest partition

    System.out.println(d < 0 ? "evil" : d);
}

int c(List<String> a) {                                                  //Grade a partition
    List<Integer> b = a.stream().map(c->c.length()).collect(Collectors.toList()), d; //Map to length of parts

    int e = d(b.toArray(new Integer[0])), f = 0, g = 0, h;

    d = b.stream().map(A -> e / A).collect(Collectors.toList());         //Figure out the weight of each part

    Map<Character, Integer> i = new HashMap(), j = new HashMap();

    for (; g < a.size(); g++){                                           //Count instances of each character and
        h = d.get(g);                                                    //weight of each character
        String k = a.get(g);
        for (char l : k.toCharArray()){
            i.put(l, i.getOrDefault(l, 0) + 1);
            j.put(l, j.getOrDefault(l, 0) + h);
        }
    }

    for (char k : i.keySet())
        f += i.get(k) * j.get(k);                                        //Sum cost of each character

    return f;
}

int d(Integer... a) {                                                    //Find lcm
    int b = a.length, c, d, e;
    if (b < 2)
        return a[0];
    if (b > 2)
        return d(a[b - 1], d(Arrays.copyOf(a, b - 1)));
    c = a[0];
    d = a[1];
    for (;d > 0;d = c % d, c = e)
        e = d;
    return a[0] * a[1] / c;
}

List b(String a) {                                                       //Find all partitions of a string
    List<List> b = new ArrayList(), c;                                   //Uses recursion
    for (int i = 0; ++i < a.length();b.addAll(c)){
        String d = a.substring(0, i), e = a.substring(i);
        c = b(e);
        for (List f : c)
            f.add(0, d);
    }
    b.add(new ArrayList(Arrays.asList(a)));
    return b;
}

This also abuses generics quite a bit to reduce the byte count. I'm pretty surprised I was able to get all of it to compile.
Thanks Ypnypn :)

Wow, this is impressive! A few golfing notes: There are extra spaces with in the i.put... line and the while loop; I think while(d!=0) can be while(d>0); there's no need for new ArrayList at the end since Arrays.asList gives an ArrayList anyway; in the final method you can define b as a plain List.

@Ypnypn Thank you for your suggestions :) Arrays.asList returns an unmodifiable ArrayList, so I can't use that without getting an OperationNotSupportedException. b can be a plain list, but c needs to stay a List<List<String>>. I'll check to see if while(d>0) works tomorrow.

C# 679 Bytes
This solution is roughly based off my the structure of my original test implementation, and initially was just a golfed re-write, but then I inlined all the functions, and now it's horrifying. It's reasonably fast, solving Establishments in under a second. It's a complete program that takes the input word as a single paramater of ARGV.
using Q=System.String;class P{static void Main(Q[]A){Q s="";foreach(var c in A[0]){var z=(char)(c|32);if(c<z)s+=z;A[0]=s+=z;}int r=S(A);System.Console.WriteLine(r<1?"evil":""+r);}static int S(Q[]s){int r=0,t,j,k,L=1,Z=s.Length,i=Z,T=0,R=2;for(;i-->0;R=t<1?0:R){t=s[i].Length;k=L;for(j=2;t>1;)if(t%j++<1){t/=--j;if(k%j<1)k/=j;else L*=j;}}foreach(var C in Q.Join("",s))for(i=Z;i-->0;){for(k=s[j=i].Length;j-->0;)R=k==s[j].Length?0:R;j=s[i].IndexOf(C)+1;R=j*R*s[i].IndexOf(C,j)>1?1:R;T+=j>0?L/k:0;}i=R<1?0:Z;for(var U=new Q[Z+1];i-->0;)for(j=s[i].Length;j-->1;r=r<1|((t=S(U))>0&t<r)?t:r)for(U[k=Z]=s[i].Substring(j);k-->0;U[i]=s[i].Substring(0,j))U[k]=s[k];return r<1?R<2?R-1:T:r;}}

The Main method starts by creating a copy of the input with the capitals replaced. It then calls S, the "solver", which returns the score of a given segmentation (the first segmentation being that with a single segment which is the whole word). It then either prints "evil" or the score, depending on the score.
The "solver" (S) does all the interesting stuff, and was originally broken down down into 4 methods, which were rolled together. It works by first scoring the current segmentation, making a note of whether it is invalid (and crucially, whether it is so invalid we shouldn't try to further segment it (for performance), skipping the rest of the computation if it is). Then, if it hasn't been skipped, it splits each segment in the segmentation everywhere it can be split, and finds the best score of all of these (recursively calling S). Finally, it either returns the best score of the subordinate Segmentations, else it's own score, or invalid if it's own segmentation is invalid.
Code with comments:
using Q=System.String; // this saves no bytes now

class P
{
    // boring
    static void Main(Q[]A)
    {
        // this can surely be shorter
        // replace capitals
        // I refuse to put this in S (would give us a Q, but we'd have to pay for the Action=null)
        Q s="";

        foreach(var c in A[0])
        {
            var z=(char)(c|32); // ugly
            if(c<z)
                s+=z; // ugly
            A[0]=s+=z; // reuse the array
        }

        int r=S(A); // reuse the array
        System.Console.WriteLine(r<1?"evil":""+r);
    }

    // solve
    static int S(Q[]s) // s is current solution
    {
        int r=0,t,j,k,
        L=1,Z=s.Length,i=Z,
        T=0, // is score for this solution (segmentation)
        R=2; // R is current return value, as such, 0 -> return -1, 1 -> return 0, 2 -> return T

        // score first
        // factorise stuff, L is LCM
        for(;
            i-->0; // for each segment
            R=t<1?0:R) // segment too short (skip)
        {
            t=s[i].Length;

            k=L; // we cut up k as we cut up c, when we can't cut up k, we need to build up L
            for(j=2;t>1;)
                if(t%j++<1) // j goes into t
                {
                    t/=--j; // cut up t
                    if(k%j<1) // j goes into k
                        k/=j; // cut up k
                    else
                        L*=j; // j does not go into k, build up L
                }
        }

        // recycle i, j, k, (t)

        foreach(var C in Q.Join("",s)) // for each character
            for(i=Z;i-->0;) // for each segment
            {
                for(k=s[j=i].Length;
                    j-->0;) // for all the segments that follow
                    R=k==s[j].Length?0:R; // repeat length (skip)

                j=s[i].IndexOf(C)+1;

                // these both check if this segment contains the char (j > 0)
                R=j*R*s[i].IndexOf(C,j)>1?1:R; // duplicate char (allow)

                T+=j>0?L/k:0; // add on the segment weight
            }

        // R is whether we are invalid or not
        // T is our score

        i=R<1?0:Z; // if segmentation invalid and can't be segmented, skip everything (performance)

        // recycle i, j, k, t
        // first use of r=0

        for(var U=new Q[Z+1];
            i-->0;) // for each segment
            for(j=s[i].Length;
                j-->1; // for each place we can split it
                r=r<1|((t=S(U))>0&t<r)?t:r) // solve where we split thing at i at position j, if this score is better than r, replace r with it
                for(U[k=Z]=s[i].Substring(j); // put second half of s[i] in last position (order doesn't matter)
                    k-->0; // for each char in s[i]
                    U[i]=s[i].Substring(0,j)) // put first half of s[i] in p position
                    U[k]=s[k]; // copy across everything else

        return r<1?R<2?R-1:T:r; // if we didn't find a valid solution more segmented than this, return our score (unless we are invalid, in which case, return R-1), else the score for the more segmentation solution
    }
}


text:
A Basic Pyth-like Syntax Checker
Pyth is a golfing language based on Python. It uses prefix notation, with each command having a different arity (number of arguments it accepts).
Your task is to write a syntax checker for a (non-existent) Pyth-like language, Pith.
Pith's syntax
Pith only has 8 single-char commands:
01234()"

01234 each have arity of the corresponding number, and hence expect that many arguments after it. For example,
400010

is a correct Pith program because 4 is followed by four arguments 0 0 0 and 10, the last of which is a 1 followed by the single argument 0. To visualise this, we can look at the following tree:
      R
      |
      4
      |
-------------
|   |   |   |
0   0   0   1
            |
            0

where R is the root node. An alternative way to think about this is that each number refers to the number of children the corresponding node has in the tree above.
Here's another valid Pith program, with more than one base command:
210010

corresponding to
           R
           |
     -------------
     |           |
     2           1
     |           |
 ---------       0
 |       |
 1       0
 |
 0

On the other hand,
3120102100

is not a correct Pith program because the initial 3 only has two arguments, which we can see by looking at the tree below:
                R
                |
                3
                |
     ------------------------ ??
     |          |
     1          2
     |          |
     2        ------
     |        |    |
   ------     1    0
   |    |     |
   0    1     0
        |
        0

Next ( starts an unbounded, and ) ends an unbounded. An unbounded takes any number of arguments (greedily), and counts as a single argument to any parent command. Any unboundeds still open by the end of the program are automatically closed. A ) command is not an error if no unboundeds are open — it just does nothing.*
For instance, the Pith program
)31(0)0(201000100

corresponds to the tree
            R
            |
            3
            |
    ------------------------------
    |       |                    |
    1       0                    (
    |                            |
    (              -----------------------------
    |              |      |      |      |      |
    0              2      0      0      1      0
                   |                    |
                -------                 0
                |     |
                0     1
                      |
                      0

Empty unboundeds are okay, so () is a valid Pith program.
An invalid Pith program with an unbounded is
12(010

since the 2 only receives one argument (the unbounded).
Finally, " starts and ends a string, which is always 0 arity and counts as a single argument, e.g.
2"010""44)()4"

which is just a 2 being passed two string arguments "010" and "44)()4". Like unboundeds, strings may also be empty, and any unclosed strings by the end of the program are automatically closed.
*This part is different from the original Pyth which actually does do something in a case like 1), ending the 1-arity and raising an error.
Input/output
Input will be a single non-empty string consisting of only the characters 01234()". You may optionally assume that an additional trailing newline is always present. You may write a function or a full program for this challenge.
You should output a truthy value if the input is syntactically valid Pith, or a falsy value otherwise. The truthy and falsy values must be fixed, so you can't output 1 for one valid program and 2 for another.
Scoring
This is code-golf, so the code in the fewest bytes wins.
Test cases
Truthy:
0
)
(
"
()
""
10
400010
210010
("")00
3"""""
(0)))0)1)0
2(2(2(0)0)0)0
2"010""44)()4"
)31(0)0(201000100
())2)1))0"3())"))
3("4321("301(0)21100"4")"123"00)40"121"31000""01010

Falsy:
1
1(310
(1)0)
12(010
4"00010"
3120102100
20(2((0)(0)))
2(2(2(0)0)0)01)
4(0102)00)00000
2"00"("00"2(""))

Shouldn't the tree for 20100100 (in the first unbounded example) be [( [2 [0] [1 [0] ] ] [0] [1 [0]] [0] ]? The one you have has branches of 2, 0, 0, 1 and 0 - the second one shouldn't be there.

@bcsb1001 Thanks and corrected. I wanted to show that unboundeds can go above 4.

@Ypnypn there are test cases saying that its valid to have multiple roots

Would you please add the test case for ())2)1))0"3())")) (which should be true, I think).

@n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ Added - it is indeed true (since it's basically ()210"" with a lot of no-ops)

Also (0)))0)1)0 (true)  and (1)0) (false).

@user23013 Thanks and added

"Any unboundeds still open by the end of the program are automatically closed. A ) command is not an error if no unboundeds are open — it just does nothing.*" is there any reason for this bit of syntax to exist other than to pander to code golf and miscellaneous source formatting challenges?

@Sparr Admittedly that was the only part of the spec I messed up, because what I meant was that unmatched ) on the top level was not an error. It's a bit late to change though, unfortunately.

CJam, 65 bytes
q'"/La+2%{0s*}:Z~_,:L')*+{L{4{)_Z+s/Z}/L{'(\Z')++/Z}/}*')-}2*0s-!

Gosh, I wish CJam had Regex, this could have been completed in less than 50 bytes then
The main idea is to keep reducing stuff to 0 i.e. 10 to 0, 200 to 0 and so on. Once that is done, we reduce all matched brackets to 0, i.e. () to 0, (0) to 0, (00) to 0 and so on. The we repeat the cycle L times, where L is the input length.
The input string initially goes through extra processing where we adjust for unmatched " and add lots of ) to compensate for unmatched (
This ensures that after all the iterations, we should only have 0 (and no-op )) left in the string.
Update - fixed a bug where top level ) no-op are considered harmful
Code expansion
q'"/La+2%{0s*}:Z~_,:L')*      "Part 1 - Preprocessing";
q'"/                          "Read the input and split it on quote";
    La+                       "Add an extra empty array to the split array to compensate";
                              "for unmatched ending quote";
        2%                    "Take every other splitted part, ignoring the contents";
                              "of the strings in the code";
          {0s*}:Z~            "Join the parts by string 0. Also create a function Z";
                              "that does that for future use. We are now done with";
                              "reducing "XYZ" to 0 ";
                  _,:L        "Store the length of the remaining code in L";
                      ')*     "Append L ) to the string to compensate for unmatched (";

{L{4{)_Z+s/Z}/L{'(\Z')++/Z}/}*')-}2*   "Part 2 - the reducing loop";
 L{                         }*         "Run the reduction logic L times";
   4{)_Z+s/Z}/                         "Part 2a - reducing arities";
   4{       }/                         "Run the iteration for 0, 1, 2 and 3";
     )_                                "Increment the iteration number and make a copy";
       Z+s                             "Get that many 0 and append it to the number";
          /Z                           "Split the code onto this number and convert it";
                                       "to 0. This successfully reduces 10, 200, ";
                                       "3000 and 4000 to 0";
              L{'(\Z')++/Z}/           "Part 2b - reducing groups";
              L{          }/           "Run the iteration for 0 through L - 1";
                '(\Z')++               "Get the string '(<iteration number of 0>)'";
                        /Z             "split on it and join by 0. This successfully";
                                       "reduces (), (0), (00) and so on .. to 0";
                              ')-      "After running the part 2 loop L times, all";
                                       "reducible arities and brackets should be reduced";
                                       "except for cases like '30)00' where the no-op )";
                                       "breaks the flow. So we remove ) from the code";
                                       "and run Part 2 L times again";

0s-!                          "Now, if the code was valid, we should only have 0 in the";
                              "remaining code. If not, the code was invalid";

Try it online here or run the whole suite

Regex, PCRE flavor, 83 bytes
^(?3)*\)*$(()((?(2)|\)*)(\((?1)*(\)|$)|0|"[^"]*.?|(1|(2|(3|4(?3))(?3))(?3))(?3))))?

Try it here.
Regex, PCRE flavor, 85 bytes
^((?(3)|\)*)(?>\((?2)*(()(?1))?(\)|$)|0|"[^"]*.?|(1|(2|(3|4(?1))(?1))(?1))(?1)))*\)*$

Try it here.
Used some ideas in this dan1111's answer.
Some explanations about (?2)*(()(?1))?.

(?2)*(()(?1))? is the final puzzle piece I was looking for. Nice find! ;)

If I understand the (?2)*(()(?1))? part correctly, the (()(?1))? part never matches anything, since (?2)* already eats up everything that (()(?1))? can match, and this construct is used to set capturing group 3 when we enter ( and unset capturing group 3 when we are outside () construct (to allow for matching unpaired )).

80386 Assembler, 97 bytes
Hex dump:
0000000: 8b54 2404 5589 e531 c96a ff8a 022c 303c  .T$.U..1.j...,0<
0000010: f275 04f6 d530 c084 ed75 263c f875 0141  .u...0...u&<.u.A
0000020: 3cf9 750f 84c9 7419 4958 3c00 7c03 50eb  <.u...t.IX<.|.P.
0000030: 2430 c084 c075 0958 483c ff7f 0140 ebf3  $0...u.XH<...@..
0000040: 5042 8a02 84c0 75c5 4a84 edb0 2275 be84  PB....u.J..."u..
0000050: c9b0 2975 b85a 31c0 39e5 7501 4089 ec5d  ..)u.Z1.9.u.@..]
0000060: c3                                       .

This runs through the input once, pushing numbers greater than zero onto the stack and decrementing them when a zero is processed. Unboundeds are processed as a -1.
Function prototype (in C) (function returns 0 if invalid and 1 if valid):

int __cdecl test(char *in);

Equivalent assembly (NASM):
bits 32
; get input pointer into edx
mov edx, [esp+4]                ; 8B 54 24 04

; save ebp; set ebp = esp
push ebp                        ; 55
mov ebp, esp                    ; 89 E5

; clear ecx
xor ecx, ecx                    ; 31 C9

; push base -1
push byte(-1)                   ; 6A FF

; get top char
mov al, [edx]                   ; 8A 02

    sub al, 0x30                ; 2C 30

    ; if al == quote
    cmp al, 0xF2                ; 3C F2
    jne $+6                     ; 75 04
        ; set ch (in quote?) to opposite
        not ch                  ; F6 D5
        ; set value to 0
        xor al, al              ; 30 C0

    ; if in quote, continue
    test ch, ch                 ; 84 ED
    jnz $+40                    ; 75 26

    cmp al, 0xF8                ; 3C F8
    jne $+3                     ; 75 01
        ; increment cl=depth
        inc ecx                 ; 41

    cmp al, 0xF9                ; 3C F9
    jne $+17                    ; 75 0F
        ; check depth = 0
        test cl, cl             ; 84 C9
        jz $+27                 ; 74 19
        ; decrement cl=depth
        dec ecx                 ; 49
        ; pop and check -1
        pop eax                 ; 58
        cmp al, 0               ; 3C 00
        jl $+5                  ; 7C 03
            push eax            ; 50
            jmp $+38            ; EB 24
        xor al, al              ; 30 C0

    test al, al                 ; 84 C0
    jnz $+11                    ; 75 09
        pop eax                 ; 58
        dec eax                 ; 48
        cmp al, -1              ; 3C FF
        jg $+3                  ; 7F 01
            inc eax             ; 40
        jmp $-11                ; EB F3
    push eax                    ; 50

    inc edx                     ; 42
    mov al, [edx]               ; 8A 02
    test al, al                 ; 84 C0
    jnz $-57                    ; 75 C5

    dec edx                     ; 4A

    ; in quote?
    test ch, ch                 ; 84 ED
    mov al, 0x22                ; B0 22
    jnz $-64                    ; 75 BE

    ; depth not zero?
    test cl, cl                 ; 84 C9
    mov al, 0x29                ; B0 29
    jnz $-70                    ; 75 B8

; pop base -1
pop edx                         ; 5A

; set return value based on ebp/esp comparison
xor eax, eax                    ; 31 C0
cmp ebp, esp                    ; 39 E5
jne $+3                         ; 75 01
inc eax                         ; 40
; restore esp
mov esp, ebp                    ; 89 EC
; restore ebp
pop ebp                         ; 5D
; return
ret                             ; C3

The following code in C can be used with GCC on a POSIX system to test:

#include <sys/mman.h>
#include <stdio.h>
#include <string.h>

int main(){
    char code[] = {
        0x8b, 0x54, 0x24, 0x04, 0x55, 0x89, 0xe5, 0x31, 0xc9, 0x6a, 0xff,
        0x8a, 0x02, 0x2c, 0x30, 0x3c, 0xf2, 0x75, 0x04, 0xf6, 0xd5, 0x30,
        0xc0, 0x84, 0xed, 0x75, 0x26, 0x3c, 0xf8, 0x75, 0x01, 0x41, 0x3c,
        0xf9, 0x75, 0x0f, 0x84, 0xc9, 0x74, 0x19, 0x49, 0x58, 0x3c, 0x00,
        0x7c, 0x03, 0x50, 0xeb, 0x24, 0x30, 0xc0, 0x84, 0xc0, 0x75, 0x09,
        0x58, 0x48, 0x3c, 0xff, 0x7f, 0x01, 0x40, 0xeb, 0xf3, 0x50, 0x42,
        0x8a, 0x02, 0x84, 0xc0, 0x75, 0xc5, 0x4a, 0x84, 0xed, 0xb0, 0x22,
        0x75, 0xbe, 0x84, 0xc9, 0xb0, 0x29, 0x75, 0xb8, 0x5a, 0x31, 0xc0,
        0x39, 0xe5, 0x75, 0x01, 0x40, 0x89, 0xec, 0x5d, 0xc3,
    };
    void *mem = mmap(0, sizeof(code), PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
    memcpy(mem, code, sizeof(code));
    int __cdecl (*test)(char *) = (int __cdecl (*)(char *)) mem;

    #define TRY(s) printf(s ": %d\n", test(s))

    printf("Truthy tests:\n");
    TRY("0");
    TRY(")");
    TRY("(");
    TRY("\"");
    TRY("()");
    TRY("\"\"");
    TRY("10");
    TRY("400010");
    TRY("210010");
    TRY("(\"\")00");
    TRY("3\"\"\"\"\"");
    TRY("(0)))0)1)0");
    TRY("2(2(2(0)0)0)0");
    TRY("2\"010\"\"44)()4\"");
    TRY(")31(0)0(201000100");
    TRY("())2)1))0\"3())\"))");
    TRY("3(\"4321(\"301(0)21100\"4\")\"123\"00)40\"121\"31000\"\"01010");

    printf("\nFalsy tests:\n");
    TRY("1");
    TRY("1(310");
    TRY("(1)0)");
    TRY("12(010");
    TRY("4\"00010\"");
    TRY("3120102100");
    TRY("20(2((0)(0)))");
    TRY("2(2(2(0)0)0)01)");
    TRY("4(0102)00)00000");
    TRY("2\"00\"(\"00\"2(\"\"))");

    munmap(mem, sizeof(code));
    return 0;
}

lex, 182 bytes (157 w/ fixed-size stack)
These programs require the input to be a single new-line terminated string of valid characters.
%%
 int n=0,s=0,*t=0;
[0-4] n+=*yytext-48-!!n;
\( (t=realloc(t,(s+1)*sizeof n))[s++]=n-!!n;n=0;
\) if(s&&n)exit(1);s&&(n=t[--s]);
\"[^"]*.? n-=!!n;
\n while(s)t[--s]&&n++;exit(!!n);

The above program will segfault if it runs out of memory, which could theoretically happen if you give it enough (. But since a segfault counts as failure, I'm taking that as "falsey", although the problem description doesn't say what to do if resources don't suffice.
I cut it down 157 bytes by just using a fixed-size stack, but that seemed like cheating.
%%
 int n=0,s=0,t[9999];
[0-4] n+=*yytext-48-!!n;
\( t[s++]=n-!!n;n=0;
\) if(s&&n)exit(1);s&&(n=t[--s]);
\"[^"]*.? n-=!!n;
\n while(s)t[--s]&&n++;exit(!!n);

To compile:
flex -o pith.c pith.l    # pith.l is the above file
c99 -o pith pith.c -lfl

Test:
while IFS= read -r test; do
  printf %-78s "$test"
  if ./pith <<<"$test"; then echo "OK"; else echo "NO"; fi
done <<EOT
0
)
(
"
()
""
10
400010
210010
("")00
3"""""
2(2(2(0)0)0)0
2"010""44)()4"
)31(0)0(201000100
3("4321("301(0)21100"4")"123"00)40"121"31000""01010
1
1(310
12(010
4"00010"
3120102100
20(2((0)(0)))
2(2(2(0)0)0)01)
4(0102)00)00000
2"00"("00"2(""))
EOT

Test output:
0                                                                             OK
)                                                                             OK
(                                                                             OK
"                                                                             OK
()                                                                            OK
""                                                                            OK
10                                                                            OK
400010                                                                        OK
210010                                                                        OK
("")00                                                                        OK
3"""""                                                                        OK
2(2(2(0)0)0)0                                                                 OK
2"010""44)()4"                                                                OK
)31(0)0(201000100                                                             OK
3("4321("301(0)21100"4")"123"00)40"121"31000""01010                           OK
1                                                                             NO
1(310                                                                         NO
12(010                                                                        NO
4"00010"                                                                      NO
3120102100                                                                    NO
20(2((0)(0)))                                                                 NO
2(2(2(0)0)0)01)                                                               NO
4(0102)00)00000                                                               NO
2"00"("00"2(""))                                                              NO

I guess I should have been a bit clearer - you can assume that either the newline is never there, or is always there. Does that help?

Would it be possible to use the fixed size stack program, but to set the size of the stack to the length of the input?

@isaacg Since the input is stdin, we have no idea until it is read. I could easily have written a driver which uses a command line arg or string but golf has other priorities. The dynamic stack in 25 chars isn't bad by c standards, but I'm sure it can still be golfed.

Python 2, 353 bytes
The parse function steps through the tokens one at a time and builds a tree of the program structure. Invalid programs trigger an exception which causes a zero (Falsy) to be printed, otherwise successful parsing results in a one.
def h(f,k=0):
 b=[]
 if k:
  while f:b+=[h(f)]
  return b
 q=f.pop(0)
 if q==')':return[]
 elif q=='"':
  while f:
   q+=f.pop(0)
   if q[-1]=='"':break
 elif q=='(':
  while f:
   if f and f[0]==')':f.pop(0);break
   b+=h(f)
 else:
  for i in range(int(q)):b+=h(f)
  assert len(b)==int(q)
 return[[q,b]]
try:h(list(raw_input()));r=1
except:r=0
print r

The output of the tests showing the parser output:
------------------------------------------------------------
True: 0
    0

------------------------------------------------------------
True: )

------------------------------------------------------------
True: (
    (

------------------------------------------------------------
True: "
    "

------------------------------------------------------------
True: ()
    (

------------------------------------------------------------
True: ""
    ""

------------------------------------------------------------
True: 10
    1
        0

------------------------------------------------------------
True: 400010
    4
        0
        0
        0
        1
            0

------------------------------------------------------------
True: 210010
    2
        1
            0
        0
    1
        0

------------------------------------------------------------
True: ("")00
    (
        ""
    0
    0

------------------------------------------------------------
True: 3"""""
    3
        ""
        ""
        "

------------------------------------------------------------
True: 2(2(2(0)0)0)0
    2
        (
            2
                (
                    2
                        (
                            0
                        0
                0
        0

------------------------------------------------------------
True: 2"010""44)()4"
    2
        "010"
        "44)()4"

------------------------------------------------------------
True: )31(0)0(201000100
    3
        1
            (
                0
        0
        (
            2
                0
                1
                    0
            0
            0
            1
                0
            0

------------------------------------------------------------
True: 3("4321("301(0)21100"4")"123"00)40"121"31000""01010
    3
        (
            "4321("
            3
                0
                1
                    (
                        0
                2
                    1
                        1
                            0
                    0
            "4"
        "123"
        0
    0
    4
        0
        "121"
        3
            1
                0
            0
            0
        ""
    0
    1
        0
    1
        0

------------------------------------------------------------
False: 1
0
------------------------------------------------------------
False: 1(310
0
------------------------------------------------------------
False: 12(010
0
------------------------------------------------------------
False: 4"00010"
0
------------------------------------------------------------
False: 3120102100
0
------------------------------------------------------------
False: 20(2((0)(0)))
0
------------------------------------------------------------
False: 2(2(2(0)0)0)01)
0
------------------------------------------------------------
False: 4(0102)00)00000
0
------------------------------------------------------------
False: 2"00"("00"2(""))
0

The code before the minifier:
def parse(tokens, first=False):
    toklist = []
    if first:
        while tokens :
            toklist += [parse(tokens)]
        return toklist
    tok = tokens.pop(0)
    if tok == ')' :
        return []
    elif tok == '"':
        while tokens:
            tok += tokens.pop(0)
            if tok[-1] == '"' :
                break
    elif tok == '(':
        while tokens:
            if tokens and tokens[0] == ')' :
                tokens.pop(0);
                break
            toklist += parse(tokens)
    else:
        for i in range(int(tok)) :
            toklist += parse(tokens)
        assert len(toklist) == int(tok)
    return [[tok, toklist]]

try :
    parse(list(raw_input()));
    r = 1
except :
    r = 0
print r

Nice (ab)use of exceptions!  You can save some spaces by swapping the order of the operands to == in the tests--putting the strings first means you can do if')'==q.  I believe one of the break statements could be replaced with f=0, since that will get you out of the while f loop just as well.  Finally, instead of assert x==y you can use 1/(x==y) for a ZeroDivisionError.  ;)

@DLosc, thanks for some very useful golfing tips. If I was among the leaders in the golfing competition, I would use your ideas to compete. As my entry is far from competitive (golf-wise), I would rather leave it as a mostly readable example. I have noted your clever techniques though for future use ;-)

Javascript (ES6), 289 288 285 282 278 244 241 230 bytes
c=prompt(k="0"),j=c[l="length"];if((c.match(/"/g)||[])[l]%2)c+='"';c=c[R="replace"](/".*?"/g,k);c+=")".repeat(j);while(j--)c=c[R](/\(0*\)/,k)[R](/10/g,k)[R](/200/g,k)[R](/3000/g,k)[R](/40000/g,k);alert(!c[R](/0/g,"")[R](/\)/g,""))

Pip, 88 72 bytes
Idea taken from Optimizer's CJam. My original stab at the problem with a recursive descent parser was... rather longer.
Qpz:,5.iX,5AL'(.0X,#p.')p^:'"Fj,#pIj%2p@j:0p:Jpp.:')X#pL#ppR:z0!pRM')Rz0

Formatted, with explanation:
Qp                Query user for p
z:                Store the following list in z:
  ,5 . 0X,5         For x in range(5), concatenate x zeros to it
  AL                (append list)
  '(. 0X,#p .')     For x in range(len(p)), concatenate x zeros inside parens
p^: '"            Split p on " and assign result back to p
Fi,#p             Loop over the indices of the resulting list:
 Ii%2               If index is odd:
  p@i:0               Replace that item with 0
p: Jp             Concatenate the results and assign back to p
p.: ')X#p         Append len(p) closing parens to p
L#p               Loop len(p) times:
 pR:z0              Replace every occurrence in p of items of z with 0
! pRM')Rz0        Remove ) from result and replace z with 0 one more time; then
                  take logical negation, which will be true iff string is empty OR
                  consists only of zeros

Interesting tricks:

Many operators work item-wise on lists and ranges. So 0X,5, for example, is 0 X [0 1 2 3 4] == ["" "0" "00" "000" "0000"].
As of a few days ago, the ternary Replace operator can take a list for any of its arguments: "abracadabra" R ["br" "ca"] 'b gives ababdaba, for example. I make good use of this feature with z here.
Falsy values in Pip include the empty string "", empty list [], and any scalar that is zero. Thus, 0 is false, but also 0.0 and "0000000". This feature is inconvenient sometimes (to test whether a string is empty, one must test its length because "0" is false too), but for this problem it's perfect.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

authors: n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

sort: votes


text:
Write a GIF encoder
Yes, the good old GIF. Loved for its versatility, hated for its patents and partly obsoleted due to its limitations (and patents), GIF consists, at the core, of a color palette and a palette-indexed image compressed using the LZW algorithm.
Your task is to write a program that reads an image in ASCII PPM format ("P3" magic number) from the standard input, and writes the same image (identical pixel-by-pixel) in GIF format to the standard output. The output can either be in binary form, or ASCII text with each byte represented by a number between 0 and 255 (inclusive), separated by whitespace.
The input image is guaranteed not to have more than 256 different colors.
Scoring:
Your program will be tested on 3 sample images, and your score will be calculated as:
program size + sum(output size - reference size for each sample image)
Lowest score wins.
Requirements:

Your program must work with any similar kinds of images of various sizes, and not be limited to the sample images. You could, for example, restrict the dimensions to be multiples of 2 or assume that the ppm max color is 255, but it should still work with a wide variety of input images.
The output must be a valid GIF file that can be loaded with any compliant program (after converting back to binary if using the ASCII output option).
You can not use any image processing functions (built-in or third-party), your program must contain all the relevant code.
Your program must be runnable in Linux using freely available software.
The source code must use only ASCII characters.

Sample images:
Here are the 3 sample images that will be used for scoring. You can download a zip archive with the ppm files (use the download button on the top of that page). Or you can convert them from the png images below, using ImageMagick with the following command:
convert file.png -compress none file.ppm

I am also providing the MD5 checksums of the ppm files for confirmation.
1. amber

Reference size: 38055
MD5 checksum of ppm: d1ad863cb556869332074717eb278080
2. blueeyes

Reference size: 28638
MD5 checksum of ppm: e9ad410057a5f6c25a22a534259dcf3a
3. peppers

Reference size: 53586
MD5 checksum of ppm: 74112dbdbb8b7de5216f9e24c2e1a627

Moderator note: Off-topic/obsolete comments removed. Please see meta for discussion on the sample images in this question.

It seems the second image was treated with something like this: http://www.websiteoptimization.com/speed/tweak/lossy/ that would explain better compression ratio it has and sensitivity to the LZW encoder tweaks.

“The source code must use only ASCII characters.”—so, in other words, we are not allowed to do this challenge in APL?

@FUZxxl true, but you can use J. You are also not allowed to use Aheui or to do base conversion tricks in GolfScript/CJam.

Perl, 515 + -2922 + 0 + -2571 = -4978
Another approach. This time I am trying to save the image in tiles of size 64xH. This is fine according to specs, but some software may show only the first tile or an animation. The tiles compress better because of better spacial locality. I still do normal compression as well for the second image and choose whatever came shorter. Since this compresses the image twice, it is twice as slow compared to my previous solution.
#!perl -n0
sub r{$r.=1&"@_">>$_ for 0..log(@d|256)/log 2}
@k=/(\d+) (\d+)/;
@l=map{$$_||=(push(@t,split$"),++$i)}/\d+ \d+ \d+/g;
print+GIF89a,pack(vvCxxC768,@k,~8,@t);
sub v{($w,$h)=@_;for$k(0.."@k"/$w-1){
$k*=$w;$r='';@d=();@p=grep+($z++-$k)%"@k"<$w,@l;
$"=' ';$_="@p ";$"='|';while(/./){
r 256;%d=map{($_,$_-1)}@d=1..256;
$d{$&}=@d+2,r$d{$1},unshift@d,$&while@d<4095&&s/^(@d) (\d*)/$2/}
r 257;$_=pack"b*",$r;
$h.=pack"Cv4n(C/a)*",44,$k,0,$w,$k[1],8,/.{0,255}/gs
}$b=$h if!$b||length$b>length$h}
"@k"%64||v 64;v"@k";print"$b;"

Perl, 354 + 12 + 0 + -1 = 365  418 9521 51168 56639
Either there is some bug in my code or the second image is optimized for a specific encoder as seemingly insignificant change reduced the size to the reference exactly. Takes about 30s-60s per image.
Golfed version.
#!perl -n0
sub r{$r.=1&"@_">>$_ for 0..log(@d|256)/log 2}
@k=/(\d+) (\d+)/;
@p=map{$$_||=(push(@t,split$"),++$i)}/\d+ \d+ \d+/g;
$_="@p ";$"='|';while(/./){
r 256;%d=map{($_,$_-1)}@d=1..256;
$d{$&}=@d+2,r$d{$1},unshift@d,$&while@d<4095&&s/^(@d) (\d*)/$2/}
r 257;$_=pack"b*",$r;
print+GIF89a,pack(vvCxxC768,@k,~8,@t),
pack("Cx4vvn(C/a)*",44,@k,8,/.{0,255}/gs),';'

The only decision a GIF compressor can take is when to reset the LZW dictionary. In general because of how the images for this task were chosen the best moment to do so is each 4096 codes which is the moment the dictionary would overflow. With such limit the dictionary never overflows which saves a couple of bytes in the implementation.
This is how it works in detail:
#!perl -n0
# function to add one codeword to the output stream @r.
# the current codeword length is based on the dictionary size/
sub r{push@r,map"@_">>$_,0..log(@d|256)/log 2}
# get the dimensions into @k
@k=/(\d+) (\d+)/;
# get pixel indexes to @p and palette to @t
@p=map{$$_||=(push(@t,split$"),++$i)}/\d+ \d+ \d+/g;
# convert index table into space separated string
$_="@p ";$"='|';
# LZW encoder; while something to encode
while(/\S/){
# output reset code
r 256;
# reset code dictionary $d is the last code number,
# %d is the map of codes and @d list of codes
$d=257;%d=map{($_,$_-1)}@d=1..256;
# find codes using regexp, stop at dictionary overflow
while($d<4096&&s/^(@d) (\d*)/$2/){
unshift@d,$&;$d{$&}=++$d;r$d{$1}}}
# end LZW encoder; output end code
r 257;
# convert bit string @r to bytes $f
vec($f,$j++,1)=$_ for@r;
# output header up to the color table
print+GIF89a,pack(vvCvC768,@k,~8,0,@t),
# output rest of the header
pack(Cv4CC,44,0,0,@k,0,8),
# output the LZW compressed data $f slicing into sub-blocks
$f=~s/.{0,255}/chr(length$&).$&/egsr,';'

Perl, 394 + -8 + 0 + -12 = 374
Adding a heuristic to guess the reset point improves compression a bit but not enough to justify the extra code:
#!perl -n0
sub r{$r.=1&"@_">>$_ for 0..log(@d|256)/log 2}
@k=/(\d+) (\d+)/;
@p=map{$$_||=(push(@t,split$"),++$i)}/\d+ \d+ \d+/g;
$_="@p ";$"='|';while(/./){
r 256;%d=map{($_,$_-1)}@d=1..256;
$d{$&}=@d+2,r$d{$1},unshift@d,$&while
(@d<4001||(/((@d) ){11}/,$&=~y/ //>12))&@d<4095&&s/^(@d) (\d*)/$2/}
r 257;$_=pack"b*",$r;
print+GIF89a,pack(vvCxxC768,@k,~8,@t),
pack("Cx4vvn(C/a)*",44,@k,8,/.{0,255}/gs),';'

Very nice! Although it takes a lot more than 30s per image here. I was quite impressed with the -30 from the previous version, I wonder if you can combine the methods and get a lower score. Also, could you write a bit about what the program does?

Requiring the width to be a multiple of 64 seems a bit extreme...

@aditsu, It is not required, if the width is not multiple of 64 the tiling method is not tried and regular compression is used. Of course at a cost of another ~100 characters I could make the last tile variable size.

Very slow, and the tiled images show as animations, but.. well done, it's quite impressive to see you can really make them smaller.

CJam, score 155 + 35306 + 44723 + 21518 = 101702
Just a dumb reference implementation. It's slow, doesn't do any actual compression and it's not golfed.
"GIF89a":iS*SqN/S*S%1>:i3/:M0=2<256f{md\}S*:ZS247S0S0SM1>_|:PL*_,768\m0a*+S*S44S0S0S0S0SZS0S8SM1>Pf{\a#}254/256a*{512+2b1>W%}%:+8/{W%2b}%255/{_,S@S*S}/0S59

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Transmit Pi... precisely
Following on from Monte Carlo estimator of Pi this challenge is to produce the shortest  code for the constant Pi. Except here your code must output consecutive digits of pi forever.
This is code golf, so the shortest submission (in bytes) wins except that it must output the first 10,000 digits in less than 10 seconds on a reasonable PC and it must never terminate.
You can't use any built-in for Pi or trig functions.

Removed the hard limit on code size.

By tweetable, do you mean that the code must be less than 140 characters?

@Ypnypn That was the idea. I am generally assuming that any golfed answer will be shorter than that in any case.

The challenge would be much more interesting if it was meant to display as many Pi digits as possible in a tweet (140 chars) AND in less than 10s.

@xem That would be interesting as well. However having to output consecutive digits forever gives its own challenge.

The problem in itself seems challenging without the character limitation.

@BobTheAwesome Removed the character limit by popular demand.

Most methods of calculating pi need some idea of desired accuracy (memory use). Though sums of an infinite series converge, storing the sum with total accuracy means storing it in lossless format (e.g. as a/b where a&b are integers.) Can we assume infinite memory? Also, you can only print a digit once you're sure it wont be changed by a carry. Newton-raphson seems to use less memory but see discussion http://mathforum.org/library/drmath/view/65244.html . The BBP algorithm spits out hex digits without needing to remember previous ones, but it seems there's no known equivalent in decimal!

@steveverrill Assume finite memory for the first 10,000 digits but you can assume infinite memory for the "must never terminate" part.

Do the digits have to be all after another, or can they be seperated by newlines? Do the digits have to start with 3.141, or can they start with 141 or even 3141?

It's Pi, of course it needs the first digit, and of course it should print the decimal point. It wouldn't be Pi otherwise... it'd be Pi - 3, or Pi * 10^n.

@mbomb007 It's not obvious at all that the decimal point must be printed, or that the digits may not be seperated by whitespace. The challenge is merely to "output consecutive digits of pi". The decimal dot is not a digit. 3141... is that - consecutive digits of pi.

It would be best if the number printed out was Pi so there was no space between digits for example. It would be even better if it included the decimal point.

CJam - 48
3.1o{1YAZ2*:Z#*{_2$*2$2*)/@)\}h*]:+sX2*:X>X<o1}g

This calculates π as 2*sum(k!/(2k+1)!!) with greater and greater precision and at every step prints a bunch of digits from where it left off.
You can try online a modified version that does only 8 (outer loop) iterations and prints 512 digits, or use the java interpreter for the real thing. On my laptop it gets to 16384 digits in about 6 seconds.
Note: this program is very memory-hungry; a better behaved but slightly longer version is:
3.1o{T2AZ2*:Z#*1{@2$+@2$*2$2*)/@)1$}g;;sX2*:X>X<o1}g

Explanation:
3.1o              print 3.1
{…1}g             repeat indefinitely
    1YA           push 1, 2 and 10 (Y=2, A=10)
    Z2*:Z         push Z*2 (Z=3 initially) and store back in Z
    #*            calculate 2*10^Z (2 from the formula and 10^Z for precision)
                  this is the term for k=0, and the earlier 1 represents k
    {…}h          do-while
                  at each iteration, the stack contains: terms, k, last-term
        _2$*      copy the previous term and k and multiply them
        2$2*)/    divide the previous number by 2*k+1
                  this is the current term of the series
        @)\       increment k and move it before the current term
                  the current term now serves as the loop condition
                  so the loop terminates when the term becomes 0
    *             multiply k and the last term (0), to get rid of k
    ]:+s          put all the terms in an array, add them and convert to string
                  we obtain an approximation of π*10^Z
    X2*:X         push X*2 (X=1 initially) and store back in X
    >X<o          print X digits starting from the X position

Python, 138 bytes
q,r,t,i=1,180,60,2
while 1:u,y=27*i*(i+1)+6,(q*(27*i-12)+5*r)//(5*t);print(y,end="");q,r,t,i=10*q*i*(2*i-1),10*u*(q*(5*i-2)+r-y*t),t*u,i+1

Implementation of http://www.cs.ox.ac.uk/jeremy.gibbons/publications/spigot.pdf.

Beat me to it by 5 minutes..... :)

This is great. I was however hoping the digits would all be on one line. In other words, that the output would look like Pi.

@Lembik I changed my answer - 7 bytes longer, but now all on one line.

GolfScript (81 chars)
1:i:^3{3i):i*(.(*3*.@*.5*3$27i*12-*+@^*:^5*/.print^*2$5i*2-*--\10*i*2i*(*\10*.}do

Online demo (that's much slower than a reasonable desktop, and has trivial code changes to loop a finite number of times).
I have, of course, used the spigot algorithm which I mentioned in an earlier comment, but it took me a while to golf it to my satisfaction. The algorithm as presented in Gibbons' paper is (pseudocode)
q = 1; r = 180; t = 60; i = 2
while (true) {
    u = 3*(3*i+1)*(3*i+2)
    y = (q*(27*i-12)+5*r) / (5*t)
    print y
    r += q*(5*i-2)-y*t
    r *= 10*u
    q *= 10*i*(2*i-1)
    t *= u
    i += 1
}

The GolfScript above is equivalent to (pseudocode)
t = i = q = 1; r = 3
while (true) {
    u = 3*(3*i+1)*(3*i+2)
    i += 1
    r *= u
    t *= u
    y = (q*(27*i-12)+5*r) / (5*t)
    print y
    r -= y*t - q*(5*i-2)
    q *= 10*i*(2*i-1)
    r *= 10
}

which saves some characters in the initialisation and in the stack management.

Pyth - 87 85 bytes
Another translation of http://www.cs.ox.ac.uk/jeremy.gibbons/publications/spigot.pdf. I was gonna do Python but @orlp beat me to it, so I did Pyth. Small enough to fit in a tweet.
=H3=d1=bd=Gd#K+**hb27b6~b1=H*HK=d*dKJ/+*-*27b12G*5H*5d=H*T-H-*Jd*-*5b2G=G***GTbtybpkJ

It gives output to stdout, albeit in intermittent steps because of the print buffer that comes from setting end="" in print. I currently don't print the decimal point since the spec says "consecutive digits". Its the assignments that are killing my score.
=H3                     Set H to 3
=d1                     Set d to 1
=bd                     Set b to d which is 1
=Gd                     Set G to d which is 1
#                       Infinte Loop
  K                     Set K to
    +**hb27b6           27*b*(b+1)+6
  ~b1                   b+=1
  =H*HK                 H*=K
  =d*dK                 d*=K
  J                     Set J to
    /                   Integer division
      +*-*27b12G*5H     G*(27*b-12)+5*H
      *5d               5*d
  =H                    Set H to
    *T-H-*Jd*-*5b2G     10*(H-(J*d -G*(5*b-2)))
  =G                    Set G to
    ***GTbtyb           G*10*b*(2*b-1)
  pkJ                   Print J with the end as "", not a newline

Try it here. (Note: Since the online interpreter only give completed results, the infinite loop is out, so it only prints first 100 which increases code size. To try out infinite, download the local interpreter.)
Timing
On my google cloud compute micro instance, according to gnu time it took: real: 0m2.062s so it is obviously fast enough.

Scala, 599 bytes
The code below is a straight port of the Pascal code from Appendix 2 of A Spigot Algorithm for the Digits of Pi. Clearly very little golfing has yet been done. The code does generate 10,000 digits in under 10 seconds with piSpigot(10000) and if one has infinite memory can be parameterized to generate many digits, but not infinite. I am not sure if this is meeting the problem constraints so please provide feedback.
def piSpigot(n: Int): Unit = {
  val len=10*n/3
  var nines=0
  var predigit=0
  val a=Array.fill(len)(2)
  (1 to n).foreach {_=>
    var q=0
    (1 to n).reverse.foreach{i=>
      var x=10*a(i)+q*i
      a(i)=x%(2*i-1)
      q=x/(2*i-1)
    }
    a(1)=q%10
    q/=10
    if (q==9) {
      nines+=1
    } else if (q==10) {
      print(predigit+1)
      1.to(nines).foreach(_=>print(0))
      predigit=0
      nines=0
    } else {
      print(predigit)
      predigit=q
      if (nines!=0) {
        1.to(nines).foreach(_=>print(9))
        nines=0
      }
    }
  }
  println(predigit)
}
piSpigot(10000)

I think that the requirement to produce digits ad infinitum means that you need to use a streaming algorithm rather than one which takes a parameter n. See e.g. http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf

Infinite memory and infinite time should give an infinite number of digits .

Befunge-98 (PyFunge), 120 bytes
cf*10p'<20p11>00p1+:30p:::*+39**6+:30g39**c-00g*10gv
>:2*1-*00g*a*^
^:p02*g02p01*a*-*g02\+g01*g00-2*5g03,+*86:/*5g02+*5<

Try it online!
This is borderline in terms of the timelimit. 10,000 digits take around 11 seconds on my laptop, but I'm sure there must be a "reasonable" PC that could do it faster than that.
However, if you're trying it out on TIO, note that it won't return anything until it hits the 60 second time limit, since the algorithm is designed to keep going forever. By that time you'll have a lot more than 10,000 digits though.
I'm using the Jeremy Gibbons spigot algorithm, which I think is the same as most other answers here. However, note that this relies on the interpreter having arbitrary precision memory cells, and the only implementation I'm aware of that supports that is PyFunge.
Explanation
cf*10p                     Initialise r to 180.
      '<20p                Initialise t to 60.
           11              Initialise i and q on the stack to 1.

>                          Start of the main loop.
 00p                       Save the current value of q in memory.
    1+:30p                 Increment i and save a copy in memory.
          :::*+39**6+      Calculate u = 27*(i*i+i)+6.
                     :     Make a duplicate, since we'll need two copies later.

       30g39**c-00g*10gv   Calculate y = (q*(27*i-12)+5*r)/(5*t).
              /*5g02+*5<
        ,+*86:             Convert y to a character so we can output it.

*a*-*g02\+g01*g00-2*5g03   Calculate r = 10*u*(q*(i*5-2)+r-y*t)

         p01               Save the updated r.
     *g02                  Calculate t = t*u
  p02                      Save the updated t.

>:2*1-*00g*a*              Calculate q = 10*q*i*(i*2-1).
^:
             ^             Return to the start of the main loop.


text:
Palindromic palindrome generator
Create a program, that converts input string to a palindrome starting with the input string. The program itself must be a palindrome.
For example input: neverod, print neveroddoreven. You should handle multi-word, multi-line inputs as well.

This seems very similar to this question, except here we're generating instead of checking. Chances are the same tricks will be employed to make the program a palindrome, though.

I can totally understand the question downvote, but why was the answer downvoted?

@JanDvorak I'm guessing its because it uses comments to make the palindrome, which specifically makes that strategy ok. It's not a very interesting way and is specifically banned in at least one question requiring palindromic code:http://codegolf.stackexchange.com/q/28190/15599  . Tomek, welcome to programming puzzles and codegolf. I'm upvoting anyway so you have access to our sandbox http://meta.codegolf.stackexchange.com/q/2140/15599 however I recommend you stick around and answer a few questions before you ask another one. Also, remember to search for similar questions before posting

Are functions allowed (instead of whole programs)?

Can we use a delimiter for the palindrome generated? i.e. neverod -> neverodadoreven (with the a in between)

This question now has a duplicate: http://codegolf.stackexchange.com/questions/98325/palindromize-this-string

Do we have to handle null bytes in input? I have a lang that can, but itd save bytes if i didnt have to

Dyalog APL, 6 4
⌽,,⌽

Try it here.
Other solutions:
⌽,⊢⊢,⌽
⌽⊢⊢,⊢⊢⌽

Explanation
They are just:
{⌽((,⍵),(⌽⍵))}
{⌽((,⍵)⊢((⊢⍵),(⌽⍵)))}
{(⌽⍵)⊢((⊢⍵),((⊢⍵)⊢(⌽⍵)))}

Monadic , and ⊢ does nothing on strings. Dyadic , is concatenation. Dyadic ⊢ returns its right operand. And ⌽ is obviously reversion.

Note that this only works in Dyalog APL.

piet 19x2 = 38

Accepts input until it encounters 0x00. Doesn't terminate, but output will be correct.

Symmetric: yes; palindromic: ?

@Blue I don't think it's possible to make a PNG image file palindromic due to the header and footer. Also, PNG compression means that the bytes in the image are almost certainly not palindromic.

@EsolangingFruit Though one could argue that the image equivalent of a palindrome should be centrosymmetric.

APL, 9
⍞←Z,⌽,Z←⍞

Explanation:
       Z←⍞  ⍝ read a line from the keyboard, and store it in Z
      ,     ⍝ flatten into one-dimensional array (this has no effect here)
     ⌽      ⍝ reverse
   Z,       ⍝ concatenate Z to its reverse
⍞←         ⍝ explicit output (not necessary, but it makes it a palindrome)

CJam, 13 bytes
qL;_-1%1-_;Lq

qL;                 "Read the input, Put an empty array on stack and pop that array";
   _-1%             "Now the string is on top, make a copy and reverse the copy";
       1-           "Remove occurrences of integer 1 from the reverse string. [no-op]";
         _;         "Copy the reversed string and pop it";
           Lq       "Put an empty array on stack and read the remaining input. Remaining";
                    "input will be empty as we already read whole of the input";

Try it online here

or..
GolfScript, 9 bytes
.-1%}%1-.

.                 "Input is already on stack. Make a copy";
 -1%              "Reverse the copy";
    }             "This marks the beginning of a super comment. Anything after this in the";
                  "code is a comment";
     %1-.         "no-op comment";

Try it here

I think you've found a bug in the GolfScript parser with your "super-comment". Mind you, an ordinary # comment would work just as well there.

@IlmariKaronen Its not me, } has been known to be a super comment since ages :)

C++, 162 bytes
#include<cstdio>//
main(){int c=getchar();if(c>0)putchar(c),main(),putchar(c);}//};)c(rahctup,)(niam,)c(rahctup)0>c(fi;)(rahcteg=c tni{)(niam
//>oidtsc<edulcni#

C, 117 bytes
main(c){c=getchar();if(c>0)putchar(c),main(),putchar(c);}//};)c(rahctup,)(niam,)c(rahctup)0>c(fi;)(rahcteg=c{)c(niam

god bless the two slashes lol

suggest replacing c>0 with ~c, also ISO C++ forbids declaration of ‘main’ with no type but gcc allows it

Haskell, 102+22=124 bytes
a b fa=fa<|>b
fa=reverse>>=a
main=interact fa
niam=main
af tcaretni=niam
a=>>esrever=af
b>|<af=af b a

This must be run with the Control.Applicative module in scope, which can be set via the ghci init file .ghci: :m Control.Applicative (-> +22 bytes).
No comment trick, just 7 functions where 4 of them are never called.
If functions (instead of programs) are allowed:
Haskell, 55+22=77 bytes
a b fa=fa<|>b
f=reverse>>=a
a=>>esrever=f
b>|<af=af b a

Usage f "qwer"-> "qwerrewq"
Edit: the previous version was just wrong.

Pyth, 11 bytes
+z_z " z_z+

In Pyth, anything preceding with a space is not printed. So we simply add the negative of the string to itself, put a space, start a string and mirror the left side of the quote"
Try it online here

Ruby, 44
s=gets p
s+=s.reverse||esrever.s=+s
p steg=s

Takes a multiline string as input from stdin, outputs a Ruby representation of that string concatenated to its reverse. Could trim a character by replacing || with # to comment out the dead code on the second line.

s=gets p!=p steg=s

...true, I have no idea what I meant by that.

Jolf, 9 bytes
Try Here
aη+i_i+ηa

Explanation: I only just started Jolf and I don't think I'm explaining this properly.
aη         alert function, arity of the function can't be reduced by 1 so it stays at 1
  +i_i     concatenate the input with the reversed input
      +η   arity of the add reduced by 1, it just takes the following character (a)
        a  returns the input

Welcome to PPCG! I saw your other answer, and I fondly appreciate you using this language! It is my own inventions, I hope you like it :) This is a really nice solution, very well done! I like the way you used η in the solution, very well done. You can save two bytes by eliminating the mu, as: a+i_i+a. (Jolf also has implicit input to fill in the rest of the arguments, but this isn't a problem since only one input is given at a time.) I would keep your original solution in the answer, still.

@Cᴏɴᴏʀ O'Bʀɪᴇɴ Thanks! I just chose a golfing language that didn't seem too scary and jumped in, I've been enjoying figuring it out. I was trying to figure out where the η came from and realized that it was from trying to fix my starting point of +i_i+. Thanks for the info!

PowerShell, 67
$args|%{$_+-join$_[$_.Length..0]}#}]0..htgneL._$[_$nioj-+_${%|sgra$

Try it online
As suggested by @mazzy the code can be shortened by 12 bytes when using a static range. This, however, limits the input length to 9KBytes. Theoratically 9MBytes would be possible but it would slow down the code significantly.
$args|%{$_+-join$_[9kb..0]}#}]0..bk9[_$nioj-+_${%|sgra$

Alternative 67 bytes: param($s)$s+-join$s[$s.Length..0]#]0..htgneL.s$[s$nioj-+s$)s$(marap

if input string length less then 9Kbytes then $args|%{$_+-join$_[9Kb..0]}#}]0..bK9[_$nioj-+_${%|sgra$ (55 bytes)

Japt, 4 bytes
êêêê

Try it online!
How it works
U.ê("ê".ê("ê"))  Transpiled to JS

       .ê("ê")   String.ê(string): true if `this` is palindrome
    "ê".ê("ê")   true (treated same as 1)
U.ê(          )  String.ê(number): palindromify
                   "abc"->"abccba" if `number` is odd, "abcba" otherwise
                 `true` is odd number, so we achieve the desired function

Alternative 4 bytes
pwwp

Try it online!
How it works
U.p("w".w("p"))  Transpiled to JS
    "w".w(   )   Reverse of "w" ("p" is ignored)
U.p("w")         Append U.w(), which is reverse of U, to the right of U

Fuzzy Octo Guacamole, 17 bytes
^dz''sjX@Xjs''zd^

Alt solution in 19 bytes:
^Czs''.jX@Xj.''szC^

They both take input, duplicate and reverse, and join the stack.
Explanation:
^dz''sj@js''zd^
^                # Get input
 d               # Duplicate ToS (input)
  z              # Reverse ToS
   ''            # Push empty string (for joining separator)
     s           # Move the empty string to the inactive stack
      j          # Join the active stack with the top of the inactive stack as the delimiter and push the result.
       X         # Print the ToS
        @        # End the program
        Xjs''zd^  # Backwards version of the beginning.

<>^v, 55 bytes
.~""?§0 26 0«0 72!=0_~?(___|___(?~_0=!27 0«0 62 0§?""~.

Explanation
.~""?§0 26 0«0 72!=0_~?(___|___(?~_0=!27 0«0 62 0§?""~.

.                            Input string, push to stack
 ~                           Print top of stack without newline
  ""                         Push empty string to stack
    ?                        Swap top two elements
     §                       Split top of stack (now the user input) with second element of stack (`""`)
      0                      Push 0
        26                   Push 26
           0                 Push 0
            «                Goto ; redirects program to the `|`
                           | Reverses instruction pointer direction, now going left
                          _  Pop stack
                         _   Pop stack (again)
                        _    For the third time, pop the stack
                       )     Decrement top of stack
                      ?      Swap top two elements
                     ~       Print top of stack without newline
                    _        Pop stack
                   0         Push 0
                  =          Execute next instruction only if top two elements of the stack are equal
                 !           Exit, executed only if the top two elements of the stack are equal
               72            Push 27 (pointer is going left, so literal 72 -> value 27
             0               Push 0
            «                Goto _
                          _  (Loop goes on, go back to the first "Pop stack")
                            ___(?~_0=!27 0«0 62 0§?""~. This part is useless and never executed, only for the palindrom requirement

What it does is first print the first part of the palindrom, the string itself. Then it stores every letter of the string and the string's length on the stack in reverse order, and print them.
run online (> is the prompt, it is not an output of the program)

Or, with the string reverse operator :
.~—;!;—~.

Inputs a string, prints it, reverses it, and prints it.
run online

tinyBF, 40
|=||==>|=|=|=+|=>==||==>=|+=|=|=|>==||=|

My first thought was Brainfuck, but it's impossible to match the braces... fortunately tinyBF has simpler flow control.
No comments, it takes a null terminated string as input and returns the result in a null terminated string.  You can test it here, just be forewarned that it doesn't halt (although Firefox at least prompts to stop the unresponsive script).
Commented:
|=|                        Retrieve a byte of input.
|                          Positive (opening) bracket.
   ==                      Output the byte.
   >                       Move the pointer in positive direction.
   |=|                     Retrieve a byte of input.
   =                       Switch direction to negative.
|                          Negative (closing) bracket.
=                          Switch direction.
+                          Increment byte to execute return loop.
|                          Opening bracket.
   =>                      Move the pointer in negative direction.
   ==                      Output the byte.
|                          Closing bracket.
|=|                        Output the null terminator.
|==>|=|=|=+|=>==|          ...and keep null terminating it just to be sure.

Note that if you encode it into 2 bit instructions, it cuts the size to 10 bytes (wouldn't be a palindrome).

Python 3, 59 bytes
a=input()#
print(a+a[::-1])#([1-::]a+a)tnirp
#()tupni=a

I tried my best to find a solution that only used one line but I had no luck.
Python 3, 79 bytes
a=input()#()tupni=a#
print(a+a[::-1])#([1-::]a+a)tnirp
#a=input()#()tupni=a

My original attempt in which every line is a palindrome. I don't think that it is necessary for this challenge, but I included it just in case.

One-line but even longer (73, since lambda is so long): print((lambda a:a+a[::-1])(input()))#)))(tupni()]1-::[a+a:a adbmal((tnirp

Very nice. I'm less familiar with lambdas but I'm slowly getting used to them. Thanks for sharing.

Vitsy, 9 bytes
z:Zr?rZ:z
z          Grab all string input from the command line arguments.
 :         Duplicate this stack.
  Z        Print all elements in this stack as a string.
   r       Reverse (reverses an empty stack).
    ?      Go right a stack.
     r     Reverse (reverses the input).
      Z    Print all elements in this stack as a string.
       :   Duplicate the stack (duplicates an empty stack).
        z  Grab all input from the command line (the command line arguments stack is already empty).

Try it online!

Befunge, 37 bytes
~:0`!#v_:,
  >:#,_@_,#:>
,:_v#!`0:~

Try it online!
The top line pushes and prints every character of input. The second line (before the @) prints the stack in reverse, but we enter at the contional _ to consume the -1 generated when finish reading input. The other half of the code (including those ugly trailing newlines) makes the source a palindrome, but nevers runs.

C# (33 32 + 1) * 2 = 68 66 bytes
saved 2 bytes to the use of .Aggregate()
s=>s+s.Aggregate("",(a,b)=>b+a);//;)a+b>=)b,a(,""(etagerggA.s+s>=s

Oh the good old lambda, you can catch it with
Func<string, string> f=<lambda here>

and then call it with
f("neverod")

Perl, 45 bytes
;print$_=<>,~~reverse;m;esrever~~,><=_$tnirp;

Pretty straightforward, prints the input ($_=<>) followed by the reverse of it. reverse returns $_ because we're using it in scalar context by prefixing with ~~. Then we match (m// using ; as delimiter), in void context, against the reverse of the script.
If we can guarrantee we won't have to create a palindrome of esrever,><=_$tnirp we can shorten the code to 43 bytes:
g.print$_=<>,reverse.m.esrever,><=_$tnirp.g

Usage
echo -n 'neverod' | perl -e 'g.print$_=<>,reverse.m.esrever,><=_$tnirp.g'
neveroddoreven

Perl, 26 bytes
Includes 25 bytes code + 1 for -p.
$_.=reverse;m;esrever=._$

I don't think this is valid since it requires the -p flag which I don't think can be easily combined into the script contents to make a true palindrome. Pretty much the same calls as above, except it relies on the fact that -p also adds a ; behind the scenes (on newer Perls...) to close the m//.
Usage
echo -n 'neverod' | perl -pe ';$_.=reverse;m;esrever=._$;'
neveroddoreven

05AB1E, 5 3 bytes
R«R

-2 bytes thanks to @ovs.
Try it online.
Explanation:
R        # Reverse the (implicit) input
         #  i.e. "neverod" → "doreven"
 «       # Append it to the (implicit) input
         #  → "neveroddoreven"
  R      # Reverse it (no-op, since it's a palindrome)
         # (after which the result is output implicitly)

If we are allowed to output neverodoreven for the input neverod, which is still a palindrome, it can be done in 1 byte instead with the palindromize builtin:
û

Try it online.

I think R«R works. Reversing a palindrome doesn't do much

@ovs Ah, of course. Smart thinking, thanks!

MathGolf, 5 3 bytes
x+x

Try it online.
Or 1 byte if overlapping the last character would be allowed, with the palindromize builtin:
ñ

Try it online.
Explanation:
x    # Reverse the (implicit) input
 +   # Append it to the (implicit) input
  x  # Reverse it (no-op, since it's a palindrome)
     # (after which the entire stack is output implicitly)

Vyxal, 1 byte
m

Try it Online!
A simple 1-byter - m mirrors input by appending its reverse.

Pyth, 15
 k k+ z_z +k k

Notice the space at the beginning and at the end.
Quite annoying task in Pyth. z_z prints the desired palindrome, but it prints z (the input string) and _z the inverse on two different lines. + combines the two words, but + at the end requires two new statements at the end (and at the beginning). I choose k and k, which are just empty strings. Then a lot of white space, which suppresses printing (and printing empty spaces, which generate of course line breaks).
Since the white space suppresses every output except the +z_z, you can replace the ks and literal with arity 0. E.g. 1 2+ z_z +2 1 or T Z+ z_z +Z T.
Try it online.

I have an 11 one in Pyth, which I did not post yet coz I thought you will surely beat it ;)

Javascript, 138 bytes
I'm not using the "comment trick" but I am using the escaped quotation mark trick lol.
"a\"};))''(nioj.)(esrever.)''(tilps.b(tacnoc.b nruter{)b(a noitcnuf;";function a(b){return b.concat(b.split('').reverse().join(''));};"\a"

I don't think this counts; the two central chars are ";. Adding a ; as the last char inside the string should fix this.

As it stands this answer is invalid. Please either fix it or remove it.

JavaScript, 58 bytes
p=>p+[...p].reverse().join``//``nioj.)(esrever.]p...[+p>=p

Python 2, 51 bytes
s=input();print s+s[::-1]#]1-::[s+s tnirp;)(tupni=s

I'm surprised no-one thought of this! Needs quoted input (' or "). If functions were allowed, I could have done this for 37 bytes instead:
lambda x:x+x[::-1]#]1-::[x+x:x adbmal

PHP, 28+1+28=57 bytes
<?=($x=$argv[1]).strrev($x);#;)x$(verrts.)]1[vgra$=x$(=?<

takes input from command line argument. quote for multi-word, escape newlines for multi-line.

C++14, 152 116 bytes
As unnamed lambda, assumes s to be string
[](auto s){decltype(s)r;for(auto c:s){r=c+r;}return s+r;}//};r+s nruter};r+c=r{)s:c otua(rof;r)s(epytlced{)s otua(][

Old solution:
[](auto s){auto r=s;for(auto p=s.rbegin()-1;++p!=s.rend();r+=*p);return r;}//};r nruter;)p*=+r;)(dner.s=!p++;1-)(nigebr.s=p otua(rof;s=r otua{)s otua(][

Usage:
auto f=[](auto s){decltype(s)r;for(auto c:s){r=c+r;}return s+r;};

main(){
 string a="123456789";
 cout << f(a) << endl;
}

x86-64 Assembly (Microsoft x64 calling convention), 89 bytes:
80 39 00 48 8B D1 4C 8B C1 74 0B 48 FF C2 49 FF C0 80 3A 00 75 F5 48 FF CA 8A 02 41 88 00 48 8B C2 48 FF CA 49 FF C0 48 3B C1 77 ED C3 ED 77 C1 3B 48 C0 FF 49 CA FF 48 C2 8B 48 00 88 41 02 8A CA FF 48 F5 75 00 3A 80 C0 FF 49 C2 FF 48 0B 74 C1 8B 4C D1 8B 48 00 39 80

Disassembled:
 0000000000000000: 80 39 00           cmp         byte ptr [rcx],0
 0000000000000003: 48 8B D1           mov         rdx,rcx
 0000000000000006: 4C 8B C1           mov         r8,rcx
 0000000000000009: 74 0B              je          0000000000000016
 000000000000000B: 48 FF C2           inc         rdx
 000000000000000E: 49 FF C0           inc         r8
 0000000000000011: 80 3A 00           cmp         byte ptr [rdx],0
 0000000000000014: 75 F5              jne         000000000000000B
 0000000000000016: 48 FF CA           dec         rdx
 0000000000000019: 8A 02              mov         al,byte ptr [rdx]
 000000000000001B: 41 88 00           mov         byte ptr [r8],al
 000000000000001E: 48 8B C2           mov         rax,rdx
 0000000000000021: 48 FF CA           dec         rdx
 0000000000000024: 49 FF C0           inc         r8
 0000000000000027: 48 3B C1           cmp         rax,rcx
 000000000000002A: 77 ED              ja          0000000000000019
 000000000000002C: C3                 ret
 000000000000002D: ED                 in          eax,dx
 000000000000002E: 77 C1              ja          FFFFFFFFFFFFFFF1
 0000000000000030: 3B 48 C0           cmp         ecx,dword ptr [rax-40h]
 0000000000000033: FF 49 CA           dec         dword ptr [rcx-36h]
 0000000000000036: FF 48 C2           dec         dword ptr [rax-3Eh]
 0000000000000039: 8B 48 00           mov         ecx,dword ptr [rax]
 000000000000003C: 88 41 02           mov         byte ptr [rcx+2],al
 000000000000003F: 8A CA              mov         cl,dl
 0000000000000041: FF 48 F5           dec         dword ptr [rax-0Bh]
 0000000000000044: 75 00              jne         0000000000000046
 0000000000000046: 3A 80 C0 FF 49 C2  cmp         al,byte ptr [rax+FFFFFFFFC249FFC0h]
 000000000000004C: FF 48 0B           dec         dword ptr [rax+0Bh]
 000000000000004F: 74 C1              je          0000000000000012
 0000000000000051: 8B 4C D1 8B        mov         ecx,dword ptr [rcx+rdx*8-75h]
 0000000000000055: 48 00 39           add         byte ptr [rcx],dil
 0000000000000058: 80

Note that the code after the ret instruction at 2C is unreachable so it doesn't matter that it's nonsense

Backhand, 33 27 bytes
iH~0}|{<:: oi]io ::<{|}0~Hi

Try it online!
Unlike a lot of the solutions here, this one actually does use the palindromised code!
Explanation:
i  0 |{      Get the first character and enter the loop
        :  o    Output the character while preserving it
              i  :     Get input and duplicate it
                   <{  Turn around
             ]         Increment the copy to check if EOF
    }| <    Loop again if not EOF
  ~   If EOF, pop the extra copy of EOF
 H    Terminate, printing the contents of the stack.

Altogether, the unexecuted instructions are:
       :   i  o :   |}0~Hi

Zsh + coreutils, 33 23 bytes
tee >(rev) # )ver(> eet

Try it online!

Python 3, 53 bytes
t=input();print(t+t[::-1])#)]1-::[t+t(tnirp;)(tupni=t

Try it online!

Pyth, 7 bytes
+ Q_Q +

Try it online!
Uses implicit variables at the end of the program, which was not a feature when the other Pyth answers here were posted.

05AB1E, 1 byte
º

Try it online! For multiline input, surround the input in triple quotes (""").
º  # full program
º  # push...
   # implicit input...
º  # concatenated with...
   # implicit input...
º  # reversed
   # implicit output

I'm afraid this doesn't work for all characters that will be mirrored (e.g. /<{([).

@KevinCruijssen Good catch!

Kotlin, (26+1)*2=54 (19+1)*2=40 bytes
    var palindrome:(String)->String=

    {s->s+s.reversed()}//})(desrever.s+s>-gnirtS:s{

Try it online!

Headascii, 63 bytes
{N)UPO}:+E.N-)++E:{UN)RO}:RPNE.!.ENPR:}OR)NU{:E++)-N.E+:}OPU)N{

Try it here! Code will have to be copied and executed like this:
erun("{N)UPO}:+E.N-)++E:{UN)RO}:RPNE.!.ENPR:}OR)NU{:E++)-N.E+:}OPU)N{","your input")

This was rough. You can't have mismatched curly braces in headass/ascii in code blocks that are accessed, even if the braces are never reached, so I couldn't do anything clever with reusing backwards code.
Explanation:
{N)UPO}:+E.N-)++E:{UN)RO}:RPNE.!.ENPR:}OR)NU{:E++)-N.E+:}OPU)N{

{N)UPO}:+E.  Block 0

{     }      Loop, which
 N)    :     While there is still unread input,
   UP        Reads input and concatenates it to the string register
     O       And pushes the input to the "output" array.
        +E   Go to block 1, pop the entire output array,
              and push it onto the input array
          .  Block separator

N-)++E:{UN)RO}:RPNE.  Block 1

N-)                   If there is nothing left in the input array
   ++E                  Go to block 2
      :               Else
       {     }          Loop, which
        U               Reads and discards an input byte
         N)             If there's still more input,
           RO             Recall the discarded byte and
                           save it to the output array
              :         Else, exit the loop, and
               R          Recall the discarded byte and
                P         concatenate it to the string register
                 NE     Return to the start of block 1,
                         pop the entire output array,
                         and push it onto the input array
                   .    Block separator

!.  Block 2

!   Print the string register
 .  Block separator, end execution

ENPR:}OR)NU{:E++)-N.E+:}OPU)N{  Blocks 3 and 4

     }     {           }     {  Tragic mismatched curly braces
                                 which prevent me from reusing
                                 reversed code. These blocks
                                 are invalid and inaccessible

Copies the string, repeatedly concatenates the last character of the copy to the original and removes it from the copy, until the copy is gone.
I think block 1 is golfable, but im out of ideas for now. This is pretty much just the canonical solution, without much actual golfing other than A()=>A) and [+ => N type stuff, small optimizations.

Scala, 30 bytes
s=>s+s.reverse//esrever.s+s>=s

Just the "comment trick", I was not able to provide a shorter solution without it :)
Try it online!

JavaScript, 56 bytes
f=([c,...d])=>c?c+f(d)+c:''//'':c+)d(f+c?c>=)]d...,c[(=f

Try it online!
Why no one recurse?

C (gcc), 100 bytes
main(c){read(0,&c,1)&&putchar(c,main(write(1)));}//};)))1(etirw(niam,c(rahctup&&)1,c&,0(daer{)c(niam

Try it online!

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/