y is sphere surface 4pi R^2

Imagine a giant hoop passing through south and north poles. If I build a railroad along the equator and pull the hoop one complete

round, the hoop would have swept the entire surface exactly twice. The hoop perimeter is 2?R or 2? assuming R=1.

Imagine yourself holding one point of the hoop during the sweep. You can further imagine all the people (about 7,000,000,000)

holding on the hoop shoulder to shoulder from North pole to the equator. We would cover a quarter hoop. In one round we would sweep

half the sphere area. Each person's travel path distance will be different. The longest path is the equator — 2?R. At the pole the

sweep path is 0.

Q: what's the average travel among all those people? I think answer turns out to be 4R, which is slightly short of 66.666% of the

equator length.

Q: (To keep this question simpler, we can keep the hoop still.) What's the average distance from the axis? I think it's 2R/?


matrix multiplying – simple, memorable rules

Admittedly, Matrix multiplication is a cleanly defined concept. However, it’s rather non-intuitive and non-visual to many people. There are quite a few “rules of thumb” about it, but many of them are hard to internalize due to the abstract nature. They are not intuitive enough to “take root” in our mind.

I find it effective to focus on a few simple, intuitive rules and try to internalize just 1 at a time.

Rule — a 2×9 * 9×1 is possible because the two “inside dimensions” match (out of the 4 numbers).

Rule — in many multiplication scenarios, you can divide-and-conquer the computation process BY-COLUMN — A vague slogan to some students. It means “work out the output matrix column by column”. It turns out that you can simply split a 5-column RHS matrix into exactly 5 columnar matrices. Columnar 2 (in the RHS matrix) is solely responsible for Column 2 in the output matrix. All other RHS columns don’t matter. Also RHS Column 2 doesn’t affect any other output columns.

You may be tempted to try “by-row”. I don’t know if it is valid, but it’s not widely used.

By-column is useful when you represent 5 linear equations of 5 unknowns. In this case, the RHS matrix comprises just one column.

Rule — Using Dimension 3 as an example,

(3×3 square matrix) * (one-column matrix)  = (another one-column matrix). Very common pattern.

yield-/smile-curves are !! directly related to greeks

The yield curve and smile curve (or surface) are the output of curve fitting engines, calibrated using a lot of commercial market data, discarding outliers. These are the most valuable soft market data objects. Directly used by decision makers, including trade pricing. Each trading desk guards these curves as highly proprietary trading secrets.

However, these curves are imprecise. You shouldn’t compute the gradient at each point on these curves. The most you do with such gradient is computing the gradient at the anchor vol point, which gives you the skew of the entire curve.

In contrast, the price-vs-impliedYield curve and the valuation-vs-spot curve are a different class of curves. (The valuation-vs-impliedVol curve is another example.) I call these “range of possibilities” curves. They are mathematically precise enough to let us compute gradient at every point. You get duration and delta. These are known as sensitivities, essential soft market data for risk management.

python pseudo constructors4everyday tasks

These Python builtin functions have something in common:

* pseudo [1] constructors — manufacture an object of the specified type
* conversion constructors — converting some input value into an object of the specified type

[1] Actually builtin functions rather than ctor. I guess the fine differences between builtin functions, keywords and operators are not that important at this stage.

P64 [[essential ref]] lists these and more, as “type conversion” functions.

– str()
– dict()
– list() — see py list initialize []^list()
– tuple()
– set()
– int()

– file() — very similar to open()

linear independence ^ basis

Let’s use dimension of 3 as a simple example. A 3-dimension space consists of all points in a 3-D coordinate system (real-valued). An address (or point) in this space always has 3 real-valued coordinates – x, y and z. Linear Algebra represents such an address using a column vector
Now, a family of two, there or more vectors can be either linearly independent, or form a basis of this 3-D space, or both (or neither).
LI can be defined this way – using vector linear operations (i.e. addition/scaling) within the family, we can’t express any vector using the sisters. If we can, then one of the vectors can be linearly constructed with the other vectors. In such a case, another family member can also be linearly constructed. There’s plenty of redundancy in the family.
Now Basis (not a definition) – using vector linear operations (i.e. addition/scaling) within the family, we can express _any_ vector in the entire space. In we can, then the family qualifies as a basis of the space, but no redundancy please.
Note, since a basis is a Minimal family, a basis family must be LI. The converse doesn’t hold — A LI family may not form a basis.

