I’m not sure how they handle things like tan, but overall the theory seems pretty solid. It is however predicated on small changes in standard deviation which change in value - whihc is rather what you would expect would be needed.
Where I think Python/Numpy is a bit of a game changer is that the paradigm for numpy is close enough to Matlab that Matlab users can feel at home, and transliteration of many codes is not difficult, and close to automatic. But the ability to augment the system in all sorts of neat ways, such as the uncertainly package get you a significant step further in utility. However, I do worry that there isn’t the rigour across this landscape of packages that you might hope from a commercially supported product. The scope for weird interactions and oddities means that the end user needs to be quite rigorous themselves about testing and analysis of results - which is no bad thing. There is a lot of bad science out there already from poor understanding and use of numerical tools.
I made a fucking pyramid out of bricks. It took me 7 hours and I used two separate logical operators (I might be using wrong terminology). I made it green, then I made the bricks 1/4 of the size but 4x as many, then I made it with green stripes - that was pretty exciting. I did accomplish my goal of not leaving the house though, that’s something. Just thought I’d share.
No, it isn’t insane. More a comment on the common perception of coding in Fortran.
Once you are working on getting the performance in serious code you use the right tool for the job. There are times when Fortran is very much the right tool for the job. Indeed if you look at a modern Fortran it makes some of the the supposedly modern languages look much quite stone age. (This most certainly includes C++. ) But you must have a very clear and detailed understanding of what is actually happening in the hardware. So no matter what level you are coding at, you need to be performing deep analysis of the code’s performance, and on the constant lookout for problems that rob you of performance.
The right answer comes from the problem you are trying to solve. The gamut of HPC problems is so large that until you have a pretty clear idea about the problem, from top to bottom, you can’t make a sensible choice about anything. These choices include languages, programming paradigms, and most assuredly, the hardware. They all interrelate, and you converge on a system design as you explore the options. For really big problems you need to run around the cycle a couple of times.
OpenMP is a bit of a weird beast. It’s handy if one has an “embarrassingly parallel” problem that can be chopped up at a high level and you don’t have a lot of time to spend on the parallelization. I’ve used it myself for a number of toy projects and it’s fine.
However, it’s no replacement for understanding the low-level OS synchronization and threading primitives. If you really need to squeeze every last bit out of a system, you don’t really have a choice.
In my experience, OpenMP also has some weird issues. Last I checked, on Windows it would slam every core to 100% utilization as soon as you used a parallel primitive. Apparently it used a spin loop (as opposed to a halt instruction or the like that would be more power efficient) to minimize latency. Horrible if you care about power at all, but the alternative is potentially worse–your app actually getting slower because it takes longer to spin up all the threads than any savings it would get.
Mr. Nylock, what do you mean about the pyramid? Did you write a program that draws a pyramid on the screen, or is that a metaphor for a long task that took a lot of work but is now completed?
Francis Vaughan, for some of us, the mere words “modern Fortran” are enough to elicit a giggle. Yes, I know that modern versions of it exist, but one is far more likely to encounter Fortran in the form of legacy code, which will be F77 at best. Using that monstrosity, any time you could possibly avoid doing so, is indeed insane.
ETA if there were some advantage to using, say, C++ for such a fundamental and critical piece of software, I’m sure they would, so the choice of language is telling.
I literally wrote a program that draws a pyramid on the screen. It took like 7 hours and was only about 14 lines or so. I used a while loop statement with 2 ifs, I think I might have been able to use a nested for loop; I’ll try that today. I’m very bad/at a very novice level at programming; but I’m still accomplishing my main goal of finding a way to occupy myself without spending any money.
One problem with that approach is that English words don’t quite mean what they do in programming and logic. In particular, the English “or” is usually an exclusive or.
I don’t have peanut butter and jelly.
Isn’t the same as:
I don’t have peanut butter or I don’t have jelly.
Instead, it means:
I don’t have peanut butter or I don’t have jelly or I have neither peanut butter nor jelly.
I think you’re missing the point. Or maybe I’m missing the point. Or maybe I’m confusing myself or you’re confusing me or I’m confusing you or perhaps we’re confusing each other and everyone else. Is an eel a fish?
Decades ago, in my spare time, I wrote a communications program in Pascal on a VAX that let users talk to each other. Pretty simple. (Confession - the first version polled so much it brought the server to a crawl - but I fixed it quickly and it barely consumed any resources). So, in my real work writing Ada for the Air Force, they liked the little communications program, and wanted to use it. Woo hoo! They just wanted a translation (rubbing hands thinking about translating it to Ada). “Just translate it to Fortran 77”. Jaw drops - but okay. So I translated my Pascal program to Fortran 77!
I was wondering if I could use switch in this program I wrote yesterday; the book and lectures don’t really spend much time talking about switch, but I think that using switch could make the code a little cleaner. My coding is ugly, but it works. Don’t worry, lives aren’t at stake, money isn’t on the line.
public class FindRange extends ConsoleProgram {
/** Setinel value and min/max initialization. */
double SENTINEL = 0;
int min = 1;
int max = 1;
public void run() {
println("This program finds the largest and smallest numbers.");
int question = readInt("? ");
int firstInt = question;
/** For instances where the sentinel is first entry. /
if (question == SENTINEL){
println(“You typed in sentinel dumbass.”);
}
/* For instances where the sentinel is second entry. /
if (question != SENTINEL){
int question2 = readInt("? ");
if (question2 == SENTINEL){
println("Min. = " + question);
println("Max. = " + firstInt);
}
/* Finds minimum and maximum of two or more numbers entered. */
if (question2 != SENTINEL){
int questionInfinity = readInt("? ");
if (question2 > question){
min = question;
max = question2;
}
else{
min = question2;
max = question;
}
while (true){
if (questionInfinity != SENTINEL && questionInfinity < min){
min = questionInfinity;
}
if (questionInfinity != SENTINEL && questionInfinity > max){
max = questionInfinity;
}
if (questionInfinity == SENTINEL){
println("Min. = "+ min);
println("Max. = “+ max);
break;
}
questionInfinity = readInt(”? ");
}
}
}
}
}
I tried using code tags but it messed up the formatting. Even copy and pasting does not format the tabs a paragraphs correctly.
So I gather you type in a sequence of numbers with 0 as the terminating value and after the second number it starts telling you what the minimum and maximum numbers you entered were.
You don’t need switch. You need to clean up a bunch of things. What is ‘firstint’ for? It has the same value as ‘question’. In your loop you are repeating the condition ‘questionInfinity != SENTINEL’. You don’t need the && in those if conditions, you need to nest if-elses, and do your min/max logic in an inner if-else. You don’t need ‘questionInfinity == SENTINEL’ at all, it’s just the else condition for the first if.
Thank you for taking the time to look at my code (I have to figure out how to get the formatting right, so I know it’s a little bit more difficult to read than it should be - I can use a lot of advise as is apparent. The firstInt is something I forgot to erase I think. You pretty much have the right idea as far as the general way the program works (it is a fairly simple program) :
There are the three conditions that must be met :
If the sentinel is the first integer typed in, the message must appear and the program must be stopped.
If the sentinel is the second integer typed in, both the min. and max. must display the first integer and the program must be stopped.
If the sentinel is the third or any integer thereafter, the program must display the min. and max. and the program should stop.
I like your suggestions; I think I’ll work on the nesting ifs and elses. For some reason I’ve been trying not to nest too much, but think that I need to have more practice implementing if/else statements.
I’ll look at the code again in a day or two and see if I can make it cleaner. I’m writing a different program today so I might not have time to look at this one today.
BTW, why am I having so much formatting trouble copying code from eclipse?
I should have mentioned that you should use a return if you detect the 0 as the first or second entry. There’s no need to fail out of conditions all the way to the end of the code. Yes, I saw you were displaying the min and max after the 0, I didn’t exactly write it that way in my description.
Anyway, the thing to note is the repetition in the if conditions. That will tell you that you should be nesting ifs.
The code tags don’t work properly on the new message board skin, but they still work fine on the old skin. There’s a drop-down in the blue bar at the bottom of the page you can use to switch back, if you’d like. Meanwhile, a workaround is to use php tags instead of code tags, which are almost the same but with a little color-coding that won’t actually be relevant to non-PHP languages. Why the php tag works when code doesn’t, I don’t know, but there you go.
I remember toggling between the two a few weeks ago and wondering if there was any practical difference for me posting. Well, now I guess I have the correct answer.
On a more general level of coding the question is useful.
First up, you need to understand finite state automata. Understand the basic idea of any sort of input specification being expressible as a grammar, and that these grammars can be transformed into a finite sate automata. Now there is a lot of theory here, but unless you are writing a compiler, you can ignore most of it.
What you do, in general, is construct your code so that it lives in a loop that is reading input “tokens”. Where a token is the basic unit of the grammar. Here you have two tokens. Integer and sentinal. The top of the loop reads the next token. The program has a “state” - basically a simple enumeration, that defines the current execution state of the automata. On he basis of the current state, and the token you receive, the internals of the loop take an action.
A switch statement can be used here. You switch on the state value to decide on the action to take.
Structuring your code like this has a huge number of advantages. You can formally reason about the code. You can automatically create automata from other formal specifications. But most of all, this is the tactic that is most likely to get you error free and maintainable code.
For your problem the states are something like:
initial
one values read
two values read
and the input tokens are integer, sentinal.
Your code looks a bit like like
state = initial
while not done:
input = read_integer()
switch state
initial:
if input = sentinal:
barf
done = true
else
calcualate stuff
state = one_value_read
endif
one_value_read:
....
state = two values_read
two_values_read:
....
end switch
end do
Sorry, I accidentally hit the post button before I was done, and didn’t have time in the edit window to properly write the example. So the indenting is messed up and it could do with some more cleaning up generally, but there should be enough to get the overall idea. I can hack it some more if needed to get the idea across.