2020-08-24 MATH 3600

464 days ago by calkin

x=3 
       
type(x) 
       
<type 'sage.rings.integer.Integer'>
<type 'sage.rings.integer.Integer'>
 
       
x.coprime_integers(10) 
       
[1, 2, 4, 5, 7, 8]
[1, 2, 4, 5, 7, 8]
type(y) 
       
Traceback (click to the left of this block for traceback)
...
NameError: name 'y' is not defined
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_12.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dHlwZSh5KQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpHmvGXe/___code___.py", line 2, in <module>
    exec compile(u'type(y)
  File "", line 1, in <module>
    
NameError: name 'y' is not defined
var('y') 
       
y
y
type(y) 
       
<type 'sage.symbolic.expression.Expression'>
<type 'sage.symbolic.expression.Expression'>
y.binomial(4) 
       
1/24*(y - 1)*(y - 2)*(y - 3)*y
1/24*(y - 1)*(y - 2)*(y - 3)*y
print(x) 
       
3
3
print(y) 
       
y
y
print(z) 
       
Traceback (click to the left of this block for traceback)
...
NameError: name 'z' is not defined
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_24.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cHJpbnQoeik="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmp7lUBHV/___code___.py", line 2, in <module>
    exec compile(u'print(z)
  File "", line 1, in <module>
    
NameError: name 'z' is not defined

How to determine the number of digits in a number $n$.

We could compute len(n.digits()).

We could compute $\lceil \log_{10}(n+1) \rceil=\lceil \log_{e}(n+1)/\log_{e}(10) \rceil $.

n=1234567890 
       
digit_list= 
       
Traceback (click to the left of this block for traceback)
...
SyntaxError: invalid syntax
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_29.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZGlnaXRfbGlzdD0="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpG4cBkO/___code___.py", line 2
    digit_list=
              ^
SyntaxError: invalid syntax
digit_list=n.digits() 
       
len(digit_list) 
       
10
10
n=123456789123456789 print(len(n.digits())) print("Success!") 
       
18
Success!
18
Success!
num_digits=log(n)/log(10) 
       
num_digits.n() 
       
17.0915149776036
17.0915149776036