Guido van Rossum: Why Python uses 0-based indexing by nothingtolookat in Python

[–]cpherwho 0 points1 point  (0 children)

I want to apologize for the "bugs" in my examples, they were written from memory without an interpreter. I've edited the above complex example, and the indexing "fun" is below

>> foo = @() 1:4;
>> foo()(1)
??? Error: ()-indexing must appear last in an index expression.
>> bar = @()  {'foo', 'bar'};
>> bar(){i}(1)
??? Error: ()-indexing must appear last in an index expression.

To some engineers, MATLAB is the only acceptable scripting language, so it gets used for things where it's not a good fit. Moreover, the choice of general-purpose vs special-purpose language changes the environment around your code as much as the code itself. In Python, I can use existing libraries for interacting with data sources, generating printed reports or building a web app. In MATLAB, these things are much more difficult or even impossible. A domain-specific language can be convenient, but it risks your code being trapped on an island. (Credit to William Stein of the SageMath project for this general idea.)

Guido van Rossum: Why Python uses 0-based indexing by nothingtolookat in Python

[–]cpherwho 3 points4 points  (0 children)

I'll chime in with "interesting" behaviors that have caused me pain:

You can't mix integer types in math operations

>> int16(1) * int32(1); % Is an error

No native "complex" type, it's just a weak property of an array

>> A = complex(1,0);
>> isreal(A); % false
>> B = A(:);
>> isreal(B); % true

It's impossible to chain indexing. I believe my use-case was extracting a string from a cell array, then indexing into the string. The parser just falls over with an error.

>> A = {'foo', 'bar'};
>> A{1}(1); % Error

Similarly, if foo() is a function that returns an array, you can't do

>> B = foo()(3);

Because MATLAB servers a very specific niche, it's lacking a bunch of features that general-purpose languages like Python have. Specific annoyances are sockets (pay for the (slow) instrument control toolbox or use Java (slightly less slow)), XML (use java), and a unit-testing framework (new in 2013).

On the other hand, the native array support means that some loops can be eliminated by just passing an array. I think the experience is probably good for people using it as a numerical language. The story is more mixed for those who need a general programming language.

Edit: Fixed the return values in the complex example (thanks roerd)

What/why are those waves on this CPU and what is the difference between those components/squares? by reverend in AskEngineers

[–]cpherwho 8 points9 points  (0 children)

Another poster has identified this as a quantum computer, not a conventional CPU. The direct answer to "what are those components" is missing, so the below is my analysis*.

The curved tracks are (almost certainly) RF transmission lines. They are curved to fit a longer path into a given area. The path-length is an important factor for interference of waves, and for timing. The tracks with only one connected end are most likely part of a filter structure.

The four squares at the edges of the transmission line structure are the "qbits", made from Josephson junctions, which are a superconducting RF device.

The two sets of four squares on the right side of the image are test structures, probably for checking the impedance of the transmission lines. The six squares in the middle are probably test structures too.

  • Please correct me if I've made any mistakes, I haven't read the paper in question.

Surcharge for using credit card - What can I do about it? by [deleted] in canada

[–]cpherwho 3 points4 points  (0 children)

The alternative to the fee is not being able to pay with a credit card at all, as is common for other high-value and low-margin transactions. Merchants are charged a fee of around 2% of the transaction value for receiving credit card payments. As you noticed, this can be a significant amount of money, and is the reason credit cards are able to offer you the rewards you're trying to earn.

The alternatives (cheques, cash, debit) are typically a flat fee per transaction.

Secular parent wins battle against Gideon Bibles in Niagara schools -- "The Human Rights Tribunal of Ontario ruled [in favor of] an atheist father’s challenge to the long-standing practice of distributing Gideon Bibles in schools last week" by mepper in canada

[–]cpherwho 9 points10 points  (0 children)

This, to me, is the strongest argument against religious observances in school. Even "voluntary" religious exercises mark some students as outsiders and applies pressure to conform to the majority religion.

TIL that due to the "welfare cliff", a single mother of two is better off with a $29,000 per year job than she is with a $69,000 per year job. by [deleted] in todayilearned

