text:
# Running Interactive Shell¶

We will be using python 2.7 in this class.

Check if you have python installed by running the following in your terminal.

python --version

It is useful to install jupyter notebooks you can do so by running

pip install jupyter

Note: Make sure you are using the correct pip command, if you have multiple versions of python installed on your system!

# Data Types and Variables¶

Python is a dynamically-typed language.

• There is no explicit is no explicit way of declaring the type of a variable
i = 10 # int
j = 10.123 # float
a = "A" # str
b = [1, 2, 3] # list

Note: you can check the type of a variable by using the built-in type function

In [81]:
i = 20
type(i)

Out[81]:
int

# Operators¶

The usual operators are used in python with few you might not have seen before, if you c/c++ background.

• + : addition
• - : subtraction
• * : multiplication
• % : modulo
• / : division
• //: truncation division
• ** : exponentiation

# Logical Operators¶

• ~ : bitwise negation
• or : logical or
• and : logical and
• not : logical not
• <, <=, >, >=, !=, ==
• |, &, ^ : bitwise or, and, xor
• in : element in (a list, tupple, dictionary..)
• <<, >> : left shift and right shift

# If/Else Block¶

It's useful to be able to check whether a particular statement is True/False prior to executing a code block.

The if else block in python

if (True):
print("if")
elif (statement):
print("elif")
else:
print("else")

Note: statements used in paranthesis must be boolean statements i.e. result in either a True or False value.

# For/While Loop¶

for i in range(n):
#code goes here
#iterate n times.

range(start, stop, step) function generates a list of numbers, which is used to iterate over in loops, starting at start and ending with stop - 1 using step increments.

Say we want to add the first 100 integers, we can do this using a for loop.

In [82]:
cum_sum = 0
for i in range(101):
cum_sum += i
print(cum_sum)

5050

This is equivalent to the following while loop

In [83]:
cum_sum = 0
i = 0
while(i < 100):
i += 1
cum_sum += i
print(cum_sum)

5050

# Compute Fibonnaci Sequence Using a Loop¶

In [84]:
n = 11
old, new = 0, 1
for i in range(n - 3):
t = new
new = old + new
old = t

print("fib_" + str(n - 2) + ": " + str(old) + " fib_" + str(n - 1) + ": " + str(new))

fib_9: 21 fib_10: 34

# Lists/Tuples/Dicts¶

We will be dealing with different data structures, and those are:

• Lists : mutable list
• Tuples : non-mutable list
• Dicts : mutable list of <key, value> pairs

Mutability means the data structure can be modified after creation.

## Lists¶

You can create lists using brackets a = [1, 2].

In [85]:
a = [1, 2, 3] # list with 3 elements
b = [10] * 10; # list with 100 elements all of which are 10.

print('a = ', a)
print('b = ', b)

a =  [1, 2, 3]
b =  [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]

Indexes in python start from 0. You can index through a list using the indexing operator [] for example a[1], will index the 2nd element 2.

You can get the length of a list by using the len function.

In [86]:
len(a)

Out[86]:
3

It is quite common to run through a list to check if a particular value is present. Python makes it is easy by providing the in operator. It checks if a particular value is present in a list. You can also use the not in which checks if it is not present in the list.

In [87]:
a = [1, 2, 3]
1 in a

Out[87]:
True
In [88]:
10 not in a

Out[88]:
True

### List Slicing¶

Python lists support slice indexing syntax. If you're not familiar with slice indexing it's simple...

print(a[start:end])

Will print elements of array a from $[start, end)$ exclusive (i.e. end will not be included in the set of indexes that will be returned).

Either start or end can be left out, for example

print(a[:end]) # will print from index 0 to end exclusive
print(a[start:]) # will print from index start to end of list

In general when slicing an array you can use set start, end, step, where

• start: starting index to begin slicing
• end: last index at which array will be sliced at
• step: increments from start index to end index
a[start:end:step]

In [89]:
a = 'hello world'
print(a[0:3])  # print the first 3 characters
print(a[0:-5]) # print everything besides the last 5 characters (note the -5 used as the end value)
print(a[::-1]) # start from index 0 to end and take steps of -1
# i.e. the slices will be end - 1, end - 2, .., 0
# which will reverse the string; in one line!

hel
hello
dlrow olleh

### List Comprehension¶

Say we want a list with all even numbers between 0 to 101. This can be written in one line using list comprehension as follows:

zero_to_101 = [i for i in range(101) if i % 2 == 0]
print(zero_to_101)

If you look at the way mathematicians would write out a set using math notation, you would see that there are quite a bit of similarity between list comprehension and the mathematical notation.

$$S = \{~ x^3 : x\text{ in }[0, 9]~\}$$ $$A = \{3, 6, 9, 12, ..., 300\}$$ $$D = \{ x~ | ~x ~\text{ in } A \text{ and } ~x \text{ in } S \}$$

The above sets can be converted into list comprehension in one line of code

$$S = \{~ x^3 : x\text{ in }[0, 9]~\}$$

In [90]:
S = [x ** 3 for x in range(0, 10)]
S

Out[90]:
[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]

$$A = \{3, 6, 9, 12, ..., 300\}$$

In [91]:
A = [3 * i for i in range(0, 301)]
first_4_elements = str(A[:4]).strip(']')
last_4_elements =  str(A[-4:]).strip('[')
print(first_4_elements, " ,..., ", last_4_elements)

[0, 3, 6, 9  ,...,  891, 894, 897, 900]

$$D = \{ x~ | ~x ~\text{ in } A \text{ and } ~x \text{ in } S \}$$

In [92]:
D = [x for x in S if x in A]
print(D)

[0, 27, 216, 729]

