Math-related jokes

 

A mathematical tragedy: two parallel lines fall in love.

Q: What’s green and really far away?
A: The lime at infinity.

Q: What’s a polar bear?
A: A rectangular bear after a coordinate transform.

Q: Why did the vector cross the road?
A: It wanted to be normal.

Q: Why shouldn’t you argue with a decimal?
A: Decimals always have a point.

A girl to her mathematician boyfriend:
– Let’s do something that is forbidden tonight.
– Divide by zero?

-How can you distinguish a mathematician from a physicist?
-Ask for an antonym for the word parallel.
-And?
-A mathematician will answer perpendicular, and a physicist serial.

Q: Why is 6 afraid of 7?
A: Because 7 8 9

Q: What does the zero say to the the eight?
A: Nice belt!

-Some bike thief managed to open my combination lock. How could they possibly guess that the combo was the year of the canonization of Saint Dominic by Pope Gregory IX at Rieti, Italy?
-What year was that?
-1234.

-Mike, here are 10 chocolates. Give half of them to your brother.
-OK. I’ll give him three chocolates.
-You can’t count?
-I can, but he can’t.

– Do you know a statistics joke?
– Probably, but it’s mean!

A traffic policeman stops a car:
– You’re going 70 in a 35 miles-per-hour zone.
– But there are two of us!

A mathematician’s son:
– Dad, how do I write the number 8?
– That’s easy: rotate the infinity symbol by pi over 2.

Archimedes, Pascal and Newton play hide and seek. Archimedes is the seeker. Pascal hides, but Newton draws a 1-meter square around himself. Archimedes opens his eyes and shouts:
– I see Newton!
– Oh, no! One newton per square meter is the pascal.

There are two types of people: those who know nothing about fractals and those who think that there are two types of people: those who know nothing about fractals and those who think that there are two types people…

A Roman walks into a bar, holds up two fingers, and says, “Five beers, please.”

A poet, a priest, and a mathematician are discussing whether it’s better to have a spouse or a lover.
The poet argues that it’s better to have a lover because love should be free and spontaneous.
The priest argues that it’s better to have a spouse because love should be sanctified by God.
The mathematician says, “I think it’s better to have both. That way, when each of them thinks you’re with the other, you can sit down and do some mathematics.”

– We’ll split the money 50-50.
– I want 70.
– Okay, 70-70!

– If a black cat crosses in front of you and then crosses back, what does it mean? Is your bad luck doubled or canceled?
– Is this a scalar or a vector cat?
– Huh?
– A scalar cat doubles and a vector cat cancels.

higherpowers

Sources

[1] Tanya Khovanova’s Math Blog

[2] Zev Chonoles

Advertisements

Can Machines Think?

alan_turing
Alan Turing

Alan Turing in his famous “Computing Machinery and Intelligence” (published in 1950) initially addresses the question “can machine think?” but later he forms the problem in terms of a game, which is called the “Imitation Game”. The reason for that approach is to avoid the ambiguity between the concepts “machine” and “think”.

The “Imitation Game” defines that three players are allowed to play: a man (A), a woman (B) and an interrogator (C) who may be of either sex. The object of the game is the determination of the sex between A and B by C. The interrogator is based in a closed room and he/she is allowed to put questions to A and B and give the conclusive answer in the form of determination of their gender identity. The point is for C to think and then deduce the answer from the way his questions about the physique of the persons in question are answered. A and B voices since they reveal their gender identity must be “transferred” into a typewritten form. Therefore, if the game requires a considerable thinking process and also if the A and B are replaced with a machine, the question that must be asked is if C is able to distinguish between the machine and the persons. Hence, Turing initial question “can machines think” after the replacement of the “Imitation Game” concludes to the determination criterion which states that a machine can think arises from the interrogator’s inability to distinguish the difference between the machine and the person.

The argument “machines can never make mistakes”.

Turing avoids to answer the simple question whether or not machine can make mistakes. He adopts “a more sympathetic attitude” and he introduces the distinction between errors of functioning and errors of conclusion. He mentions that the question whether or not machines can make mistakes depends on a confusion between those two kinds of mistakes. Firstly, he states that errors of functioning are based on an electrical or mechanical fault, which causes the machine to operate not the way that it was designed to. Considering a philosophical perspective and assuming that those errors could not be arise because of the mathematical fiction of those “abstract machines” then “machines can never make mistakes”. However, he emphasizes that in case they are physical objects (as practical machines are) and therefore not theoretical discussions then those errors are inevitable in case of mechanical or electrical faults. Secondly, Turing talks about errors of conclusion that “can only arise when some meaning is attached to the output signals of the machine”. An example of this kind of errors is having an output “30” in response to the input “15+16”. Humans make many errors of this second class and Turing points out that machines could also make errors of conclusion. If a machine is programmed to do for example mathematical operations in the way that people actually solve mathematical operations then the machine might as humans, answer to some mathematical operations with an incorrect result.

