Showing posts with label logic. Show all posts
Showing posts with label logic. Show all posts


debugger != exterminator

over the years i've learnt the hard way that it's not possible to go through opiate withdrawal and debug Java at the same time. (trust me on this one.) interestingly, i've been seeing quite a few students who can't use a debugger at all - even the shockingly intuitive NetBeans onboard one - and i gotta admit, when you first see it, you're gonna be weirded out if you're not a programmer.

of course, having coded in hospital, on sedatives, with cannulae in both arms, for a good few weeks of my programming lifetime so far, i got a fair amount of sympathy for the kiddies i see trying to wade through their 5000+ lines of Java one by one, trying to find "the bit that won't work". and being the friendly campus opiate addict that i am, i decided to shoulder-surf my way around the lab for a while last week instead of doing my own work, in the hopes of finding out what they were commonly fucking up.

before i get going, don't get no wrong ideas here. i have no problem with people fucking up - i do it myself all the time, and as it's often been stressed over at Coding Horror, everybody fucks up. with that in mind, i found out they were pretty much all doing the same thing.

nobody was debugging their half-finished code. nobody had written either JUnit tests, or little test classes with souts to the console (System.out.println, that is); the main route seemed to be

1. write (usually quite good) code for the entire program
2. run
3. notice bugs, attempt to debug whole program (5+ classes) at once
4. realise sheer monstrosity of task, give up, go for milkshake.
obviously, this isn't exactly the most efficient way to be doing your shit. it's stressful, and more's the problem, it's a total waste of your precious lab hours. it's actually simple to avoid: you just have to run the program after every method, or group of interdependent methods.

that means, your cycle is code method, compile, test, debug, code method. if you gotta write biddy little classes to test your functions, go for it. the time you'll spend writing those is nothing compared to the stress you'd experience trying to work out all the bugs in a program when nothing's been tested, nothing is guaranteed to work and anything could be the problem.

that is, a debugger isn't an exterminator. it's not a flamethrower for removing a huge infestation of glitches, it's a pinpoint laser for picking them off one by one as they arrive; you just gotta keep looking for them, as you go, constantly.

(taking out kitchen roaches with a DVD-burning laser)


open thread: evolution, Roger and homo sapiens sapiens

so over at Pharyngula i ended up in a bigass discussion with Roger the Creationist, who won't accept that evolution is a fact, and i offered to start up a debate here (since the original thread is from ages ago).

so, here is an open thread. i'm not expecting anything decent.

actually, pessimism being my premier mindset, i'm not expecting anyfuckingthing. i'm like the antithesis of Deepak Chopra.



of Vista and pot plants

Vista has proven remarkably adaptive to the Toshiba's hardware, which i still suspect was made for it. i don't like OS-specific hardware: to me it seems to be violating users' basic choice over OS, and it puts a hell of a strain on open-source users to either find compatible drivers, deal with the Rubik's cube of ndiswrapper and MadWifi installs under Linux (assuming those are even applicable, which they're sometimes not) or write their own (no, i'm not good enough to do that).

that, and other good points with dark sides, mean i can't write off Vista as the memory-hogging, shiny-fronted, dubious-underbellied OS it really is. for instance, i like the tree view in folders, i like my hardware working, i like Windows Sidebar (although Tomboy Notes for GNOME is better) and i love the wallpapers. Aero is beautiful, but slow as fuck on a limited system; i can just run it, but not for long, i think. and of course, it being Windows, all kinds of external security apps, additions and fixes become necessary. i'm still undecided, though; more later.

on, then, to today's cool thing: a simple way to get students started with propositional logic. this is the Pot Plant Problem.

you want your students to determine whether these two propositions are logically equivalent:

x: If it has rained and it's been cold, then the plant is dead.
y: If it has rained, then either it hasn't been cold or the plant is dead.

it's not a difficult one to solve:

let r: it has rained, c: it has been cold, d: the plant is dead.

x translates in FProp to:
(r /\ c) -> d
y translates to:
r -> (¬c \/ d)

truth table for x:

r c d r/\c (r/\c)->d

truth table for y:

r ¬c d ¬c\/d r->(¬c\/d)

the last rows are the same, so the two statements are equivalent; that is,
(r/\c)->d <=> r->(¬c\/d).

the reason this particular problem is useful is simple: it's "truthy", so to speak. most students will be able to "see" on some level that the two statements are logically equivalent; most will use a real-life workthrough of them to determine whether they're true, which is why meatspace analogies are so useful to (non-wired) students when teaching them something new. more on teaching the wired ones later.

