They have the same one. Under what circumstances do identical rows have the same reference? Solutions collect form web for “Under what circumstances do the same rows have the same reference?”

Physics problem - 2379

2017-03-16
Two identical spheres have the same temperature. One of the balls is on a horizontal plane, the other is suspended on a thread. The same amount of heat is transferred to both balls. The heating process proceeds so quickly that there is no loss of heat due to heating of neighboring objects and the environment. Will the temperatures of the balls be the same or different after heating? Justify your answer.


Solution:


Fig.1

Fig.2
The difference will be associated with the behavior of the centers of mass of the balls.

As the balls heat up, let their volumes increase. In this case, the height of the center of mass of the first ball above the horizontal plane will increase (Fig. 1), and the center of mass of the suspended ball will lower (Fig. 2).

Based on the first law of thermodynamics, we can write:

a) $Q = cm \Delta T_(1) + mgh, \Delta T_(1) = \frac(Q - mgh)(cm)$;
b) $Q = cm \Delta T_(2) - mgh, \Delta T_(2) = \frac(Q + mgh)(cm)$;

where $x$ is the specific heat capacity of the substance from which the ball is made, $m$ is its mass.

It follows that $\Delta T_(2) > \Delta T_(1)$, i.e. a hanging ball should heat up to a higher temperature than a ball lying on a horizontal surface. Let's evaluate the resulting effect. Let the radius of the ball be $R$, and the coefficient of linear expansion of the material from which the ball is made is equal to $\alpha$. Then the ratio of the change in the temperature of the ball due to a change in the position of its center of mass to the change in temperature $\Delta T$ due to the imparting of the amount of heat $Q$ to it will be equal to

$\frac( \Delta T^( \prime))( \Delta T) = \frac(mgh)(cm \Delta T) = \frac(mgR \alpha \Delta T)(cm \Delta T) = \frac (g)(c) R\alpha$.

By calculating the estimated values, for example, for an iron ball of radius $R = 0.1 m (c = 450 J/(kg \cdot K), \alpha = 11.7 \cdot 10^(-6) K^(-1) )$, we get: $\Delta T^( \prime) / \Delta T = 2.6 \cdot 10^(-8)$.

Thus, the effect discussed in the problem is negligible and lies beyond the possibility of experimental detection.

I searched the web and searched through questions but couldn't find the answer to this question. An observation I made is that in Python 2.7.3, if you assigned two variables to the same single character string, e.g.

>>> a = "a" >>> b = "a" >>> c = " " >>> d = " "

The variables will then have the same reference:

>>> a is b True >>> c is d True

This is also true for some longer strings:

>>> a = "abc" >>> b = "abc" >>> a is b True >>> " " is " " True >>> " " * 1 is " " * 1 True

>>> a = "ac" >>> b = "ac" >>> a is b False >>> c = " " >>> d = " " >>> c is d False >>> " " * 2 is " " * 2 False

Can anyone explain the reason for this?

I suspect there may be simplifications/substitutions made by the interpreter and/or some caching mechanism that takes advantage of the fact that strings are immutable to optimize in some special cases, but what do I know? I tried making deep copies of strings using the str constructor and the copy.deepcopy function, but the strings are still incompatible with references.

The reason I'm having problems is that I'm testing for string reference inequality in some unit tests I'm writing for new style python class clone methods.

3 Solutions collect form web for “Under what circumstances do the same rows have the same reference?”

The details of when strings are cached and reused are implementation dependent, may vary from Python version to Python version, and should not be relied upon. If you want to test strings for equality, use == rather than .

In CPython (the most commonly used Python implementation), string literals that occur in source code are always interned, so if the same string literal occurs twice in source code, they end up pointing to the same string object. In Python 2.x, you can also call the built-in intern() function to force interning of a specific string, but you shouldn't actually do that.

Change the actual purpose of checking whether attributes are distributed incorrectly between instances: this kind of checking is only useful for mutable objects. For attributes of an immutable type, there is no semantic difference between shared and non-shared objects. You can exclude immutable types from your tests using

Immutable = basestring, tuple, numbers.Number, frozenset # ... if not isinstance(x, Immutable): # Exclude types known to be immutable

Note that this also excludes tuples containing mutable objects. If you want to test them you will need to descend recursively into the tuples.

In CPython, as an implementation detail, the empty string is common, as are single-character strings whose code is in the Latin-1 range. You Not should depend on this as it is possible to bypass this feature.

You can request a string for internment using sys.intern ; this will happen automatically in some cases:

Typically, names used in Python programs are automatically interned, and dictionaries used to store module, class, or instance attributes have interned keys.

sys.intern is exposed so that you can use it (after profiling!) for performance:

Inner strings are useful for gaining a little performance when looking up dictionaries - if the keys in the dictionary are interned and the lookup key is interned, key matching (after hashing) can be done using pointer comparisons instead of string comparisons.

Note that intern is a Python 2 built-in.

I think it's implementation and optimization. If the string is short, they can (and often?) "split", but you can't depend on that. Once you have more rows you will see that they don't match.

In : s1 = "abc" In : s2 = "abc" In : s1 is s2 Out: True

longer lines

In : s1 = "abc this is much longer" In : s2 = "abc this is much longer" In : s1 is s2 Out: False

use == to compare strings (and Not is operator).

OP's observation/hypothesis (in the comments below) that this may be related to the number of tokens seems to be supported by the following:

In : s1 = "abc" In : s2 = "abc" In : s1 is s2 Out: False

when compared to the original abc example above.


Figure 3.2 - Formation of contours

coastline at points B. By projecting it onto the same plane P, we obtain a second closed curved line BB. Continuing the rise of water in the same sequence higher, on plane P we obtain an image of the hill using horizontal lines.

For greater clarity, the direction of decline of the slopes is shown by dashes called berg strokes. To indicate the heights of the horizontal lines, their marks are signed in the breaks of the horizontal lines, placing the top of the numbers in the direction of the top of the slope. To make the relief more expressive, as a rule, the fifth and sometimes the tenth horizontal lines are thickened.

The difference in heights of two adjacent horizontal lines is called the height of the relief section.

The distance between two adjacent horizontal lines on a plane is called the lay.

Horizontals have the following properties:

  • a) all points lying on the same horizontal line have the same height;
  • b) all horizontal lines must be continuous;
  • c) horizontal lines cannot intersect or bifurcate;
  • d) the distances between horizontal lines in plan characterize the steepness of the slope - the smaller the distance (lay), the steeper the slope;
  • e) the shortest distance between horizontal lines corresponds to the direction of the greatest steepness of the slope;
  • f) watershed lines and axes of hollows are intersected by horizontal lines at right angles;
  • g) horizontal lines representing an inclined plane look like parallel straight lines.

Often, to clarify relief shapes, additional horizontal lines are used, which are depicted by dash-dotted lines and are called semi-horizontals. Typically, semi-horizontals are usually drawn in cases where the distance between horizontal lines on the plan exceeds 2 cm. In Fig. 3.1, b shows the horizontal image of individual terrain elements.

CATEGORIES

POPULAR ARTICLES

2024 “kingad.ru” - ultrasound examination of human organs