[Question]
  [
Who needs to compare things case insensitively when you're able to generate every permutation of uppercase and lowercase? No one! That's the answer. No one does. Your task is to achieve this feat; generate all possible permutations of uppercase/lowercase for a given input.
## Input
A string of printable standard ascii characters. Input should not be assumed to be all lowercase. Input will always be at least one character.
## Output
Every permutation of uppercase and lowercase for the inputted string (no duplicates). This should only change characters with a small and large version (numbers will stay the same). Each permutation must be output as a string or a list of characters; lists of singleton strings are not allowed.
## Examples
```
a1a
['a1a', 'a1A', 'A1a', 'A1A']
abc
['abc', 'abC', 'aBc', 'aBC', 'Abc', 'AbC', 'ABc', 'ABC']
Hi!
['hi!', 'hI!', 'Hi!', 'HI!'] 
```
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer (in bytes) wins.
As a fun extra see how much additional effort it will take to handle the extended ascii characters, here is an extra test case:
```
ž1a -> ['ž1a', 'ž1A', 'Ž1a', 'Ž1A']
```
(your program does not need to support this)
  
[Answer]
# Pyth, ~~13~~ ~~12~~ 11
```
{msrVQd^U2l
```
1 byte thanks to Leaky Nun!
Another byte thanks to Jakube!
[Try it here](http://pyth.herokuapp.com/?code=%7BmsrVQd%5EU2l&input=%22ab1c%22&debug=0) or run a [Test Suite](http://pyth.herokuapp.com/?code=%7Bms.nd%2aFrRR2&input=%22ab1c%22&test_suite=1&test_suite_input=%22a1a%22%0A%22abc%22%0A%22Hi%21%22%0A%22%C5%BE1a%22&debug=0)
We create a list of lists True/False values by taking the cartesian product of the list `[0, 1]` with itself a number of times equal to the length of the input string. So each of the sublists has the same length as the input string. Then we apply the `r` function as a vector operation over the input and the list, so we get `r letter value` for each sub element. `r` with second argument zero is to lowercase and with one it is to upper case. This creates duplicates on non-letters, which means we need to remove duplicates from the result.
[Answer]
# [Jelly](http://github.com/DennisMitchell/jelly), 6 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
żŒsŒpQ
```
This is a monadic link (function) that expects a string as left argument and returns a list of strings.
Handles non-ASCII characters. [Try it online!](http://jelly.tryitonline.net/#code=xbzFknPFknBRCsOH4oKsRw&input=&args=ImExYSIsICJhYmMiLCAiSGkhIiwgIsW-MWEi)
### How it works
```
żŒsŒpQ  Monadic link. Argument: s (string)
 Œs     Swapcase; change the case of all letters in s.
ż       Zipwith; pair each character with itself with changed case.
   Œp   Take the Cartesian product of all pairs.
     Q  Unique; deduplicate the Cartesian product.
```
[Answer]
# Python, ~~74~~ 71 bytes
```
f=lambda s:s and{r[0]+t for r in{s,s.swapcase()}for t in f(s[1:])}or{s}
```
Handles non-ASCII characters. Test it on [Ideone](http://ideone.com/buAQWf).
[Answer]
# Oracle SQL 11.2, 276 bytes
```
WITH v AS(SELECT SUBSTR(:1,LEVEL,1)c,ROWNUM p FROM DUAL CONNECT BY LEVEL<=LENGTH(:1))SELECT w FROM(SELECT REPLACE(SYS_CONNECT_BY_PATH(c,','),',','')w FROM(SELECT UPPER(c)c,p FROM v UNION SELECT LOWER(c),p FROM v)START WITH p=1CONNECT BY PRIOR p=p-1)WHERE LENGTH(:1)=LENGTH(w);
```
Un-golfed
```
WITH v AS
( -- Split input into an array of characters 
  SELECT SUBSTR(:1,LEVEL,1)c,ROWNUM p FROM DUAL CONNECT BY LEVEL<=LENGTH(:1)
)
SELECT w 
FROM   ( -- Build every string combination
         SELECT REPLACE(SYS_CONNECT_BY_PATH(c,','),',','')w 
         FROM   ( -- Merge upper and lower arrays, keep same position for each character, it allows to mix cases
                  SELECT UPPER(c)c,p FROM v UNION SELECT LOWER(c),p FROM v
                )
         START WITH p=1          -- Start with first character (either lowercase or uppercase)
         CONNECT BY PRIOR p=p-1  -- Add the next character (either lowercase or uppercase)
       )
WHERE LENGTH(:1)=LENGTH(w); -- Keep only full strings
```
Ugly as hell, must be more golfable.
[Answer]
## 05AB1E, 17 bytes
**Code:**
```
vyDš‚N0Êiâvy˜J})Ù
```
**Explained:**
```
vy                     # for each character in input
  Dš‚                  # create a pair of different case, eg: ['ž', 'Ž']
     N0Êiâ             # for all pairs but the first, take cartesian product
                         result will be a list of layered lists eg: [['ž', '1'], 'a'] 
            vy         # for each such list
              ˜J}      # deep flatten and join as a string eg: ž1a
                 )Ù    # wrap in array and remove duplicates