C++ Quiz no.4

Fix the following code so the B is destroyed properly:

struct A {};
struct B: A {};

int main()
{
   A * p = new B;
   delete p;
}

————————————

Answer to C++ Quiz no.3

#include <iostream>
class example
{
 public:
   example& operator+(const example& obj1);
};

example &example::operator+(const example& obj2)
{
 return *this; //Every object in C++ has access to its own address through an important pointer called this pointer.
}

int main(void)
{
  example a, b;
  example* c;
  c = &(a + b);
  //std::cout<< &c <<" "<<"\n";
}

C++ Quiz no.3

Write minimal implementation of A and B such that the following expression to be legal:

A x;
B y;
y = & ( x + 1);

————————————

Answer to C++ Quiz no.2

#include <iostream>
using std::cout;

struct Row
{
 int a[3];
 Row(int x) { a[0] = x; a[1] = ++x; a[2] = ++x; }
 int * begin() { return a; } // a == &a[0]
 int * end() { return a + 3; } // a + 3 == &a[3]
};

struct Matrix
{
 Row r[3] = { 1, 4, 7 };
 Row * begin() { return r; }
 Row * end() { return r + 3; }
};

int main()
{
 Matrix m;
 for ( auto r : m ) //in pre-C++11 == for ( Row * r = m.begin(); r!= m.end(); ++r) // inside the body we need to use *r which is type Row
 {
  for ( auto e : r )
    cout << ' ' << e;
  cout << '\n';
 }
}

C++ Quiz no.2

Implement a Matrix class for which

Matrix m;
for( auto r : m )
{
   for( auto e : r )
      cout << ' ' << e;
   cout << '\n';
}

prints

1 2 3
4 5 6
7 8 9

————————————

Answer to C++ Quiz no.1

There is an invalid conversion from [int** -> const int**] although [int* -> const int*] is a legal conversion. Trying to increase constness with [int** -> const int**], we introduce a gap between pointer q and object c (i.e. a pointer p between our pointer q and the object c). In order to cover this hole, the following two efforts introduce errors for different reasons (included as comments):

int main ()
{
  const int c = 1;
  const int * p;
  const int ** q = &p; 
  *q = &c; 
  *p = 10; // error: assignment of read-only location (*p) i.e. no way to deceive const restrictions (without explicit conversions).
}
int main ()
{
  const int c = 1;
  int * p;
  const int * const* q = &p;
  *q = &c; // error: assignment of read-only location (*q) i.e. (*q) is a const variable and cannot be modified.
  *p = 10;
}

Shell Script for Building a Complete GCC Cross-Compiler

This article illustrates how to install on a Debian-based distribution the complete toolchain to cross compile in a shell-script automated way. A short intro In several cases it happens that the platform you’re developing on and the computer you’re developing for don’t match. For instance, you may want to develop an application for ARM or PowerPC on your x86 computer. In order to do that, it is necessary to build a cross-compiler that will enable you to build applications for other targets on your machine i.e. a compiler that knows how to write machine code for your target platform.  The required process to install the compiler is provided in the following bash script: a script to download packages for, configure, build and install a GCC cross-compiler from scratch.

#!/bin/sh

#-------------------------------------------------------------------------------------------
# Author: Charalambos Konstantinou 
# W: http://harryskon.com/
# Github: https://github.com/harryskon/cross_compilers
# 
# This script will download packages for, configure, build and install a GCC cross-compiler.
# 
# Published also @ http://w3-tutorials.com/item/29-shell-script-for-building-a-complete-gcc-cross-compiler
#-------------------------------------------------------------------------------------------

# See http://gcc.gnu.org/install/specific.html for more examples on host and target specifics
# For our case: HOST="x86_64-pc-linux-gnu"

# Choose your target: https://gcc.gnu.org/install/specific.html
TARGET="powerpc-eabisim"
# Tried parallel build with e.g. MAKEOPTS="-j 2" but didn't work thus leave it empty
MAKEOPTS=""

abort() {
 echo "**************************************************************"
 echo error: $@
 echo "**************************************************************"
 exit 1
}
success() {
 echo "***************************************************************"
 echo success: $@
 echo "***************************************************************"
 echo "\a"
 sleep 3s
}

# GCC should not be build in the source directory: why? http://gcc.gnu.org/ml/gcc-bugs/2007-06/msg00234.html
prepare_clean_build() {
 rm -rf $BUILDDIR
 mkdir $BUILDDIR
 cd $BUILDDIR
}

CROSSDIR=$HOME/ppc
BUILDDIR=$CROSSDIR/build
SOURCEDIR=$CROSSDIR/sources
DOWNLOADS=$CROSSDIR/downloads
INSTDIR=$CROSSDIR/cross-gcc

export PATH="$INSTDIR/bin:$PATH"