(for those not sure what i'm talking about, wired refers to a person whose life is intimately connected with the world of machines and the Net, or sometimes a Net addict; meatspace is the opposite of cyberspace, and refers to the non-mechanical world.)

oh yeah - and Vista's native Mahjong is a fucking kickass timewaster.




i really don't like this holiday fuckaround. everything in the whole of your average university shuts down, leaving people like me the only fuckers on campus - and in the case of yours truly, the only fucker on campus. it's bizarre - the cafes and shops close down, the labs are empty, professors and tutors stop checking their email, all the experiments you can usually earn a good few bob from stop running and you're left to sort shit on your own. i hate summer vacation.

this means two things: one, i can eat cornflakes in the lab, and two, i have a lot of time on my metal-filled little hands. (there's a half a cannula in my left hand where the NHS suck.) thus, i have time to show you cool shit like the contrapositive implication.

in propositional logic, the IMPLIES operator looks like this: -> . if P implies Q, the implication can only be false where P is true and Q is false. the contrapositive is the reverse and NOT of an implication; that is, where P->Q, the contrapositive is !Q->!P. interestingly, it always gives the same truth value as the original implication.

you can prove this with a truth table:

P Q P->Q Q->P !Q->!P
t t t t t
t f f t f
f t t f t
f f t t t

the rows for P->Q and !Q->!P are the same, so the contrapositive is the same as the implication. cool, huh? so the next time you see a nasty-looking thing like !Q->!P, you know you can simplify it to P->Q.

man, i really gotta get a hobby.



the universal tautology conjecture

to begin with, i bring something interesting to the table. this concerns formal logic, one of the most simplistically beautiful things to learn in my field, and one of the most rewarding; i shall be happy to explain the basics of predicate, propositional and fuzzy logic to any member of the set of homo sapiens capable of looking at a negation and asking in all honesty, "What the fuck is this line thing for?", so please ask if it's necessary. logic is a tool everyone should have access to.

there are some statements which are always agreed to be true; these are tautologies, and there are an infinite number of them. for all P, (P \/ ¬P) - "either P is true, or not P is true" - is one; i'm not talking outside the realms of formal calculae here, so "There is too a God" and "Lepht is a narrow-minded bastard" are not.

by the same token, a contradiction is a statement which is always agreed to be false. for all P, (P /\ ¬P) is one of the simplest ones - that is, "both P and not P are true".

there's a problem with this, though. logic comes in different systems; the statements i've showed you are tautological or contradictory under propositional logic. if i quantified them, they would be so under predicate logic, too. but there are many logical systems.

the one that chucks the proverbial spanner in the mail sorting machine and giggles like a heathen in church as it all explodes in a fountain of shredded paper and jiffy-bag shrapnel, so to speak, is fuzzy logic. fuzzy's a new system, and it's all fucked up: the fundamental difference between it and the older systems is that truth, in the old ones, is a binary value.

this deserves further inspection. under a system with binary truth values, truth is one of two things: 0 or 1, T or F. any value P can be either true, or false; it can't be neither, and it can't be both.

fuzzy logic kicks that in the balls: under this new system, truth is a double. so P can have any truth value from 0 to 1: it can have one of 0.009, or 0.56, or 0.987. the biggest ramification of this is, then, that P can belong to the groups "true" and "false" at the same time: that's why it's called "fuzzy": it blurs the once-concrete lines of 0 and 1 into a strange continuum of half-truths and grey areas that can't be used in the same precise way.

enter the propositional tautology. analyse it again, and unfortunately it loses its status: under fuzzy logic, P and ¬P can both have a non-zero truth value, meaning superficially that neither one of them is false.


this, friends, is my problem. it's my opinion that for any given tautology or contradiction, Q, a system of formal logic can be devised for which Q does not hold; that's my conjecture, the "universal tautology problem". i haven't tried it exhaustively, of course, but i'd like to write an algorithm that could; it would be non-halting, though, until it found a tautology or contradiction it couldn't invalidate, and so it probably wouldn't finish during my lifetime (in fact my research hypothesis for the experiment involvong such an algorithm would be that the machine eventually stops, the null being that it's a non-halter).

there are many more famous problems in logic (at some point i'll chew through Bertrand Russell's paradox of naive set theory, purely because it's so stunningly obvious post hoc and so easy to miss when you first encounter sets). it's the ability to dissect these kinds of problem that make homo sapiens sapiens so awesomely intelligent.

and i'm not talking about myself. let the first game of Correct Lepht begin: discuss, my friends, discuss!