list comprehensions are useful one lines if you want to create masks, set of indexes, etc..

## Somethings to keep in mind¶

When working with lists you might find yourself the need to create a copy or extend a an existing one.

Simply assigning an array to another variable does not copy the content, it just copies a reference to the other variable, so you end up with two variables pointing to the same list.

a = [1, 2, 3]
b = a # does not create copy

To create a copy you can either call the list() built-in function or slice the array

b = a[:]
#  OR
b = list(a)

There are different ways of appending/extending a list in python.

• append
• extend
• + operator

### extend¶

extend method appends elements to the end of a list from an iterable list , so for example a.extend([1, 2]) will add elements, 1, 2 to list a like so [1, 2, 3, 1, 2]

In [93]:
a = [1, 2, 3]
a.extend([1, 2])
a

Out[93]:
[1, 2, 3, 1, 2]

note: An iterator is a stream of data. An iterable is an object that has an __iter__ method implemented that returns an iterator. Or it has the __getitem__ method implemented that given an index it returns an item.

### append¶

Append is different from extend in that it appends the data to the end of the list.

a.append([1, 2]) # a will become [1, 2, 3, [1, 2]]

In [94]:
a = [1, 2, 3]
a.append([1, 2])
a

Out[94]:
[1, 2, 3, [1, 2]]

### + operator overloaded¶

The plus + operator is semantically similar to extend, i.e. when you're extending a list with another object that object has to be iterable.

There is a difference if you were to use + or += when mutating a list. In the first case it will extend the array and create a new copy, where as the second case will extend the array in place.

a_list = a_list + your_list #will make a new copy

a_list += your_list #will extend a_list in place

In [95]:
a = [1, 2, 3]
b = [3, 4, 5]
id_before = id(a)
a = a + b
id_after = id(a)
print(id_before)
print(a)
print(id_after)

140191917476296
[1, 2, 3, 3, 4, 5]
140191917247304

### Tuples¶

Tuples are similar to lists, but they are not mutable i.e. once a tuple has been created you cannot append more data to it or change the data.

tupple = ("hello", "my", "name")
tupple[0]
'hello'

#### Why use tuples instead of lists?¶

• it protects against accidental change. If you know your list shouldn't change then declare it as a tupple.
• they are also faster than lists.

### Dictionaries¶

Like lists dictionaries are mutable data structure. They can grow and shrink. The difference is in how elements are accessed. In dictionaries elements are accessed by using keys, whereas in lists we index through it using integer values.

Dictionaries in python are implemented as hash tables, so finding a particular value is fast!

In [96]:
full_name = {} # empty dictionary
full_name["First Name"] = "Sajad"
full_name["Last Name"]  = "Darabi"

print(full_name)

{'First Name': 'Sajad', 'Last Name': 'Darabi'}

We could have initialized the full_name dictionary in one line as well

full_name = {"First Name": "Sajad", "Last Name": "Darabi"}

We can access individual elements by using the corresponding key, for example full_name["First Name"]

# Passing Parameters¶

### Pass by reference¶

By default in python when passing a parameter to a function, it is passed by reference. Take a look at the function below

In [97]:
def passbyreference(x):
print(x, id(x))
x = 20
print(x, id(x))

x = 10
print(x, id(x))
passbyreference(x)

10 140192660368096
10 140192660368096
20 140192660368416

We declare a variable x, and the id function returns a unique integer assigned to that variable. (note: the ids might be different if you run it on your own computer!)

# Side effects¶

A function produces a side effect if it modifies the callers environment in any way in addition to returning a value. Typical side effects are mutating the data, printing to the screen, etc..

In python if a function uses the extending in place operator += on a list, it will mutate the original list.

In [98]:
def mutateList(l):
print(l)
l += [2, 1]
l = [4, 3]
mutateList(l)
print(l)

[4, 3]
[4, 3, 2, 1]

The function has modified the content of the original list. To avoid this you can pass the list by creating a new copy: mutateList(l[:]).

In [99]:
def mutateList(l):
print(l)
l += [2, 1]
l = [4, 3]
mutateList(l[:])
print(l)

[4, 3]
[4, 3]

The function hasn't modified the list.

# Using External Modules¶

We can use modules written by others by importing them into our python environment

Let's use the module numpy this module is often used for processing large listst and matrices data structures.

Make sure you have numpy installed, if you don't run pip install numpy in terminal. (you might have to use pip3 depending on how you have python setup on your computer)

In [100]:
import numpy as np
np.random.randn(5, 1) # creates a column vector with dimension 5 and assigns random values.

Out[100]:
array([[-0.47876023],
[ 0.89474721],
[ 2.05896199],
[ 0.57109483],
[-0.35903142]])

format: plain


text:
create a 3-D complex plot - Maple Help

Home : Support : Online Help : Graphics : Packages : plots : plots/complexplot3d

plots[complexplot3d] - create a 3-D complex plot

 Calling Sequence complexplot3d([expr1, expr2], x=a..b, y=c..d) complexplot3d([f1, f2],  a.. b,  c.. d) complexplot3d(expr3, z=a + b*I..c + d*I) complexplot3d(f2, a + b*I..c + d*I)

Parameters

 expr1, expr2 - algebraic; expressions in parameters x and y f1, f2 - procedures; functions to be plotted expr3 - algebraic; expression in parameter z a, b, c, d - realcons; endpoints of parameter ranges

Description

 • The four different calling sequences to the complexplot3d function above all define plots in three space for expressions or procedures mapping