```
[Try it online](http://05ab1e.tryitonline.net/#code=dnlExaHigJpOMMOKacOidnnLnEp9KcOZ&input=xb4xYQ)
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~25~~ 22 bytes
```
:ef:1fd.
:2ac.
@u.|@l.
```
This works as well as the lowercase/uppercase predicates of Prolog, therefore it works on non-ASCII letters too:
```
?- run("ž1a",Z).
Z = ["Ž1A", "Ž1a", "ž1A", "ž1a"] .
```
### Explanation
Unlike all other answers as of the moment I'm posting this, this does not use the cartesian product approach at all.
* Main Predicate
```
:ef       Split the Input string into a list of 1-char strings
   :1f    Find all valid outputs of predicate 1 with the previous list
          of outputs as input
      d.  Unify the Output with that list excluding all duplicates
```
* Predicate 1
This is used to apply uppercasing or lowercasing on each char of the input, thus computing one possible permutation. Using findall on this predicate in the main predicate allows to compute all possible permutations (with some duplicates).
```
    :2a       Apply predicate 2 on the each element of the Input
       c.     Unify the Output with the concatenation of the elements of
              the previous list
```
* Predicate 2
This is used to turn a character of the string into either its uppercase or its lowercase version.
```
    @u.       Unify the Output with the uppercase version of the Input
       |      Or
        @l.   Unify the Output with the lowercase version of the input
