Wikipedia:Reference desk/Mathematics

From Wikipedia, the free encyclopedia
Jump to: navigation, search

The Wikipedia Reference Desk covering the topic of mathematics.

Welcome to the mathematics reference desk.
Shortcut:
Want a faster answer?

Main page: Help searching Wikipedia

How can I get my question answered?

  • Provide a short header that gives the general topic of the question.
  • Type ~~~~ (four tildes) at the end – this signs and dates your contribution so we know who wrote what and when.
  • Post your question to only one desk.
  • Don't post personal contact information – it will be removed. We'll answer here within a few days.
  • Note:
    • We don't answer (and may remove) questions that require medical diagnosis or legal advice.
    • We don't answer requests for opinions, predictions or debate.
    • We don't do your homework for you, though we’ll help you past the stuck point.


How do I answer a question?

Main page: Wikipedia:Reference desk/Guidelines

  • The best answers address the question directly, and back up facts with wikilinks and links to sources. Do not edit others' comments and do not give any medical or legal advice.
 
See also:
Help desk
Village pump
Help manual


May 19[edit]

Probability question[edit]

According to Bayes theorem P(B|A)=P(A|B)*P(B)/P(A). But using the same theory, I can't work out why P(B'|A')=P(B')+P(A|B')*P(B')/P(A'). There is obviously another rule which has been used here but which rule is it? — Preceding unsigned comment added by 94.0.242.23 (talk) 01:33, 19 May 2015 (UTC)

P(B'|A')=P(B')+P(A|B')*P(B')/P(A') is not true in general i.e.without additional constraints on the events. To see that choose A=B'c (complement of B'), in which case P(A|B') = 0 and your relation reduces to P(B'|A')=P(B'), which obviously doesn't hold in general. Abecedare (talk) 02:13, 19 May 2015 (UTC)

May 21[edit]

How To Convert Decimal To Binary?[edit]

Hello. I Am trying ton convert a Decimal Number (say, 16) to Binary. The article on binary numbers says, "To convert from a base-10 integer numeral to its base-2 (binary) equivalent, the number is divided by two, and the remainder is the least-significant bit. The (integer) result is again divided by two, its remainder is the next least significant bit. This process repeats until the quotient becomes zero." I don't understand how to do this. Could some one explain step by step how to convert the number 16 to binary? The correct binary representation of 16 is 10000. Thanks in advance —SGA314 (talk) 15:10, 21 May 2015 (UTC)

16 divided by 2 is 8 with remainder 0.
8 divided by 2 is 4 with remainder 0.
4 divided by 2 is 2 with remainder 0.
2 divided by 2 is 1 with remainder 0.
1 divided by 2 is 0 with remainder 1.
So the digits of the binary representation of 16 *from right (least significant) to left* are 0,0,0,0 and 1. Reversing this to write the binary representation from left to right we get 10000. Gandalf61 (talk) 15:21, 21 May 2015 (UTC)
The method I use is to find the largest power of 2 less than or equal to the number, in this case 16, then subtract that:
16 - 1 sixteen = 0
I then continue with each smaller power of 2:
0 - 0 eights = 0
0 - 0 fours  = 0
0 - 0 twos   = 0
0 - 0 ones   = 0
That gives me 10000. I find it easy to use my fingers to record the binary digits, allowing for binary numbers up to 1111111111, or 1023 in decimal. StuRat (talk) 15:32, 21 May 2015 (UTC)
I tend to show people that I don't like the fact that I can count to 132. :)Naraht (talk) 16:17, 21 May 2015 (UTC)
Ok Gandalf61, I understand. But how would I do this using a calculator, considering the fact that a calculator will divide into fractions and have no remainder(as in the case of dividing 1 by 2 which yields 0.5). My reason for asking this is because I am writing a program that can convert a decimal number to a Binary number and the reverse. Oh and i am using Visual Basic For Applications as my programming language. —SGA314 (talk) 18:24, 21 May 2015 (UTC)
Programming languages normally provide a modulo operator that gives you the remainder that division would produce. According to the article I linked, in Visual Basic that operator is named Mod, and this page from Microsoft tells you how to use it. --174.88.135.200 (talk) 19:11, 21 May 2015 (UTC)
Cool Thanks! problem solved. Now I can convert decimal numbers to and fro binary! Thanks for your help everyone. —SGA314 (talk) 19:15, 21 May 2015 (UTC)
Here is the final VB script i came up with. if you have any suggestions to improve/simplify it let me know. Output from this script is 110001.
Sub ConvertDecToBin()
    'Decimal To Binary Conversion Script.
    'Written By SGA314
    Dim Num, Remain, Times, i, Result As Double
    Dim BinNum As String
    Num = 49 'Insert number to convert to binary here.
    Times = Num / 2
    Result = Num
    While Not Result = 0
        Remain = Result Mod 2
        BinNum = BinNum + CStr(Remain)
        Result = Int(Result / 2)
    Wend
    Debug.Print StrReverse(BinNum)
End Sub

SGA314 (talk) 20:15, 21 May 2015 (UTC)

I don't have time to check your code, but you may be interested in seeing how this example works [1]. SemanticMantis (talk) 20:24, 21 May 2015 (UTC)
It's been a while since I've written in VB, and it was mostly in normal VB rather than VBA, but:
  1. Not sure how you intend to use this, but hardcoding the value to convert makes little sense. It would be more meaningful to have the value given as a parameter. It might also make more sense to have it a Function instead of a Sub, and print the result in the calling sub.
  2. You have values you're defining but never using.
  3. The code isn't equipped to handle fractions, so unless you want to modify it to do that, it would make more sense to work with ints rather than doubles.
  4. The \ operator represents integer division in VB, so you can replace Int(Result/2) by Result\2.