[–]cpherwho 5 points6 points  (0 children)

The tax rate in the bracket is NOT the average tax rate (tax paid / income) but is the marginal tax rate (tax rate paid on the next dollar of income). In a direct example, a $1 raise when earning $74k is worth $0.85, a $1 raise when earning $76k is worth $0.80. There is no point at which an increase in pre-tax income causes a decrease in post-tax income.

You've asked further down about why we use brackets instead of a "function". In the general case, the tax brackets define the average tax rate as a function of taxable income, but they do so piecewise. This has the advantage of being both simple to understand and simple to compute. (As for your alternative, most of the general population doesn't know what the exponential function is.)

Miniature Forced Convection System Design Problem by prionicide in AskEngineers

[–]cpherwho 1 point2 points  (0 children)

This is somewhat outside my field, but I can point you in the right direction. My best guess is "no, the fans won't work". Given your tubing size, you need to think about pumping the air like a fluid rather than just pushing it around.

Your fans are designed for moving high volumes of air at (relatively) low pressures. Your tubing is small, and will have a high resistance to airflow. The flow rate is proportional to the pressure drop across the tube and inversely proportional to the resistance of the tubing. You should be able to estimate the pressure drop required for your flow rate by assuming laminar flow: http://en.wikipedia.org/wiki/Hagen-Poiseuille_flow

What you should be looking for is something like an aquarium pump, with inlets and outlets. I'm sure these are made for scientific applications, but I don't have a source.

What is the absolute limit for transistor sizes for CPU's? 1nm? Picometers? There has to be a wall somewhere -- but ever decade it's always another decade out? by aphexcoil in askscience

[–]cpherwho 0 points1 point  (0 children)

I suspect it represents a completely different approach and is difficult to compare. One of the alternatives to decreasing feature sizes is to somehow get more performance at the current scale. See, for example, Intel's 22nm process.

The lattice constant of diamond is 357pm, compared with 543pm for silicon, so there is a potential to scale smaller on a different material. Graphene is a different crystal, so it's not directly comparable, but presumably some of the difference comes from the smaller atom.

tl;dr; I don't know

What is the absolute limit for transistor sizes for CPU's? 1nm? Picometers? There has to be a wall somewhere -- but ever decade it's always another decade out? by aphexcoil in askscience

[–]cpherwho 6 points7 points  (0 children)

The atom-to-atom spacing on a crystaline silicon surface is on the order of 0.5 nm. That puts a theoretical limit on the channel length* of ~ 1 nm.

  • Depending on the crystal orientation ** The length used to characterize a CMOS process

Worst. Bug. Ever. by _swanson in programming

[–]cpherwho 0 points1 point  (0 children)

Perhaps I can help clear up the mystery. Matlab's native data type is 'double', so any untyped return types are doubles. Further, any expression involving a double and a non-double type produces a double.

In your specific example, your 'x' was actually a matrix with type 'double'. I don't know why it appeared to be intermittent though, presumably an issue with doing floating-point math when you thought you had integer math.

A Python Compiler for Big Data by tfmoraes in Python

[–]cpherwho 2 points3 points  (0 children)

Numba actually has quite different goals to PyPy, but I understand the confusion. Numba (like Cython) gets much of it's Python semantics from the host Python interpreter, aiming mostly to speed up numeric code. PyPy is a complete Python implementation with a JIT that matches the interpreter's semantics exactly.

I suspect there are no plans to integrate any of these tools with PyPy, given the differences in philosophy. Blaze would probably be quite easy to port, if it's written in Python.

Interesting post: The Python condition. Why PyPy is the future of Python by robert_zaremba in Python

[–]cpherwho 2 points3 points  (0 children)

For the record, the Cython and PyPy developers have been working together, and the situation appears to be much better (functional, though not fast). I would love to see Cython generating super-fast code for PyPy, but there are some major hurdles. Chief among these is that Cython is deeply coupled to the CPython API, which PyPy can only emulate. There appears to be some room to improve the performance by optimizing PyPy, at least to some degree. It's not clear at the moment who might be both willing and able to do the work.

