News for hackers. Stuff that matters.
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by jl6 on Monday August 28, 2023 @05:29PM (#37300636)
The UNIX philosophy’s logical extreme is the NAND gate. Does one thing, does it well, and can be composed into arbitrary applications.
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by Drakim on Monday August 28, 2023 @05:30PM (#37300648)
Only if the NAND gate is expressed as a file
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by Waterluvian on Monday August 28, 2023 @05:33PM (#37300672)
Okay… please… someone implement ‘nand’ and write a script that does something simple using only it.
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by scarmig on Monday August 28, 2023 @05:35PM (#37300697)
nand.sh

  A_DIR="./A"
  B_DIR="./B"
  OUTPUT_DIR="./OUTPUT"
  FILENAME="input.txt"

  if [ -f "$A_DIR/$FILENAME" ] && [ -f "$B_DIR/$FILENAME" ]; 
  then
      rm -f "$OUTPUT_DIR/$FILENAME"
  else
      touch "$OUTPUT_DIR/$FILENAME"
  fi
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by jewel on Monday August 28, 2023 @06:36PM (#37301264)
Sure! Here's an implementation of nand and a 2-bit adder that uses it: https://github.com/jewel/nand
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by Waterluvian on Monday August 28, 2023 @06:48PM (#37301376)
Hah this is awesome!

I’m going to poke around and see how much it would take to stretch this into a basic Turing machine emulator.

Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by hmcq6 on Monday August 28, 2023 @07:13PM (#37301535)
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by thaumasiotes on Monday August 28, 2023 @07:44PM (#37301730)
Great find. People who like this might also like http://incredible.pm/ .

I don't know how I feel about the message "This is optimal!" displaying when you use one NAND gate to build an inverter at level 2. Level 1 forces you to build an NAND gate out of (1) an AND gate, plus (2) an inverter. It feels like it'd be more optimal to just reuse that inverter.

(And then level 3 is an AND gate, the other primitive† you started with...)

† Technically, you start with two primitives, implementing f(a, b) = a ∧ b and g(a,b) = ¬(b ⟶ a). You also get the ability to provide 0 and 1 as fixed inputs, thus ¬a ≡ g(a,1). What you lose after implementing the NAND gate is the ability to provide a fixed 1 input - instead, you are informed that you assume all gates automatically draw from this. Worst of all possible worlds.

Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by porridgeandrice on Tuesday August 29, 2023 @04:32AM (#37304856)
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by Someone on Monday August 28, 2023 @06:25PM (#37301150)
One thing? It does a logical and and then negates the result. The shell doesn’t really let users compose commands this way, but

  alias NAND="AND | NEG"
Also, a NAND command would need to have 2 stdin’s.
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by layer8 on Monday August 28, 2023 @07:20PM (#37301575)
It seems that Unix commands are the reverse of logical gates, having only one standard input but two standard outputs. Maybe they could be leveraged for reversible computing?

https://en.wikipedia.org/wiki/Reversible_computing

Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by thaumasiotes on Monday August 28, 2023 @07:29PM (#37301644)
> One thing? It does a logical and and then negates the result.

Sorry? Take a second to think about what you're saying.

In what conceivable sense is "doing a logical and" one thing while "doing a logical nand" isn't?

You can equally claim that

    x & y
is really just

    (x ↑ y) ↑ (x ↑ y)
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by Skgqie1 on Monday August 28, 2023 @08:29PM (#37302071)
Not the person you asked, but the initial point was taking that idea to the extreme. The concept of "one thing" in the NAND case is more extreme (in terms of granularity). No need to be sorry, it's ok.
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by thaumasiotes on Monday August 28, 2023 @08:40PM (#37302135)
Right, the person I asked is claiming that NAND is two things. You appear to have responded as if you disagree with my comment while not actually disagreeing with any part of it.

What did you think I meant by this question?

>> In what conceivable sense is "doing a logical and" one thing while "doing a logical nand" isn't?

Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by Skgqie1 on Monday August 28, 2023 @10:40PM (#37302948)
Sorry, I will try to make it more clear.

NAND is more complex than AND, in the sense that it is more expressive than AND (having functional completeness which AND does not).

Similarly, it can be built from other less complex operators (AND and NAND).

If you're taking "One thing" to the extreme, in terms of the granularity or complexity of that "one thing", NAND is not as granular or simple as AND - and therefore isn't taking it to as far "to the extreme".

Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by thaumasiotes on Tuesday August 29, 2023 @12:05AM (#37303458)
What's the argument that AND is less complex than NAND? It's true that NAND has completeness and AND doesn't, but so what? What you can build from something is not a measure of how complex it is. You measure complexity in terms of what it takes to describe something.
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by TylerE on Tuesday August 29, 2023 @12:32AM (#37303597)
It seems naively obvious to me that a(b(x)) is more complex than b(x). Practically tautology.
Re:Reaching the Unix Philosophy's Logical Extreme with WebAs... by thaumasiotes on Tuesday August 29, 2023 @01:57AM (#37303971)
You have to justify why you've chosen the particular starting point. NAND isn't defined as being "first you do AND, and then you negate it". It's defined like this:

    +---+---+-------+
    | a | b | a ↑ b |
    +---+---+-------+
    | 0 | 0 |   1   |
    +---+---+-------+
    | 0 | 1 |   1   |
    +---+---+-------+
    | 1 | 0 |   1   |
    +---+---+-------+
    | 1 | 1 |   0   |
    +---+---+-------+
AND is defined like this:

    +---+---+-------+
    | a | b | a & b |
    +---+---+-------+
    | 0 | 0 |   0   |
    +---+---+-------+
    | 0 | 1 |   0   |
    +---+---+-------+
    | 1 | 0 |   0   |
    +---+---+-------+
    | 1 | 1 |   1   |
    +---+---+-------+
You may notice that they are almost exactly the same.

> It seems naively obvious to me that a(b(x)) is more complex than b(x).

This is just obvious gibberish; if you define b(x, y) = x & y and a(x) = ~x, then you can say "I think a(b(x, y)) looks more complex than b(x, y)", but how do you respond to "when c(x, y) = x ↑ y, I think c(c(x,y), c(x,y)) looks more complex than c(x,y)"? The two claims can't both be true!

Everything, no matter how simple, can be described as the end of an arbitrarily long chain of functions. So what?