News for hackers. Stuff that matters.
Re:Truth Functional Logic for Hackers by mcguire on Tuesday March 11, 2025 @03:14PM (#43336016)
The important part is at the end of the article: "For those interested in building a stronger foundation in logic, the Open Logic Project provides excellent free educational resources on propositional and predicate logic, formal proof systems, and other topics such as modal logic and set theory - all targetted towards a non-mathematical audience."

https://openlogicproject.org/

Re:Truth Functional Logic for Hackers by tantalor on Tuesday March 11, 2025 @02:52PM (#43335803)
I don't get it. Isn't this what compilers are for? So I don't have to rewrite my code in an equivalent but stupider way just to get a marginal performance gain.
Re:Truth Functional Logic for Hackers by bbaron63 on Tuesday March 11, 2025 @03:36PM (#43336210)
Presumably, the compiler is not aware of the hardware bug in the OR operation, so it won't do any transforms to avoid using the OR operation.
Re:Truth Functional Logic for Hackers by tantalor on Tuesday March 11, 2025 @06:57PM (#43338007)
Okay so... then patch the compiler? This is basic stuff.
Re:Truth Functional Logic for Hackers by spartanatreyu on Tuesday March 11, 2025 @07:29PM (#43338243)
If it were "basic stuff", then you probably weren't using a high performance compiler to begin with.
Re:Truth Functional Logic for Hackers by etbebl on Tuesday March 11, 2025 @10:14PM (#43339291)
I think what you're missing is that the premise of a hardware bug is just a frame story for a lesson in manipulating logical statements, which is the main point.
Re:Truth Functional Logic for Hackers by tantalor on Wednesday March 12, 2025 @10:57AM (#43343952)
Okay, it's just incredibly contrived.

You might as well replace "hardware bug" with "a wizard put a curse on the OR operator" or "the president put a tariff on OR imports", and it would be more believable.

Re:Truth Functional Logic for Hackers by lucaspauker on Tuesday March 11, 2025 @03:45PM (#43336314)
Re:Truth Functional Logic for Hackers by cluckindan on Tuesday March 11, 2025 @05:15PM (#43337082)
The code blocks’ font size varies line by line on mobile. Hint: set it to be smaller than the body text size because monospace fonts tend to be a bit larger than proportional ones.
Re:Truth Functional Logic for Hackers by ChilledTonic on Tuesday March 11, 2025 @05:35PM (#43337270)
You've discovered a CSS issue that I did not notice for seven years.

Thanks.

The issue was that for some reason, different types of code had different font size settings.

Re:Truth Functional Logic for Hackers by hoppp on Tuesday March 11, 2025 @06:37PM (#43337855)
My first thought was to rewrite it without any or and operation. just return early from if statement.

If user is blacklisted return access denied; If account is expired return access denied; If no conditions match return access granted;

Wouldn't that be more effective?

Re:Truth Functional Logic for Hackers by ChilledTonic on Tuesday March 11, 2025 @08:09PM (#43338550)
You are touching on an inherent truth in TFL, which is that there are nearly infinite equivalent statements for any logical sentence.

The idea for the article was to make a real example of logical equivalence, as books on the subject stay pretty abstract. - like others have mentioned, in the real world there are smarter choices to be made.

Re:Truth Functional Logic for Hackers by nvader on Tuesday March 11, 2025 @06:53PM (#43337983)
In this blog article from 2021, I warn about making this change without appropriate care, as it has been a source of common bugs: https://danverbraganza.com/writings/de-morgans-flaw-perform-...
Re:Truth Functional Logic for Hackers by jonsen on Tuesday March 11, 2025 @08:01PM (#43338512)
> At every place X in the following expression, introduce a boolean negation if there isn’t one (or, equivanently remove one if there is), and

I think it should read:

At every place X in the following expression, introduce a boolean negation if there isn’t one and remove one if there is, and

Maybe even better:

At every place X in the following expression, introduce a boolean negation. If you get two concecutive NOT's, they can be removed.

Next, I don't see how

  timespent <= duration
is the negation of

  duration > time_spent

?