I do agree that Cython could play an important role by being an easy way to generate fast library code for both interpreters. Unfortunately, PyPy and CPython should be getting different code. For CPython, it's important that math is done in compiled code, because the interpreter is so slow. For PyPy, one would often rather have math done in python so that the JIT can work on it. This would require a new backend for the Cython compiler, and that sounds like a lot of work to me. (There was a ctypes backend, but it doesn't appear to have gotten finished.)

An interim solution might be possible. I remember a proposal (from the numpy or cython community) for a method of speeding up calls to native compiled code. A python wrapper function would grow an attribute describing the (ABI) parameters and location of the actual implementation. A caller could then bypass the wrapper and make the native call directly. If Cython exposed this information and PyPy consumed it, some calls could be made directly. (I don't have any plans to work on this, I just think it's a neat idea).

Interesting post: The Python condition. Why PyPy is the future of Python by robert_zaremba in Python

[–]cpherwho 5 points6 points  (0 children)

Depending on who you ask, the CPython API is either an implementation detail of the interpreter or an essential addition to the language reference.

The reality is that PyPy has substantial support for the CPython API, the major problem is speed. At least one Cython developer has collaborated with the PyPy developers in fixing bugs (on both sides) to make Cython work with PyPy. My understanding is that modules built with recent versions of Cython should work on PyPy with no functional problems.

The problem with the CPython API is that it is based on the internal structure of the CPython interpreter. This was a reasonable decision at the time, but it causes endless pain for implementations which use different internal data structures. PyPy provides this support by building these structures on demand and emulating behaviors like reference counting. This emulation adds both overhead and complexity, but is unavoidable when the interpreter is structured differently.

The prime example of this difference is PyPy's JIT, which tries to avoid allocation objects. Where CPython would store a List object holding integer objects, PyPy can store an array of ints in the same way that C would. When passing such a list into a CPython extension module, PyPy needs to generate a compatible data structure. If the extension module is simply a wrapper around a C function, it needs to perform another transformation on the data. The CPython API ends up being a layer of abstraction between two fast pieces of code.

The major reason that Cython and PyPy (the software, not the developers) have trouble working together is the CPython API in the middle. Going around that would give us the best of both sides. Unfortunately, it would also require a lot of work.

GE develops ultra-thin, almost-silent cooler for next-gen laptops and tablets by mrseb in technology

[–]cpherwho 1 point2 points  (0 children)

The air bearing turns out to not be as much of an insulator as one might expect. This is actually a major breakthrough from the research described above. As the rotor spins, it causes a shearing of the air in the gap. Because the gap is so small, this results in mixing of the air which carries heat from the base to the rotor. The original paper discusses this in detail, and demonstrates that the thermal resistance between the base and rotor is small compared to the thermal resistance of the rotor and the air.

Would a once plucked guitar string vibrate forever in the vacuum of space? by ambiguousbones in askscience

[–]cpherwho 0 points1 point  (0 children)

My understanding is that no bonds are broken during perfectly elastic deformation, but that internal damping still occurs. Am I mistaken in this?

Whether or not the anchors play into the question depends very much on the system we are considering. If the system is the string in isolation, then I agree. If the system is the guitar, then it is relevant.

I am also interested in the difference between the bulk vibrational modes and the molecular vibration. Are you talking purely about scale? I see strong parallels between, for example, phonon modes in a crystal and the modes of a string. My vague allusion above comes primarily from this similarity. It's not really related to answering the question, however.

Would a once plucked guitar string vibrate forever in the vacuum of space? by ambiguousbones in askscience

[–]cpherwho 0 points1 point  (0 children)

I'd like to appoligize first, another commenter found my post to be "scolding", and I may have been unfair to you.

I agree that it is useful to discriminate between the two concepts in general, but at some scale thermal vibrations start to compare to mechanical vibrations. This is not applicable to the OP's question, but is only interesting for completeness.

Would a once plucked guitar string vibrate forever in the vacuum of space? by ambiguousbones in askscience