${R}^{2}\to {R}^{2}\mathrm{or}C\to C.$

 For 2-D complex plots, see plots/complexplot.
 • For plotting functions from ${R}^{2}$ to ${R}^{2}$ complexplot3d plots the first component while coloring the graphic using the second component.
 • For plotting functions from C to C complexplot3d plots the magnitude of the function while coloring the resulting surface using the argument of the function.
 • The first two calls plot expressions and procedures, respectively, from ${R}^{2}$ to ${R}^{2}$. In the second case f1 and f2 take two arguments and return a real value. The form of the range specifications determine whether an expression or a procedure is to be plotted. The last two calls plot expressions and procedures, respectively, from C to C.
 • The range components a, b, c, and d must evaluate to real constants. Note that operator notation is used in the second and fourth calls, that is, the procedure name is given without parameters specified, and the ranges must be given simply in the form a..b, rather than as an equation.
 • Any additional arguments are interpreted as options as described in the plot3d/options help page.  For example, the option $\mathrm{grid}=\left[m,n\right]$ where m and n are positive integers specifies that the plot is to be constructed on an m by n grid instead of on the default 25 by 25 grid.

Examples

 > $\mathrm{with}\left(\mathrm{plots}\right):$

Plot a complex procedure:

 > $f:=z→\mathrm{sec}\left(z\right)$
 ${f}{:=}{z}{→}{\mathrm{sec}}{}\left({z}\right)$ (1)
 > $\mathrm{complexplot3d}\left(f,-2-2I..2+2I\right)$

Plot an expression from ${R}^{2}$ to ${R}^{2}$, where the plot is of the first component colored by the second component:

 > $\mathrm{complexplot3d}\left(\left[{x}^{2}-{y}^{2},2xy\right],x=-2..2,y=-2..2\right)$

Repeat the previous example using operator form.

 > $\mathrm{f1}:=\left(x,y\right)→{x}^{2}-{y}^{2};$$\mathrm{f2}:=\left(x,y\right)→2xy$
 ${\mathrm{f1}}{:=}\left({x}{,}{y}\right){→}{{x}}^{{2}}{-}{{y}}^{{2}}$
 ${\mathrm{f2}}{:=}\left({x}{,}{y}\right){→}{2}{}{x}{}{y}$ (2)
 > $\mathrm{complexplot3d}\left(\left[\mathrm{f1},\mathrm{f2}\right],-2..2,-2..2\right)$

Plot an image created from Newton's iteration:

 > $f:=z→z-\frac{{z}^{3}-2}{3{z}^{2}}$
 ${f}{:=}{z}{→}{z}{-}\frac{{1}}{{3}}{}\frac{{{z}}^{{3}}{-}{2}}{{{z}}^{{2}}}$ (3)
 > $\mathrm{complexplot3d}\left({f}^{\left(4\right)},-3-3I..3+3I,\mathrm{view}=-4..4,\mathrm{grid}=\left[50,50\right]\right)$

Plot $\left|f\left(z\right)\right|$, where $z=r{ⅇ}^{I\mathrm{\theta }}$ and $f\left(z\right)=\frac{z}{{ⅇ}^{z}-1}$, in cylindrical coordinates, with r ranging from 0 to 10 and theta from 0 to $2\mathrm{\pi }$.

 > g := proc(z) local w; w := Re(z)*exp(Im(z)*I); w/(exp(w)-1) end proc:
 > $\mathrm{changecoords}\left(\mathrm{complexplot3d}\left(g,0..10+2\mathrm{π}I,\mathrm{axes}=\mathrm{boxed}\right),\mathrm{cylindrical}\right)$

The command to create the plot from the Plotting Guide is

 > $\mathrm{complexplot3d}\left(\mathrm{sec}\left(z\right),z=-2-2I..2+2I,\mathrm{grid}=\left[10,10\right]\right)$


text:
# How to partition a set into disjoints subsets each of given size?

The input: Given a set $U=\{1, \ldots, k\}$ called the universe. Let $C=\{S_1, \ldots, S_n\}$ be a collection of subsets of $U$ and let $s_j$ be a nonnegative integer for all $j=1,\ldots,n$ such that $\sum_{j=1}^{n} s_j=k$.

The question: Are there $n$ subsets $A_j$ of $S_j$ (i.e., $A_j\subset S_j$) such that

$$\quad\bigcup\limits_{j=1}^{n}A_j=U,\\ \quad \quad\;\;\;\,\;\;\,A_j \cap A_i = \emptyset, i\neq j,\\ |A_j|=s_j.$$

Is this problem NP-hard?

I was trying to reduce PARTITION to this problem by setting $n=2$ and $k$ an even number and $s_j=k/2$ but the constraints $|A_j|=k/2$ do not help me.

When $s_j = 1$ for all $j$, the problem is the same as deciding whether a bipartite graph has a perfect matching. In the general case, we can solve it using maximum flow.

Set up a flow network with the following components:

• A source $s$, a sink $t$, a vertex $S_j$ for each set, and a vertex $x_i$ for each element in the universe.

• Connect $s$ to each $S_j$ with an edge of capacity $s_j$.

• For each $x_i \in S_j$, connect $S_j$ to $x_i$ with an infinite capacity edge.

• Connect each $x_i$ to $t$ with an edge of capacity $1$.

Now compute the maximum flow. If it equals $|U|$ then the instance has a solution. Moreover, you can extract the solution from a maximum integer flow.

The max flow min cut theorem also gives us a Hall-like criterion: a solution exists if for every set $X$ of elements, $$\sum_{j\colon S_j \cap X \neq \emptyset} s_j \geq |X|.$$ That is, if we sum the "capacities" $s_j$ for all sets $S_j$ that intersect $X$, then we need to get at least $|X|$. This is clearly a necessary condition, and the max flow min cut theorem shows that it is sufficient.


text:
TIL #036 – pandas show_versions

Today I learned how to use the function pandas.show_versions to get system diagnostic information.

