I think I first heard of Kdb (precursor to kdb+) back in 1998 thanks to my friend PX. It claimed to be the fastest database in the block, but the K language and the fact that it aimed an industry not close to my interests made me download it a couple of times, fire up the 32bit interpreter and then go on with life. Fast forward some years and I learn that KX was aquired and that in the mean time Q was in the system to make it more accessible. In fact Q is written in K and you can read the implementation if you download the evaluation version. My interest was rekindled thanks to this arraycast episode and I ordered Fun Q. While waiting for the book, I watched the nine first videos from “An introduction to Kdb+” and tried to think whether I can write anything fancy with so little study.
Two simple and basic programs came to mind, FizzBuzz and the Collatz conjecture function. Could I do it with this little exposure to the language and some googling around? It turns that there are more articles about Q/Kdb+ than I expected on the net, so it was possible to figure things out. Let’s see:
Here is my take on the FizzBuzz:
{f:0=x mod 3;b:0=x mod 5;fb:f&b;$[1=fb;"fizzbuzz";1=f;"fizz";1=b;"buzz";x]} '[1+til 35]
1
2
"fizz"
4
"buzz"
"fizz"
7
8
"fizz"
"buzz"
11
"fizz"
13
14
"fizzbuzz"
16
17
"fizz"
19
"buzz"
"fizz"
22
..
I wanted to make a version like this in Python print(((x mod 3 == 0) * "fizz") + ((x mod 5 == 0) * "buzz") or x)
but you can’t multiply strings with booleans in Q (or you can, but I have not figured it out yet). So I worked it out with a switch statement instead. The difficult part for me was figuring out the “execute the function for each of the numbers from 1 to 100” (the '[1+til 100]
part of the expression).
To write the Collatz function, you do something like {$[0 = x mod 2; x%2; (1+3*x)]}[45]
which finds the next term in the sequence starting from 45. But we want to make it run recursively. Q has the /
and \
operators for this, and thus a run could be like {$[0 = x mod 2; x%2; (1+3*x)]}\[45]
which is supposed to feed each run’s output to the next run and also print the intermediate returns so that we see the sequence build. However, since the run does not converge we will never see an ouput and we need something to limit the runs to a finite number, which allows us to see the sequence:
q){$[0 = x mod 2; x%2; (1+3*x)]}\[18;45]
45
136
68f
34f
17f
52f
26f
13f
40f
20f
10f
5f
16f
8f
4f
2f
1f
4f
2f
q)
I do boolean expression comparisons with 0 = x mod 2
instead of x mod = 0
because q has no precedence and evaluates from right to left. So the x mod 2 = 0
is equal to x mod (2 = 0)
which is definitely not the comparison I wanted. That is why this gives 0N
as a result. In Q you’re supposed to code golf a bit and I believe that is why 0 = x mod 2
is preferred to (x mod 2)=0
.
I really do not know the proper idiomatic way to write this stuff yet, but I hope I stay engaged long enough to find out.
Update: After posting this blog, I googled “q language fizzbuzz” and came accross the Kx solution. I read it between the TV commercials and here is what I came up with:
{fb:sum 1 2*0=x mod/:3 5;$[fb=0;x;fb=1;"fizz";fb=2;"buzz";"fizzbuzz"]}'[1+til 17]
Update 2: Assuming we consider reaching to 1 a stop condition for the Collatz function, then using the convergence feature for scanning we can have the following function in order to compute the sequence: -1 _ {$[1=x;1;0=x mod 2;x%2;1+3*x]}\[18]
. We use the drop last item (-1 _
) because the scan prints the 1
twice (since convergence stops the iteration until two consecutive iterations return the same result; plus or minus some delta I think).
PS: You may also want to read about the new data platform from the reclusive genius of banking IT
All images © Cap_able, shared with permission
Here’s some unusual criteria to consider when deciding what to wear: if you’re scanned by facial-recognition software, do you prefer being detected as a zebra, giraffe, or a dog? Cap_able, an Italian fashion-meets-tech startup, prompts consumers to consider individual rights to privacy when making decisions about self-expression. The studio’s inaugural project, the Manifesto Collection, combines knitwear with an algorithm into a kind of 21st-century camouflage that protects the wearer’s biometric data without the need to conceal the face.
Built on ideas of collaboration and awareness, Cap_able was established in 2019 to fuse technology, textiles, and fashion into a high-tech product with everyday applications. Evocative of Magic Eye puzzles, the technology behind the Manifesto Collection‘s psychedelic patterns is an innovative system “capable of transposing images called adversarial patches onto a knitted fabric that can be used to deceive people detectors in real time,” the company says.
“Choosing what to wear is the first act of communication we perform every day. (It’s) a choice that can be the vehicle of our values,” says co-founder and CEO Rachele Didero. Likening the commodification of data to that of oil and its ability to be sold and traded by corporations for enormous sums—often without our knowledge—Didero describes mission of Cap_able as “opening the discussion on the importance of protecting against the misuse of biometric recognition cameras.” When a person dons a sweater, dress, or trousers woven with an adversarial image, their face is no longer detectable, and it tricks the software into categorizing them as an animal rather than a human.
The idea for the startup was planted in 2019 when Didero enrolled at the Fashion Institute of Technology in New York City, where she was introduced to topics and issues around privacy and human rights. The idea of combining fashion and computer science evolved during months of research in working with textiles and studying artificial intelligence. She developed the now-patented concept of knitting adversarial imagery directly into the fabric of the garments, giving them the ability to respond to an individual’s size and shape, as opposed to existing versions which could only be applied to surfaces. After developing prototypes and testing the patterns using different types of recognition software, Didero teamed up with business partnert Federica Busani to launch the first collection.
Unlike most clothing items you’ll find on the rack, Cap_able’s garments are accompanied by some unique fine print: “The Manifesto Collection‘s intent is not to create an invisibility cloak, rather, it is to raise awareness and protect the rights of the wearer wherever possible.” See the full collection on Cap_able’s website.
Do stories and artists like this matter to you? Become a Colossal Member today and support independent arts publishing for as little as $5 per month. The article Trick Facial Recognition Software into Thinking You’re a Zebra or Giraffe with These Pyschedelic Garments appeared first on Colossal.
All images © Ruby Silvious, shared with permission
When we steep a cup of tea, we typically toss out the bag once it has served up its brew, but for Ruby Silvious, this humble sachet provides the basis for a distinctive artistic practice. Known for her miniature paintings that use tea bags as canvases, she has expanded her use of the material by employing it as a fabric for larger-scale works that are inspired by her family history and an interest in fashion. “It gives me a chance to do large scale work, the antithesis to my miniature paintings,” she tells Colossal. “It’s only natural that my art has always been inspired by fashion. My maternal grandmother was a brilliant seamstress. I was only 20 years old when I migrated to the U.S. from the Philippines, and my very first job was at Bergdorff Goodman in New York City.”
Silvious began making garments in 2015, spurred by an ongoing fascination with the various methods of printing, staining, and assembling the deconstructed segments together. “I have accumulated bins of used tea bags,” she says, “not just from my own consumption but also from friends and family who have generously contributed to my growing collection.” She has made more than ten full-size kimonos, each requiring up to 800 used bags to complete. Pieces in her most recent series, Dressed to a Tea, average approximately 75 to 125 sachets, each one emptied out, flattened, and ironed before being glued together into shirts, slips, or child-size dresses. “Some tea bag pieces have monoprints on them, and the simpler designs are assembled with plain or slightly stained, used tea bags, giving them a more delicate and fragile look,” she explains.
A number of pieces from Dressed to a Tea will be on view in a weeklong exhibition at Ceres Gallery in New York from December 5 to 10. Her work will also be featured in a solo exhibit at the Ostfriedsisches Teemuseum in Norden, Germany, from March 4 to April 29, 2023. You can find more of Silvious’s work on her website and Instagram.
Do stories and artists like this matter to you? Become a Colossal Member today and support independent arts publishing for as little as $5 per month. The article Thousands of Used Tea Bags Assemble in Ruby Silvious’s Delicate Full-Size Garments appeared first on Colossal.
I am subscribed to the Fermat’s Library newsletter. Their paper of the week is The Economic Organization of a P.O.W. Camp. The author, R. A. Radford, observed the life of the prisoners and their economic interactions. I guess this is a coping mechanism in a way. Use what you know to understand the situation you are in and survive the best way you can.
Radford’s paper and the use of cigarettes as currency reminded me also of the use of rum as currency in 1790 Australia (the most popular form in fact). Which also came with its own set of problems: Farmers had no incentive to produce crops only to be paid in rum. They had to pay workers in rum and with many workers drinking their pay, productivity was lowered.
It reminds me also of the book Games Prisoners Play, where its author Marek M. Kaminsky, while imprisoned in Communist Poland, started mapping the dynamics between groups of prisoners and analysing them using Game Theory.