If it's bad to use inline SQL, how does using LINQ to perform queries differ in practice?

Question: What's the general consensus on using LINQ to perform queries and manipulation inline and how does this differ to embedding SQL statements into your code (which is considered a no no)?
Answer: Ignoring all the non-SQL related uses of LINQ and just considering LINQ-to-SQL.
LINQ queries are objects that retain a query definition and the equivalent SQL is only instantiate at the moment the query is actually iterated. That permits components to be properly separated and allow a pipeline style processing where queries are returned by lower layers (eg. by repositories) and transformed by higher components on the stack. The query can accommodate new filters, joins and other 'artifacts' from each component in the processing pipe, until it reaches the final form that is eventually iterated. This manipulation is impossible in practice using straight text SQL.
Another advantage of LINQ is that its syntax is easier to comprehend for non-database developers. SQL syntax expertise is a surprisingly hard to find asset. Few developers are willing to spend time learning subtler points of SQL beyond SELECT * FROM  ... WHERE .... The linq syntax is closer to the .Net everyday environment and leverages the existing skill set at that layer (eg. lambda expressions) as opposed to forcing the developer to learn the proper SQL for the targeted back end (T-SQL, PL-SQL etc). Given that the linq expression expresses the desired result pretty much straight in relational algebra, the providers have a much easier job into generating the appropriate SQL (or even generate straight the execution plan!). Compare this with the impossible task 'generic' database drivers had to face preciously with SQL text. Remember ODBC escape syntax, anyone?
Answer: You're right: "Embedding SQL statement in your code is not bad." It is terrible.
Doing so makes your application highly coupled, brittle and difficult to maintain. At least, if you have it all in procs, when you alter something, you can do a search on dependancies.
stored procs, I feel really need to go away too for those procs that are handling business logic.
The reason is that business logic belongs in the business layer - not the data layer.
Of course, if the generated Linq to SQL turns out something messy & slow, you've got to use a proc.
One of the great advantages of Linq To SQL is that you can chain together filters - you're where clause is just added dynamically via your logic as required. You don't need to create new procs just because you want to call for a set of data based on multiple params.
Answer: Embedding SQL statement in your code is not bad. It all depend on which layer of your application you are writing them.
Anything that is related to reading and writing to the data store, should be on the Data Access Layer.
Comment: @Sir Psycho, stored procs don't provide any advantage in this scenario.  For example when you add a new DB field, any stored proc that is related needs to be changed, often including the parameter list.  But the tooling for doing this is nowhere near as good as if you had a real DAL written in C# using Linq to SQL or inline queries.  As a result I see Stored Procs as complimentary to a full DAL, not an alternative.
Comment: Yes but if a change is needed, it requires a compilation of that entier layer + deployment. Stored Procs offer an advantage in this scenario and to my knowledge, is the reason I keep hearing 'inline SQL is bad'.
Comment: Data Access Layer can cover a large topic. Its true that having stored procedure can help maintenance. You could also have some WebService act as the data layer and that can be updated without having to update the main application. One way or another, some data sanitation is done on the Data Layer, even if you are using procedure.
Comment: @Ash: of course SProc offer a benefit: if there's a bug in a stored proc, you can just simply fix it and deploy the SProc - no code changes and app install needed!
Answer: Two advantages of "Linq To Sql" versus (the common worst-case of) "inline SQL".
Parameters are treated as parameters, not just as concatenated text -- this overcomes SQL injection problems.
The separate model layer allows for compile time checking that the generated sql will match the schema. (In a worst case of inline sql, you'd have no way to know at compile time if you were referencing a column that had been deleted, for example)
Answer: For one thing LINQ statements are parameterized - inline queries are not necessarily so. For another, LINQ basically creates an ORM layer - allowing database objects to be treated essentially as objects within the code - providing compile time checking. An inline query on the other hand is a blob of text that will not break at compile time...
Answer: Looking at the other answers, maybe I misunderstood the question... but I'm talking about normal LINQ on collections in C#, not LINQ-to-SQL:
When you embed SQL statements in your code (as opposed to making them variables or otherwise parameterizing your SQL), you're making it much more difficult for yourself if you want to support a different database in the future.  As old and standardized as SQL is, there are still many incompatibilities between vendors.
With LINQ, portability is no longer an issue -- your code is written in C#, and LINQ is C#.
Answer: From my little understanding, whether you use LINQ-to-SQL or any other ORM or your own code which wraps SQL calls, it is basically giving you an abstraction whereby you don't have to worry about SQL.
Also, if I am correct - LINQ to SQL supports SQL Server only.
I think, it lets you construct your criteria in a SQL like manner using LINQ syntax.
Personally, I don't know why someone would use LINQ to SQL.
Can an expert help me understand the need of it?
Comment: I think you want to say "stay away from LINQ to SQL" as well as inline SQL. Is that right?
Comment: A change to the LINQ query however requires recompilation as opposed to a stored proc. I thought this is the reason to stay away from inline SQL code.
Answer: At some line of code, someone, sometime, will decide if it's appropriate to type the SQL. But instead of doing that, you'll use LINQ.
So it's not a matter if LINQ should be inlined when SQL should not. The question is where you want your data storage access representation to be. If you're writing LINQ at some line of code, and you don't feel confortable of this scope having access to the stored data, then it's the wrong place.
LINQ is just an abstraction for data manipulation. It's a shortcut for filtering sets. Just like databases understand SQL, the .NET environment has a language to talk with data.
What's the difference between LINQ and doing if statements inside a loop, on data that came from a file, or a network socket? None, it's just the syntax. If you SELECT * FROM table, filtering every row against a function, what's the difference from doing where c.SomeProperty < x with LINQ? Just the syntax.
Sure, LINQ knows and do more than simply returning rows from a database. It lets you instantiate objects from a collection, but so does = new ClassName(column1, colum2) from SQL statement results.
In short, if somewhere writing inline SQL in your code is a no-no, so it should be writing LINQ.
But this varies from project to project. Databases mostly understand SQL, so at least somewhere in your code, library or environment there are inlined SQLs.
Answer: Have worked extensively with embedded SQL, the real danger is that it is a code generation technology.  You write C code (or whatever language) and then you switch to SQL, then back to C again.  Later prior to compilation a prepocessor rewrites the code to be all C.  The results can generate very confusing error messages.  You are forced to learn the API to interact with the database which embedded SQL was supposed to free you from.  Finally, you run the risk of embedding business rules into your queries confusing the business layer and data layer.
Linq avoids some of these issue.  First, Linq is part of the language.  The constructs work more or less as a programmer expects.  There is some SQL type syntax involved, but mostly the syntax is focused on the host language (i.e. C#).  The compilation checks are done on the actual code you wrote.  Therefor there is not need to translate the errors into the syntax before preprocessing.  The results of the query are objects and collections, just as you would expect.  There is still a danger of mixing business logic in the data layer however.  Additionally, Linq has it's own issues with error messages where the field in question is often not included.  Still it is a good compromise between the object world and the relational world.


Navigation Based Application with TabBar

Question: I have a Navigation-Based Application that shows a TableView where you can select a cell and it brings you to a "Detail View" for that cell. I want this view to then have a TabBar where I can select between 3 subviews. I have found several solutions online for this but none are very helpful. Is there a tutorial for this specifically or is their source code indicating how it can be done? Thanks
Answer: Basically What you need to do is push a Tab View Controller onto the Navigation Controller's viewcontroller stack.
Starting with a fresh "Navigation-Based Application" template.  I added the following method in RootViewController.m :
<code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Navigation logic may go here. Create and push another view controller.
UIViewController *viewOneViewController =   [[UIViewController alloc] init];
viewOneViewController.title = @"One";
viewOneViewController.view.backgroundColor = [UIColor redColor];

UIViewController *viewTwoViewController =   [[UIViewController alloc] init];
viewTwoViewController.title = @"Two";
viewTwoViewController.view.backgroundColor = [UIColor orangeColor];

UIViewController *viewThreeViewController = [[UIViewController alloc] init];
viewThreeViewController.title = @"Three";
viewThreeViewController.view.backgroundColor = [UIColor greenColor];

UITabBarController *anotherViewController = [[UITabBarController alloc] init];
anotherViewController.viewControllers = [NSArray arrayWithObjects:viewOneViewController, viewTwoViewController, viewThreeViewController, nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
</code>
}
Changed this to 25 to test:
<code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 25;
}
</code>
Now when I build and run I'll see what you are looking for in a basic way.  What you will want to do after you get this working is to change the UIViewControllers to Custom Subclasses that you create to hold the code for each view.  (If you are also using Interface Builder, change the init to initWithNibNamed:).
Hope this helps you get on your way a bit.
Comment: You should also want to create a custom subclass of UITabBarController, in which you allocate its viewControllers, thats more clean then put everything in the didSelectRow method. Next to that, you forgot some 'release's. But still +
Comment: if we wan't tabs with xib then..??
Answer: You should be aware that it's possible Apple will reject your application if you do this though.
From "Combining Tab Bar and Navigation Controllers"
It's very common to combine tab bar and navigation controllers, as illustrated in Figure 4. To do this, you simply add navigation controllers to a tab bar controller (however, you should never add a tab bar controller to a navigation controller).
So it's likely to be against the Human Interface guidelines and so could you get rejected.
Answer: I'm trying to do this very same thing.  The application "Tweetie" is doing something similar.  They have a TableView of accounts and then you select an account and TabBar appears.
Anyways, straight from Apple's Documentation:

pushViewController:animated:
  Pushes a view controller onto the receiver's stack and updates the display.

(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

Parameters
  viewController
  The view controller that is pushed onto the stack. It cannot be an instance of tab bar controller. This method does nothing if the view controller is already on the stack.
animated
  Set this value to YES to animate the transition. Pass NO if you are setting up a navigation controller before its view is displayed.

So maybe we're just stuck using a TabBar and not a TabBarController?
-JP


mice and sound traveling through brick party wall joist pockets

Question: We live in a 1912 row house that I believe has joist pockets that allow sound and mice to travel freely between me and my neighbors' houses. For instance, my neighbor hired pest control to deal with his mice last winter and one of the dying mice staggered into my living room, clearly in distress from the poison. Assuming my hunch is correct and the joist pockets are to blame, what's the best way to repair them so that mice AND sound are abated?  I've already rejected spray foam since mice can chew through it and it lacks sufficient mass to block sound.
Comment: It's certainly not clear to me what you mean by "deteriorating joist pockets".  If my understanding of your problem is correct, mice and noise are the LEAST of your concerns.  Joist pockets support the joists which in turn support the brick walls.  So it sounds like your home is on the verge of collapse!!
Comment: This is a common problem (sound and mice) in old row houses, they are structurally sound, but there are gaps between masonry and joists that allow passage of mice and sound. Perhaps deteriorating was too strong of a word.  Edited that out.
Comment: Had to look up what "joist pockets" are. @jwh20  From what I saw online, they support the floor joists, not the brick wall itself (hopefully), but still a serious problem, you are right.  Regarding the critters, I've successfully used ultrasonic pest deterrents with some degree of success. The OP might need several in strategic locations, but they do work.
Answer: The right way to do that would be to use metal flashing, fabricated to go around the joists and abut the pockets. Fill the spaces with metal screen or coarse steel wool (to discourage rodent teeth), followed by the foam for sound deadening, then seal it up with the metal flashing, bent to go flush against the brick and nailed into the joists.


Texas instruments C1101 RF1100 module Schematics

Question: does anyone got schematic from this module. I tried searching around but didn't get anything except main header pin-out. There are also 2x2 pin on each corner, but there is no info about them.
Comment: The 2x2 holes are most likely to facilitate mounting.
Answer: If you look closely, you see the four small copper lines that connect the 2x2 pins to the ground plane. My multimeter confirms this: 0.4 Ohm from ground to each of the 'pins', the same reading for shorted probes.
Besides the chip there isn't much on the PCB that could be interesting: a 26 MHz crystal, a maching network for the antenna, some power decoupling. Probably a copy of the circuit on p25 of the datasheet:


Can't join Server 2003 domain with XP Pro

Question: I installed windows server 2003 on my laptop using vmware and also installed xp pro using vmware on my desktop pc .. I have setup a domain using the Server 2003 wizard but when I try to set up the XP machine to join the domain (called ABCD.edu), I get "A domain controller for the domain ABCD could not be contacted." how i can fix this problem?
Comment: check your network settings.... make sure they are connected and on the same subnet. Then make sure they are using the same DNS server or did you install the feature in your Windows Server 2003? You usually install AD/DNS/DHCP all on the same server if you are testing in your env...
Comment: are you on the same network? can you ping each other? check your network settings.
Comment: Request time out
Comment: btw, you should not use ".edu" locally unless you own it. Use ".local" or ".anything" besides edu, com, net etc....
Comment: I checked them ..still same error :(
Comment: The Problem in Vmware .. I checked on Bridge and still same problem
Answer: You need to

install the DNS-server on the Windows 2003 machine and make it as AD-integrated DNS
Configure your XP machine to use the IP of Windows 2003 machine as DNS server
Answer: After 10 hours of searching and testing I solved this Problem.
This Problem can Happens for 2 reasons :
1- Bridge Problem.. before installing Windows Server you should check the Network adapter in vmware and I prefer check customize then choose "vm0" if your connection is wired then in advanced setting choose the NIC that the "vm0" will take.
2- Firewall problem... Not only windows firewall but even the firewall of anti virus you have.. in my situation I have Bitdefender internet Security 2015 and when i Disabled its firewall, The problem solved directly.


How many Operating Systems allowed in a single computer

Question: How many operating systems are allowed in a single computer.
Is any extra RAM is need for each extra operating system?
Comment: no extra RAM is needed because you execute only one SO each time you boot.
Answer: No extra RAM needed, just enough hard drive space (or hard drives) to hold them all.
There is no limit... using boot loaders and similar technologies, you can simplyfy the process - When I was a younger geek, I used to think it was cool having everything from Windows 3.1 to XP and a few flavors of Linux on the same machine....
...As I grew older, I realised it was just a waste of time and a maintenance nightmare.
If you want multiple operating systems, I highly advise you stick with one and explore technologies such as virtualisation which will allow you to run multiple Operating systems from within one without all the headaches.
Answer: As many as they can fit in your storage space.
Your MBR can have up to 4 physical partitions, while each of them can have logical partitions in it. But you can actually boot some Linux distributions from an image files inside other partitions even with FAT or NTFS file formats, so as many as they fit.
Note that not all operating systems supports the same boot methods, especially closed ones.
RAM is only important for each individual OS, so it's depends of that specific OS minimum requirements.
Answer: I would imagine that as long as you have the hard drive space for it, you can partition and install as many operating systems as you like. The RAM requirements will vary depending on the particular OS, but the number of systems won't be affected. Using a VM will make this whole process a lot easier.
You can even find out how to install 145 operating systems if you want.
Answer: Infinite. Well at least by theory. You can have as many operating systems as your hard drive can handle. The smaller the size of the OS the more OS's you can have.
Comment: @phihag What has the system bit-ness got to do with how many OSes one can install, and why 2^2^64?
Comment: The hard drive is not a boundary; you can safely boot without one via PXE. And on actual computers, the number is not infinite: on a 64 bit system, there can be at most 2^2^64 different OSs.
Comment: @MichaelKjörling Oops, the boundary is wrong; it must be higher. If we define an `OS on a single computer` as a permutation of bytes in memory at "OS start" time, the number of OSs is finite on a physical computer. That's because there are only `256^n` permutations of n bytes, and the highest possible n on a 64 bit system is 2^64, **256^2^64** is an upper boundary. This number is large (more than a hundred quadrillion times the number of atoms in the universe), but finite.
Comment: @phihag 64-bit systems can support more than 2^64 bytes of memory, just like 16-bit systems can support more than 2^16 bytes of memory. It's more useful on 16- and 32-bit systems, but the same techniques (bank switching, paging, memory overlays, ...) can equally well be used on a 64-bit system. So all of an OS does not need to fit inside the CPU's data bus bitwidth or the architecture's address width (the latter of which may or may not have any relevance on the physical hardware's usable address space). Hence the factor 2^64 becomes limited by available total storage rather than address width.
Comment: @MichaelKjörling Oh, you're right, I just assumed that the bootloader(s) can't use any of these techniques, but that's of course not true. So the number of permutations of the total memory is the limiting factor here, and the size of the hard drive does not matter.
Answer: Older operating systems (such as MS-DOS) had certain requirements which could limit how many you could have on a single machine. I believe (correct me if I'm wrong) that the mentioned MS-DOS had to be installed on the first primary partition.
With modern operating systems there's no limit; you can have as many as you want provided you have the disk space to hold them all and a properly configured boot loader.
However, having worked with multiples OS's on a single machine I can say this is rarely worth the effort. A much better alternative is to have them running in a virtual environment; the requirements are slightly higher then (you need to have enough resources to run your regular OS and then enough resources to run the added OS within that).
Unless of course you're asking how many OS's can run at the same time on a single machine (all virtual)... RAM becomes the main limit then. But as CPU cores and disk space becomes shared, resources will get spread thinner and thinner and all VMs will be slower and slower. There's no theoretical limit on how many OS's you can have running as long as you have the RAM, but calculating it would require answering some questions like "what kind of OS". An old DOS requires far less resources to run than Windows Vista.
Answer: With VM (VirtualBox, VMWare etc ...):
Extra RAM must be added for every guest OS that you need to run at the same time, plus the memory needed for the host OS
With boot manager:
No extra RAM; just size your memory for the biggest OS+application that you need


Body impedance and electrical stimulation. What is the skin load in electrical stimulation?

Question: An electrical stimulator device like Geko T-1 provides a 27 mA output current. On the specification for the load impedance range they mention a 200 Ω to 3 kΩ range for 27 mA output. How did they conclude to that for the skin resistance? When I search online I get way higher values, even 100 kΩ. Using Ohm's law, with an output of 27 mA and 90 V an electrical stimulator can only surpass 3333 Ω. Is it something to do with the use of electrodes?
Comment: 90 volts and 27 mA is 3.33 kohm not ohms.
Comment: Perhaps they measure skin resistance under various conditions - something the medical industry would be  interested in since electrical sensors are used for ecg, and higher charges applied with defibrillators. Also consideration would be given to skin resistance for an  electric chair...
Answer: You've raised an interesting question. The impedance between two spaced-apart electrodes on the body is the sum of the two electrode-to-skin impedances and the impedance along the body path (e.g., arm-to-arm for a Lead I EKG), and does usually run in the 100k ohm range as you've researched.
However, the Geko nerve stimulator is a special case. First, the electrodes are fairly large in area and use hydrogel, both of which help lower the impedance. Second, the conduction distance through the body is extremely short - basically half the width of the calf band, maybe 1-2 cm. Finally, the stimulation is not DC but a short, sharp pulse, letting capacitive effects come into play to lower the impedance.
Answer: I recommend

J. Rosell, J. Colominas, P. Riu, R. Pallas-Areny and J. G. Webster,
"Skin impedance from 1 Hz to 1 MHz," in IEEE Transactions on
Biomedical Engineering, vol. 35, no. 8, pp. 649-651, Aug. 1988, doi:
10.1109/10.4599.

Skin impedance is fairly complex (no pun intended).  It depends on many things.  Obviously, electrode area will have a big impact.  Skin  prep can also have a big impact (electrode prep pads often have some abrasive in them to reduce impedance).
It's also incredibly frequency dependent.  At 1 Hz, Webster's group reports (for the electrode size they used) tens of kiloohms to a megaohm.  At 100 kHz, they report hundreds of ohms.
Answer: The lumped-element model approximation of skin surface impedance generally looks like this:

simulate this circuit – Schematic created using CircuitLab
The value of R1+R2+R3 can range from the 100 ohm range to the 100kohm range depending on electrode parameters like surface area and material (dry electrode vs hydrogel, etc). Generally speaking, impedance decreases with both increasing surface area and electrode 'wetness'.
For any electrode, there is a minimum amount of current required before a sensation can be felt. The thresholds for perceptible sensations are function of current density, and therefore change with electrode size; the larger the electrode, the more current is required before a sensation can be felt. Low current density is also generally more comfortable, i.e. a large electrode with more current feels less painful than a small electrode with less current. Very small electrode surface area can damage skin and cause pain at the minimum perceptible sensation level.


Relearn Math From The Ground Up

Question: I have a question that I have been wanting to ask for quite some time. I am currently a senior Computer Science student who will be graduating in a few months. I have taken all my required math courses (statistics, calculus 1-3, discrete mathematics, linear algebra, etc.) despite doing fairly well I feel like I lack any real understanding of mathematics. What I want to know is if there are any resources out there to learn math completely from the beginning starting at basic algebra and progressing into advanced topics. Right now I feel like I just know how to follow instructions and plug in formulas and numbers. I would like to eventually have a real understanding of exactly why I am doing what I am doing and how to use mathematics to solve future problems. Thanks for any advice!
Comment: Mathematics nowadays is quite vast. I think it would be best to try and limit the scope of your undertaking somewhat. For instance, when you write "advanced topics", how "advanced" are we going? Is it "advanced" as in mathemathics at an undergraduate university level, or is it "advanced" as in research level mathematics? And what branches of mathematics are you interested in learning more about? Calculus/analysis, geometry, discrete maths, linear/abstract algebra, graph theory, etc.?
Comment: @Scounged You are correct my original question was a little broad. When saying advanced I more or less mean advanced at an undergraduate level with enough knowledge to purse further if the opportunity presents itself. The topics which interest me the most are without a doubt discrete mathematics, graph theory and linear/abstract algebra. Thank you for your response!
Answer: Here's a possible ordered list of undergraduate-level books that could help you in your quest, but I have to warn you it will take some time. You're wanting to go all the way from understanding the 'why' to problem-solving and applications. That's quite a broad sweep of mathematics.

Language, Proof, & Logic, by Barwise and Etchemendy. Gotta have logic to understand advanced math. I prefer the natural deduction system to any other symbolic logic proof system.
Foundations of Analysis, by Edmund Landau. You can find free electronic copies of this. This book actually proves a lot of the basic properties of the number systems used in advanced mathematics.
Axiomatic Set Theory, by Patrick Suppes. Set theory and functions undergird all of advanced mathematics.
Abstract Algebra, by Israel Herstein.
Linear Algebra, by W. Keith Nicholson.
Essential Topology, by Martin Crossley.
Principles of Mathematical Analysis, by Walter Rudin.
Numerical Analysis, by Burden and Faires.
How to Solve It, by George Polya.
How to Solve It: Modern Heuristics, by Michalewicz and Fogel.

Relearn Math From The Ground Up


What's the time complexity for max heap?

Question: I'm trying to figure out the time complexity for this whole algorithm. Isit O(nlogn) or O(n)? I've been searching online and some says max heap it's O(nlogn) and some are O(n). I am trying to get the time complexity O(n).
def max_heapify(A, i):
    left = 2 * i + 1
    right = 2 * i + 2
    largest = i
    if left < len(A) and A[left] > A[largest]:
        largest = left
    if right < len(A) and A[right] > A[largest]:
        largest = right
    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        max_heapify(A, largest)

def build_max_heap(A):
    for i in range(len(A) // 2, -1, -1):
        max_heapify(A, i)
    return A

Comment: There is no *complexity for max heap* (or any other data structure). What operations are you asking about?
Answer: The code you have in the question rearranges array elements such that they satisfy the heap property i.e. the value of the parent node is greater than that of the children nodes. The time complexity of the heapify operation is O(n).
Here's an extract from [Wikipedia page on Min-max heap](https://en.wikipedia.org/wiki/Min-max_heap#Build

Creating a min-max heap is accomplished by an adaption of Floyd's linear-time heap construction algorithm, which proceeds in a bottom-up fashion.[10] A typical Floyd's build-heap algorithm[11] goes as follows:
function FLOYD-BUILD-HEAP (h):
    for each index i from floor(length(h)/2) down to 1 do:
        push-down(h, i)
    return h

Here the function FLOYD-BUILD-HEAP is same as your build_max_heap function and push-down is same as your max_heapify function.
A suggestion: the naming of your functions is a little confusing. Your max_heapify is not actually heapifying. It is just a part of the heapify operation. A better name could be something like push_down (as used in Wikipedia) or fix_heap.
Answer: A heap is a data structure which supports operations including insertion and retrieval. Each operation has its own runtime complexity.
Maybe you were thinking of the runtime complexity of heapsort which is a sorting algorithm that uses a heap. In that case, the runtime complexity is O(n*log(n)).


What are some of the disadvantages of working with log likelihood function instead of likelihood function?

Question: As the title suggested, I want to know why people often use log likelihood function, instead of likelihood function by itself. What I know, is that, if $\hat{\theta}$ is the maximum of a likelihood function $f(\theta; \mathbf{x})$, then it is also the maximum of $g(\theta) := \log (f(\theta; \mathbf{x}))$. Are there some other reasons why we are interested in $g$ instead of $f$?
Answer: If you were to use the likelihood function in your maximization routines you may encounter issues of underflow/overflow depending on parameter values and the amount of data you have.
Apart from the numerical reason above, log likelihood functions are sometimes nicer to deal with analytically as product of several factors transforms into a sum and you get rid of the exponential (if you are dealing with normal, exponential densities) which makes life a bit easier when computing MLE analytically.


How do you know if you're being too dramatic?

Question: I want to write a sad scene where a mother finds out that her son passed away. What things/clichés should I avoid in order to not make it overly dramatic?
Comment: Can you add context to this question…? As written, you are just asking **"how not to write a bad scene"**. The mother's reaction should be based on her character and her arc, the son's age and dependence on her, their current relationship, the circumstances of his death, and how she has discovered the news (also who is present – like maybe the person who killed him)…. As for not being 'so dramatic' I guess don't have her recite Hamlet's soliloquy on the stage while holding a skull…? **Better to ask what to do, than ask what to avoid** since we don't know what you need to show with this scene.
Comment: By "over drama" you probably mean melodramatic. This article gives several clues to keep it dramatic rather than over-the-top melodramatic: https://screencraft.org/blog/the-single-difference-between-cinematic-drama-and-melodrama/
Answer: By "over drama" you probably mean "melodramatic." The following article gives us several clues to keep it dramatic rather than over-the-top melodramatic: https://screencraft.org/blog/the-single-difference-between-cinematic-drama-and-melodrama/
Drama depicts realistic scenes and character actions while melodrama does not. So make sure your scene properly grounds the mother in reality.
Comment: +1 for the melodrama. Could you provide a summary of the linked content, or highlight the main takeaways?
Comment: @NofP The article highlights a definitive break between the dramatic and melodramatic. The few points I make sum up the article. It doesn't go into much depth.
Answer: Don't
If your scene can be summarized as "Mom gets bad news, and feels sad." I would skip that scene.
There's no chance for any character to meaningfully change the way this scene plays out - the news is bad, and the that's that. There's no stakes. There's nothing to risk, and nothing to gain.
Since there isn't any source of tension in the scene, it will inevitably feel weak.
Contrast
Contrast the "Mom gets bad news, and feels sad" scene with on like "I need to tell Mom her kid is dead, but lie to her about how he died."
The second scene has stakes - the POV character has to lie, and lie well, otherwise they will be caught. Mom's pain becomes meaningful to the reader, because the POV character has to look into the grieving mother's eyes and lie through their teeth. It affects the POV character. (or it doesn't, which could tell you a lot about the kind of person they are.)
The Indirect Approach
If you don't have good stakes for a conversation with Mom, you can show her pain indirectly. Pick a different scene, and insert her grief into it. You could:

Start the scene directly after Mom has been told. Everyone is ready to move on to "What do we do next?" Describe Mom wiping her eyes. POV character thinks She took that well. Someone escorts her out of the room to grieve somewhere else. Mom has a lot of the info they need to make decisions, so everyone is keenly aware of her absence.
OR Someone volunteers to break the news. POV character tries to convince another character [something]. At just the right moment in the conversation, an anguished wail pierces the night. Everyone knows that Mom just got the news.

In any case, something else is providing tension in the scene, and the reader just gets a glimpse of Mom's pain rippling out into the world. The reader will care more about a little peak into grief that occurs during a strong scene than a long view of grief in a weak scene.


Measuring outside of multimeter range

Question: While preparing a measuring setup for a project, I've realized that the multimeter our lab can provide only supports resistance measurements up to 10^8 Ohm. Since the materials we want to measure go way beyond that, I intended to connect the material in parallel to another resistance and simply add one calculation step to get the desired value, but what if the samples cannot be prepared that way, are there other alternatives to appropriating the measurement for the multimeters range?
Comment: Megaommeter is used for those tasks.
Comment: If you have a resistor which you think is near the value of the resistance you are trying to measure, you could use a Wheatstone bridge.
Comment: If you can connect a multimeter then you can connect a parallel resistor. Think about it.
Comment: Hi everyone, thank you for the comments and help.
I should have specified that we are working inside an isolated fume hood, thus having the setup as small as possible is essential. That's what motivated the question to look for alternatives to additional elements.
Comment: In a pinch, an [Insulation Tester](https://duckduckgo.com/?q=insulation+tester) might also work.  Note that these typically output a large voltage (up to thousands of volts, careful!) in order to measure high resistances.
Answer: If the things you want to measure have a resistance that goes way beyond what you can measure with a DMM, then paralleling a shunt resistor to bring it into range will rapidly turn small measurement errors into big device under test errors.
You would do better to go back to first principles and devise your own measurement system. For modest number of GΩ you can buy GΩ level resistors and use a very low bias current CMOS opamp as a buffer. Measuring the voltage Wheatstone style will also work.
For even higher resistances, measuring the discharge rate of a good PTFE capacitor (ie sample the voltage, disconnect, then sample again a minute later) shunted by the sample will allow you to observe very small currents.
Comment: If you measure the discharge rate of a good PTFE capacitor connected to a 1 GΩ  resistor, a voltmeter with 10 MΩ input resistance will discharge the capacitor during a second more than the 1 GΩ  resistor during a minute. Discharge is a 100 times faster.
Comment: @Uwe Did you read my last paragraph, which says `(ie sample the voltage, disconnect, then sample again a minute later)` ? The 'disconnect' bit is important, but perhaps I should have emphasised 'disconnect the meter'
Comment: Of course I read your last paragraph, which says (ie sample the voltage, disconnect, then sample again a minute later). If you need a second to sample, the interval between two samples should be several minutes long to get a precise result. The discharge rate of  PTFE capacitor alone should be much smaller than the rate with the resistor in parallel.
Answer: Lets do the math. A 1 GΩ resistor in parallel to a 100 MΩ resistor, the result is 90.90 MΩ. A 2 GΩ resistor instead is 95.238 MΩ.
A large change of the GΩ resistor will result in a small change of the parallel connection. A precise measurement of the GΩ resistors is impossible this way.
Answer: Here's a way, using a DC voltage source (< 50 V), a DMM having an input impedance around 10 MΩ (to measure current using its voltage function), and a calculator to calculate the resistance of the specimen.

Measuring gigaohms with a simple multimeter
Courtesy: https://www.giangrandi.org/electronics/gigaohm/gigaohm.shtml#voltage_source
Answer: Measure the current and voltage instead. And calculate the resistance with R=U/I.
(Atleast if the current and voltage are  in range of the DMM)

Measuring outside of multimeter range


The blind adherence to progress

Question: Does science need a moral framework from which it should operate? How would we go about choosing such a framework? There is various religions that can provide such a framework or even secular humanism. I wonder if progress is all that is required of the scientific community that this may lead in the future to weapons of mass destruction that can lead to suffering on such a scale that has never been seen before.
Comment: For starters, honesty is essential practically by definition in any endeavor of a community to begin consolidating their acquired knowledge.
Comment: Perhaps related: ["Now I am become Death, the destroyer of worlds."](http://en.wikipedia.org/wiki/J._Robert_Oppenheimer)
Comment: Psychologists and biologists are routinely subject to ethical scrutiny. Physicists are doing less work these days on subjects impinging on morality. And economists aren't scientists, so their lack of ethical oversight is not on-topic.
Answer: Yes, science requires a moral framework. Science is predicated upon:

the ability and willingness to reach intersubjective agreement
sufficient training of enough who are mentally/experientially qualified for research
enough money to fund science
not destroying all of humanity, which would prevent further scientific progress

Here are some ways that the above can be hindered:

egocentrism, which gives less value to evidence, hypotheses, and theories of others
deception, which falsifies data or dependence on other work to elevate self

classism, which will ignore many with innate scientific talents
egocentrism, which says 'I am too important to spend time learning to teach well'

nearsighted vision, which stunts research which pays in 10+ year timepsans
favoritism, which prevents the most promising research from being maximally valued
hardball politics, which can stall government-funded research

irreparable inequality, which promotes violence above diplomacy
megalomania, which makes psychopathic villains

As an example of some of the above, the United States is currently suffering from 'nearsighted vision'; the 2013 budget sequestration greatly harmed e.g. NIH funding. As another, the 2013 government shutdown forced the NIH to shut down (doors to research labs are locked); a PhD biophysicist told me that it can take a month 'spin down' mammalian cell lines; this means the process must be started when government shutdowns are near, and if insufficient warning is given, those cell lines are lost and it can take months to reestablish new ones.

Choosing a moral framework requires:

a shared vision (or telos)
a shared ethic (means)
a good enough model of 'human nature'

I'm definitely channeling Alisdair MacIntyre's 1981 After Virtue, where he contrasts current-day Emotivism with pre-enlightenment meta-ethical moral frameworks. I quote him in several answers; here's the third use of this bit:

Each of the three elements of the scheme—the conception of untutored human nature, the conception of the precepts of rational ethics and the conception of human-nature-as-it-could-be-if-it-realized-its-telos—requires reference to the other two if its status and function are to be intelligible.

In other words, 3. → 2. → 1. Alternatively, to avoid the is-ought problem, we define the ought as our shared vision, so that we can get: is → means → telos.

Our shared vision includes scientific progress. It will also need to include this progress positively impacting enough people (likely through application). How to define 'enough' is tricky, but we can imagine a world where scientific advancements are withheld from e.g. all of Africa, with the only perceivable solution being the destruction of science (in order to restart the system so it doesn't stick to such a local maximum).
Our ethic must be sufficient to avoid the hindrances mentioned in the beginning. My guess is that it will include issues not mentioned which may not seem to lead directly to science, but are nonetheless required.
Here, science can help us tremendously. We must be careful to make fewer mistakes, like the one in the Milgram experiment, where fourth year psychologist students and medical school psychiatrists underestimated human submission to authority by 1.8-2.8 orders of magnitude. The Stanford prison experiment and The Third Wave are also instructive. In my opinion, our current idea of 'human nature' (this is a debated term) is too rosy. Perhaps religious belief could help here? Christianity traditionally has a larger emphasis on 'sin' than contemporary cultures.

A big issue is whether people feel part of the scientific enterprise, or part of the 'society' which hosts it. For example, consider how sports fans often feel part of the sports enterprise. There is a danger in society-building: Social connection enables dehumanization. Beyond the above, I am not sure how to avoid this problem (encouraging 'us vs. them' mentalities) while simultaneously building a society which values scientific progress.
Comment: Note that while the end of humanity would inhibit the progress of science, to say the least, there is nothing in the ethics of the scientific mindset in itself that prevents species-destroying risk-taking. The fact that scientists would avoid such risk is probably better pinned to an implicit humanism (to say nothing of self-preservation and a respect for the hard work of others) rather than anything to do with science per se.
Comment: @NieldeBeaudrap: "there is nothing in the ethics of the scientific mindset in itself that prevents species-destroying risk-taking" — really? See [Studies of deadly H5N1 bird flu mutations test scientific ethics](http://articles.latimes.com/2011/dec/26/science/la-sci-bird-flu-20111227). I don't think the situation is as clear/agreed upon as you intimate. Computer science results which would insanely aid devastating computer viruses have been plausibly described to me (I'm a software engineer with an admiration for theory). Stuxnet-type stuff.
Comment: Lots of this is good, but I'm curious: the mention of "current-day emotivism" seems out of left-field. Most ethicists working today reject emotivism (though I'm not suggesting it's wrong!). I'm not sure why you mention it.
Comment: @ChristopherE, theorists are often far ahead of popular  beliefs, and I think this is an instance.
Comment: I'm not saying that scientists would happily see the world burn. I work with more than a few. I also don't think that science even inclines one slightly towards world destruction. But I think that any (understandable and frankly good) hesitation comes from values which are independent, or at best have a common cause as, those of their values that one might call "scientific". That is: not all of the values that a scientist may have, is due to their being a scientist.
Answer: We must ask ourselves what qualifies as "progress". For example, in "Industrial Society and its Future", Ted Kaczynski raises some interesting points, basically arguing that "freedom and technological progress are incompatible". I bet most would agree that freedom is more important than technological progress.
Also, from Oswald Spengler's The Decline of the West (1918-1922) and Lothrop Stoddard's The Revolt against Civilization (1922) to this 2015 article by professor emeritus of political economy Robert Skidelsky, ample authorative sources have documented an on-going decline in the civilization of the West, from the American & French revolutions onwards until this very day.
Unfortunately, the decline of the West has largely been ignored during the last couple of decades, mostly because it didn't suit the political agendas of the leaders of the West, which is precisely what allowed the process to accelerate to an almost nauseating pace since especially the second half of the 20th century.
So is there a blind adherence to "progress"? IMO, that couldn't be further from reality. I would even go as far as to say that there appears to be a blind adherence to self-destruction.

Edit
So can / should a solid moral framework prevent industrial progress the industrial system's hold on civilization and the corresponding decline of human happiness & freedom? "Industrial Society and its Future" explains why that won't work!
Comment: How does this relate to the question? You talk about progress but the question is about progress in science.
Comment: Please stop adding "edit" paragraphs. Rewrite your answer to incorporate new information or additional explanation.
Comment: @EliranH : I address both progress at the civilizational level (which is more generic) and technological progress specifically (which is **very closely** and **directly** related to scientific progress).
Comment: This does not appear to answer the question...
Comment: @virmaior : As I said in my response to, I address both progress at the civilizational level (which is more generic) and technological progress specifically (which is very closely and directly related to scientific progress). How does this not answer the question?
Comment: The question is `Does science need a moral framework from which it should operate? How would we go about choosing such a framework? ` Nothing in the answer explains how we should chose a framework. Nor does anything in the answer address whether science needs a moral framework. Instead, it's the opinions of some pretty outlandish people paraded together with "IMO"s
Comment: @virmaior : My answer was a response to the title of the question `The blind adherence to progress` and the remark `I wonder if progress is all that is required of the scientific community` in the question.
Comment: @virmaior : I added a line at the bottom to address the question `Does science need a moral framework from which it should operate?` specifically.
Comment: @JohnSlegers If your answer to this question is another question, then doesn't that mean you think this question is a dupe?

The blind adherence to progress


PC says "Press CTRL+ALT+DEL to unlock" upon restart

Question: I noticed that my PC has been logging me in instantly upon reboot. I wouldn't get any verbose messages like I'm used to when logging in, I would just hit ENTER and immediately my desktop would appear.
I discovered that the following setting was turned on:

I turned that off and I also went to Power Options and disabled Fast Startup, to ensure that a shutdown would be as close as possible to the "real" shutdowns in previous versions of Windows.
I restarted and this time, I got the traditional verbose messages leading up to "Preparing your desktop" before actually seeing my desktop.
However, the Windows Security logon screen still says "Press CTRL+ALT+DEL to unlock" rather than "Press CTRL+ALT+DEL to signin". As previous versions of Windows say "Press CTRL+ALT+DEL to logon (or use the Windows Security button, etc.)" when nobody was logged in and said "Press CTRL+ALT+DEL to unlock this computer" when a user was logged in, I can only surmise that even with the "Use my sign-in" setting toggled off and Fast Startup disabled, somehow I am not being completely signed out, as otherwise I would see "signin" instead of "unlock" at the Windows Secure logon screen.
What other settings need to be changed in order to make Windows truly log out upon shutdown/restart, so that I see "Press CTRL+ALT+DEL to signin" instead of "Press CTRL+ALT+DEL to unlock" as I see now?
Answer:
Run (Windows + R) netplwiz
When the "User Accounts" window opens, select the "Advanced" tab and uncheck the box for "Require users to press Ctrl-Alt-Del."
Comment: I don't want to disable Windows Secure Logon, which is what that does. I want to change the message so that it is accurate.
Comment: "to change the message so that it is accurate" <--- I don't see this need/requirement mentioned in your original question..


Can black holes form in a finite amount of time?

Question: One thing I know about black holes is that an object gets closer to the event horizon, gravitation time dilation make it move more slower from an outside perspective, so that it looks like it take an infinite amount of time for the object to reach the event horizon. It seems like a similar process should slow the formation of the black hole itself: As the star collapses, its gravitational time dilation make itself collapse more slowly. This make me wonder, are what astronomers claim to be black holes really black holes, or are they stars that progressively make themselves more similar to one without actually reaching the stage of having an event horizon?
EDIT: Contemplating one answer, I realize the question is ambiguous. What does finite time mean in general relativity. Here is a less ambiguous question: Is there a connected solution of 3+1 dimensional general relativity with one space-like slice not have a singularity, and another space-like slice having one.
Comment: Seems like every single answer here missed the actual point and went straight to showing off their maths skills . the question simply is that if you are far away from collapsing core of a star (say on earth) would you ever see the collapsing core form a blackhole before infinite time has passed on earth?
Comment: I suggest to replace "singularity" by "an intersection with an event horizon" in your rephrased question, since you want to know about black hole formation and not singularity formation. The answer is then "yes", with the Vaidya solution being the simplest example. See e.g. Fig. 4 in http://arxiv.org/abs/0809.2213 for its Penrose diagram.
Comment: duplicated by http://physics.stackexchange.com/q/21319/
Comment: Spacelike singularities occur in uncharged nonrotating black holes. You must then distinguish between physical singularities and coordinate singularities. For example, the Schwarzchild metric has a coordinate singularity at the Schwarzchild radius that may be eliminated by a change in coordinates, but I doubt this is what you meant.
Comment: Also note that for the Schwarzschild spacetime, the singularity is spacelike, so this answer to your question is "yes" for the case of the Kruskal extension of the Schwarzschild spacetime.
Comment: related: https://physics.stackexchange.com/questions/391848/at-what-moment-will-matter-falling-into-a-black-hole-affect-its-size
Comment: Nikodem J. Poplawski has, between 2010 & 2020, written numerous preprints on the Arxiv site (several of them subsequently printed by such reputable publishers as Elsevier) showing that, by use of 1929's Einstein-Cartan Theory rather than 1915's General Relativity, explanations employing singularities can be avoided in a model of inflation based on torsion, rather than the non-rotating (scalar) field usually employed in inflationary cosmology.  Like some descriptions of them on PSE, the preprints can be found by his name.
Comment: My impression had been that stars pass thru the usual cycle, ending in the formation of a neutron star, before collapsing (if their mass is sufficient) in the formation of black holes and (usually) leaving a former binary partner continuing in the elliptical orbit they had previously shared.  The former partners of more than 90, in those orbits, have been seen telescopically.
Answer: The conceptual key here is that time dilation is not something that happens to the infalling matter. Gravitational time dilation, like special-relativistic time dilation, is not a physical process but a difference between observers. When we say that there is infinite time dilation at the event horizon we don't mean that something dramatic happens there. Instead we mean that something dramatic appears to happen according to an observer infinitely far away. An observer in a spacesuit who falls through the event horizon doesn't experience anything special there, sees her own wristwatch continue to run normally, and does not take infinite time on her own clock to get to the horizon and pass on through. Once she passes through the horizon, she only takes a finite amount of clock time to reach the singularity and be annihilated. (In fact, this ending of observers' world-lines after a finite amount of their own clock time, called geodesic incompleteness, is a common way of defining the concept of a singularity.)
When we say that a distant observer never sees matter hit the event horizon, the word "sees" implies receiving an optical signal. It's then obvious as a matter of definition that the observer never "sees" this happen, because the definition of a horizon is that it's the boundary of a region from which we can never see a signal.
People who are bothered by these issues often acknowledge the external unobservability of matter passing through the horizon, and then want to pass from this to questions like, "Does that mean the black hole never really forms?" This presupposes that a distant observer has a uniquely defined notion of simultaneity that applies to a region of space stretching from their own position to the interior of the black hole, so that they can say what's going on inside the black hole "now." But the notion of simultaneity in GR is even more limited than its counterpart in SR. Not only is simultaneity in GR observer-dependent, as in SR, but it is also local rather than global.

Is there a connected solution of 3+1 dimensional general relativity with one space-like slice not have a singularity, and another space-like slice having one.

This is a sophisticated formulation, but I don't think it succeeds in getting around the fundamental limitations of GR's notion of "now." Figure 1 is a Penrose diagram for a spacetime that contains a black hole formed by gravitational collapse of a cloud of dust.[Seahra 2006]

On this type of diagram, light cones look just like they would on a normal spacetime diagram of Minkowski space, but distance scales are highly distorted. The upright line on the left represents an axis of spherical symmetry, so that the 1+1-dimensional diagram represents 3+1 dimensions. The quadrilateral on the bottom right represents the entire spacetime outside the horizon, with the distortion fitting this entire infinite region into that finite area on the page. Despite the distortion, the diagram shows lightlike surfaces as 45-degree diagonals, so that's what the event horizon looks like. The triangle is the spacetime inside the event horizon. The dashed line is the singularity, which is spacelike. The green shape is the collapsing cloud of dust, and the only reason it looks smaller at early times is the distortion of the scales; it's really collapsing the whole time, not expanding and then recontracting.

In figure 2, E is an event on the world-line of an observer. The red spacelike slice is one possible "now" for this observer. According to this slice, no dust particle has ever fallen in and reached the singularity; every such particle has a world-line that intersects the red slice, and therefore it's still on its way in.
The blue spacelike slice is another possible "now" for the same observer at the same time. According to this definition of "now," none of the dust particles exists anymore. (None of them intersect the blue slice.) Therefore they have all already hit the singularity.
If this was SR, then we could decide whether red or blue was the correct notion of simultaneity for the observer, based on the observer's state of motion. But in GR, this only works locally (which is why I made the red and blue slices coincide near E). There is no well-defined way of deciding whether red or blue is the correct way of extending this notion of simultaneity globally.
So the literal answer to the quoted part of the question is yes, but I think it should be clear that this doesn't establish whether infalling matter has "already" hit the singularity at some "now" for a distant observer.
Although it may seem strange that we can't say whether the singularity has "already" formed according to a distant observer, this is really just an inevitable result of the fact that the singularity is spacelike. The same thing happens in the case of a Schwarzschild spacetime, which we think of as a description of an eternal black hole, i.e., one that has always existed and always will. On the similar Penrose diagram for an eternal black hole, we can still draw a spacelike surface like the red one, representing a definition of "now" such that the singularity doesn't exist yet.

Figure 3 shows the situation if we take into account black hole evaporation. For the observer at event E$_1$, we still have spacelike surfaces like the blue one according to which the matter has "already" hit the singularity, and others like the red according to which it hasn't. However, suppose the observer lives long enough to be at event E$_2$. There is no spacelike surface through E$_2$ that intersects the cloud of infalling dust. Therefore the observer can infer at this time that all the infalling matter has hit the singularity. This makes sense, of course, because the observer has seen the Hawking radiation begin and eventually cease, meaning that the black hole no longer exists and its history is over.
Seahra, "An introduction to black holes," http://www.math.unb.ca/~seahra/resources/notes/black_holes.pdf
Comment: What a great answer!
Comment: Why do most people (physicists?) associate events happening with "seeing" them happen: "If we cannot see it, it didn't happen or happens in the future". Just because light from beyond the visible universe cannot reach us doesn't mean it lies in our future. Am I missing something?
Comment: Seriously? Like really? You're considering the fact that one cannot see the black hole form with naked eye as an argument?
Comment: @Ben Crowell, @ user1062760
It is an argument that (among others) shows a problem of coherence in GR. For example, it can not be said simultaneously that the horizon is an appearance due to the difference of the reference frames (and in fact, as on the sea, it retreats when one approaches it), but that it is also an objective reality which produces physical effects (locally, it can only be traversed in one direction, it produces Hawking radiation, etc.). (cont.)
Comment: @Jus12: I agree with you that equating "seeing" with "being" would be a mistake here. I think the OP implicitly seems to have made that mistake. I don't think physicists generally make that mistake, although you may see it in popularizations or in writing by people who lack specialized expertise.
Comment: One question (as I'm still struggling a bit with Penrose diagrams): In figure 2, would there also always be a sensible "now slice" for  which nothing has crossed the event horizon yet?
Comment: According to the last picture E2 sees Hawking radiation all at one moment
Comment: @Anixx No. It is a conformal diagram, that corner at the right end of the dotted line is simply the last burst of Hawking radiation. The black hole got smaller ever since the horizon formed (or since its temperature dropped below background) just like that infalling matter was always falling inwards even though the picture makes it look like it is going out. The diagram makes causal structure easy to see, other structure not so easy. So regardless of how big the event horizon gets or shrinks we draw it as a 45 degree line to indicate that the inside stays in, it doesn't mean the size is fixed.
Comment: @Timaeus light travels along the 45 degree line so according this diagram all Hawking radiation travels along the horizon tll the final burst.
Comment: @Anixx The diagram shows casually connected regions, it does not contain a drawing of the region from whence Hawking Radiation emerges (except that last burst). The region from where Hawking radiation emerges is always below the event horizon. Which by black hole complementarity might as well be the point r=0 (for the outside observers) though you have to fix a coordinate system before you can really say something like that.
Comment: @Timaeus this diagram shows all these regions. From r=0 to the horizon and above. And time frame from before BH forms to its disappearance.
Comment: @Anixx The region where E1 and E2 are and the whole region outside the event horizon is a fine region where every event has its own past included. Its a thing you can do science with. And by complementarily is a perfectly fine region. Sure it has timelike curves that stop after a finite proper time. But so does the bigger region that includes the inside. It isn't better that the curvature blows up for curves that go inside, all that matters is the curve stops after a finite proper time. The region outside has every event include its past so you can do science with it.
Comment: @Anixx Including more than the outside is actually a bit silly for observers that stay outside since the inside can't affect things outside.
Comment: Ben, what software did you use to draw the diagrams?
Comment: (cont.) Another example, if the distant observer or universe can only see Hawking radiation once the BH and its horizon really disappeared from the universe, it would be necessary to be able to express this disappearance according to a universal time, which does not exist not in GR. Ditto for the formation of the horizon. The fact that there is no universal time in GR to describe the history of the universe and history in the universe is not the solution but the problem behind all these questions.
Comment: Dust collapse differs from the stellar collapse discussed by the OP, as it's on a much larger scale:  I believe that only one instance of it (in Sagitarrius A) has been observed, and it's been discussed on the Astronomy Stack Exchange.
Comment: Well, let's forget about what is in the Black Hole "now" and "seeing". Let's focus only on one important (for observer) question: is the Black Hole "observable" by the outside observer? Am I got this correctly that an external observer will see the Black Hole "always forming" and never gets formed? So, from observational point of view, there couldn't be (observed even by side effects) any Black Holes?
Comment: If time at the Event Horizon for the external observers "slows down" to zero (distance between events became huge), how one should see the interaction of such "frozen in time" object with the neighbors? Let's say, the Black Hole formed somewhere, but it moves through space and between other stars. If it "hold" at the "moment of emergency", how will it interact with other stars for the observer if it is frozen at creation place and at the same time already near another star?
Comment: "Why do most people (physicists?) associate events happening with "seeing" them happen: "If we cannot see it, it didn't happen or happens in the future". ...  Am I missing something?"

Yes.  You are missing limiting behavior.  So, when mass is falling into the black hole you can see spectrum shifting.  This is also associated with time dilation.  This means that if some mass has spent 10,000 years falling in, it spent a much larger amount of time in the observer's clock.  Nothing to do with horizon effects!
Answer: You are simply looking at it from an observer's viewpoint. Yes, looking from outside, matter tends to asymptotically approach but never reach the event horizon. If you were part of that matter spiraling into a black hole, there would be no problem reaching the horizon, crossing it, and going right down to the singularity.  The event horizon is not a physical barrier.
You could be free falling, and your time would not be infinitely dilated. So the answer is yes they can form easily in a finite time.
Comment: "If you were part of that matter spiraling into a black hole, there would be no problem reaching the horizon, crossing it, and going right down to the singularity." - why if the time of the black hole existence is finite? The BH will simply evaporate befgore you reach the horizon. Probably you got this quote from a very old book that does not accout for BH evaporation.
Comment: Downvoted as this answer is irrelevant to op's question.
Comment: @Anixx: Exactly the opposite is the case. Black hole evaporation is the only thing that ever makes it possible for a distant observer to say *yes*, the infalling matter has definitely hit the singularity. See figure 3 in my answer and the explanation below.
Comment: Assuming most things in the unverse are not spiralling into a black hole, including us, doesn't that means that in our frame of reference, nothing have ever crossed an event horizon?
Comment: @Ivella I think, event horizon not, but singularity, yes. The Big Bang.
Answer: To begin with, there is a connected solution of 3+1 GR in which particles fall to the singularity in finite time. In particular, Gullstrand-Painleve coordinates do this. The big difference with Schwarzschild coordinates is that the speed of light depends on direction: light moves into a black hole faster than it moves out.  See:
http://en.wikipedia.org/wiki/Gullstrand%E2%80%93Painlev%C3%A9_coordinates
For the formation of a black hole in these coordinates, see:
Phys.Rev.D79:101503,2009, J. Ziprick, G. Kunstatter,  Spherically Symmetric Black Hole Formation in Painlevé-Gullstrand Coordinates
http://arxiv.org/abs/0812.0993
For the generalization of Gullstrand-Painleve coordinates to the rotating black hole, see the very readable paper that gives an intuitive explanation for what is going on, see:
Am.J.Phys.76:519-532,2008, Andrew J. S. Hamilton, Jason P. Lisle, The river model of black holes
http://arxiv.org/abs/gr-qc/0411060
Note: that the above paper is peer reviewed and shows that yes indeed, particles falling past the event horizon travel with speeds greater than the 1 (in GP coordinates). In GR, the speeds of objects depend on the choice of coordinates. Consequently, this exceeding of the speed 1 is not equivalent to exceeding the speed of light. In GP coordinates, a light beam moving towards the singularity inside the event horizon also moves at speed greater than 1. Consequently, there is no violation of special relativity.
Comment: @Anixx; Re: "no massive object can follow this path." Rather than arguing the point, I'm going to note that I'm the only amateur who's ever won an honorable mention at the annual gravitation essay contest, and that the topic of my paper was GP coordinates: http://arxiv.org/abs/0907.0660 For more information on GP coordinates, see "The River Model of Black Holes" cited in the answer.
Comment: Another reference I like (g) is my paper on Gullstrand-Painleve coordinates, which shows how to write them as F=ma: Int.J.Mod.Phys.D18:2289-2294,2009, "The Force of Gravity in Schwarzschild and Gullstrand-Painleve Coordinates", http://arxiv.org/abs/0907.0660
Comment: Gullstrand-Painleve coordinates use local time of the free-falling object. On the event horizon this time corresponds to the infinite time of the external observer. Thus the infalling object still cannot reach horizon in finite time. Also in Gullstrand-Painleve coordinates the infalling object reaches the local speed of light at the horizon and even higher speed inside which is impossible for any object that has internal structure. For an object that has mass its kinetic energy will also exceed that of its mass which contradicts the conservation of energy.
Comment: So yes, such coordinates are possible. No, no massive object can follow this path.
Answer: (this answer addresses the new question)
As a consequence of the singularity theorems, it is not only possible but (arguably) inevitable for singularities to form in a finite amount of "time" in a physically reasonable spacetime. The word "time" in this context means "proper time along a specific timelike geodesic". For example, if there is a trapped surface* in spacetime, then a singularity will appear within a finite amount of proper time (along a timelike geodesic) in the future of that surface; so, an observer sitting in a collapsing star will reach the singularity in finite time. Thus, the collapse of matter is one possible way to create a singularity "out of nothing". If your spacetime is globally hyperbolic and you foliate it by Cauchy surfaces you can say in a much more "universal" way that the singularity didn't exist at time [$t_{0}$] and came to exist at time [$t_{1}$].
I should point out that the singularities are a generic feature of physically reasonable spacetimes; take a look at the Hawking-Penrose theorem- it applies in very general situations.
Also, as the original question was about black holes and not singularities, I should advise you to make a clear distinction between the two concepts. Trapped surfaces form due to the condensation of matter (this is the famous Schoen-Yau theorem), and under a certain extra hypothesis, these surfaces will be hidden inside black holes. This extra hypothesis is the well-known (weak) Cosmic Censorship Conjecture (CCC). If it does not hold, gravitational collapse can create naked singularities, that is, singularities not "causally hidden" by the event horizon of a black hole. Much of what is known in general about black holes depend crucially on the CCC.
*A trapped surface is a two-dimensional spacelike compact surface such that the null geodesics departing from it are accelerating towards each other - mathematically, we say that the expansion of the congruence of future-directed null geodesics orthogonal to the surface is negative.
Comment: I think the question actually was about the possibility of formation of trapped surfaces in finite time. You say "if there are trapped surfaces then there is singularity" but can the trapped surfaces formate in finite time themselves?
Comment: @Rodrigo Barbosa You've missed the point of OP's question completely, he's referring to an observer far away from the black hole and not the one inside.
Comment: I don't think Schoen and Yau actually answers @Anixx 's question. It states that when sufficient mass is already concentrated, then there must exist a trapped surface. For actual dynamical formation of apparent horizons you need something like [Pin Yu's recent paper](http://arxiv.org/abs/1105.5898) (or, going historically, you have the pioneering work of Oppenheimer-Snyder on dust, Christodoulou on scalar field in spherical symmetry in the 90s, Christodoulou on vacuum gravitational collapse in 2009 etc.)
Comment: @Anixx Yes. See the [Schoen-Yau paper](http://projecteuclid.org/DPubS/Repository/1.0/Disseminate?view=body&id=pdf_1&handle=euclid.cmp/1103940419) on formation of apparent horizons (the relevant result is theorem 2).
Comment: @Willie Wong thank for the remark. Indeed the main question here is whether sufficient mass can be concentrated in finite time to form a trapped surface since the closer mass particles approach each other, the slower they move due to gravitational time slowing effect.
Comment: Downvoted as this is irrelevant to op's question
Answer: What astronomers claim to be black holes are objects that "progressively make themselves more similar to [a black hole] without actually reaching the stage of having an event horizon", as they reckon. That's assuming that GR is valid, since all such claims depend on GR's equations. Plenty of books on GR note that black holes are perhaps better named "frozen stars" from a distant observer's perspective.
Comment: @Timothy a black hole will take infinite amount of time to form for the observer who had never been inside it. So all those answers claiming "BuT tImE dIlAtIoN iS rElAtIvE" are completely garbage answers in context of op's question
Comment: I think this information is wrong. The space inside a black hole does exist according to general relativity. Outside observers just don't see what's going on in there.
Answer: Ben's answer did not show that black holes/event horizons can ever form from a distant observer's (e.g. our) perspective. In our frame of reference, strictly according to GR, no event horizon could ever have formed. For us, it doesn't matter what happens in the reference frame of collapsing matter of a star that went super nova, no matter how many Penrose diagrams one shows.
Comment: "*In our frame of reference, strictly according to GR, no event horizon could ever have formed*" Can you elaborate on this, please? I could use some more detail. Where does this come from? Thank you, and welcome to physics.SE!
Comment: Thank you. As to where this comes from, well, the statements of special and general relativity concern what really **is**, not just what **appears** to happen in the reference frame of an observer. Ben wrote "... the main conceptual issue that was confusing the OP, which is that they seemed to have assumed that "seeing" and "being" are the same thing". And he is wrong about that. An in-falling object does not just appear to slow down to us, in our frame of reference, it really does.
Comment: Ikr bens answer is kinda garbage because it assumes the observer to be inside the horizon since start.
Comment: ... Then, Ben's blue and red equitemporality ("now") lines in Fig.2 and 3 are wrong. Equitemporality lines of outside observers do not cross the event horizon. If need be, I can provide a diagramm with coordinates to make that clear. I am actually surprised that this kind of misinformation appears on physics.stackexchange and doesn't get corrected for years.
Comment: To AccidentalFourierTransform: I have waited quite a long time now, and still Ben's answer appears here as correct, even though it is completely wrong. From his answer and his comments he apparently really thinks (and conveys) that, from an outside observer's perspective, collapsing masses / in-falling observers just **appear** to slow down to a standstill at the coordinate event horizon, whereas they really **do**, like e.g. Nathaniel correctly described in his answer to quite the same question here:"how can anything ever fall into a black hole as seen from an outside observer".
Answer: I wouldn't know that any of the answers above has shown that, from an outsider's perspective, anything can ever reach the horizon, which was essentially the question of the OP. From an in-falling observer's point of view, there is no problem because kinematic time dilation and gravitational time contraction of the rest of the universe ("looking" in the rear view mirror of an in-falling observer's space ship, let's say) cancel each other out, exactly. But from an outsider's point of view, this is never the case.
Btw, that does not contradict any of the phenomena of black holes like jets and accretion disk-dependent events.
P.S. I suggest to not first think about e.g. light signals when we want to understand the nature of relativistic phenomena. The reality can always be "retro-engineered" from light signals, their arrival time and location and their redshifts, but that's very complicated and confusing to begin with. In order to understand things, we should first assume an instant information transfer.
Comment: It seems to me that Ben's answer does discuss both the infalling & external observer.
Comment: I think this answer is useless. The space inside the event horizon does exist. Only if it didn't exist could you say that in one coordinate system that described all of space, the infaller's gravitational time dilation and the dilation of them receiving signals from the outside cancel each other out.
Answer: I get lost in the Jargon of most of the above replies.
My original question may have been answered but I am not able to follow it.
I understand that to an observer falling into a Black Hole (BH), time seems just normal up until the state of Singularity is attained.
However, my question is - to anyone far outside of the BH's Event Horizon (our observation place), there has not been enough of "our time" that has passed for the material inside the BH to have reached the singularity.  The age of our Universe right now is fixed to 13.8 Billion Years.  13.8 Billion years inside a BH (now) has not been attained - right ?
If a BH formed (began) at 1 Billion Years (in our time), by now 12.8 Billion years has elapsed for us, but inside the BH only 1.00000001 Billion years may have elapes since the Big Bang.....the inside may be only a few seconds old !
I hope I am saying this correctly - 13.8 Billion years (the age of our Universe) has passed for us outside the BH, but much less elapsed time has passed (relative to the outside) inside any BH.  Thus, what passes for the elapsed time inside the BH, is much, much less than what has passed outside the black hole.  Yes ?
In our time outside the BH, the BH is still in the process of collapsing.
If someone inside the BH were able to travel back to the outside, they would be young in a universe that had aged maybe thousands of times faster.  In the big picture (the whole universe) the insides of BH's must be very young - i.e. less than 13.8 Billion years old and therefor still in the early stages of collapse.
Thank you for your patience.
Comment: For the outside observer, there is no *observable* "inside of the black hole". It's not part of their observable universe.
Answer: It seems like, if there is a sufficient amount of matter localized during the Big Bang, then a Black Hole could form.  But after that, a massive star, as seen by the rest of the universe could never shrink to the size of the event horizon.
In other words, a Black Hole would have to preexist in the universe to be an actual Black Hole.
Comment: At best I think this needs to be fleshed out to be worth an answer rather than a comment. And I'm not really convinced that this can be fleshed out to make sense. A Schwarzschild singularity is a spacelike singularity that exists in the future of observers, i.e., timelike worldlines terminate on it in the future, so I don't see how you can talk about having one existing at the big bang. This answer also fails to address the main conceptual issue that was confusing the OP, which is that they seemed to have assumed that "seeing" and "being" are the same thing.
Comment: @BenCrowell well well Mr. Crowell your answer seem to fail to explain that the said future of the external observer is going to be infinitely far away since collapsing matter slows down exponentially from external observer's perspective and hence the blackhole would never form for him
Answer: I like your question.  This model of a stellar black hole is created by freezing time as it is created from the inside out.  It ends being solid frozen neutron matter with no singularity or event horizon, which is known as a black star.  This is all relative to a remote location.
Using a program written in Excel it was found that a supernova remnant, with a mass between 1.44 and 2 solar masses, contracts down to a neutron star.  The physical compressive forces during a supernova cause the remnant to contract down to neutron matter.  Due to increased gravity, it continues to contract down to where the pressure, beginning at the center, supports the incoming mass where the contraction stops.  During this contraction the decreasing gravitational potential also caused time to slow, but it was not enough to cause time to freeze.
For larger solar mass remnants, during the contraction, the increased gravitational potential is enough to causes time to relatively freeze starting at the center and stop the contraction before the pressure gets high enough to stop it, as it did in a neutron star.  This also freezes the flow of information concerning the decrease in gravitational potential, thus; the frozen portions remain frozen and do not contract down any further.  While this remnant is contracting down through a point where its' radius is about 1.75 times the Schwarzschild radius, the gravitational potential meets the condition that causes time to first freeze at the center.  By freeze I mean the rate of time flow becomes equal to the square root of a value that gets ever so close to zero; but, it never crosses over and becomes negative, where the rate of time flow would become imaginary.  This means that in the position where time is getting close to being frozen, the coordinates do not reverse and become null light-like instead of time-like as it would on the inside of an event horizon or a radius that is frozen.  The remaining shells of matter, which have not been frozen, continue to contract in and cause the gravitational potential to decrease which causes the next layer is freeze.  Most of all the remaining unfrozen shells will continue to contract and freeze each successive layer almost all the way to the surface.  The last bit of contracting matter will only have enough mass to cause time to significantly slow, but it will not quite freeze.  If the freeze made its way to the surface, it would meet the condition of a black hole, having a Schwarzschild radius; but, it does not quite get there.  What has been created is sometimes called a black star which has no event horizon or singularity and has matter through-out its volume.
The frequency of the light emitted by a black star is gravitationally red shifted and the rate of photon emission is also reduced.  Because of this and the small size, a black star is almost black and extremely hard to see.  These black stars are fairly uniform in density except near the surface where the density increases.  The density is about the same as that of neutron stars with the larger black stars having a smaller density.
This model also discusses how the Chandrasekhar limit relates to black stars which in turn answers questions like:

Why is there such a large size gap between stellar black holes and super massive black holes?
Why are there no stellar black holes below 2 solar masses?
Why are there no supernova created stellar black holes above 15 solar masses?
Why does the smallest super massive black hole start at 50,000 solar masses?
Are super massive black holes made before or after the existence of first-generation stars in a galaxy?

These questions cannot be answered using black holes that have a singularity.  They are answered by this model of the formation of black stars. The information produced by this model agrees with observation when available.
A link to my article,
http://file.scirp.org/pdf/JHEPGC_2017072816470248.pdf
was recently published in the pier reviewed Journal of High Energy Physics, Gravitation and Cosmology, in which I discuss this computer model that poses an alternative process to the accepted theory of the formation of a black hole.  Due to a unique requirement of creating black holes by freezing time and space from the inside out, the conventional method of deriving results from general relativity could not be used.  Instead I used the Newtonian model, while factoring in relativistic corrections derived from general relativity which includes the relative contraction of both time and space and the equivalence principal.  This mathematical model, using Excel and Visual Basic, takes about a day to run.
Comment: They are doing quantum physics on Microsoft excel now? Jesus these are dark days for science
Comment: This answer does not answer the question. Also, it has wrong information. According to general relativity, black holes do form and the space inside it does exist. Outsiders just never see it.
Comment: @Timothy so if i throw a lot of matter together then for me being outside it it'll be frozen due to time dilation while still existing where? where would it get it's matter to feed on?


In what sense is the polis/city self-sufficient for St. Thomas Aquinas?

Question: De Regno cap. 2 n. 14:

Now since man must live in a group, because he is not sufficient unto himself to procure the necessities of life were he to remain solitary, it follows that a society will be the more perfect the more it is sufficient unto itself to procure the necessities of life. There is, to some extent, sufficiency for life in one family of one household, namely, insofar as pertains to the natural acts of nourishment and the begetting of offspring and other things of this kind. Self-sufficiency exists, furthermore, in one street with regard to those things which belong to the trade of one guild. In a city, which is the perfect community, it exists with regard to all the necessities of life. Still more self-sufficiency is found in a province because of the need of fighting together and of mutual help against enemies.

I didn't understand what Thomas Aquinas meant by "necessities of life" when talking about the self-sufficiency of the city. And I also don't understand how the city can be self-sufficient in all "necessities of life" if it, unlike the province, is incapable of dealing with war issues on its own.
This passage from the Summa Theologica I-II q. 105 a. 4 co. perhaps explains what Thomas meant by "necessities of life", but I still cannot understand how the city can be self-sufficient if there are things it cannot do alone (unlike the province, for example):

I answer that, The mutual relations of the members of a household regard everyday actions directed to the necessities of life, as the Philosopher states (Polit. i, 1). Now the preservation of man's life may be considered from two points of view. First, from the point of view of the individual, i.e. in so far as man preserves his individuality: and for the purpose of the preservation of life, considered from this standpoint, man has at his service external goods, by means of which he provides himself with food and clothing and other such necessaries of life: in the handling of which he has need of servants. Secondly man's life is preserved from the point of view of the species, by means of generation, for which purpose man needs a wife, that she may bear him children.
Answer: St. Thomas mentions "necessaries of life" (necessaria vitæ) in 91 places of his works.
De regno lib. 2 mentions some of these necessaries, that cities

"should have wholesome air" (cap. 2)
"an abundant supply of food" (cap. 3)
"charm the inhabitants by its beauty" (cap. 4)


Transmission of heat from fluid flowing through a pipe

Question: If we hold a pipe, filled with almost scalding water (say 50 °C), does it make any different whether the water is flowing along the pipe and, if yes, at what speed?
Comment: *does it make any different?* Make any difference in what way?
Answer: Yes.
Since the water will exchange heat trough the pipe trough convection, the faster the water the more turbulent the flow and more heat is exchanged.
If the flow is laminar, you would have less heat exchange.
Answer: The rate of heat flow through the walls of the pipe depends on the difference in temperatures between the inner and outer surfaces of the pipe.

If the temperature of the static water at the inner surface of the pipe is not maintained at 50 °C by some means then it will fall and the rate of transfer of heat through the walls of the pipe will also fall. This assumes that the temperature at the outer surface does not change.
If there is a source of heat which maintains the temperature of the water at 50 °C then the rate of transfer of heat out through the walls of the pipe will be constant.
If the water is flowing along inside the pipe then there will be a temperature gradient along the pipe. The rate of heat transfer will fall along the pipe accordingly.

The faster the water flows the smaller the temperature gradient and the smaller the difference in rate of heat transfer between one end of the pipe and the other. If the flow is fast enough then the temperature difference will be insignificant and the rate of heat transfer will be constant along the pipe, as in case 2 above.
In this situation you would not be able to tell from the rate of heat transfer out of the pipe whether the water inside was still and heated (case 2) or flowing very fast (case 3).


Where did the view handler design pattern come from?

Question: I'm trying to figure out the origin of the view handler design pattern in software engineering. Many of the design patterns in software engineering were inspired by things which pre-date computers, and I was wondering if anybody had any insights on the origin of this particular pattern.
Comment: Can you provide any further information about the pattern? Maybe it is better known under other name...
Answer: It feels a lot like a rule systems for updating construction or planning drawing dependencies. Or to rephrase, it seems like an automation of the work rules and cross-indexes required to keep a set of architectural plans synchronized as changes are made on each drawing.
Answer: Look in POSA1 - Pattern-Oriented Software Architecture Volume 1: A System of Patterns (from 1996 i think).
There is a chapter about view handler. There are examples of the usage of a such pattern in 1985 (Macintosh Window Manager) and 1993 (Ms Word).
But i am not sure we are talking about the same pattern. Where you heard about this pattern name?


Why are there so many devices in /dev?

Question: I read that your devices are listed in /dev. I do not have nearly as many devices attached to my system as there are listed in that directory. Why are there so many devices there? And how do I get informations about a particular one?
Answer: Not every device in /dev corresponds to a physical device. The devices in /dev also include pseudo-devices allocated by the kernel which allows the kernel to interact with these abstractions using standard IO as if they were ordinary files. Here is the device list as it appeared in the 2.6 kernel which also provides some details for each (pseudo)device.
Answer: /dev lists block and character devices the kernel has drivers for, but

not all the device pseudo-files are necessarily physically present
some devices such as network cards don't have nodes in /dev

To see what devices are actually present you're better off using something like the lshw command.

Why are there so many devices in /dev?


How would I find out the cost for flights that have already taken place?

Question: I would like to know what the RT cost would have been to fly from CMI to MSP on July 30, 2021. Return on August 3, 2021.
Comment: Why do you think there's only one price?  Prices for the exact flight vary depending on when you book/how many seats are left, and there are several flights per day on that route.  I doubt you'll get a better estimate than just using the same as for a near-future date, as even those vary by a factor of 2.
Comment: This isn't well defined. Many different fares would have been available at different times. Are you expecting to find a distribution of all fares? An average price paid by actual passengers on that flight? A simulation of what would have been available to you at some point in time? Not that any of this would be easily available as far as I know.
Comment: Probably more than $200 and less than $2000.
Answer: The simple answer is that there's no way to find out.
The price of flights varies not just based on the dates of the flights, but also multiple factors including :

How far in advance of travel the tickets were booked
How many seats were available at the time of booking
The exact date the flights were booked, in terms of any fare sales/etc occurring at the time.
The country that the tickets were booked in
The exact route for the flight (there do not appear to be any direct flights between CMI and MSP)

and probably numerous other factors.
Even if you were to find someone that flew that exact route on those exact days, and asked them what they paid, it would not be a good indication as it still wouldn't cover most of the above points - in particular when the ticket was purchased.
You can get a very (very!) rough estimate for the price by looking at a similar flight sometime in the future. eg, October 22->27 (Friday -> Wednesday as per your original dates) shows prices ranging from $317 up to $547 for a 1-stop trip.  This MIGHT give an indication of a typical price for such a trip booked 3+ weeks in advance - or it might not as pricing can vary depending on the exact days (eg, school holidays, events occurring in the relevant towns increasing demand, etc, etc), sales occurring at the time of booking, etc.
Comment: Cost will also vary by the class of service: First Class costs more than Business which costs more than Coach...and there are additional levels offered by many carriers.
Comment: And the flexibility of the ticket.
Comment: ..and what was happening in the destination country around that time, for example sporting events..
Comment: You can slightly refine the estimate in the last paragraph by googling events around the original  dates at either end of the trip, and either choosing dates without events or ones with similar events as appropriate (big conventions, sporting events, concerts etc.)