What is the pandas function show_versions for?

The function pandas.show_versions is a very useful function when you need to get some information about your system and/or the versions of installed packages that are related to pandas.

If you import pandas into your session and call the function pandas.show_versions, you get something like this:

>>> import pandas
>>> pandas.show_versions()
INSTALLED VERSIONS
------------------
commit           : bb1f651536508cdfef8550f93ace7849b00046ee
python           : 3.9.7.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
Version          : 10.0.22000
machine          : AMD64
processor        : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : English_United States.utf8

pandas           : 1.4.0
numpy            : 1.21.3
pytz             : 2021.3
dateutil         : 2.8.1
pip              : 22.0.4
setuptools       : 57.4.0
Cython           : None
pytest           : 6.2.5
pyxlsb           : None
s3fs             : None
scipy            : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
zstandard        : None

The first section contains information about your machine and the next section contains information about packages that are related to pandas. In particular, the function pandas.show_versions tells you the version of pandas you are running.

Alternatively, you can use the parameter as_json to have the information printed in the JSON format:

>>> pandas.show_versions(as_json=True)
{
"system": {
"commit": "bb1f651536508cdfef8550f93ace7849b00046ee",
"python": "3.9.7.final.0",
"python-bits": 64,
"OS": "Windows",
"OS-release": "10",
"Version": "10.0.22000",
"machine": "AMD64",
"processor": "Intel64 Family 6 Model 158 Stepping 10, GenuineIntel",
"byteorder": "little",
"LC_ALL": null,
"LANG": "en_US.UTF-8",
"LOCALE": {
"language-code": "English_United States",
"encoding": "utf8"
}
},
"dependencies": {
"pandas": "1.4.0",
"numpy": "1.21.3",
"pytz": "2021.3",
"dateutil": "2.8.1",
"pip": "22.0.4",
"tables": null,
"tabulate": null,
"xarray": null,
"xlrd": null,
"xlwt": null,
"zstandard": null
}
}

Alternatively, the parameter as_json accepts a string representing the path of a file where the JSON with this information should be dumped on.

In conclusion, you would typically use the function show_versions if you were doing something like filing a bug report; show_versions isn't the kind of function you will actually use in your data analysis work.

How to check the pandas version?

If you want to check the version of your pandas installation you can use the function pandas.show_versions, but you can also import pandas and then check the dunder attribute __version__:

>>> import pandas
>>> pandas.__version__
'1.4.0'

That's the fastest way because you don't have to read the whole information printed by show_versions.

That's it for now! Stay tuned and I'll see you around!

I hope you learned something new! If you did, consider following the footsteps of the readers who bought me a slice of pizza 🍕. Your small contribution helps me produce this content for free and without spamming you with annoying ads.


text:
# Intuition for the CES consumption index in New-Keynesian DSGE models

I don’t understand, from an intuitive point of view, the CES aggregator in the context of a New Keynsian DSGE model. I understand that the consumption index Ct is the sum of all consumption goods and we conceive of a continuum of goods over the interval (0,1) and, as such, have;

I understand that we are making assumptions here about the imperfect substitutability of goods and that this is what gives firms market power in the monopolistic setting of the DSGE models in question.

What I do not understand is the intuition of how levels of consumption of all different goods maps onto the expression for Ct above. How can we represent this using an integral over a range? I do not understand the intuition, and nowhere seems to provide a decent explanation. I would be very grateful if one of you could possibly explain it to me?

Heuristically, you can think of the integral as just a sum:

$$\bar{C} = \left( \sum_{i=1}^n C_i^{1-\frac{1}{\epsilon}} \right)^{\frac{\epsilon}{\epsilon - 1}}$$

where $\bar{C}$ is an index of aggregate consumption, and utility is given by $u \left( \bar{C} \right)$.

It's easy to check that the marginal rate of substitution between goods $j$ and $k$ is given by

$$\text{MRS}_{jk} = \left( \frac{C_j}{C_k} \right)^{-\frac{1}{\epsilon}}$$

which means that the (absolute value of the) elasticity of substitution is $\epsilon$.

With a continuum of goods, the analogue of summation is integration, and you can (loosely) think of the MRS between goods $j$ and $k$ as

$$\left( \frac{C_t (j)}{C_t (k)} \right)^{- \frac{1}{\epsilon}}$$


text:
# This Is It

265
4
• 2003.02.05
• 3:56
AWAで聴く

## 歌詞

There've been times in my life I've been wonderin' why Still, somehow I believed we'd always survive Now, I'm not so sure You're waiting here One good reason to try But, what more can I say What's left to provide (You think that maybe it's over) (Only if you want it to be) Are you gonna wait for a sign, your miracle Stand up and fight (This is it) Make no mistake where you are (This is it) You back's to the corner (This is it) Don't be a fool anymore (This is it) The waiting is over, no, don't you run No way to hide No time for wonderin' why It's here, the moment is now, about to decide Let 'em believe Leave 'em behind But keep me near in your heart Know whatever you do I'm here by your side (You say that maybe it's over) (Not if you don't want it to be) For once in your life Here's your miracle Stand up and fight (This is it) Make no mistake where you are (This is it) You're goin' no further (This is it) Until it's over and done (No one can tell you what you know) Whoa-oh-ho, whoa-aaah (Who makes the choice of how it goes) It's not up to me this time (You know) Comes a day in every life (This is it) Make no mistake where you are (This is it) You're goin' no further (This is it) Until it's over and done (This is it) One way or another (This is it) (No one can tell what the future holds) (This is it) Your back's to the corner (This is it) (You make the choice of how it goes) (This is it) The waiting is over (This is it) (No one can tell what the future holds) (This is it) You're goin' no further (This is it)

このページをシェア

