this post was submitted on 26 Mar 2024
15 points (89.5% liked)
Programming
17397 readers
200 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Ermph, maybe there is a mathematical correspondence but the connotations are different. We usually think of an algorithm in terms of the relationship between its input and its output. But determining that by inspecting the state diagram of a Turing machine is literally impossible, by a result called Rice's theorem. Are you taking a class or reading a book? Or just curious, etc. (that is fine)? What direction do you want to take this in?
A "Turing machine" is a mathematical construction that can be given a formalized definition, but "algorithm" is a jargon word that is a bit less formal and has some wiggle room. But, if you say there is an algorithm to compute X, that means (except in some special contexts) that there is a Turing machine that does it, and vice versa.
Actually nowadays "algorithm" can include steps where you generate random numbers ("roll a 6 sided die and do X with the result"). Turing machines are deterministic and that difference is sometimes significant. There is additional jargon to make this precise, that I'll skip here.
Reading a book actually. A programmer by craft who never studied CS, so decided to do it on my own. I appreciate the depth of your answer, thank you! :)
So Turing machines cannot be considered equivalent to algorithms when we involve steps like random number generation? How does church-turing address this? Isn't that part of what's "computable"?
In applied CS, it's common to talk about pure and impure functions instead of Turing machines.
Pure functions are, broadly speaking, equivalent to Turing machines. A pure function may only depend on its inputs (like a Turing machine) and has no outputs besides the return value (like the end state of a Turing machine's tape).
Impure functions cover algorithms that aren't Turing machines. For example, you might have a random number generator
rand: 1 → N
that outputs different natural numbers on every invocationrand()
and is hence impure. Output functions are also impure, e.g., a functionwrite: N → 1
that writes a number into a file can't be a Turing machine, because Turing machines have no concept of files.Computer programs that consist entirely of pure functions aren't very useful, because they can't interact with the user or reality. The typical approach to solving this is to put the core program logic inside pure functions that interact with impure parts through a limited interface. That way, you can apply CS concepts to the important parts of the program and neatly separate out the impure parts.
Edit: Changed ∅ to 1 (singleton set) in function definitions. A function can't return ∅ and a function taking ∅ can't be called.