What is the origin of magic number 42, indispensable in coding? [closed] - language-agnostic

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Update:
Surprised that it is being so heavily downvoted...
The question is coding-related and before asking this question I have googled for "42" in combination with:
site:msdn.micrsoft.com
"code example"
"c#"
"magic number"
And I am not an expert/fan of Western culture/literature.
Also found, Why are variables “i” and “j” used for counters? [duplicate] which was not closed but even protected.
I feel that everybody knows it, except me...
What is the origin of ubiquitous magic digit 42 used all over the code samples and samples?
How have you come using 42? because I have not ever come or ever used 42
After some search, I found MSDN doc on it: Magic Numbers: Integers:
"Aside from a book/movie reference, developers often use this as an arbitrary value"
Well, this did not explain me anything.
Which movies and books have I missed for all those years of being involved in development, coding and programming and around-IT related activities like rwquirements analysis, system administration, etc??
Some references to some texts using code snippets with 42 (just C#-related):
Jérôme Laban. C# Async Tips and Tricks, Part 3: Tasks and the Synchronization Context
var t = Task.Delay(TimeSpan.FromSeconds(1))
.ContinueWith
(
_ => Task.Delay(TimeSpan.FromSeconds(42))
);
MSDN Asynchronous Agents Library
send(_target, 42);
Quickstart: Calling asynchronous APIs in C# or Visual Basic
Office.context.document.setSelectedDataAsync(
"<html><body>hello world</body></html>",
{coercionType: "html", asyncContext: 42},
function(asyncResult) {
write(asyncResult.status + " " + asyncResult.asyncContext);
Asynchronous Programming in C++ Using PPL
task<int> myTask = someOtherTask.then([]() { return 42; });
Boxing and Unboxing (C# Programming Guide)
Console.WriteLine(String.Concat("Answer", 42, true));
How To: Override the ToString Method (C# Programming Guide)
int x = 42;
Trace Listeners
// Use this example when debugging.
System.Diagnostics.Debug.WriteLine("Error in Widget 42");
// Use this example when tracing.
System.Diagnostics.Trace.WriteLine("Error in Widget 42");
|| Operator (C# Reference
// The following line displays True, because 42 is evenly
// divisible by 7.
Console.WriteLine("Divisible returns {0}.", Divisible(42, 7));
// The following line displays False, because 42 is not evenly
// divisible by 5.
Console.WriteLine("Divisible returns {0}.", Divisible(42, 5));
// The following line displays False when method Divisible
// uses ||, because you cannot divide by 0.
// If method Divisible uses | instead of ||, this line
// causes an exception.
Console.WriteLine("Divisible returns {0}.", Divisible(42, 0));
WIKIPedia C Sharp (programming language)
int foo = 42; // Value type.

It's from The Hitch Hiker's Guide to the Galaxy.
In The Hitchhiker's Guide to the Galaxy (published in 1979), the
characters visit the legendary planet Magrathea, home to the
now-collapsed planet-building industry, and meet Slartibartfast, a
planetary coastline designer who was responsible for the fjords of
Norway. Through archival recordings, he relates the story of a race of
hyper-intelligent pan-dimensional beings who built a computer named
Deep Thought to calculate the Answer to the Ultimate Question of Life,
the Universe, and Everything. When the answer was revealed to be 42,
Deep Thought explained that the answer was incomprehensible because
the beings didn't know what they were asking. It went on to predict
that another computer, more powerful than itself would be made and
designed by it to calculate the question for the answer. (Later on,
referencing this, Adams would create the 42 Puzzle, a puzzle which
could be approached in multiple ways, all yielding the answer 42.)

The answer is, as people already have stated, The Hitchhiker's Guide to the Galaxy.
I made a little experiment and put a couple of numbers in the search field, and these are the results:
It seems like 42 beats its neighbors clearly, but it can't touch regular numbers like 40, 45 and 50, no matter how magical it is.
It would be interesting to do the same search in source code only.

Dude!
It's the Answer to the Ultimate Question of Life, the Universe, and Everything! As computed by Deep Thought supercomputer, which took 7.5 million years!
http://en.wikipedia.org/wiki/The_answer_to_life_the_universe_and_everything#Answer_to_the_Ultimate_Question_of_Life.2C_the_Universe_and_Everything_.2842.29

Check this out. 42 is the ultimate answer to the ultimate question of life the universe and everything

This is from The Hitch hikers Guide to the Galaxy and is:
The Answer to the Ultimate Question of Life, the Universe, and Everything
WikiLink

Refer The Hitch Hiker's Guide to the Galaxy.

Related

Is it possible to use the prediction of a CNN for images not belonging to the model classes?

I am using photos of faces of individuals of 10, 12, 14, 16, 18, and 20 years old. The question I am trying to answer is: How does the face "evolves"? Will it remain +/- similar until a certain threshold where it will suddenly change?
To answer this question, I trained a CNN on 2 classes, the 10 year old photos (labelled as "0") and the 20 year old photos (labelled as "1").
I used this model to predict the categories that do not belong to the model's classes (the 12 to 18 years old), to compute the average prediction for each age group. The result is shown in the figure, where each value is respectively the mean prediction for 12, 14, 16, 18 years old. Mean prediction for 12,14,16,18 years old
My question here is : Does it make sense to use this model to predict other age groups and say for example "The 12 years old have a mean prediction of 0.2, which means they are more similar to the 10 years old faces than the 20 years old faces" ?
As the values are increasing with age, can I say that the faces are getting more similar to 20 years old faces ? And are there any references of articles using a model to predict images belonging to none of the model's classes ?
Thank you !
This is quite an interesting question. Let me answer this in two ways.
Q1: Can CNN predict image whose class is not included in the training set?
A1: Yes. However, instead of training the model and comparing the output probabilities, we use a method called “few-shot learning”, or “zero-shot learning” to figure this out. The basic idea is: first, we train the model so that it recognizes the high-level features underlying the data (e.g., the edges or the shape of eyes in your example). Then we implement the model to a new dataset, relying on its generalizability. This research is also closely related to transfer learning.
As a starting point, here is a good paper.
Generalizing from a Few Examples: A Survey on Few-shot Learning
Q2: If the probability is higher, can we say the faces are more similar to 20 year old faces?
A2: The short answer is, YES. The reason is that we only have two classes in your training data – if the value of probability is higher, it means the model has more confidence that the picture belongs to the class of 1 (i.e., 20 year old photos). But we cannot make sure how the model makes this prediction. You may want to visualize outputs of intermediate layers to see which feature the model finds. You can have a check at this blog.
Understanding CNN (Convolutional Neural Network)

Does any programming language support the expressions like "12.Pounds.ToKilograms()"? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
Converting units and measurements from one system to another can be achieved in most programming languages in one or another way. But, Can we express something like "12.Pounds.ToKilograms()" in any programming language?
Not exactly in that syntax but you may want to take a look at Frink: https://frinklang.org
Frink syntax is similar to Google Calculator or Wolfram Alpha but not exactly the same. Whereas Google and Wolfram Alpha uses the in keyword to trigger unit conversion Frink uses the -> operator. So in frink, the following is valid source code:
// Calculate length of Wifi antenna:
lightspeed / (2.4GHz) / 4 -> inches
As I mentioned, this syntax is similar to Google. For reference, the same calculation in Google syntax is speed of light / 2.4GHz / 4 in inches. Frink predates both Google calculator and Wolfram Alpha. I was first aware of frink sometime in the early 2000s.
Frink is unit aware. A number in frink always has unit even if that unit is simply "scalar" (no units). So to declare a variable that is 12 pounds you'd do:
var x = 12 pounds
To convert you'd do:
x -> kg
Or you can simply write the expression:
12 pounds -> kg
In Smalltalk you could express this as
12 pounds inKilograms
Notice however that it is up to you to program both messages pounds and inKilograms (there are libraries that do that kind of things also). But the key point is that the expression above is perfectly valid in Smalltalk (even if these messages do not exist).
I can't say I've ever seen this as a valid expression. 12 would have to be defined as a type. Let's assume 12 is an integer. An integer type only knows that it is an integer and in most languages there are built in functions/ methods for integers. For this to be a valid expression you would need to define a weight type and within that object you could define methods of conversion or inherit child types with conversion methods.
You could do it in Ruby because of it's syntactic sugar.
Actually there's a ruby gem - alchemist - you should check it out.
For example you could write:
10.miles.to.meters

Getting musical notations using aubio library [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Well, this is my first question on stackoverflow so kinda excited about it :)
Here it is: My input is a wave file. For now, I have recorded a piece using my guitar. So the wave file contains this instrumental recording. What I want to do is, get the musical notation(A,B,C and so on) of each note that is being played. I have heard about techniques like the FFT but considering my poor knowledge of how to use FFT, I thought of using the aubio library.
So aubio provides:
aubiopitch which extracts pitch candidates and
aubiocut which extracts onsets.
Where I am stuck is: How do I get the frequency at the particular time of the note played using aubio?
According to me, aubiopitch and aubiocut would help but I dont understand how to do the mapping between them. Any help would be greatly appreciated :)
Hi piem: Thanks for your answer. Could you please analyse this output?
aubiopitch -i Reverse_Open.wav
1.408 68.9486465454
1.536 81.7372512817
1.664 164.290893555
1.792 164.464691162
1.92 82.6862487793
2.048 328.539306641
2.176 218.885116577
2.304 219.06237793
2.432 219.042160034
2.56 219.133621216
2.688 145.751785278
2.816 146.437744141
2.944 146.199829102
3.072 195.059829712
3.2 194.912689209
3.328 195.724975586
3.456 195.517547607
3.584 247.317428589
3.712 246.764221191
3.84 246.857452393
3.968 145.454727173
4.096 328.569610596
4.224 329.625823975
4.352 329.16619873
4.48 328.906402588
4.608 328.96786499
4.736 329.187835693
4.864 145.741394043
My notes with frequencies are: E(82 approx),A(110),D(147),G(197),B(247),E(329.2)
which are played at 1.344,1.888,2.4,2.88,3.36,3.872 resp(according to aubiopitch which I suppose is correct).
Any idea how do I extract these 6 notes and their times from the above output?
aubiopitch outputs a list of tuple. Each tuple contains two floats:
a timestamp in seconds
a fundamental frequency in Hertz
Here is an example on a guitar sound:
$ aubiopitch -i guitar_Cold_Blood_-_Baby_I_Love_You.wav | head
0.000000 0.000000
0.005805 293.884338
0.011610 386.387207
0.017415 0.000000
0.023220 551.689758
0.029025 3608.569336
0.034830 3588.231201
0.040635 416.824066
0.046440 3606.715576
0.052245 417.116425
if you are curious (please be), you can get the latest git version and try the demo script demo_pitch.py:
$ ./python/demos/demo_pitch.py bass_Don_Ellis_-_Conquistador.wav
you would get the following plot:
The first row represents the waveform.
The second row, the extracted pitch track, in midi frequency.
The third, the confidence of these pitch candidates (using the yinfft algorithm).
In this sample of a bass line, extracting the pitch during the transient attacks is more challenging than in the steady state. Pitch candidates that are found below an arbitrary threshold (here 0.8) can be discarded (dashed green line), while others can be kept (solid blue line).

Tautology Checker for GNU Prolog [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I am looking for open-source implementations of tautology checkers written in GNU Prolog (implementation for SWI-Prolog is acceptable as well, but GNU Prolog is preferred).
I'd like to feed program input with queries like:
A and (B or C) iff (A or B) and (A or C).
or
3^2 * (X + 2) == (9 * X) + 18.
of course, notation can be different, like this:
(3 power 2) mul (X plus 2) equals (9 mul X) plus 18.
What I expect as result, is boolean answer , like "Yes/No", "Equals/Different", "Prove found/Failed to find prove" or similar.
I've found tautology checker for GNU-Prolog on ftp://ftp.cs.yorku.ca/pub/peter/SVT/GNU/ , but licence is not attached and no clue how to apply Gnu Prolog Arithmetic constraints and Arithmetic capabilities in order to extend just logical model with arithmetic.
Any other simmilar solvers?
Some examples how arithmetic capabilities might be used in order to extend model.
Thanks, Greg.
P.S. According arithmetic, I am looking for partial support - I want to handle only some basic cases, which I can code by hand with simple heuristics (gnu-prolog integer functions examples welcome as well) if proposed solution will handle classical logic properly and open-source code will be nice to extend :).
P.P.S As #larsmans noted, according to Gödel's incompleteness theorems there is no way to prove "all" formulas. That's why I am looking for something that proves, what can be proven from given set of axioms and rules, as I am looking for Gnu Prolog program, I am looking for examples of such sets of axioms and rules ;). Of course checker may fail - I am expecting it will work in "some" cases :). - On the other hand, there is Gödel's completeness theorem ;).
If you want an extensible theorem prover in Prolog, check out the family of lean theorem provers, of which leanCOP is the main representative; it handles classical first-order logic in 555 bytes of Prolog.
Version 1.0 is the following program:
prove(M,I) :- append(Q,[C|R],M), \+member(-_,C),
append(Q,R,S), prove([!],[[-!|C]|S],[],I).
prove([],_,_,_).
prove([L|C],M,P,I) :- (-N=L; -L=N) -> (member(N,P);
append(Q,[D|R],M), copy_term(D,E), append(A,[N|B],E),
append(A,B,F), (D==E -> append(R,Q,S); length(P,K), K<I,
append(R,[D|Q],S)), prove(F,S,[L|P],I)), prove(C,M,P,I).
The leanCOP website has more readable versions, with more features. You'll have to implement equality and arithmetic yourself.
You could use constraint logic programming for your problem. Equality
gives you directly a result (example GNU Prolog):
?- X*X #= 4.
X = 2
For inequality you will typically need to ask the system to generate
instanciations after the constraints have been set up. This is typically
done via a labeling directive (example GNU Prolog):
?- 27 * (X + 2) #\= (9 * X) + 18.
X = _#22(0..14913080)
?- 27 * (X + 2) #\= (9 * X) + 18, fd_labeling(X).
X = 0 ? ;
X = 1 ? ;
X = 2 ? ;
Etc..
A list that shows which prologs do have which kind of CLP can be found here. Just
check the CLP multi column.
Overview of Prolog Systems, Ulrich Neumerkel
Bye
I've found some tautology checkers, in Mathematical Logic for Computer Science by Ben-Ari, Mordechai, unfortunately they cover boolean logic. What advantage, his implementations are in Prolog, and present a variety of approaches related with automated proving, or solving such equations (or, automatically verifying proofs).

Are there any open source/free LOGO implementations that support dynaturtles? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm looking for an implementation of the LOGO programming language that supports 'dynaturtles' - animated turtles that can programmatically change shape, speed and direction as well as detect collisions with each other or other objects in the environment.
Back in the mists of time when the earth was new and 8 bit micros ruled supreme, Atari LOGO did this famously well. One could create all sorts of small games and simulated environments using this technique very easily as that implementation of the language had a very well thought out, elegant syntax.
I know about LCSI's Microworlds but I'm looking for something I can use to get some friends and their kids involved in programming without breaking my budget.
Digging around a bit online, I've found OpenStarLogo. Though they don't specifically mention "dynaturtles" the docs do mention collision detection. The site has code and documentation downloads.
From this wikipedia article, under the Implementations section, there is a PDF listing known current and antique implementations. Some of these, such as StarLogo TNG and Elica have support for 3D objects. These are definitely not like the LOGO programs I wrote as a kid...
I use microworlds for my logo... I know of kturtle for kde kturtle
I also found a few links that could be interesting
python turtle
fmslogo
MSWlogo
Check out the turtle python package. It is in the standard python distribution and it supports a graphical turtle interface.
If you use win-logo (www.win-logo.de/eng/e_index.htm; you must register and then you can try for 30 days), you can practise this code (german version Nr. 2):
PR test
;* ##### Startdatei ######
SETZE "sprung.x" 0
SETZE "sprung.y" 0
flug
ENDE
PR flug
sprung
tasten
flug
ENDE
PR sprung
SETZE "sprung.x" :sprung.x + (SIN KURS)/2
SETZE "sprung.y" :sprung.y + (COS KURS)/2
AUFXY (XKO + :sprung.x) (YKO + :sprung.y)
ENDE
PR tasten
SETZE "t" TASTE
WENN :t = "d" DANN LI 30
WENN :t = "e" DANN DZ "Abbruch!" AUSSTIEG
WENN :t = "f" DANN RE 30
WENN :t = "h" DANN sprung
tasten
ENDE
OK?
Greetings. Michael Kraus
Two additions to my post of yesterday, concerning LOGO-procedures with dynaturtle:
1.) the key "d" is NUM 4
the key "e" is NUM 5
the key "f" is NUM 6
the key "h" is NUM 8
2.) After hitting "e" = NUM 5 to stop the recursive procedures, you have also to click the exit-button. - I have tried to find out why, but I have no idea.
Michael Kraus