## Kenny Logginsのアルバム

18曲2012年
10曲2012年
9曲2010年
9曲2010年
11曲2010年
9曲2010年
Kenny Loggins
の他の曲も聴いてみよう
AWAで他の曲を聴く
はじめての方限定
1か月無料トライアル実施中！

アプリでもっと快適に音楽を楽しもう
ダウンロード
フル再生


text:
### Force Waves

Referring to Fig.C.14, at an arbitrary point along the string, the vertical force applied at time to the portion of string to the left of position by the portion of string to the right of position is given by

 (C.41)

assuming , as is assumed in the derivation of the wave equation. Similarly, the force applied by the portion to the left of position to the portion to the right is given by

 (C.42)

These forces must cancel since a nonzero net force on a massless point would produce infinite acceleration. I.e., we must have at all times and positions . Vertical force waves propagate along the string like any other transverse wave variable (since they are just slope waves multiplied by tension ). We may choose either or as the string force wave variable, one being the negative of the other. It turns out that to make the description for vibrating strings look the same as that for air columns, we have to pick , the one that acts to the right. This makes sense intuitively when one considers longitudinal pressure waves in an acoustic tube: a compression wave traveling to the right in the tube pushes the air in front of it and thus acts to the right. We therefore define the force wave variable to be

 (C.43)

Note that a negative slope pulls up on the segment to the right. At this point, we have not yet considered a traveling-wave decomposition.
Next Section:
Wave Impedance
Previous Section:
Spatial Derivatives


text:
# Base change and relative Ext over noncommutative rings

Given two smooth projective schemes $X$ and $Y$ over some algebraically closed field $k$, we have $X\times Y$ with the projections $p$ to $X$ and $q$ to $Y$. Furthermore we have a "nice" sheaf of algebras $R$ on $X$, i.e. locally free and of global dimension at most dim($X$), e.g. Azumaya or something similar. Given two $p^{\*}R$-modules $M$ and $N$ on $X\times Y$, which are coherent and torsion free.