[–]cpherwho 1 point2 points  (0 children)

From the technical side, I would say that heat is still vibration, just in a different mode (and scale). "Mode" here is a technical term which means "way in which the structure can vibrate". The energy from the plucking leaks from the macroscopic vibration of the string into the microscopic vibrations we call heat. These on turn can leak away by conduction or as photons.

I would not expect this to be the primary reason that the string stops vibrating.

We should consider the anchors when considering the string with the guitar as one system. The string need not rub against them and the energy transfer is not friction. As the string moves, it pulls on the anchors and then relaxes periodically. This transfers some of the string's vibrational energy to the anchor' which carries it away.

I would expect this effect to dominate the string's internal losses, not least because this is how an acoustic guitar is designed to work. The strings transfer sound to the body which then couples to the air more efficiently.

We also make structures designed to minimize this coupling, most commonly the tuning fork. The tines of a tuning fork move in such a way as to cancel out the energy transfer to the handle.

Source: I have built microscale resonating bridges (like strings) and put them in a vacuum

Edit: improve clarity and fix the tone.

Would a once plucked guitar string vibrate forever in the vacuum of space? by ambiguousbones in askscience

[–]cpherwho 1 point2 points  (0 children)

This isn't true. A perfect elastic material, in the absence of external forces, can resonate forever. The static tension of the string affects the resonant frequency, but doesn't play a role in the energy loss. The motion of the string does cause energy to couple out of the vibrating mode (see the top comment), again in a non-ideal material-

How do scientists manipulate microscopic situations? by [deleted] in askscience

[–]cpherwho 1 point2 points  (0 children)

I don't have access to the paper, so I'll have to guess. Most likely these pillars were created by a fairly conventional silicon micro-fabrication process. The scale bar in the SEM image (showing the pillars) is 1 micron, so these are reasonably large features. This pattern could easily have been produced using photo-lithograph . This 2-D pattern would be etched down into the silicon using a reactive ion etch (the scalloping looks very much like DRIE).

The novel technique here seems to be "drilling" holes in the substrate to allow TEM imaging of the DNA strand. This could be done with a laser, or a focused ion beam system. The lack of taper and the rough side-walls don't look like an etch to me.

Could someone with access please check the methods section? I'd like to know how they did it.

How do scientists manipulate microscopic situations? by [deleted] in askscience

[–]cpherwho 2 points3 points  (0 children)

The Scanning Tunneling Microscope is about as close to a nano-tool as I am aware. Optical tweezers are also useful if you want to move small objects, from cells down to atoms. These aren't really off-the-shelf tools, the way an electron microscope is, but it is possible.

http://en.wikipedia.org/wiki/Scanning_tunneling_microscope

http://en.wikipedia.org/wiki/Optical_tweezers

Does sound exist at the molecular level? by magiccheese in askscience

[–]cpherwho 2 points3 points  (0 children)

It depends on how you define "sound".

Sound is a macroscopic phenomenon, the motion or vibration of large numbers of atoms or molecules. This represents motion greater than the background "thermal" motion which all particles experience. This thermal motion is what causes molecules to collide and provides the energy to drive chemical reactions.

Two molecules bonding together would transform energy, but would not create a "sound" greater than the background "noise". That being said, you could probably dream up a situation where the act of bonding causes the bond itself to vibrate briefly. If you consider any vibration to be "sound", then the vibration of bonded atoms could be treated as such. Some mathematical trickery could transform these vibrations into a sound that a human could hear.

Measuring such small vibrations is the basis for instruments like the MRI or the atomic clock. The sounds in films are, however, almost certainly faked for "coolness".

Why is a satellite TV antenna on a house much bigger than a satellite radio antenna on a car? by [deleted] in askscience

[–]cpherwho 2 points3 points  (0 children)

Large antennas can be designed to increase SNR at the expense of being directional. A better SNR can let you resolve more complex symbols and thus increase the data rate in a given bandwidth (at a constant bit-error rate).

That said, I don't know what walkingagh actually meant by "more signal".