event/method pairs in WPF

In learning WPF/Silverlight, I had a few confusions that are similar. These confusions probably fall into the same category. In all cases, one class has both an Event and a Method of a similar name. Here are some cases in point.

Tip: On*** is usually a method

1) Method OnPropertyChanged() vs PropertyChanged event
PC is more fundamental than OPC. PC is heart of the familiar INotifyPropertyChanged interface. As a result, wpf developers (like us) are frequently required to raise PC events explicitly. How do we raise? Often in a non-static OnPropertyChanged() method. So /there you are/, the link between PC and OPC.

http://msdn.microsoft.com/en-us/library/ms743695.aspx is an MSDN tutorial showing exactly this OPC/PC pattern.

The authoritative MSDN documentation http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx shows the same pattern except the OPC method is actually named NotifyPropertyChanged.

OPC is not a standard method name dictated by the framework. It’s more of a method naming convention.

2) This case is found in the commanding infrastructure of WPF. Method CanExecute() vs CanExecuteChanged event. Once the event fires[2] and a command source object [3] gets its callback method invoked[1], that callback method internally calls CanExecute() to check if it should paint itself dimmed.

[1] often on the GUI thread.
[2] (by invoking each callback on the inv list),
[3] (eg button)

delegate instance is passed by value@@

myEvent += myDelegate;

Q: Is myDelegate passed by reference?
A: No. member-wise copying. In other words, each item in the delegate inv list is passed in (by reference?).
A: No. The invocation list (say 2 callbacks) are appended to myEvent’s internal inv list, and new list is ReBound to myEvent internal delegate variable.

That’s a short answer. For the long answer, we need to forget events and callbacks and focus on pure delegates as list objects holding simple “items”. Suppose dlg1 variable points to address1, and dlg2 points to address2.

dlg1 += dlg2 // translates to
dlg1 = Delegate.Combine(dlg1, dlg2). // Note: re-binding dlg1

Now dlg1 points to newly allocated address11. At this address there’s a new-born delegate object whose inv list is

[item1 at addr1,
item2 at addr1 …
itemN at addr1,
item1 at addr2,
item2 at addr2, ….
itemM at addr2]

According to http://msdn.microsoft.com/en-us/library/30cyx32c.aspx, some of the items could be duplicates — Legal.

30 seconds after the Combine() operation, suppose dlg2 is subsequently modified (actually re-bound). Instead of 2 callbacks at addr2, variable dlg2 [1] now points to addr22 with 5 callbacks. However, this modification doesn’t affect the inv list at addr11, which dlg1 now points to.

Therefore, we can safely say that in a Combine() operation the RHS delegate’s inv list is copied-over, passed by value or “pbclone”.

[1] like all java reference variables, a c# delegate variable is a 32-bit pointer object. As explained in
http://bigblog.tanbin.com/2012/03/3-meanings-of-pointer-tip-on-delete.html, the compiler is likely to allocate 32 bit of heap for this 32-bit object.

y java object always allocated on heap, again

Short answer #1: Because java objects are passed by reference.

Suppose a holder object (say a collection, or a regular object holding a field) holds a Reference to a student1 object. If student1 object were allocated on stack, and de-allocated when stack frame unwinds, the holder would hold a stray pointer. Java is allergic to and won’t tolerate a single stray pointer.

Java primitive entities are always passed by value (pbclone). No stray pointer – no pointer involved at all.

Short answer #2: all pbref entities live safer on heap.

How about c# and C++? Somewhat more complicated.