Like in the commutative case, i define the i-th relative $\mathcal{E}xt$-sheaf on $Y$ to be: $\mathcal{E}xt^i_{p^{\*}R,q}(M,N):=(R^i(q_{\*}\mathcal{H}om_{p^{\*}R}(M,-))(N)$

Can I expect them to have the same properties as in the commutative case?

For example:

(1) Do we have $\mathcal{E}xt^i_{p^{\*}R,q}(M,N)=0$ for $i>dim(X)$?

(2) Given $y\in Y$ is there a map $\mathcal{E}xt^i_{p^{\*}R,q}(M,N)\otimes k(y) \rightarrow Ext_R^i(M_y,N_y)$

(3) If $Ext_R^i(M_y,N_y)=0$ for all $y\in Y$ does this imply $\mathcal{E}xt^i_{p^{\*}R,q}(M,N)=0$?

(4) Is there a kind of base change theorem for the $\mathcal{E}xt^i_{p^{\*}R,q}(M,N)$?

Or do I need more conditions for $M$ and $N$ to have the desired properties? I'm especially interested in the case, where $M=p^{\*}P$ for some $R$-module $P$ on $X$.

-
Can we presume that R is an O_X algebra; ie, an algebra object in the category of quasi-coherent sheaves? Note that this fails for some sheaves of algebras that still have nice localization properties, like differential operators. –  Greg Muller Nov 9 '10 at 21:10
Yes, $R$ is supposed to be an $O_X$-algebra. I'm mainly interested in the cases where $R$ is Azumaya, i.e. etale locally just $M_n(O_X)$ or a maximal order of suitable global dimension. –  TonyS Nov 9 '10 at 21:39


text:
Notation

• A Kotlin string is implemented as an array of characters.
• Individual characters in a Kotlin string can be accessed through a nonnegative integer index using the [] notation.
• For a string $$X$$, we write $$X[i..j)$$ to denote the substring of $$X$$ consisting of all characters from position $$i$$ to position $$j-1$$ inclusive. (Note that this is not a Kotlin notation, it's our convenient notation for talking about substrings.)
• For example, if $$X$$ is AFRICA, then $$X[1..4)$$ is FRI and $$X[0..6)$$ is AFRICA itself.

Definitions

• If one deletes characters at certain positions from a string $$X$$, what remains is called a subsequence of $$X$$.
• For example, deleting the characters at positions 1 and 4 from AFRICA leaves us with the string ARIA. So we may say that ARIA is a subsequence of AFRICA.
• Deleting no characters is also permitted. So, for instance, AFRICA is considered a subsequence of itself.
• A sequence $$Z$$ is a common subsequence of sequences $$X$$ and $$Y$$ if $$Z$$ is a subsequence of both $$X$$ and $$Y$$.
• For instance, DIN is a common subsequence of DYNAMICPROGRAMMING and DIVIDEANDCONQUER.
• A longest common subsequence (LCS) of sequences $$X$$ and $$Y$$ is a common subsequence of $$X$$ and $$Y$$ of maximum possible length.
• For instance, DYNAMICPROGRAMMING and DIVIDEANDCONQUER have DICOR as an LCS. This is because DICOR is their common subsequence and no common subsequence of length 6 exists.
• DICON is another LCS, so LCS's are not unique.

Problem

• Let two sequences $$X=X_0X_1\dots X_{m-1}$$ and $$Y=Y_0Y_1\dots Y_{n-1}$$ be given. We want to find an LCS of $$X$$ and $$Y$$.
• Trying to solve the problem in a straightforward manner, we could do the following

we keep track of the current longest LCS found so far
for each subsequence Z of X do
if Z is also a subsequence of Y then
update the current longest LCS if needed
• However, this algorithm has to generate more than an exponential number of pairs of subsequences and check them for equality—an enormous amount as a function of m and n. We need a better way.

Solution by dynamic programming

• For $$0\le i < m$$ and $$0\le j < n$$, let OPT$$(i, j)$$ be the length of an LCS of $$X[i..m)$$ and $$Y[j..n)$$.
• We seek OPT$$(0, 0)$$.

Optimal substructure property

• Suppose $$Z=Z[0..k)$$ is an LCS of $$X[i..m)$$ and $$Y[j..n)$$.
• If $$X_i=Y_j$$, then necessarily $$X_i=Z_0$$. We can show that $$Z[1..k)$$ is an LCS of $$X[i+1 .. m)$$ and $$Y[j+1 .. n)$$.
• If $$X_i\ne Y_j$$, then $$X_i\ne Z_0$$ or $$Y_j\ne Z_0$$.
• If $$X_i\ne Z_0$$, we can show that $$Z$$ is an LCS of $$X[i+1..m)$$ and $$Y[j..n)$$.
• If $$Y_j\ne Z_0$$, we can show that $$Z$$ is an LCS of $$X[i..m)$$ and $$Y[j+1..n)$$.
• We know that one of the above cases must occur.
• This gives us the following recurrence. $\mbox{OPT}(i, j) = \left\{ \begin{array}{ll} 0, & \mbox{if i=m or j=n} \\ \mbox{OPT}(i+1, j+1) + 1, & \mbox{if 0 \le i < m, and 0 \le j < n, and X_i = Y_j} \\ \max\{\,\mbox{OPT}(i,j+1),\ \mbox{OPT}(i+1,j)\,\}, & \mbox{if 0\le i < m, and 0\le j < n, and X_i\ne Y_j} \end{array} \right.$

M A R C H
A 2 2 1 0 0 0
P 1 1 1 0 0 0
R 1 1 1 0 0 0
I 0 0 0 0 0 0
L 0 0 0 0 0 0
0 0 0 0 0 0

LCS algorithm

• [Step 1] Fill in a table of OPT$$(\cdot, \cdot)$$ values. This can be done row-by-row, column-by-column, or diagonal-by-diagonal.
• [Step 2] Find the LCS by following maximizer pointers, starting from OPT$$(0, 0)$$.
• Note: The maximizers can be found by pre-computation and kept in a table in Step 1, or they can be computed on the fly in Step 2.


text:
# Integrate the function $\frac{1}{1-\ tanx}$
$\begin{array}{1 1} \frac{1}{2} x+\frac{1}{2}\log|\sin x+\cos x|+c\\ x+\log(\sin x-\cos x)+c \\ x-\log(\sin x+\cos x)+c \\ x-\log(\sin x-\cos x)+c\end{array}$


text:
# Headphones

(14)
Finding the perfect combination. That’s what multivariate testing is all about. A multivariate test is a test that simultaneously tests several combinations of several variables. The idea is to modify several elements simultaneously on the same page and then define which one, among all of the possible combinations, has the most impact on the indicators being tracked. Multivariate testing (MVT) helps test associations of variables.
back to top

×


text:
# Mean of binomial distribution

Prove that mean of binomial distribution is:

$$E(X)$$ = $$np$$

Where n=number of trials and p=probability of success.

Since I could not think of how to put it as an mcq i decided to put it in a note.

Enjoy solving....!

Note by Mahimn Bhatt
3 years, 3 months ago

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold
- bulleted- list
• bulleted
• list
1. numbered2. list
1. numbered
2. list
Note: you must add a full line of space before and after lists for them to show up correctly
paragraph 1paragraph 2

paragraph 1

paragraph 2

[example link](https://brilliant.org)example link
> This is a quote
This is a quote
    # I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
# I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
MathAppears as
Remember to wrap math in $$...$$ or $...$ to ensure proper formatting.
2 \times 3 $$2 \times 3$$
2^{34} $$2^{34}$$
a_{i-1} $$a_{i-1}$$
\frac{2}{3} $$\frac{2}{3}$$
\sqrt{2} $$\sqrt{2}$$
\sum_{i=1}^3 $$\sum_{i=1}^3$$
\sin \theta $$\sin \theta$$
\boxed{123} $$\boxed{123}$$

Sort by:

Please do help me in this one .

- 3 years, 3 months ago

$$E(X)=\displaystyle \sum_{x=1}^{n} x\binom{n}{x} p^{x}(1-p)^{n-x}$$

$$= \displaystyle \dfrac{n!}{x!\times (n-x)!}xp^{x}(1-p)^{n-x}$$

$$= \displaystyle np\dfrac{n!}{(x-1)!\times (n-x)!}p^{x-1}(1-p)^{n-x} \quad x=t+1 ,n=m+1$$

$$=\displaystyle \dfrac{m!}{t!\times (m-t)!}xp^{x}(1-p)^{m-y} \\= np\sum p_{i}$$

$$= \displaystyle np \quad \because \sum p_{i}=1$$

P.S. I think you understand why I didn't start the sum with x=0 .

- 3 years, 3 months ago

haha yes i understand. I know how to derive i was just posting it as a problem.......:)

- 3 years, 3 months ago

Ok .

- 3 years, 3 months ago


text:
# zbMATH — the first resource for mathematics

Efficient computation of addition chains. (English) Zbl 0812.11072
An addition chain for a positive integer $$n$$ is a finite sequence of positive integers beginning with 1 and ending with $$n$$, such that each term except the first is the sum of two of its predecessors. Addition chains for $$n$$ generate multiplication schemes for the computation of $$x^ n$$; the smallest number of multiplications required is the minimal length $$\ell(n)$$ of an addition chain for $$n$$.
The paper studies $$cf$$-chains as introduced by the authors and C. Duboc [J. Algorithms 10, 403-412 (1989; Zbl 0682.68025)]. These are a class of sub-optimal addition chains, obtained through continued fraction expansions for $$n/k$$, where $$1<k<n$$. The length of $$cf$$-chains is asymptotically equivalent to $$\log_ 2(n)$$, as in $$\ell(n)$$. Most of the popular effective strategies for computing addition chains are obtained as special cases of the $$cf$$-chain method. The total number of operations required for the generation of an addition chain for all positive integers up to $$n$$ is $$O(n \log^ 2 n\gamma_ n)$$, where $$\gamma_ n$$ is the complexity of computing the set of choices corresponding to the strategy.

##### MSC:
 11Y16 Number-theoretic algorithms; complexity 11Y65 Continued fraction calculations (number-theoretic aspects) 68Q25 Analysis of algorithms and problem complexity
Full Text:


text:
# Memory consumption for importing numerical data from an ascii file

I am importing a file which contains data consinsting of 8918347 lines and 6 columns of the following type:

1187.40   725.79     4.04    -7.51  0103753  0913
1363.31   724.57     0.00     0.00  0103754  0913
564.34   725.77     0.00     0.00  0103755  0913
1174.40   726.31     0.00     0.00  0103756  0913
527.56   728.31    -3.82     1.38  0103757  0913
543.29   727.94    -0.80     0.24  0103758  0913
1510.04   729.10     0.00     0.00  0103760  0913
1565.91   738.97     1.80     1.37  0103762  0913
. . .

input = Import["data.txt", "Table"];

The file is accessible here:

• Before I import the data Wolfram Mathematica has allocated 431 MB (fresh started)

• During the reading the allocated memory of Wolfram Mathematica goes up to about 8700 MB.

• Then still during the line is executed the memory slowly goes down to 2330 MB and the line is finally executed.

The Import takes on my computer 135 sec.

I would like to understand:

1. Why does this up and down of allocated memory occurs during importing.

2. Why ist so much memory (2330 MB - 431 MB = 1899 MB) used?

If I assume that each number uses 8 Byte. Then this results in:

8*8918347*6 Bytes = 428080656 Bytes = 408.35 MB

My computer system is: Windows 10 Pro newest update, Ram: 32 GB, Notebook Dell Precision M4800, Intel Core i7-4940MX 3.1GHz

I can only guess that the inner workings of the parsing of data with an unknown shape may be complicated. The memory used contains several copies of the data been processed.

If you want to have some fun seeing how Mathematica works inside, look at Trace. I suggest you start using trace in much simpler expressions. If you need to Trace more complex expressions see this questions, to trace to a file

An alternative that uses much less memory and it's faster:

path = "20180720_01_data.txt"

First@AbsoluteTiming[
data2 =
ReadList[path, {Number, Number, Number, Number, Number, Number}];
]
(* 19.5111 *)

Compared with

First@AbsoluteTiming[
data1 = Import[path, "Table"];
]
(* 172.437 *)

Check that the data is the same.

data1 == data2
(* True *)

Even better, with ReadList and family of function for Streams and Low-Level Input and Output you could choose which lines and columns to Read and what to Skip.

• Thank you very much for the example how to load such a file much faster … I see this the first time. I will look also in Trace ... – mrz Jul 20 '18 at 18:52
• One cute thing I had missed but someone pointed out to me is we can just do ReadList[path, Number, RecordLists->True] and it will automatically determine the table width. – b3m2a1 Jul 20 '18 at 19:18


text:
# Thread: Pigeon-hole Principle (2)

1. ## Pigeon-hole Principle (2)

(a) Let n >= 2. We select n + 1 different integers from the set {1, 2, ..., 2n}. Is it true that there will always be two among the selected integers so that one of them is equal to twice the other?
(b) Is it true that there will always be two among the selected integers so that one is a multiple of the other?

My attempt:
(a) is false. A counterexample for n = 5: {1, 3, 4, 5, 7, 9}.
I think (b) is true but cannot seem to prove it. Any ideas?

2. ## Re: Pigeon-hole Principle (2)

This says "solved", but I don't see a solution here... I was interested to see if this was correct:

Let's let $A=\{1,2,\ldots ,n\},B=\{n+1,n+2,\ldots ,2n\}$. Suppose we wanted to attempt to pick $n+1$ elements such that no one is a multiple of another. Since $|B|=n$, at least one choice must come from $A$. Let's pick $x_1\in A$. This eliminates at least one possible choice from $B$; namely, $2x_1$. Now there are only $n-1$ possible choices left in $B$ (at most) and $n$ choices left to make. It follows that we need to choose another $x_2\in A$, which eliminates at least one more choice from $B$. Iterating this process, we see that we need to pick every element from $A$ and can't pick anything from $B$, which is of course bad, since we have only chosen $n$ elements. Of course, we could probably come to a contradiction a bunch of different ways before exhausting all of $A$, but this seems to work.

I think this is right. If someone could make sure, that would be great; and if there are better solutions, I'd be interested in seeing those too.

3. ## Re: Pigeon-hole Principle (2)

Originally Posted by topspin1617
Let's pick $x_1\in A$. This eliminates at least one possible choice from $B$; namely, $2x_1$.
What if $2x_1 \in A$?

4. ## Re: Pigeon-hole Principle (2)

a) is not true:

If n=5, 2n=10; {1,2,3,4,5,6,7,8,9,10}

Now we will pick 6 elements from the above group:

{1,3,4,5,7,9}

I didn't see your solution for a...

An idea for part b)

I will give the idea via example when n=10.

n=10 the 2n=20

X={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 ,20}

I will divide set X to some subsets:

A_1={1,2,4,8,16}

A_2={3,6,9,18}

A_4={5,10,20}

A_5={7,14}

A_6={11}

A_7={13}

A_8={17}

A_9={19}

If we take 11 elements there must be at least two of the that are in the same set!

5. ## Re: Pigeon-hole Principle (2)

Originally Posted by Also sprach Zarathustra
An idea for part b)