So you can use the following code instead:
Function ConvertDecToBin(ByVal Num As Int) As String
    'Decimal To Binary Conversion Script.
    'Written By SGA314
    Dim Remain As Int
    Dim BinNum As String
    While Not Num = 0
        Remain = Num Mod 2
        BinNum = BinNum + CStr(Remain)
        Num = Num \ 2
    Wend
    Return BinNum
End Function
-- Meni Rosenfeld (talk) 21:00, 21 May 2015 (UTC)
Many languages will also contain a built-in method of converting, sometimes as simple as assigning a decimal value to a binary variable. Of course, coding it yourself is also useful for educational purposes. StuRat (talk) 03:40, 22 May 2015 (UTC)

In J (programming language) you write

   #:16
1 0 0 0 0

Bo Jacoby (talk) 06:12, 22 May 2015 (UTC).

Oops. Your right Meni Rosenfeld, I forgot to remove the Times and i Variables. These were variables that I used for a different way of converting (I was using a For Loop). And as for using Doubles instead of Integers, I am using doubles because they can hold values much higher than 32,768(I can store numbers that go into the Billions range with Doubles) and if I try to store any value higher than 32,768 in an Integer value, I will get an Overflow error. Good idea by the way on making it a Function that returns a String. I coded this as a macro in Microsoft Word, so I was going replace the hardcoded number with Selection (Selection is how you get the currently selected text in Word) instead. As for the Int(Result / 2) line, I don't know whats up with this. I don't know if it isn't necessary in VB, but in VBA if I don't include this the program will spit out
000000000000000000000000000000000000000000000000000...(a huge amount of zeros that take up way to much space on the page)1010001, instead of 110001. But if i use your version of the script(with a few mods to make it compatible with VBA) it will work just fine. I have to say, I like how you simplified the code and used 1 less variable than I used. I guess VB is a lot different from VBA, because in VBA for Word, I cant put a variable after the Return statement (I utterly disgust this). Instead I have to do this
Function A() As String
and in order to return something I have to set a variable that has the same name as the function (no I don't have to define it) like so
A = "Whatever"
this will return the String "Whatever."
That would be nice StuRat. But I don't think VBA has a function like that but that sure would be cool if it did. I thank you very much for your feed back! Here is my simplified version of the script(special thanks to Meni Rosenfeld for this)
Function ConvertDecToBin(ByVal Num As Double) As String
    'Decimal To Binary Conversion Script.
    'Written By SGA314
    'Improvments By Meni Rosenfeld
    Dim Remain As Double
    Dim BinNum As String
    While Not Num = 0
        Remain = Num Mod 2
        BinNum = BinNum + CStr(Remain)
        Num = Num \ 2
    Wend
    ConvertDecToBin = StrReverse(BinNum)
End Function

Thanks for your help everyone! I now understand how to convert a decimal number to a binary number and do the reverse. —SGA314 (talk) 13:30, 22 May 2015 (UTC)

I think the differences are less between VB and VBA, and more between modern vb.net (on which one can easily find documentation), and classic VB <= 6 (on which I think VBA is based). This goes for how to return values from a function, and also for integer data types. In classic VB, Integer refers to a 16-bit signed int, which can go up to 32767; But you also have Long which is 32-bit and goes up to ~4 billion (which might be good for you instead of Double). In the modern version, Integer is 32-bit, and Long is 64-bit and gives you much higher precision than Double. -- Meni Rosenfeld (talk) 14:53, 22 May 2015 (UTC)
Huh Good to know. Thanks. —SGA314 (talk) 15:56, 22 May 2015 (UTC)
Note, this is also something that you may consider using a recursive program on. Something like (Visual basic was a while ago)
Function RecursiveConvertDecToBin(ByVal Num As Double) As String
    If Num > 0 Then
        RecursiveConvertDectoBin = RecursiveConvertDectoBin(Num\2)&CStr(Num Mod 2)
    Else
        RecursiveConvertDectoBin = ""
    End If
End Function
Naraht (talk) 22:35, 22 May 2015 (UTC)

May 22[edit]

Generating function of the central binomial coefficients[edit]

The generating function for the central binomial coefficients is f(z) = (1-4z)-1/2 which follows by expanding f using either the binomial theorem or Taylor's series. The OEIS page (OEISA000984) mentions that if the sequence is convolved with itself you get powers of 4. In terms of the generating functions this amounts to ((1-4z)-1/2)2 = (1-4z)-1. The combinatorial interpretation of this is that the number of ordered pairs of strings a's and b's, having total length 2n, and with both strings having equal numbers of a's and b's, is equal to the number of strings of a's and b's having length 2n. For example, for n=2 this says

#{aabb|, abab|, abba|, baab|, baba|, bbaa|, ab|ab, ab|ba, ba|ab, ba|ba, |aabb, |abab, |abba, |baab, |baba, |bbaa}
=
#{aaaa, aaab, aaba, aabb, abaa, abab, abba, abbb, baaa, baab, baba, babb, bbaa, bbab, bbba, bbbb}.

Is there a combinatorial proof of this? In other words, is there a one-one correspondence between these two sets that works for all n? --RDBury (talk) 23:35, 22 May 2015 (UTC)