```
[Answer]
## Haskell, ~~69~~ 58 bytes
```
import Data.Char
mapM(\x->toLower x:[toUpper x|isAlpha x])
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElsSRRzzkjsYgrzTY3scBXI6ZC164k3ye/PLVIocIquiQ/tKAAxKzJLHbMKchIVKiI1fyfm5iZp2CrANIQr6BRUJSZV6KXpqkQrZSYpKSjlGgIJpyMlGL/AwA "Haskell – Try It Online")
Edit: @Angs saved 11 bytes. Thanks!
[Answer]
# [MATL](https://github.com/lmendo/MATL), 13 bytes
```
tYov!Z}N$Z*Xu
```
[**Try it online!**](http://matl.tryitonline.net/#code=dFlvdiFafU4kWipYdQ&input=J2ExYSc)
### Explanation
```
t       % Implicit input string. Duplicate
Yo      % Change case of string
v       % Concatenate as a 2xN char array, where N is input length
!       % Transpose: Nx2 char array. Each row has different case, if letter
Z}      % Split into rows: gives N strings of 2 chars. Each char has different 
        % case if it's a letter, or is repeated otherwise
N$      % Specify N inputs for next function
Z*      % Cartesian product of the N strings. Each combination is a row.
        % Repeated chars (i.e. non-letters) give rise to duplicate rows.
Xu      % Remove duplicate rows. Implicit display
```
[Answer]
## JavaScript (Firefox 30-57), ~~92~~ 90 bytes
```
f=([c,...s])=>c?[for(t of f(s))for(d of new Set(c.toUpperCase()+c.toLowerCase()))d+t]:['']
```
Edit: Saved 2 bytes because `new Set` will happily extract the unique characters from a string.
[Answer]
# [Perl 6](http://perl6.org), 37 bytes
```
{[X~] '',|.comb.map:{unique .lc,.uc}}
```
[Try it](https://tio.run/##XVDLTsMwELznKyYiIolIXfXSQ0sj3F7aOwckhJBjDLXIi9iuqEr4s3Lrd4Vt03Lg4p3Z2fGsXasmH3dXPobONMNMl0NVblAfu57njMJmzOT0hO6VsVPPK7a4lsKoAQ0VzgqrqxKzbvf48P2EMEy@mKyKjBWinuxcqT@cAstlwpxs247Md5buMZgh8oBQjESIWYpbAhAjDk6Vj3ianNRMntVMQmQLiDnV@QKcOCfOifP5op9ear@fXmsf65UPamC58nv18HOJOiLQwXHYH9H@FBfT2@pclLjpNyT6WjWXdQcpgmdEk3e1jQJd1s7GyWQjcqeiQH3WSlr1EsfYUZI2@P8/FwszVWMT/DnOnL1pY722@wU "Perl 6 – Try It Online")
### Explanation:
```
{
  [X[~]]                     # cross combine using &infix:<~> operator
    '',                      # empty string so that 1 character strings work
    |                        # flatten the following into outer list
      .comb                  # get every character from input string
      .map:                  # and map it with:
        { unique .lc, .uc }
}
```
### Test:
```
#! /usr/bin/env perl6
use v6.c;
use Test;
my &case-permutation = {[X~] '',|.comb.map: {unique .lc,.uc}}
my @tests = (
  'a1a' => <a1a a1A A1a A1A>,
  'abc' => <abc abC aBc aBC Abc AbC ABc ABC>,
  'Hi!' => <hi! hI! Hi! HI!>,
  'ž1a' => <ž1a ž1A Ž1a Ž1A>,
);
plan +@tests;
for @tests -> $_ (:key($input),:value($expected)) {
  is case-permutation($input).sort, $expected.sort, .gist
}
```
```
1..4
ok 1 - a1a => (a1a a1A A1a A1A)
ok 2 - abc => (abc abC aBc aBC Abc AbC ABc ABC)
ok 3 - Hi! => (hi! hI! Hi! HI!)
ok 4 - ž1a => (ž1a ž1A Ž1a Ž1A)
```
[Answer]
# Julia, ~~66~~ 60 bytes
```
!s=s>""?[~s[1:1]t for~=(ucfirst,lcfirst),t=!s[2:end]]∪[]:[s]
```
[Try it online!](http://julia.tryitonline.net/#code=IShzKT1zPiIiP1t-c1sxOjFddCBmb3J-PSh1Y2ZpcnN0LGxjZmlyc3QpLHQ9IXNbMjplbmRdXeKIqltdOltzXQoKZm9yIHMgaW4gKCJhMWEiLCAiYWJjIiwgIkhpISIpCiAgICBkaXNwbGF5KCFzKQogICAgcHJpbnRsbigpCmVuZA&input=)
[Answer]
# Python, 69 bytes
```
import itertools as i;f=lambda s:set(i.product(*zip(s,s.swapcase())))
```
[Answer]
## Actually, 28 bytes
```
;╗l2r∙`"'Ö*£"£M╜@Z"iƒ"£MΣ`M╔
```
[Try it online!](http://actually.tryitonline.net/#code=O-KVl2wycuKImWAiJ8OWKsKjIsKjTeKVnEBaImnGkiLCo03Oo2BN4pWU&input=ImExYyI)
This program can handle non-ASCII characters, thanks to the magic of Python 3.
Explanation:
```
;╗l2r∙`"'Ö*£"£M╜@Z"iƒ"£MΣ`M╔
;╗                            save a copy of input to reg0
  l                           length of input
   2r                         [0,1]
     ∙                        Cartesian product with self (length of input) times
      `                  `M   map:
       "'Ö*£"£M                 push `Ö` (swapcase) if 1 else `` for each value in list
               ╜@Z              zip with input
                  "iƒ"£M        swap the case of those values
                        Σ       join string
                           ╔  unique elements
```
[Answer]
## C ~~229~~ 252 bytes
```
i,n,j,k,l;f(char *s){l=strlen(s);for(i=0;i<l;i++)s[i]=tolower(s[i]);int v[l];for(i=0;i<l;i++)v[i]=0;for(i=0;i<pow(2,l);i++){n=i,k=0;for(;n;k++){v[k]=n;n/=2;}for(j=0;j<l;j++){v[j]%=2;if(v[j])s[j]=toupper(s[j]);else s[j]=tolower(s[j]);}printf("%s ",s);}}
```
Ungolfed version:
```
void f(char *s)
{
  int i,num,k,l=strlen(s);
  for(i=0;i<l;i++)
     s[i]=tolower(s[i]);
   int v[l];
   for(i=0;i<l;i++) 
     v[i]=0;   
   for(i=0;i<pow(2,l);i++)
   {
      num=i,k=0;
      for(;num;k++)
      {
         v[k]=num;
         num/=2;        
      } 
      for(int j=0;j<l;j++)
      {
        v[j]%=2;
        if(v[j])
         s[j]=toupper(s[j]);
        else
         s[j]=tolower(s[j]);
      }
      printf("%s \n",s);       
   } 
}
```
Explanation:
* Accept the character string, convert the string to lowercase.
* Declare integer array of length equal to that of the string. Fill it with zeroes.
* Store the numbers from 0 to `2^strlen(s)`in binary form in an `int` array.( For a 3 byte string: 000,001,010...111)
* Depending on if a bit at a position is set or, toggle the case.
* Output the string for every possible combination.
[Try it online!](https://tio.run/nexus/bash#ZZDNboMwEITvPMWKNIppnN@rQ14EcUCOgQXHtmyHqIp4dmqTVGnV2@w3o9XsCt5qWCULVFzeLuLk/AX1tj3DG10r3wbyBtx/GfGHOG9RNRFNSBXtaE8lqwlvKwufLnvIPCSkUMRlrNaWYL5neJIM1@vMFVjmXkt9F5bEIWOoPAyFLP9lh5jd/8JG38mRymx2HypH2r98plgf2VD0Za6Y2uVHNkajC4Eu7Oueblcug4M1iTKU6WKZmzFzmUCYkE7Ai/@UjHw04WZfk3TpIKXhsHGcYvFrhYpEUdmGU3j@IOihKLMH1GSWh7AAwAp/swr2bGTJCs5grG62PGk4h42epxeCjbwm291M0o9DOk3KVc6gcN8 "Bash – TIO Nexus")
[Answer]
## [Hoon](https://github.com/urbit/urbit), 242 bytes
```
|=
t/tape
=+
l=(reap (pow 2 (lent t)) t)
%+
roll
(gulf 0 (dec (lent l)))
|=
{a/@ b/(set tape)}
=+
%+
turn
(gulf 0 (dec (lent t)))
|=
n/@
=+
t=(snag n t)
=+
k=(trip t)
?:
=(0 (cut 0 n^1 a))
?:
=((cuss k) t)
(cass k)
(cuss k)
t
(~(put in b) -)
```
Ungolfed:
```
|=  t/tape
=+  l=(reap (pow 2 (lent t)) t)
%+  roll  (gulf 0 (dec (lent l)))
|=  {a/@ b/(set tape)}
    =+  %+  turn  (gulf 0 (dec (lent t)))
      |=  n/@
      =+  t=(snag n t)
      =+  k=(trip t)
      ?:  =(0 (cut 0 n^1 a))
        ?:  =((cuss k) t)
              (cass k)
        (cuss k)
      t
    (~(put in b) -)
```
I'm not sure how much smaller this could be, unfortunately.
First, we set `l` equal to a list with 2^(length t) repetitions of `t`. Hoon doesn't have a `fac` function in the stdlib, but 2^n is always bigger than n!, so we simply map over the bigger list and use a `set` (hashmap) to de-duplicate entries.
We then fold over the list [0..(length l)], accumulating into a `(set tape)`. We need to do this instead of mapping over `l` directly because we also need to know what number repetition it is (`a`), but can't simply increment an accumulator due to Hoon being a pure language.
We map over [0..(length t)] (again so we have the current index), setting `t` to the nth character in the string, checking if the nth bye of `a` and inverting the case (cuss or cass, depending if it changes or not). The return type of this map is a `tape`.
We then put the string into our hashmap, and return the hashmap of all the strings.
[Answer]
# C, 216 bytes
```
k,i,j,p,n,m;z(char *c){n=-1;m=0;while(c[++n])if(c[n]>64&c[n]<90)c[n]+=32;else if(c[n]<'a'|c[n]>'z')m++;k=1<<(n-m);for(j=0;j<k;j++){for(i=0;i<n;i++){p=1<<i;putc((j&p)==p?toupper(c[i]):c[i],stdout);}putc(0xa,stdout);}}
```
This is ~~a different approach~~, the **same** approach as the other C answer.
Should I delete this, and put it under the other answer as a comment?
Let me explain with the **Ungolfed version**
```
k,i,j,p,n,m;
z(char * c) {
    int n=-1;       // We start at -1 because of forward incrementation
    int m=0;        // this will count the characters we don't have to manipulate
    while(c[++n])   // go until we reach '\0'
    {
        if(c[n]>='a'&c[n]<='z')c[n]-=32; // If we are lower case, then convert
        else if(c[n]<'A'|c[n]>'Z')m++;   // If we are neigther lower case
                                         // nor upper, then make a note
    }
   
    // get 2 ^ ("length" - "number of invonvertibles")
    k=1<<(n-m); 
    for(j=0;j<k;j++) {      // go through the combinations
        for(i=0;i<n;i++) {  // for each combination go though the characters
            p=1<<i;         // for each character get it's bit position
            putc(
                // if the bit position is set (==1) 
                (j&p)==p ?
                   tolower(c[i]) // convert
                   : c[i], // else: don't
                stdout);
        }
        putc(0xa, stdout);  // print a newline
    }
}
```
[Answer]
# Python3, 96 bytes
```
i=input().lower()
for l in{*__import__('itertools').product(*zip(i,i.upper()))}:print(*l,sep='')
```
Late to the party but still had a go.
Thanks to DLosc for reminding me of the stuff I missed, giving me golfing tips and saving me a bunch of bytes. :)
[Answer]
## [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 55 bytes
```
""<>#&/@Union@Tuples[{#,ToUpperCase@#}]&@*Characters
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78H1CUmVei4KCloPFfScnGTllN3yE0LzM/zyGktCAntTi6WlknJD@0oCC1yDmxONVBufZ9f3usmoOWc0ZiUWJySWpR8X9NBX0HhWqlRMNEJR0FpcSkZBCVkamoVPsfAA "Wolfram Language (Mathematica) – Try It Online")
`` is the transpose operator (and displays as a superscript **T** in Mathematica).
[Answer]
# [Perl 5](https://www.perl.org/), 52 + 1 (`-n`) = 53 bytes
```
@k{glob s/./lc("{$&,").uc"$&}"/ger}++;say for keys%k
```
[Try it online!](https://tio.run/##K0gtyjH9/98huzo9Jz9JoVhfTz8nWUOpWkVNR0lTrzRZSUWtVkk/PbWoVlvbujixUiEtv0ghO7WyWDX7///EpOR/@QUlmfl5xf91fU31DAwN/uvmAQA "Perl 5 – Try It Online")
[Answer]
# Tcl, 165 ~~181~~ bytes
```
set n -1
while {[incr n]<1<<[llength [set s [split $argv {}]]]} {puts [join [lmap c $s b [split [format %0[llength $s]b $n] {}] {string to[expr $b?{u}:{l}] $c}] ""]}
```
Improvements thanks to **sergiol**.
Previous answer:
```
set s [split $argv {}]
set n -1
while {[incr n]<1<<[llength $s]} {set r ""
foreach c $s b [split [format %0[llength $s]b $n] {}] {set r $r[string [expr $b?{tou}:{tol}] $c]}
puts $r}
```
Uses a binary number to choose between upper/lower case when creating the output text.
[Answer]
## [Perl 5](https://www.perl.org/), 30 bytes
```
s/\pl/{\l$&,\u$&}/g;say<"$_ ">
```
[Try it online!](https://tio.run/##K0gtyjH9/79YP6YgR786JkdFTSemVEWtVj/dujix0kZJJV5Bye7//0TDRK7EpGSujEzFf/kFJZn5ecX/dfNy/uv6muoZGBoAAA "Perl 5 – Try It Online")
Outputs an additional space at the end of the output.
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 39 bytes
```
&Cross[Sum@V]##Unique@V#SwapCase=>Chars
```
[Try it online!](https://tio.run/##SywpSUzOSP2fZmX7X825KL@4ODq4NNchLFZZOTQvs7A01SFMObg8scA5sTjV1s45I7Go@L9fampKcbRKQUFyeixXQFFmXklIanEJSEVxdJqOQjSXAhAoJRomKukAqaRkEOWRqQiiju4DinLFxv4HAA "Attache – Try It Online")
Similar to the perl answer. (I've lost my more interesting alternative, I should be posting those in the next few hours.)
[Answer]
# JavaScript (ES6), 103
Handles non-ASCII characters
```
(a,r=new Set)=>a?f(a.slice(1)).map(v=>(C=o=>r.add(a[0][`to${o}erCase`]()+v),C`Upp`,C`Low`))&&[...r]:[a]
```
**Test**
```
f=(a,r=new Set)=>a?f(a.slice(1)).map(v=>(C=o=>r.add(a[0][`to${o}erCase`]()+v),C`Upp`,C`Low`))&&[...r]:[a]
function test() { O.textContent = f(I.value).join('\n') }
test()
```
```
<input id=I oninput='test()' value='ž1a'>
<pre id=O></pre>
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 52 bytes
```
->s{a,*b=s.map{[_1,_1.swapcase]}
a.product(*b).uniq}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsEiN9ulpSVpuhY3TXTtiqsTdbSSbIv1chMLqqPjDXXiDfWKyxMLkhOLU2NruRL1CoryU0qTSzS0kjT1SvMyC2shejcVKLhFRyslKukoGQJxolJsLERiwQIIDQA)
]