I will give the idea via example when n=10.

n=10 the 2n=20

X={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 ,20}

I will divide set X to some subsets:

A_1={1,2,4,8,16}

A_2={3,6,9,18}

A_4={5,10,20}

A_5={7,14}

A_6={11}

A_7={13}

A_8={17}

A_9={19}

If we take 11 elements there must be at least two of the that are in the same set!
6 and 9 are in the same subset but one is not a multiple of the other. Where are 12 and 15?

6. ## Re: Pigeon-hole Principle (2)

Originally Posted by alexmahone
What if $2x_1 \in A$?
Ugh. Of course.

Have to think some more.

7. ## Re: Pigeon-hole Principle (2)

Maybe the other guy was on to something up there. For $1\leq r\leq n$, let $A_r=\{2^k\cdot (2r-1)\mid k\geq 0, 2^k\cdot (2r-1)\leq 2n\}$. Certainly every element of $\{1,2,\ldots ,2n\}$ is in at least one of the $A_r$. (Of course all of the odd numbers are; for the even numbers, factor out the highest power of 2 possible, and see that it is in the set corresponding to the remaining odd factor.) Note that there are exactly $n$ of these sets $A_r$. Also, notice that for any fixed $r$, every element of $A_r$ has a divisibility relation with every other element of that same set. This means that, if we were picking elements which share no such relation, the best we could do is pick one element from each set. Since there are only $n$ sets, the best we could possibly do is pick $n$ elements.