test -d $CROSSDIR || mkdir $CROSSDIR
test -d $DOWNLOADS || mkdir $DOWNLOADS
test -d $SOURCEDIR || mkdir $SOURCEDIR
test -d $INSTDIR && rm -rf $INSTDIR; mkdir $INSTDIR

# 1. Install binutils (containing the assembler and the linker)
 BINUTILS=binutils-2.25
 cd $DOWNLOADS
 test -f $BINUTILS.tar.gz || wget http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.gz
 cd $SOURCEDIR
 test -d $BINUTILS || tar -xzf $DOWNLOADS/$BINUTILS.tar.gz
 prepare_clean_build
 $SOURCEDIR/$BINUTILS/configure --prefix=$INSTDIR --target=$TARGET --disable-nls --disable-werror
 make $MAKEOPTS all install || abort "building of $BINUTILS failed"
 success "$BINUTILS successfully installed to $INSTDIR"

# 2. Install GMP (GNU multiple precision arithmetic library)
 GMP=gmp-4.3.2
 cd $DOWNLOADS
 test -f $GMP.tar.bz2 || wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2
 cd $SOURCEDIR
 test -d $GMP || tar -xjf $DOWNLOADS/$GMP.tar.bz2
 prepare_clean_build
 $SOURCEDIR/$GMP/configure --disable-shared --enable-static --prefix=$INSTDIR
 make $MAKEOPTS all install || abort "building of $GMP failed"
 success "$GMP successfully installed to $INSTDIR"

# 3. Install MPFR (library for multiple-precision floating-point computations)
 MPFR=mpfr-2.4.2
 cd $DOWNLOADS
 test -f $MPFR.tar.bz2 || wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPFR.tar.bz2
 cd $SOURCEDIR
 test -d $MPFR || tar -xjf $DOWNLOADS/$MPFR.tar.bz2
 prepare_clean_build
 $SOURCEDIR/$MPFR/configure --disable-shared --enable-static --prefix=$INSTDIR --with-gmp=$INSTDIR
 make $MAKEOPTS all install || abort "building of $MPFR failed"
 success "$MPFR successfully installed to $INSTDIR"

# 4. Install MPC (library for the arithmetic of complex numbers with arbitrarily high precision)
 MPC=mpc-0.8.1
 cd $DOWNLOADS
 test -f $MPC.tar.gz || wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPC.tar.gz
 cd $SOURCEDIR
 test -d $MPC || tar -xzf $DOWNLOADS/$MPC.tar.gz
 prepare_clean_build
 $SOURCEDIR/$MPC/configure --disable-shared --enable-static --prefix=$INSTDIR --with-gmp=$INSTDIR --with-mpfr=$INSTDIR
 make $MAKEOPTS all install || abort "building of $MPC failed"
 success "$MPC successfully installed to $INSTDIR"

# 5. Install GCC (version 4 and above need GMP, MPFR and MPC development libraries to be installed)
 GCC=gcc-4.8.4
 cd $DOWNLOADS
 test -f $GCC.tar.bz2 || wget http://mirrors.kernel.org/gnu/gcc/$GCC/$GCC.tar.bz2
 cd $SOURCEDIR
 test -d $GCC || tar -xjf $DOWNLOADS/$GCC.tar.bz2
 prepare_clean_build
 $SOURCEDIR/$GCC/configure --prefix=$INSTDIR --target=$TARGET --disable-nls --disable-libssp --enable-languages="c" --without-headers --with-newlib --with-gmp=$INSTDIR --with-mpfr=$INSTDIR --with-mpc=$INSTDIR
 make $MAKEOPTS all install || abort "building of $GCC failed"
 success "$GCC successfully installed to $INSTDIR"

# 6. Install newlib (library implementation intended for use on embedded systems)
 NEWLIB=newlib-2.2.0
 cd $DOWNLOADS
 test -f $NEWLIB.tar.gz || wget ftp://sources.redhat.com/pub/newlib/$NEWLIB.tar.gz
 cd $SOURCEDIR
 test -d $NEWLIB || tar -xzf $DOWNLOADS/$NEWLIB.tar.gz
 prepare_clean_build
 $SOURCEDIR/$NEWLIB/configure --prefix=$INSTDIR --target=$TARGET --disable-nls
 make $MAKEOPTS all install || abort "building of $NEWLIB failed"
 success "$NEWLIB successfully installed to $INSTDIR"


echo "Use cross-compiler by typing:"
echo "$INSTDIR/bin/$TARGET-gcc sourcefile.c"
echo "For more options type: $INSTDIR/bin/$TARGET-gcc --help"
echo "For example: include the -msim option to choose the specific (ppc) machine type"

C++ Quiz no.1

The next posts will include C++ related stuff due to the current Mazonka-based mentoring. Here is a simple quiz to start with:

Is there something wrong with the following code? If yes, can you explain why?

{
 const int c = 1;
 int * p;
 const int ** q = &p; // q points to p
 *q = &c; // now p points to c
 *p = 10; // modify c !
}

Answer will be provided to the next post.