8. ## Re: Pigeon-hole Principle (2)

Originally Posted by topspin1617
Maybe the other guy was on to something up there. For $1\leq r\leq n$, let $A_r=\{2^k\cdot (2r-1)\mid k\geq 0, 2^k\cdot (2r-1)\leq 2n\}$. Certainly every element of $\{1,2,\ldots ,2n\}$ is in at least one of the $A_r$. (Of course all of the odd numbers are; for the even numbers, factor out the highest power of 2 possible, and see that it is in the set corresponding to the remaining odd factor.) Note that there are exactly $n$ of these sets $A_r$. Also, notice that for any fixed $r$, every element of $A_r$ has a divisibility relation with every other element of that same set. This means that, if we were picking elements which share no such relation, the best we could do is pick one element from each set. Since there are only $n$ sets, the best we could possibly do is pick $n$ elements.
Yeah, that's right. Good job!

### select n 1 different integers from the set {1,2,..,2n} . prove that there

Click on a term to search for related topics.


text:
# What is an example of a gas pressure practice problem?

May 24, 2014

There are many laws that deal with gas pressure.
Boyle's Law ${P}_{1} {V}_{1} = {P}_{2} {V}_{2}$, Charles' Law $\frac{{V}_{1}}{{T}_{1}} = \frac{{V}_{2}}{{T}_{2}}$, Ideal Gas Law $P V = n R T$, Dalton's Law P_1 + P_2 + P_3…= P_(Total)

Here is an example using the Combined Gas Law.

A certain sample of gas has a volume of 0.452 L measured at 87°C and 0.620 atm. What is its volume at 1 atm and 0°C?

The formula for the combined gas law is
$\frac{\left({P}_{i}\right) \left({V}_{i}\right)}{T} _ i = \frac{\left({P}_{f}\right) \left({V}_{f}\right)}{T} _ f$

We begin by identifying the values for each of the variables and identifying the missing value.

${P}_{i}$ = 0.620 atm
${V}_{i}$ = 0.452 L
${T}_{i}$ = 87 C + 273 = 360 K

${P}_{f}$ = 1 atm
${V}_{f}$ = ???
${T}_{f}$ = 0 C + 273 = 273 K

$\frac{\left(0.620 a t m\right) \left(0.452 L\right)}{360 K} = \frac{\left(1 a t m\right) \left(x\right)}{273 K}$

$\frac{\left(273 K\right) \left(0.620 a t m\right) \left(0.452 L\right)}{\left(360 K\right) \left(1 a t m\right)} = \left(x L\right)$

$x L = 0.212 L$


text:
# Imposing physical constraints (previous knowledge) in a neural network for regression

I'm trying to train a neural network to do a multiple non-linear regression $$y=f(x_i), i=1,2…N$$. So far it works good (low MSE), but some predictions $$y$$ are “non-physical”, for instance for our application it is known from first principles that when $$x_2$$ increases, then $$y$$ also has to increase ($$dy/dx_2>0$$), but in some instances the neural network’s output doesn’t comply with this constraint. Another example is that $$y + x_5 + x_7$$ should be less than a constant $$K$$

I thought about adding a penalty term to the loss function to enforce these constraints, but I am wondering if there is a "harder" way to impose such a constraint (that is, to ensure that these constraints will always hold, no only that non-physical predictions will be penalized)

• About the second one, is it x5+x7 <K or f(x5)+f(x7)<K? The former is not a constraint on the output but and error in the dataset. You should be able to weed them out without machine learning. – serali Nov 14 '19 at 11:05
• Hi serali, I had a typo in that equation, I meant the constaint y + x_5 + x_7 < K – Ken Grimes Nov 14 '19 at 11:15

1. In the case of $$dy/dx_2>0$$ you could compute the gradient using the chain rule and limit the weights so that the constrain holds
2. In the case of $$y + x_5 + x_7 < K$$ you could use a clipping function on the output layer?