text:
Double-Q spin-density wave in iron arsenide superconductors

Abstract

Elucidating the nature of the magnetic ground state of iron-based superconductors is of paramount importance in unveiling the mechanism behind their high-temperature superconductivity. Until recently, it was thought that superconductivity emerges only from an orthorhombic antiferromagnetic stripe phase, which can in principle be described in terms of either localized or itinerant spins. However, we recently reported that tetragonal symmetry is restored inside the magnetically ordered state of certain hole-doped compounds, revealing the existence of a new magnetic phase at compositions close to the onset of superconductivity. Here, we present Mössbauer data that show that half of the iron sites in this tetragonal phase are non-magnetic, establishing conclusively the existence of a novel magnetic ground state with a non-uniform magnetization that is inconsistent with localized spins. Instead, this state is naturally explained as the interference between two commensurate spin-density waves, a rare example of collinear double-Q magnetic order. Our results demonstrate the itinerant character of the magnetism of the iron pnictides, and the primary role played by magnetic degrees of freedom in determining their phase diagram.

Access options

from\$8.99

All prices are NET prices.

References

1. 1

Slater, J. C. Ferromagnetism and the band theory. Rev. Mod. Phys. 25, 199–210 (1953).

2. 2

Van Vleck, J. H. Models of exchange coupling in ferromagnetic media. Rev. Mod. Phys. 25, 220–227 (1953).

3. 3

Herring, C. in Magnetism (eds Rado, G. T. & Suhl, H.) Vol. IV (Academic, 1966).

4. 4

Moriya, T. & Takahashi, Y. Itinerant electron magnetism. Annu. Rev. Mater. Sci. 14, 1–25 (1984).

5. 5

Chubukov, A. V. Pairing mechanism in Fe-based superconductors. Annu. Rev. Condens. Matter Phys. 3, 57–92 (2012).

6. 6

Hirschfeld, P. J., Korshunov, M. M. & Mazin, I. I. Gap symmetry and structure of Fe-based superconductors. Rep. Prog. Phys. 74, 124508 (2011).

7. 7

Si, Q. & Abrahams, E. Strong correlations and magnetic frustration in the high Tc iron pnictides. Phys. Rev. Lett. 101, 076401 (2008).

8. 8

Seo, K., Bernevig, B. A. & Hu, J. Pairing symmetry in a two-orbital exchange coupling model of oxypnictides. Phys. Rev. Lett. 101, 206404 (2008).

9. 9

de’ Medici, L., Giovannetti, G. & Capone, M. Selective Mott physics as a key to iron superconductors. Phys. Rev. Lett. 112, 177001 (2014).

10. 10

Krüger, F., Kumar, S., Zaanen, J. & van den Brink, J. Spin-orbital frustrations and anomalous metallic state in iron-pnictide superconductors. Phys. Rev. B 79, 054504 (2009).

11. 11

Kontani, H., Inoue, Y., Saito, T., Yamakawa, Y. & Onari, S. Orbital fluctuation theory in iron-based superconductors: s++-wave superconductivity, structure transition, and impurity-induced nematic order. Solid State Commun. 152, 718–727 (2012).

12. 12

Chubukov, A. V., Efremov, D. V. & Eremin, I. Magnetism, superconductivity, and pairing symmetry in iron-based superconductors. Phys. Rev. B 78, 134512 (2008).

13. 13

Cvetkovic, V. & Tešanović, Z. Multiband magnetism and superconductivity in Fe-based compounds. Europhys. Lett. 85, 37002 (2009).

14. 14

Fernandes, R. M. et al. Unconventional pairing in the iron arsenide superconductors. Phys. Rev. B 81, 140501 (2010).

15. 15

Fernandes, R. M., Chubukov, A. V. & Schmalian, J. What drives nematic order in iron-based superconductors? Nature Phys. 10, 97–104 (2014).

16. 16

Johannes, M. & Mazin, I. Microscopic origin of magnetism and magnetic interactions in ferropnictides. Phys. Rev. B 79, 220510 (2009).

17. 17

Hansmann, P. et al. Dichotomy between large local and small ordered magnetic moments in iron-based superconductors. Phys. Rev. Lett. 104, 197002 (2010).

18. 18

Yin, W.-G., Lee, C.-C. & Ku, W. Unified picture for magnetic correlations in iron-based superconductors. Phys. Rev. Lett. 105, 107004 (2010).

19. 19

Yin, Z. P., Haule, K. & Kotliar, G. Kinetic frustration and the nature of the magnetic and paramagnetic states in iron pnictides and iron chalcogenides. Nature Mater. 10, 932–935 (2011).

20. 20

Bascones, E., Valenzuela, B. & Calderón, M. J. Orbital differentiation and the role of orbital ordering in the magnetic state of Fe superconductors. Phys. Rev. B 86, 174508 (2012).

21. 21

Dai, P., Hu, J. & Dagotto, E. Magnetism and its microscopic origin in iron-based high-temperature superconductors. Nature Phys. 8, 709–718 (2012).

22. 22

Avci, S. et al. Structural, magnetic, and superconducting properties of Ba1−xNaxFe2As2 . Phys. Rev. B 88, 094510 (2013).

23. 23

Avci, S. et al. Magnetically driven suppression of nematic order in an iron-based superconductor. Nature Commun. 5, 3845 (2014).

24. 24

Yu, R., Goswami, P., Si, Q., Nikolic, P. & Zhu, J.-X. Superconductivity at the border of electron localization and itinerancy. Nature Commun. 4, 2783 (2013).

25. 25

Böhmer, A. E. et al. Superconductivity-induced re-entrance of the orthorhombic distortion in Ba1−xKxFe2As2 . Nature Commun. 6, 7911 (2015).

26. 26

Allred, J. M. et al. Tetragonal magnetic phase in Ba1−xKxFe2As2 from X-ray and neutron diffraction. Phys. Rev. B 92, 094515 (2015).

27. 27

Hassinger, E. et al. Pressure-induced Fermi-surface reconstruction in the iron-arsenide superconductor Ba1−xKxFe2As2: evidence of a phase transition inside the antiferromagnetic phase. Phys. Rev. B 86, 140502 (2012).

28. 28

Khalyavin, D. D. et al. Symmetry of reentrant tetragonal phase in Ba1−xNaxFe2As2: magnetic versus orbital ordering mechanism. Phys. Rev. B 90, 174511 (2014).

29. 29

Giovannetti, G. et al. Proximity of iron pnictide superconductors to a quantum tricritical point. Nature Commun. 2, 398 (2011).

30. 30

Eremin, I. & Chubukov, A. V. Magnetic degeneracy and hidden metallicity of the spin-density-wave state in ferropnictides. Phys. Rev. B 81, 024511 (2010).

31. 31

Brydon, P. M. R., Schmiedt, J. & Timm, C. Microscopically derived Ginzburg-Landau theory for magnetic order in the iron pnictides. Phys. Rev. B 84, 214510 (2011).

32. 32

Wang, X., Kang, J. & Fernandes, R. M. Magnetic order without tetragonal-symmetry-breaking in iron arsenides: microscopic mechanism and spin-wave spectrum. Phys. Rev. B 91, 024401 (2015).

33. 33

Gastiasoro, M. N. & Andersen, B. M. Competing magnetic double-Q phases and superconductivity-induced re-entrance of C2 magnetic stripe order in iron pnictides. Phys. Rev. B 92, 140506 (2015).

34. 34

Fernandes, R. M., Kivelson, S. A. & Berg, E. Is there a hidden chiral density-wave in the iron-based superconductors? Preprint at http://arXiv.org/abs/1504.03656 (2015).

35. 35

Waßer, F. et al. Spin reorientation in Ba0.65Na0.35Fe2As2 studied by single-crystal neutron diffraction. Phys. Rev. B 91, 060505 (2015).

36. 36

Jo, T. On the possibility of the multiple spin density wave state in the first-kind antiferromagnetic FCC metals. J. Phys. F 13, L211–L216 (1983).

37. 37

Long, M. W. Effects that can stabilise multiple spin-density waves. J. Phys. Condens. Matter 1, 2857–2874 (1989).

38. 38

Fishman, R. S. et al. Structural and magnetic phase transitions in Mn–Ni alloys. Phys. Rev. B 61, 12159–12168 (2000).

39. 39

Cortes-Gil, R. & Clarke, S. J. Structure, magnetism, and superconductivity of the layered iron arsenides Sr1−xNaxFe2As2 . Chem. Mater. 23, 1009–1016 (2011).

40. 40

McGuire, M. A. et al. Phase transitions in LaFeAsO: structural, magnetic, elastic, and transport properties, heat capacity and Mössbauer spectra. Phys. Rev. B 78, 094517 (2008).

41. 41

Kitao, S. et al. Spin ordering in LaFeAsO and its suppression in superconductor LaFeAsO0.89F0.11 probed by Mössbauer spectroscopy. J. Phys. Soc. Jpn 77, 103706 (2008).

42. 42

Fernandes, R. M., Chubukov, A. V., Knolle, J., Eremin, I. & Schmalian, J. Preemptive nematic order, pseudogap, and orbital order in the iron pnictides. Phys. Rev. B 85, 024534 (2012).

43. 43

Lv, W., Wu, J. & Phillips, P. W. Orbital ordering induces structural phase transition and the resistivity anomaly in iron pnictides. Phys. Rev. B 80, 224506 (2009).

44. 44

Yu, R., Zhu, J.-X. & Si, Q. Orbital-selective superconductivity, gap anisotropy, and spin resonance excitations in a multiorbital t-J1-J2 model for iron pnictides. Phys. Rev. B 89, 024509 (2014).

45. 45

Cvetkovic, V. & Vafek, O. Space group symmetry, spin–orbit coupling, and the low-energy effective Hamiltonian for iron-based superconductors. Phys. Rev. B 88, 134510 (2013).

46. 46

Borisenko, S. V. et al. Direct observation of spin–orbit coupling in iron-based superconductors. Nature Phys. http://dx.doi.org/10.1038/nphys3594 (2015).

47. 47

Christensen, M. H., Kang, J., Andersen, B. M., Eremin, I. & Fernandes, R. M. Spin reorientation driven by the interplay between spin–orbit coupling and Hund’s rule coupling in iron pnictides. Phys. Rev. B 92, 214509 (2015).

Acknowledgements

Work at Argonne (J.M.A., K.M.T., D.E.Bugaris, M.J.K., D.Y.C., H.C., M.G.K., S.R., O.C. and R.O.) was supported by the US Department of Energy, Office of Science, Materials Science and Engineering Division. X-ray experiments were performed at the Advanced Photon Source, which is supported by the Office of Basic Energy Sciences under Contract No. DE-AC02-06CH11357. Neutron experiments were performed at the High Flux Isotope Reactor and Spallation Neutron Source. R.M.F. and J.K. were supported by the US Department of Energy, Office of Science, Basic Energy Sciences, under award number DE-SC0012336. The work of I.E. was supported by the Focus Program 1458 Eisen-Pniktide of the DFG, and by the German Academic Exchange Service (DAAD PPP USA no. 57051534). I.E. also acknowledges the financial support of the Ministry of Education and Science of the Russian Federation in the framework of Increase Competitiveness Program of NUST MISiS (N 22014015). The authors thank A. A. Aczel, A. Huq, M. J. Kirkham and P. S. Whitfield for experimental assistance, E. E. Alp for use of his Mössbauer spectrometer, and B. M. Andersen, A. V. Chubukov, M. N. Gastiasoro, A. Yaresko and Y. Zhao for fruitful discussions.

Author information

Samples were prepared by D.E.Bugaris, with additional support from D.Y.C., and M.G.K. The experiments were devised by J.M.A., K.M.T., O.C., S.R. and R.O. The X-ray and neutron diffraction experiments were performed by J.M.A., K.M.T., O.C., M.J.K., S.R. and S.H.L. Mössbauer spectroscopy was performed by D.E.Brown Magnetization measurements were performed by H.C. The data were analysed by J.M.A., K.M.T., O.C., S.R., R.O. and D.E.Brown. Theoretical interpretation was provided by J.K., R.M.F. and I.E. The manuscript and Supplementary Information were written by J.M.A., R.O., R.M.F. and I.E. with input from all the authors.

Correspondence to J. M. Allred.

Ethics declarations

Competing interests

The authors declare no competing financial interests.

Supplementary information

Supplementary information

Supplementary information (PDF 895 kb)

Rights and permissions

Reprints and Permissions

Allred, J., Taddei, K., Bugaris, D. et al. Double-Q spin-density wave in iron arsenide superconductors. Nature Phys 12, 493–498 (2016). https://doi.org/10.1038/nphys3629

• Accepted:

• Published:

• Issue Date:

• Nematic State in CeAuSb2

• S. Seo
• , Xiaoyu Wang
• , S. M. Thomas
• , M. C. Rahn
• , D. Carmo
• , F. Ronning
• , E. D. Bauer
• , R. D. dos Reis
• , M. Janoschek
• , J. D. Thompson
• , R. M. Fernandes
•  & P. F. S. Rosa

Physical Review X (2020)

• Intertwined Vestigial Order in Quantum Materials: Nematicity and Beyond

• Rafael M. Fernandes
• , Peter P. Orth
•  & Jörg Schmalian

Annual Review of Condensed Matter Physics (2019)

• Tuning from frustrated magnetism to superconductivity in quasi-one-dimensional KCr3As3 through hydrogen doping

• , Liurukara D. Sanjeewa
• , Bing-Hua Lei
• , Yuhao Fu
• , Qiang Zheng
• , David J. Singh
• , Athena S. Sefat
•  & Clarina dela Cruz

Physical Review B (2019)

• Distinct pressure evolution of coupled nematic and magnetic orders in FeSe

• Anna E. Böhmer
• , Karunakar Kothapalli
• , Wageesha T. Jayasekara
• , John M. Wilde
• , Bing Li
• , Aashish Sapkota
• , Benjamin G. Ueland
• , Pinaki Das
• , Yumin Xiao
• , Wenli Bi
• , Jiyong Zhao
• , E. Ercan Alp
• , Sergey L. Bud'ko
• , Paul C. Canfield
• , Alan I. Goldman
•  & Andreas Kreyssig

Physical Review B (2019)

• Optical and photoemission investigation of structural and magnetic transitions in the iron-based superconductor Sr0.67Na0.33Fe2As2

• R. Yang
• , J. W. Huang
• , N. Zaki
• , I. Pletikosić
• , Y. M. Dai
• , H. Xiao
• , T. Valla
• , P. D. Johnson
• , X. J. Zhou
• , X. G. Qiu
•  & C. C. Homes

Physical Review B (2019)


text:
# Lingjia Liu's Webpage

### Site Tools

kucourses:eecs769:schedulef16

# EECS 769 Course Schedule

## Fall 2016

### Detailed Schedule

Date Topic Sections Assignment
08/22/2016 Lecture 1: Questionnaire and course objectiveCourse Slides HW0
08/24/2016 Lecture 2: Fundamental questions of information theory Course Slides
08/26/2016 Lecture 3: Entropy and its properties Cover & Thomas 2.1
08/29/2016 Lecture 4: Joint entropy and conditional entropy Cover & Thomas 2.2 HW1
08/30/2016 Lecture 5: Mutual information Cover & Thomas 2.3
09/01/2016 Lecture 6: Relative entropy Cover & Thomas 2.4
09/06/2016 Lecture 7: Data processing inequality and sufficient statistics Cover & Thomas 2.8 - 2.9
09/08/2016 Lecture 8: Fano's inequality & data compression Cover & Thomas 2.10, 5.1 HW2

### Score Board

Real-time score for EECS 769 can be found here.

### A Note on Homework Submission

• Send electronic copy of your homework to “lingjialiu@ittc.ku.edu”.
• Use the title: “EECS_769_HW#” for your submission.
• File name should be: “FirstName_LastName_769_HW#.tex/pdf/doc/docx”.
• If you are submitting your homework using latex, please include the source file (.tex) as well as the pdf file (.pdf).

format: plain


text:
1. ## Using Trigonometric Identity

a) Find the exact value of sin 135 by using sin (180 – 45)

b) Find the exact value of sin 225 by using sin (270 – 45)
b) Use the value of sin 225 found in b to find sin (–15) by using sin (225 – 240)

2. Recall $\displaystyle \sin (180-\theta) = \sin \theta$

so

$\displaystyle \sin 135 = \sin (180-45) = \sin 45 = \dots$

3. Originally Posted by pickslides
Recall $\displaystyle \sin (180-\theta) = \sin \theta$

so

$\displaystyle \sin 135 = \sin (180-45) = \sin 45 = \dots$

but how i can solve part c of the question

4. Are expected to solve the problem by using

sin(A-B) = sinAcosB - cosAsinB ?


text:
# Number entry¶

Number entry parts ask the student to enter a number, which is marked if it is in a specified range.

Marking

Minimum accepted value
The smallest value accepted as correct.
Maximum accepted value
The largest value accepted as correct.
Precision restriction
You can insist that the student gives their answer to a particular number of decimal places or significant figures. For example, if you want the answer to be given to 3 decimal places, $$3.1$$ will fail this restriction, while $$3.100$$ will pass. If the precision doesn’t matter, select None.
Allow the student to enter a fraction?
This option is only available when no precision restriction is applied, since they apply to decimal numbers. If this is ticked, the student can enter a ratio of two whole numbers, e.g. -3/8, as their answer.
Must the fraction be reduced?
This option only applies when “Allow the student to enter a fraction” is ticked. If this is ticked, the student must enter their fractional answer reduced to lowest terms. For example, consider a part whose correct answer is $$5/4$$. If this is ticked, 10/8 will be marked as incorrect.
Display the correct answer as a fraction?
This option is only available when no precision restriction is applied. If this is ticked, the correct answer to the part will be rendered as a fraction of two whole numbers instead of a decimal. For example, if the answer is $$0.5$$, it will be displayed as 1/2 instead of 0.5.
Require trailing zeroes?
This option only applies when a precision restriction is selected. If this is ticked, the student must add zeroes to the end of their answer (when appropriate) to make it represent the correct precision. For example, consider a part whose correct answer is $$1.4$$, and you want the student’s answer to be correct to three decimal places. If “Require trailing zeroes?” is ticked, only the answer $$1.400$$ will be marked correct. If it is not ticked, any of $$1.4$$, $$1.40$$ or $$1.400$$ will be marked as correct. If too many zeroes are used, e.g. $$1.4000$$, the answer is marked as incorrect.
Show precision restriction hint?
If this is ticked, then some text describing the rounding the student must perform is shown next to the input box. For example, “round your answer to 3 decimal places”.
Allowed notation
The styles of number notation that the student can use to enter their answer. There are different ways of writing numbers, based on culture and context. Tick an option to allow the student to use that style in their answer. Note that some styles conflict with each other: for example, 1.234 is a number between 1 and 2 in English, while it’s the integer 1234 in French. The student’s answer will be interpreted using the first allowed style for which it is a valid representation of a number. See Number notation for more on styles of notation.


text:
MathSciNet bibliographic data MR177499 65.15 Jagerman, David L. The autocorrelation and joint distribution functions of the sequences $\{{a\over m}j^2\}$$\{{a\over m}j^2\}$, $\{{a\over m}(j+\tau)^2\}$$\{{a\over m}(j+\tau)^2\}$. Math. Comp. 18 1964 211–232. Article

For users without a MathSciNet license , Relay Station allows linking from MR numbers in online mathematical literature directly to electronic journals and original articles. Subscribers receive the added value of full MathSciNet reviews.

 American Mathematical Society 201 Charles Street Providence, RI 02904-6248 USA


text:
Global Analysis — Global Sobolev spaces

## 2.2 Global Sobolev spaces

To define Sobolev spaces on manifolds, first observe the following lemma:

Lemma

Let $U', V' \subseteq \mathbb {R}^ n$ be open and $\phi : U' \to V'$ a diffeomorphism. If $U \subseteq U'$ is precompact and $V = \phi (U) \subseteq V'$, then the induced map $H^ s(V) \to H^ s(U)$ is a bounded isomorphism for all $s \in \mathbb {Z}$.

The proof is an exercise in the chain rule (for $s \geq 0$) and duality (for $s < 0$). From now on, we always assume $s$ is an integer.

This means it makes sense to define

Definition

Let $M$ be a compact manifold and $E \to M$ a Hermitian vector bundle. Fix an open cover $\{ \varphi _ i: \mathbb {R}^ n \overset {\sim }{\to } U_ i \subseteq M\}$ and a partition of unity $\{ \rho _ i\}$ subordinate to $\varphi _ i$. For any $u \in \Gamma (M, E)$, we define the Sobolev norm by

$\| u\| _ s^2 = \sum _ i \| \rho _ i u \circ \varphi _ i^{-1}\| _ s^2,$

and define $H^ s(M; E)$ to be the completion of $\Gamma (M, E)$ with respect to $\| \cdot \| _ k^ s$.

There is an obvious inner product that gives rise to the Sobolev norm.

One should check for themselves that

Lemma

The norm $\| \cdot \| _ s$ is well-defined up to equivalence, i.e. does not depend on the choice of the $U_ i, \phi _ i, \rho _ i$.

One sees that our local theorems generalize easily to

Lemma
1. There are bounded inclusions $H^ s \to H^ t$ for $s > t$ which are compact.

2. There are bounded inclusions $H^ s \to C^ k$ for $s > \frac{n}{2} + k$.

3. There is a natural duality pairing $H^ s(M; E) \times H^{-s}(M; E) \to \mathbb {C}$.

4. Any differential operator $L: \Gamma (M, E_0) \to \Gamma (M, E_1)$ of order $k$ induces a continuous map $H^{s + k}(E_0) \to H^ s(M; E_1)$.


text:
# Quirk's Performance History

07 Nov 2016

My quantum circuit simulator Quirk is one of those projects that I keep coming back to. For years, I only touched it intermittently. Then, over the past few months, the work kinda took off and I've been stuck in a cycle of "Okay, with that release I think I can set it down now." followed by literally opening 10 issues the next day.

Last month, and this month I suppose, one of those issues was "performance". So I thought it would be interesting to go back and see how Quirk's performance has changed over time, since the beginning. There's probably some lessons to be had (... not original lessons, but lessons nonetheless).

# What I'm Measuring

Quirk doesn't do any fancy algorithmic tricks for computing particular circuits faster. The circuits that people put together with a drag-and-drop GUI just aren't large enough to justify that kind of thing. This makes Quirk's performance essentially circuit-agnostic: the types of gates you use doesn't affect performance much. What matters is how many gates you use, and of course how many wires are present (that's where the exponential costs are).

Circuit agnosticism is great for the purposes of this post, because it makes comparing versions easier. Profiling performance against a single straightforward circuit will tell us basically the whole story.

The choice of circuit to use is mostly arbitrary, but there are a few constraints. The circuit can't be too small, because the interesting question is what blows up as circuits get larger. We don't want to measure the constant-time noise that swamps out the cost of smaller circuits. The circuit also can't be too big, because that would cause unmeasurably bad performance and even OOM errors in the really old versions. Finally, we'll avoid putting inline displays in the circuit, despite that being one of Quirk's most important features, because the non-trivial displays were only added recently.

With those constraints in mind, I decided to go with a 10-qubit quantum fourier transform without the bit reversal step. It has enough gates and wires to be interesting, but not so many that I expect to break the older versions. Here's a diagram of the circuit:

Note that I want to learn about the performance in general on circuits of this size. So I won't be using the specialized QFT or phase gradient gates available in later versions, even though those gates would speed up this particular circuit.

All of my testing will be done in Chrome v54. The machine I'll be testing with is an HP Spectre x360. The CPU is an i7-5500U. The GPU is an integrated HD5500. Testing in other browsers and with other machines is of course a great idea, but just doing the one was already quite a lot of work.

What I'll actually be doing, as the profiler runs, is dragging one of the circuit's gates around. This forces Quirk to constantly react, simulate, and draw. Then I'll pick out a representative frame, made up of "react, simulate, draw" parts, show a screenshot, and discuss a bit.

Enough details, let's travel through time.

# Pre-history

This is a random widget I included in a post near the start of 2014. Quirk grew out of this widget. Unfortunately, it can't do a 10-qubit QFT... I only included it here out of a misguided desire for completeness.

# December 2014

No undo, no bookmarking the state, no build step, no webgl, fuzzy lines because they're off by a half-pixel, weird gate notation, state display outside of the circuit... yeah, that definitely takes me back. (On the other hand, it's only 2500 lines.)

This version doesn't give the user control over the number of wires, so I had to tweak the code to set the number of wires to 10. I immediately regretted that as soon I started building up the circuit. The level of slow was unbearable (so much for that "can't be too big" constraint on the circuit). So I dropped the number of wires to 8.

I entered an 8-qubit QFT, started Chrome's profiler, grabbed one of the gates, dragged it around like crazy, and watched my laptop chug away trying to keep up.

Frame time: 1.5 seconds (after adjusting for the 2-qubit handicap)

One look at the flame graph tells me what prevented me from doing a 10-qubit circuit (looking at flame graphs tends to do useful things like that, they're amazing).

This old version of Quirk is tensoring all of the gates in a column together into a single giant matrix, then smashing that matrix into the state vector. That's simple, but it's also really really inefficient. The matrices defined by single-qubit gates are sparse: you can apply them with a single scan over the state vector, in linear time. The big-fucking-matrix approach, on the other hand, does quadratic amounts of work. Which is kind of a big deal when $n=2^{10}$; literally a thousand times more expensive.

Also, these were not lightweight highly optimized matrices. They were arrays of arrays of instances of a complex number class in javascript. We're talking millions of allocations done to apply each column of gates. That poor garbage collector! No wonder the performance is so bad.

# December 2015

Apparently I hated color in 2015. Could the screenshot BE more drab?

(Keep in mind that, although the version context screenshots I'm showing have Quirk containing 4-qubit circuits, that's only for screenshot-size reasons. I'll always be profiling the 10-qubit circuit unless noted otherwise.)

Intermittently over the course of 2015, I modified Quirk to do its simulation with webgl instead of in javascript. I also rewrote it to use ES6, translated down to ES5 by Traceur. The matrix functions are still horrendously inefficient, but they're not used much anymore. The improvement is quite noticeable:

Frame time: 92ms.

An order of magnitude better than the previous version (accounting for the handicap). GPUs are amazing.

The big performance offender now is these deep spikes of anonymous functions. The root problem is that I like to write code that's very LINQ-y: layering lots of transformations, filters, grouping, and aggregation over iterables. I like it so much that I wrote lots of generator-heavy methods just for that purpose. But Traceur doesn't do a good job of translating generators into efficient ES5 code, and so here we are.

Another big problem here, exacerbated by the generator issue, is the 'pipeline' system the simulation code is using. Instead of just applying shaders, I was building up a graph of which shaders needed which outputs then interpreting over the graph. Sometimes that approach to a computation is useful, but for Quirk it was just actively unhelpful and costly. It's definitely a mistake I wish I could take back.

# March 2016

Glorious color! We jumped from total desaturation to basically what Quirk looks like nowadays. There's lots of minor details missing (e.g. no shadows under the toolbox gates, no details when hovering over displays, always-present 'deferring measurement' label), but it's recognizably Quirk. Very appropriate, since before this point I hadn't named it.

Amongst many other changes, the pipeline code has been taken out and shot. Profiler says... good decision!

Frame time: 41ms.

We halved the frame time. Interestingly, the drawing cost also dropped significantly. I think this might be from switching how I made text fit in the gate boxes: instead of searching for a font-size that resulted in the text not poking out, I used the initial text-width measurement to choose a scale factor to apply to the canvas drawing context before printing.

It's also interesting that the edit time of the circuit has shot up. Something to do with the JSON serialization, done as part of creating a bookmarkable URL for the circuit.

The costly generator code is still rearing its head (I outlined some of it in red), but unfortunately that's not going to be fixed anytime soon. Actually, we're going to be heading the wrong way performance-wise for a bit.

# April 2016

Multi-wire gates in the toolbox! But I had trouble thinking of a discoverable-on-mobile way for users to resize gates, so instead of having single resizable gates the toolbox is exploding with size variants.

April was an "add a feature" month, with no big changes that should have affected performance. There were some optimizations of the matrix code, but only for keeping the tests running quickly when comparing shader effects against a matrix. The matrix code isn't used much during simulation or drawing, so you wouldn't see any gains at runtime.

Frame time: 53ms.

Hahaha, did you laugh, when I said the changes shouldn't affect performance, without any justification? That's just not how performance works. Performance gets worse by default. You have to actively put work into keeping it good. 10ms penalty.

# May 2016

The month of four releases. A lot of stuff was added: three new displays, Fourier and arithmetic gates, the ability to resize gates... that's way more than a month's work for an intermittent weekend project. This is the first version I called attention to by putting it on social media.

Lots of new features, but no focus on measuring or improving performance. So...

Frame time: 75ms.

The performance regression continues. For context, note that in the game industry anything over 16 milliseconds gets laughed out of the room. 60fps or bust. At 75ms per frame, Quirk can't even hit 15fps.

(Weirdly, the flame graph looks quite similar to the previous month's, just with everything taking a bit longer. At first I thought my laptop had been busy or something and spoiled the run, but re-running it later gave similar results.)

# June 2016

Second toolbox has arrived, with plenty of gates in tow. Also, export/undo/redo buttons.

Another feature month, and you know what that means.

Frame time: 53ms.

Wait, what? It got better? Even though the edit cost hit slow generators and went up 50%? Wat?

After some investigation, I think the simulation cost going back to 15ms is because of code to compute the density matrices of pairs of qubits. It was added in May, but not really used by anything, and dropped in June.

As for the same performance-loss-and-recovery happening in the draw code... I think this was the month where I started batching stroke/fill calls to the canvas API.

# September 2016

Dynamic gates with yellow highlight. Arithmetic gates with independent inputs. One fewer default output display. But, most importantly, a 'Make Gate' button. Custom gates at last!

September's changes touched a lot of the circuit definition/simulation code. Gates that use an input need to be paired up with the corresponding input gate, amongst other things. Big risk of performance regressions.

Frame time: 87ms.

Ouch, that's a big hit. Apparently I severely hurt the code computing circuit properties like "does this gate have a problem requiring that it be disabled?". The cost from generators is really getting out of hand.

# October 2016

Looks the same. All the changes were under the hood. iPhone compatibility required working with byte textures, which caused huge shader rewrites.

October touched a lot of shader code, which is performance-sensitive. But the regression from the previous month was bad enough that I had actually noticed it by eye (and I have a terrible eye for frame rate issues). So the other big change in October was a focus on improving performance.

Meaning...

Frame time: 26ms.

This is what happens when you let things regress for awhile, then open up a profiler and get serious. Immediate massive improvement. (26 is nothing to brag about, but at least it's not frickin 87.)

The profiler told me the generators were slow, and where they were slowest. I switched to for loops where appropriate. The profiler told me that drawing the toolboxes was taking 10 milliseconds. I switched to drawing them once and caching the image data. The profiler told me a lot of useful things. The profiler is still telling me a lot of useful things.

# Future

I added perf tests as a way to prevent future regressions in performance. But that's not enough.

(Does anyone know how to get travis-ci, or another free continuous integration service, to run WebGL code? Add an answer to this stackoverflow question.)

Even without regressions, editing 16 qubit circuits (the maximum size that Quirk permits) feels slow and clunky. It always has. Another month of performance gains is required. Based on profiling a 16-qubit circuit, the big problem is the drawing code:

If I want to get under 30ms per frame for 16-qubit circuits, I can't draw the huge amplitude displays with canvas commands anymore. I have to do it with the GPU. Also I need to do more caching of repeated visual elements.

More long term, if I want to even think about getting below 16ms per frame, I need to avoid the cost of syncing up with the GPU. That would require quite a lot of re-architecting, because it means I can't call readPixels and all displays would have to be drawn GPU-side (including their text-heavy tooltips). Also I'd need to learn how to properly profile and optimize shaders.

It's a lot of work to do for a toy quantum circuit simulator. But, somehow, it's the toy projects that are the most engaging. So who knows.

# Summary

• Don't write horribly inefficient matrix code that does millions of allocations.
• Don't use ES6-to-ES5 generators on hot paths.
• Don't forget to track performance when adding features.
• Do use the GPU.
• Do use Chrome's profiler.
• Do cache image data of elements always drawn the same way.
• There's still a long way to go.
 « Unfathomable Bugs #9: Lossy Shader Packing Half-Baked Thoughts for a Quantum Scripting Language »


text:
# how to perform classification using function train in caret in R

I have 20 classes, and I want to classify and predict class label:

library("caret")
model=train(x=df_train,y=train_class, method="nnet")
pred=predict(model,df_test)

The output of pred is real number (it performs regression), How can I ask to return me prediction of class labels?

## 1 Answer

This question might be better suited to stackoverflow, though you have not given a reproducible example.

The following predicts the species class label for the iris dataset, adapting the example from ?train

library(caret)
library(MASS)
data(iris)
set.seed(1)
TestRows     <- c(sample(50,15), sample(50,15)+50, sample(50,15)+100)
TrainData    <- iris[-TestRows,1:4]
TrainClasses <- iris[-TestRows,5]
TestData     <- iris[TestRows,1:4]
TestClasses  <- iris[TestRows,5]
nnetFit <- train(x=TrainData, y=TrainClasses,
method = "nnet",
preProcess = "range",
tuneLength = 2,
trace = FALSE,
maxit = 100)

and gives the following result for the training set:

> table(TrainClasses, predict(nnetFit))

TrainClasses setosa versicolor virginica
setosa         35          0         0
versicolor      0         34         1
virginica       0          1        34

and for the test set

> table(TestClasses,  predict(nnetFit,TestData))

TestClasses  setosa versicolor virginica
setosa         15          0         0
versicolor      0         15         0
virginica       0          3        12

which I find surprisingly accurate for the versicolor/virginica distinction

• Thank you for the solution. But, when I apply to my data predict(nnetFit,TestData)[1] is 0.9923. It returns regression prediction of my data. I think the problem comes from levels of data. levels(iris) shows the three classes but levels(myData) is Null. Do this levels is problem? how to fix this? – Cina Apr 16 '17 at 7:11
• No - this works without levels in the input data. But without seeing your data, it is difficult to say much more. What type of data is your train_class – Henry Apr 16 '17 at 8:03


text:
# Course

## M473 - Algebraic Combinatorics

Course No:
M473
Credit:
4
Prerequisites:
M202
Approval:
2014
UG-Elective
Syllabus:
Catalan Matrices and Orthogonal Polynomials, Catalan Numbers and Lattice Paths, Combinatorial Interpretation of Catalan Numbers, Symmetric Polynomials and Functions, Schur Functions, Jacobi-Trudi identity, RSK Algorithm, Standard Tableaux, Young diagrams and q-binomial coefficients, Plane Partitions, Group actions on boolean algebras, Enumeration under group action, Walks in graphs, Cubes and the Radon transform, Sperner property, Matrix-Tree Theorem.
Reference Books:
1. R. P. Stanley, “Algebraic Combinatorics”, Undergraduate Texts in Mathematics, Springer, 2013.
2. M. Aigner, “A Course in Enumeration”, Graduate Texts in Mathematics 238, Springer, 2007.
3. R. P. Stanley, “Enumerative Combinatorics Vol. 2”, Cambridge Studies in Advanced Mathematics 62, Cambridge University Press, 1999.


text:
# nLab locally connected topos

### Context

#### Topos Theory

Could not include topos theory - contents

# Contents

## Idea

A topos may be thought of as a generalized topological space. Accordingly, the notions of

have analogs for toposes and (∞,1)-toposes

## Definition

###### Definition

An object $A$ in a topos $\mathcal{E}$ is called a connected object if the hom-functor $\mathcal{E}(A, -)$ preserves finite coproducts.

Equivalently, an object $A$ is connected if it is nonempty (noninitial) and cannot be expressed as a coproduct of two nonempty subobjects.

###### Definition

A Grothendieck topos $\mathcal{E}$ is called a locally connected topos if every object $A \in \mathcal{E}$ is a coproduct of connected objects $\{A_i\}_{i \in I}$, $A = \coprod_{i \in I} A_i$.

It follows that the index set $I$ is unique up to isomorphism, and we write

$\pi_0(A) = I \,.$

This construction defines a functor $\Pi_0 : E \to Set : A \mapsto \pi_0(A)$ which is left adjoint to the constant sheaf functor, the left adjoint part of the global section geometric morphism.

Thus, for a locally connected topos we have

$(\Pi_0 \dashv L Const \dashv \Gamma) : \mathcal{E} \stackrel{\overset{\Pi_0}{\to}}{\stackrel{\overset{Const}{\leftarrow}}{\underset{\Gamma}{\to}}} Set \,.$

This is the connected component functor. It generalises the functor, also denoted $\pi_0$ or $\Pi_0$, which to a topological space assigns the set of connected components of that space. See the examples below.

The following proposition asserts that the existence of $\Pi_0$ already characterizes locally connected toposes.

###### Proposition

A Grothendieck topos $\mathcal{E}$ is locally connected precisely if the global section geometric morphism $\Gamma : \mathcal{E} \to Set$ is an essential geometric morphism $(\Pi_0 \dashv L Const \dashv \Gamma) : \mathcal{E} \to Set$.

A proof appears as (Johnstone, lemma C.3.3.6).

###### Proof

Suppose that $(\Pi_0 \dashv L Const \dashv \Gamma) : \mathcal{E} \to Set$ exists.

First notice that an object $A$ is connected in the above sense precisely if $\Pi_0(A) = *$.

Because for all $S \in Set$ the connectivity condition demands that

$\mathcal{E}(A, \coprod_S L Const *) \simeq \coprod_S \mathcal{E}(A,*) \simeq \coprod_S * \simeq S$

but by the $(\Pi_0 \dashv L Const)$-hom-equivalence the first term is

$\cdots \simeq \mathcal{E}(A, L Const \coprod_S *) \simeq Set(\Pi_0(A), S)$

and the last set is isomorphic to $S$ precisely for $\Pi_0(A)$ is the singleton set.

So we need to show that given the extra left adjoint $\Pi_0$, every object of $\mathcal{E}$ is a coproduct of objects for which $\Pi_0(-)$ is the point.

For that purpose consider for every object $A \in \mathcal{E}$ the pullback diagram

$\array{ i_A^* {\lim_\to}_{\Pi_0(A)} * &\to& {\lim_\to}_{\Pi_0(A)} * \\ {}^{\mathllap{\simeq}}\downarrow && \downarrow^{\mathrlap{\simeq}} \\ A &\stackrel{i_A}{\to}& L Const \Pi_0 (A) } \,,$

where the bottom morphism is the $(\Pi \dashv L Const)$-unit and the right isomorphism is the identification of any set as the colimit (here: coproduct) of the functor over the set itself that is constant on the point. Since pullbacks of isomorphism are isomorphisms, also the left morphism is an iso.

By universal colimits this left morphism is equivalently

${\lim_\to}_{s \in \Pi_0(A)} (i_A^* *_s) \stackrel{\simeq}{\to} A$

and hence expresses $A$ as a coproduct of objects $i_A * *_s$, each of which is a pullback

$\array{ i_A^* *_s &\to& L Const * \\ \downarrow && \downarrow^{\mathrlap{s}} \\ A &\stackrel{i_A}{\to}& L Const \Pi_0 A } \,,$

where the right morphism includes the element $s$ into the set $\Pi_0 A$. By applying $\Pi_0$ to this diagram and pasting on the $(\Pi_0 \dashv L Const)$-counit we get

$\array{ \Pi_0(i_A^* *_s) &\to& \Pi_0 L Const * &\to& * \\ \downarrow && \downarrow^{} && \downarrow \\ \Pi_0(A) &\stackrel{\Pi_0(i_A)}{\to}& \Pi_0 L Const \Pi_0 A &\to& \Pi_0 A }$

and by the zig-zag identity the bottom morphism is the identity. This says that in

$\Pi_0( {\lim_{\to}}_{\Pi_0 A} i_A^* *_s \stackrel{\simeq }{\to} A) \simeq ({\lim_\to}_{\Pi_0 A} \Pi_0(i_A^* *_s) \stackrel{\simeq}{\to} \Pi_0(A))$

all the component maps out of the coproduct factor through the point. This means that this can only be an isomorphism if all these component maps are point inclusions, hence if $\Pi_0(i_A^* *_s) \simeq *$ for all $s \in \Pi_0 A$.

However, this doesn’t mean that essential geometric morphisms are the “relative” analog of locally connected toposes; in general one needs to impose an additional condition, which is automatic in the case of the global sections morphism, to obtain the notion of a locally connected geometric morphism.

## Properties

### Characterization over locally connected sites

See at locally connected site.

### Equivalent conditions

###### Definition

For $C$ and $C$ cartesian closed categories, a functor $F : C \to D$ that preserves products is called a cartesian closed functor if the canonical natural transformation

$F(B^A) \to (F(B))^{F(A)}$

(which is the adjunct of $F(A) \times F(B^A) \simeq F(A \times B^A) \to F(B)$) is an isomorphism.

###### Proposition

The constant sheaf-functor $\Delta : \mathcal{S} \to \mathcal{E}$ is a cartesian closed functor precisely if $\mathcal{E}$ is a locally connected topos.

### Locally connected and connected

A topos $E$ is called a connected topos if the left adjoint $L Const : Set \to E$ is a full and faithful functor.

###### Proposition

If $\Gamma \colon E\to Set$ is a locally connected topos, then it is also a connected topos — in that $L Const$ is full and faithful — if and only if the left adjoint $\Pi_0$ of $L Const$ preserves the terminal object.

This is (Johnstone, C3.3.3).

Notice that for a connected and locally connected topos, the adjunction

$Set \stackrel{\overset{\Pi_0}{\leftarrow}}{\hookrightarrow} E$

exhibits Set as a reflective subcategory of $E$. We may think then of Set as being the localization of $E$ at those morphisms that induce isomorphisms of connected components.

## Examples

###### Example

For $X$ a topological space, the category of sheaves $Sh(X) \coloneqq Sh(Op(X))$ is a locally connected topos precisely if $X$ is a locally connected space. The functor $\Pi_0$ sends a sheaf $F \in Sh(X)$ to the set of connected components of the corresponding etale space.

###### Example

For $C =$ CartSp the site of Cartesian spaces with its good open cover coverage, the topos $Sh(CartSp)$ of smooth spaces is locally connected. An arbitrary $X \in Sh(CartSp)$ is sent to the colimit $\lim_\to X \in Set$. If $X$ is a diffeological space or even a smooth manifold, then this is the set of connected components of the underlying topological space.

###### Example

Suppose that $C$ is a site such that constant presheaves on $C$ are sheaves. Then the left adjoint $\Pi_0$ exists and is given by the colimit functor: if we write $L : PSh(C) \to Sh(C)$ for sheafification, then for any sheaf $X$, we have

$Hom_{Sh(C)}(X, L Const S) \simeq Hom_{PSh(C)}(X, L Const S) \simeq Hom_{PSh(C)}(X, Const S) \simeq Hom_{Set}(\lim_\to X, S) \,.$

In particular, this is the case if every covering sieve in $C$ is connected, i.e. $C$ is a locally connected site.

If $C$ furthermore has a terminal object $1$, then the global sections functor $\Gamma\colon Sh(C)\to Set$ (the right adjoint of $L Const$) is simply given by evaluation at $1$, and so the unit $S \to \Gamma L Const S \cong L Const S(1)$ is an isomorphism. Thus in this case $Sh(C)$ is additionally connected. This situation also applies to $C=CartSp$ in example 2 above.

###### Example

If $C$ is a category with all finite limits and if the unique functor $\pi \colon C \to \ast$ to the terminal category preserves covers (for $\ast$ equipped with the trivial topology/coverage) then $Sh(C)$ is locally connected. This is because the inclusion of the terminal object $i \colon \ast \to C$ provides a right adjoint to $\pi$, so that there is an adjoint quadruple of functors on presheaf categories

$(\pi_! \simeq Lan_\pi) \dashv (\pi^\ast \simeq i_! \simeq Lan_i) \dashv (pi_\ast \simeq i^\ast ) \dashv (\pi^! \simeq i_* \simeq Ran_i) \;\colon\; PSh(C) \leftrightarrow PSh(\ast) \simeq Sh(C) \simeq Set \,,$

where $Lan_{(-)}$ and $Ran_{(-)}$ denote let and right Kan extension, respectively. Now if $C \to \ast$ indeed preserves covers and using that $C \to \ast$ trivially preserves finite limits and hence is a flat functor, then by the discussion at morphism of sites the first three functors here descend to sheaves and hence exhibit $Sh(C)$ as being locally connected.

But beware that the assumptions here are stronger than they may seem: that $C \to \ast$ preserves covers is not automatic, but is a strong condition. It is violated as soon as $C$ contains an empty object with empty cover, such as is the case in most categories of spaces, notably in categories of open subsets $Op(X)$ of a topological space $X$, as in example 1.

## References

Section C1.5 and C3.3 of

A variant is in

Discussion of characterizations of sites of definition of locally connected toposes is in

• Olivia Caramello, Site characterizations for geometric invariants of toposes, Theory and Applications of Categories, Vol. 26, 2012, No. 25, pp 710-728. (TAC)

Revised on June 20, 2013 03:35:39 by Urs Schreiber (82.169.65.155)


text:
# 4.S: Reactions in Aqueous Solution (Summary)

aqueous solutions – solutions in which water is the dissolving medium

## 4.1: General Properties of Aqueous Solutions

• electrolyte – substance whose aqueous solution contains ions
• nonelectrolyte – substance that does not form ions in solution

### 4.2.1 Ionic Compounds in Water

• dissociate – when ions separate from a solid being dissolved

### 4.2.2 Molecular Compounds in Water

• the molecular structure is maintained

### 4.2.3 Strong and Weak Electrolytes

• strong electrolytes – ionic compounds that exists entirely of ions in solution
• weak electryolytes – molecular compounds that produce a small amound of ions
• chemical equilibrium – equilibrium of forming ions and recrystalizing ions

## 4.2: Precipitation Reactions

$AX + BY \rightarrow AY + BX \nonumber$

• for methathesis to occur:
1. the formation of an insoluble product
2. the formation of either a weak electrolyte or a nonelectrolyte
3. the formation of a gas that escapes from solution

### 4.5.1 Precipitation Reactions

• precipitate – insoluble solid formed by a reaction in solution
• solubility – amount of substance that can be dissolved in a given quantity

### 4.5.2 Solubility Guidelines for Ionic Compounds

• all common ionic compounds of the alkali metal ions and of the ammonium ion are soluble in water

### 4.5.3 Reactions in Which a Weak Electrolyte or Nonelectrolyte Forms

• hydrogen and hydroxide react to form water
• insoluble metal oxides react with acids

## 4.3: Acid-Base Reactions

### 4.3.1 Acids

• substances that ionize to form hydrogen ions
• proton donors

### 4.3.2 Bases

• substances that ionize to form hydroxide ions

### 4.3.3 Strong and Weak Acids and Bases

• strong acid, strong base – strong electrolyte
• weak acid, weak base – weak electrolyte

### 4.3.4 Neutralization Reactions and Salts

• neutralization reaction – when an acid and base are mixed
• produces water and a salt

### 4.4 Ionic Equations

• molecular formula – and equation written to show the complete chemical formulas of reactants and products
• spectator ions – ions that do not play a role in a reaction
• net ionic equation – equation where the spectator ions are removed
• only soluble strong electrolytes are written in ionic form

## 4.4: Oxidation-Reduction Reactions

### 4.6.1 Reactions in Which a Gas Forms

• carbonates and bicarbonates

### 4.6.2 Oxidation and Reduction

• oxidation – loss of electrons
• reduction – gain of electrons

### 4.6.3 Oxidation of Metals by Acids and Salts

• whenever one substance is oxidized, some other substance must be reduced
• metals react with acids to form salts and hydrogen gas

### 4.6.4 The Activity Series

• activity series – list of metals arranged in order of decreasing ease of oxidation
• active metals – alkali metals and alkaline earth metals
• any metal on the list can be oxidized by ions of elements below it

## 4.5: Concentration of Solutions

• solution – homogeneous mixture of two or more substances
• solvent – component that is present in greatest quantity
• solutes – substances dissolved in the solvent

### 4.1.1 Molarity

• concentration – the amount of solute dissolved in a given quantity of solvent or solution
• molarity – number of moles of solute in a liter of solution

### 4.1.2 Dilution

• dilution - obtaining a lower concentration of a solution by adding water
• moles solute before dilution = moles solute after dilution

## 4.6: Solution Stoichiometry and Chemical Analysis

### 4.7.1 Titrations

• statndard solution – solution of known concentration
• titration – a known solution that undergoes a specific chemical reaction of known stoichiometry with the solution of unknown concentration
• equivalence point – stoichiometrically equivalent quantities of reactants are brought together
• indicator – used to show the endpoint of the titration

4.S: Reactions in Aqueous Solution (Summary) is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by LibreTexts.


text:
# EPS-HEP2019

Jul 10 – 17, 2019
Ghent
Europe/Brussels timezone

## The CMS Tracker Upgrade for the High Luminosity LHC

Jul 11, 2019, 12:30 PM
15m
Campus Ledeganck - Aud. 4 (Ghent)

### Campus Ledeganck - Aud. 4

#### Ghent

Parallel talk Detector R&D and Data Handling

### Speaker

Simone Paoletti (Universita e INFN, Firenze (IT))

### Description

The LHC machine is planning an upgrade program which will smoothly bring the luminosity to about $5-7.5\times10^{34}$cm$^{-2}$s$^{-1}$ in 2028, to possibly reach an integrated luminosity of $3000-4500\;$fb$^{-1}$ by the end of 2039. This High Luminosity LHC scenario, HL-LHC, will require an upgrade program of the LHC detectors known as Phase-2 upgrade. The current CMS Outer Tracker, already running beyond design specifications, and CMS Phase-1 Pixel Detector will not be able to survive HL-LHC radiation conditions and CMS will need completely new devices, in order to fully exploit the highly demanding conditions and the delivered luminosity. The new Outer Tracker should have also trigger capabilities. To achieve such goals, R\&D activities have explored options for both the Outer Tracker and for the Inner Tracker. The solutions developed will allow to include tracking information in the first level trigger stage. The design choices for the Tracker upgrades are discussed along with some highlights on technological approaches and R\&D activities.

### Primary author

Arnd Meyer (Rheinisch Westfaelische Tech. Hoch. (DE))


text:
# HoldForm is not working as I would expect

Why HoldForm do this?

HoldForm[a/b \[Integral]f[x] \[DifferentialD]x]

Output is this ugly looking formula: $$\frac{a \int f(x) \, dx}{b}$$

I want the output to look exactly same as I typed it: $$\frac{a}{b} \int f(x) \, dx$$

What is the purpose of HoldForm when it does not hold the form of expression as it has been typed?

It always rearranges fractions from $$\frac{a}{b} c$$ to $$\frac{a c}{b}$$.

(The basic idea is from this answer by xzczd.)

Try this:

MakeBoxes[Times[a_, b_], StandardForm] := RowBox[{MakeBoxes@a, MakeBoxes@b}]
MakeBoxes[Times[a_, Power[b_, -1]], StandardForm] := MakeBoxes[Divide[a, b]]

Now

Hold[a/b  \[Integral]f[x] \[DifferentialD]x]

• While this will not preserve the input box structure exactly, it seems to be surprisingly robust and is very simple. Nice! May 8 at 13:19
• @LukasLang Yes, technically this method doesn't do what was requested in the question: it does not hold the form of expression "as it has been typed". It just produces the formatting the OP wished to get. May 8 at 13:39
• @LukasLang The only simple way to get exactly the form in which the expression was typed is to take the box form of the expression directly from the cell when the expression was typed. Then wrap the extracted boxes with RawBoxes for producing the output. May 8 at 13:45

### Why it happens

When you enter an expression and evaluate it in Mathematica, MakeExpression is used to convert the box expression (i.e. the description of the exact input you entererd) into an expression. For example, when you enter f[a] into a Notebook, what Mathematica sees is RowBox[{"f","[","a","]"}] (you can use Cell > Show expression to see this). Only after MakeExpression is applied, is it actually converted to f[a].

Similar conversions happen for all other types of valid input. In particular, this process removes certain kinds of information from the input. For example, a+b, a+(b), Plus[a,b] are all converted to a+b. At this point, it is too late to tell how a+b was entered. Something similar is happening in your case, only that Times and Plus have some additional simplification rules that are applied during these early phases. To prevent this from happening, we have to interfere with this process at or before the MakeExpression step, see below for an example of how to do that.

### Workaround

Here's a solution similar to what the Notation  paclet does:

HoldBoxesTemplate[t_] :=
TemplateBox[{t}, "HoldBoxes", DisplayFunction -> (# &)]
MakeExpression[TemplateBox[{b_}, "HoldBoxes", ___], frm_] :=
HoldComplete@HoldBoxes[b, frm]
MakeBoxes[HoldBoxes[b_, _], _] ^:=
HoldBoxesTemplate[b]
Normal@HoldBoxes[b_, frm_] ^:=
ReleaseHold@MakeExpression[b, frm]
AppendTo[CurrentValue[EvaluationNotebook[], InputAliases],
"hb" -> HoldBoxesTemplate["\[Placeholder]"]];

You can now press EschbEsc to insert a placeholder that will keep its contents in exactly the same shape:

The trick is to have an invisible TemplateBox around your expression that ensures the box structure is preserved through MakeExpression, rather than being converted into a normal expression (at which point there expression has already been "canonicalized", so that it's no longer possible to reconstruct the original shape). The expression returned is of the form HoldBoxes[...]:

• Interesting but rather complicated. If nobody comes with a simpler method I will accept your answer. May 8 at 13:14

It is just enough to wrap a/b. Try this:

Have fun!

• What is the point of your answer? If I have complex expression that contains several compound fractions I will not rewrite it with lots of HoldForm inside in appropriate positions. For such a manual work I would use rather Latex than Mathematica. HoldForm` is simply not doing what it claims it should do. And that is the problem, not that I would not know how to do it manually. May 8 at 11:52
• @azerbajdzan What is the point of your comment? 1. Mma is just constructed in such a way as it is. It is not arranged to return results in a beautiful form. It is not a Latex. 2. If you have a "complex expression that contains several compound fractions " you should write this directly in your question. I must not guess what exactly do you have in mind. May 8 at 17:15


text:
# Create Wall 3D math oriented away from camera

I have 2 Points which has x,y,z let's say from and to I am drawing wall between them using ARkit ios

To draw wall I use static height let's say 5 Meters

    node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
from.y + height * 0.5,
from.z + (to.z - from.z) * 0.5)

now I use following code to set angles

       // orientation of the wall is fairly simple. we only need to orient it around the y axis,
// and the angle is calculated with 2d math.. now this calculation does not factor in the position of the
// camera, and so if you move the cursor right relative to the starting position the
// wall will be oriented away from the camera (in this app the wall material is set as double sided so you will not notice)
// - obviously if you want to render something on the walls, this issue will need to be resolved.

node.eulerAngles = SCNVector3(0,
-atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5,
0)

And I am rendering video into the wall.

Issue is If I draw from point1 to point2 (drag to right) Video is perfectly fine. But I start from point2 to point1 video is flipped because ofeulerAngles is different in both case

Angle point1 to point2 --> (0.000000 -1.000000 0.000000 3.735537)

Angle point2 to point1 -- > (0.000000 -1.000000 0.000000 0.478615)

Here is uploaded images of result

https://stackoverflow.com/questions/53282351/arkit-add-2d-video-flipped-by-x

Any help would be appreciated.

## 1 Answer

I have fixed issue with temporary solution still looking for a better one

Issue is of wall. wall is flipped other side of camera when draw from right to left direction. I have figure it out by setting isDoubleSided = false and by applying a image as diffuse contents which has text and I can see that image is flipped itself.

I have tried many things but this one helps me

1. Normalize vector
2. Find the cross between to SCNVectors
3. If y > 0 I just swapped from and to Value

Code

    let normalizedTO = to.normalized()
let normalizedFrom = from.normalized()
let angleBetweenTwoVectors = normalizedTO.cross(normalizedFrom)

var from = from
var to = to
if angleBetweenTwoVectors.y > 0 {
let temp = from
from = to
to = temp
}

// Inside extension of SCNVector3
func normalized() -> SCNVector3 {
if self.length() == 0 {
return self
}

return self / self.length()
}

func cross(_ vec: SCNVector3) -> SCNVector3 {
return SCNVector3(self.y * vec.z - self.z * vec.y, self.z * vec.x - self.x * vec.z, self.x * vec.y - self.y * vec.x)
}

Hope it is helpful. If anyone know better solution please answer it.


text:
# Series of a sub sequence which converges in $\mathbb{C}$

I came across an old question in the analysis course I am studying which goes like this:

Assume that $$(x_n)_{n \in \mathbb{N}}$$ is a sequence which converges to $$0$$ in $$\mathbb{C}$$. Is there always a sub sequence $$(x_{n_k})_{n \in \mathbb{N}}$$ such that the series $$\sum_k x_{n_k}$$ converges absolutely? If yes prove, if not give a counter example.

My first intuition looking at the questions is to that that the answer is yes, but I'm not really sure how to go about proving it. I know that in $$\mathbb{R}$$ if a sequence has a limit and converges, then every sub sequence has the same limit and converges as well. Thus given that the original sequence converges to $$0$$ then each sub sequence must also converge to $$0$$ and the sum of any of these sub sequences would also converge.

Is this correct or am I wrong from the start? Any help is appreaciated

Since $$x_n$$ converges towards zero, for every $$k$$ there exists $$n_k$$ such that $$|x_{n_k}|<{1\over 2^k}$$. $$\sum x_{n_k}$$ converges absolutely.


text:
String (computer Science)
Strings are applied e.g. in Bioinformatics to describe DNA strands composed of nitrogenous bases.

In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to be mutated and the length changed, or it may be fixed (after creation). A string is generally understood as a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding. A string may also denote more general arrays or other sequence (or list) data types and structures.

Depending on programming language and precise data type used, a variable declared to be a string may either cause storage in memory to be statically allocated for a predetermined maximum length or employ dynamic allocation to allow it to hold a variable number of elements.

When a string appears literally in source code, it is known as a string literal or an anonymous string.[1]

In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set called an alphabet.

## Formal theory

Let ? be a non-empty finite set of symbols (alternatively called characters), called the alphabet. No assumption is made about the nature of the symbols. A string (or word) over ? is any finite sequence of symbols from ?.[2] For example, if ? = {0, 1}, then 01011 is a string over ?.

The length of a string s is the number of symbols in s (the length of the sequence) and can be any non-negative integer; it is often denoted as |s|. The empty string is the unique string over ? of length 0, and is denoted ? or ?.[2][3]

The set of all strings over ? of length n is denoted ?n. For example, if ? = {0, 1}, then ?2 = {00, 01, 10, 11}. Note that ?0 = {?} for any alphabet ?.

The set of all strings over ? of any length is the Kleene closure of ? and is denoted ?*. In terms of ?n,

${\displaystyle \Sigma ^{*}=\bigcup _{n\in \mathbb {N} \cup \{0\}}\Sigma ^{n}}$

For example, if ? = {0, 1}, then ?* = {?, 0, 1, 00, 01, 10, 11, 000, 001, 010, 011, ...}. Although the set ?* itself is countably infinite, each element of ?* is a string of finite length.

A set of strings over ? (i.e. any subset of ?*) is called a formal language over ?. For example, if ? = {0, 1}, the set of strings with an even number of zeros, {?, 1, 00, 11, 001, 010, 100, 111, 0000, 0011, 0101, 0110, 1001, 1010, 1100, 1111, ...}, is a formal language over ?.

### Concatenation and substrings

Concatenation is an important binary operation on ?*. For any two strings s and t in ?*, their concatenation is defined as the sequence of symbols in s followed by the sequence of characters in t, and is denoted st. For example, if ? = {a, b, ..., z}, s = bear, and t = hug, then st = bearhug and ts = hugbear.

String concatenation is an associative, but non-commutative operation. The empty string ? serves as the identity element; for any string s, ?s = s? = s. Therefore, the set ?* and the concatenation operation form a monoid, the free monoid generated by ?. In addition, the length function defines a monoid homomorphism from ?* to the non-negative integers (that is, a function ${\displaystyle L:\Sigma ^{*}\mapsto \mathbb {N} \cup \{0\}}$, such that ${\displaystyle L(st)=L(s)+L(t)\quad \forall s,t\in \Sigma ^{*}}$).

A string s is said to be a substring or factor of t if there exist (possibly empty) strings u and v such that t = usv. The relation "is a substring of" defines a partial order on ?*, the least element of which is the empty string.

### Prefixes and suffixes

A string s is said to be a prefix of t if there exists a string u such that t = su. If u is nonempty, s is said to be a proper prefix of t. Symmetrically, a string s is said to be a suffix of t if there exists a string u such that t = us. If u is nonempty, s is said to be a proper suffix of t. Suffixes and prefixes are substrings of t. Both the relations "is a prefix of" and "is a suffix of" are prefix orders.

### Rotations

A string s = uv is said to be a rotation of t if t = vu. For example, if ? = {0, 1} the string 0011001 is a rotation of 0100110, where u = 00110 and v = 01.

### Reversal

The reverse of a string is a string with the same symbols but in reverse order. For example, if s = abc (where a, b, and c are symbols of the alphabet), then the reverse of s is cba. A string that is the reverse of itself (e.g., s = madam) is called a palindrome, which also includes the empty string and all strings of length 1.

### Lexicographical ordering

It is often useful to define an ordering on a set of strings. If the alphabet ? has a total order (cf. alphabetical order) one can define a total order on ?* called lexicographical order. For example, if ? = {0, 1} and 0 < 1, then the lexicographical order on ?* includes the relationships ? < 0 < 00 < 000 < ... < 0001 < 001 < 01 < 010 < 011 < 0110 < 01111 < 1 < 10 < 100 < 101 < 111 < 1111 < 11111 ... The lexicographical order is total if the alphabetical order is, but isn't well-founded for any nontrivial alphabet, even if the alphabetical order is.

See Shortlex for an alternative string ordering that preserves well-foundedness.

### String operations

A number of additional operations on strings commonly occur in the formal theory. These are given in the article on string operations.

### Topology

(Hyper)cube of binary strings of length 3

Strings admit the following interpretation as nodes on a graph:

• Fixed-length strings can be viewed as nodes on a hypercube
• Variable-length strings (of finite length) can be viewed as nodes on the k-ary tree, where k is the number of symbols in ?
• Infinite strings (otherwise not considered here) can be viewed as infinite paths on the k-ary tree.

The natural topology on the set of fixed-length strings or variable-length strings is the discrete topology, but the natural topology on the set of infinite strings is the limit topology, viewing the set of infinite strings as the inverse limit of the sets of finite strings. This is the construction used for the p-adic numbers and some constructions of the Cantor set, and yields the same topology.

Isomorphisms between string representations of topologies can be found by normalizing according to the lexicographically minimal string rotation.

## String datatypes

A string datatype is a datatype modeled on the idea of a formal string. Strings are such an important and useful datatype that they are implemented in nearly every programming language. In some languages they are available as primitive types and in others as composite types. The syntax of most high-level programming languages allows for a string, usually quoted in some way, to represent an instance of a string datatype; such a meta-string is called a literal or string literal.

### String length

Although formal strings can have an arbitrary (but finite) length, the length of strings in real languages is often constrained to an artificial maximum. In general, there are two types of string datatypes: fixed-length strings, which have a fixed maximum length to be determined at compile time and which use the same amount of memory whether this maximum is needed or not, and variable-length strings, whose length is not arbitrarily fixed and which can use varying amounts of memory depending on the actual requirements at run time. Most strings in modern programming languages are variable-length strings. Of course, even variable-length strings are limited in length - by the number of bits available to a pointer, and by the size of available computer memory. The string length can be stored as a separate integer (which may put an artificial limit on the length) or implicitly through a termination character, usually a character value with all bits zero. See also "Null-terminated" below.

### Character encoding

String datatypes have historically allocated one byte per character, and, although the exact character set varied by region, character encodings were similar enough that programmers could often get away with ignoring this, since characters a program treated specially (such as period and space and comma) were in the same place in all the encodings a program would encounter. These character sets were typically based on ASCII or EBCDIC.

Logographic languages such as Chinese, Japanese, and Korean (known collectively as CJK) need far more than 256 characters (the limit of a one 8-bit byte per-character encoding) for reasonable representation. The normal solutions involved keeping single-byte representations for ASCII and using two-byte representations for CJK ideographs. Use of these with existing code led to problems with matching and cutting of strings, the severity of which depended on how the character encoding was designed. Some encodings such as the EUC family guarantee that a byte value in the ASCII range will represent only that ASCII character, making the encoding safe for systems that use those characters as field separators. Other encodings such as ISO-2022 and Shift-JIS do not make such guarantees, making matching on byte codes unsafe. These encodings also were not "self-synchronizing", so that locating character boundaries required backing up to the start of a string, and pasting two strings together could result in corruption of the second string (these problems were much less with EUC as any ASCII character did synchronize the encoding).

Unicode has simplified the picture somewhat. Most programming languages now have a datatype for Unicode strings. Unicode's preferred byte stream format UTF-8 is designed not to have the problems described above for older multibyte encodings. UTF-8, UTF-16 and UTF-32 require the programmer to know that the fixed-size code units are different than the "characters", the main difficulty currently is incorrectly designed APIs that attempt to hide this difference (UTF-32 does make code points fixed-sized, but these are not "characters" due to composing codes).

### Implementations

Some languages like C++ implement strings as templates that can be used with any datatype, but this is the exception, not the rule.

Some languages, such as C++ and Ruby, normally allow the contents of a string to be changed after it has been created; these are termed mutable strings. In other languages, such as Java and Python, the value is fixed and a new string must be created if any alteration is to be made; these are termed immutable strings.

Strings are typically implemented as arrays of bytes, characters, or code units, in order to allow fast access to individual units or substrings--including characters when they have a fixed length. A few languages such as Haskell implement them as linked lists instead.

Some languages, such as Prolog and Erlang, avoid implementing a dedicated string datatype at all, instead adopting the convention of representing strings as lists of character codes.

### Representations

Representations of strings depend heavily on the choice of character repertoire and the method of character encoding. Older string implementations were designed to work with repertoire and encoding defined by ASCII, or more recent extensions like the ISO 8859 series. Modern implementations often use the extensive repertoire defined by Unicode along with a variety of complex encodings such as UTF-8 and UTF-16.

The term byte string usually indicates a general-purpose string of bytes, rather than strings of only (readable) characters, strings of bits, or such. Byte strings often imply that bytes can take any value and any data can be stored as-is, meaning that there should be no value interpreted as a termination value.

Most string implementations are very similar to variable-length arrays with the entries storing the character codes of corresponding characters. The principal difference is that, with certain encodings, a single logical character may take up more than one entry in the array. This happens for example with UTF-8, where single codes (UCS code points) can take anywhere from one to four bytes, and single characters can take an arbitrary number of codes. In these cases, the logical length of the string (number of characters) differs from the physical length of the array (number of bytes in use). UTF-32 avoids the first part of the problem.

#### Null-terminated

The length of a string can be stored implicitly by using a special terminating character; often this is the null character (NUL), which has all bits zero, a convention used and perpetuated by the popular C programming language.[4] Hence, this representation is commonly referred to as a C string. This representation of an n-character string takes n + 1 space (1 for the terminator), and is thus an implicit data structure.

In terminated strings, the terminating code is not an allowable character in any string. Strings with length field do not have this limitation and can also store arbitrary binary data.

An example of a null-terminated string stored in a 10-byte buffer, along with its ASCII (or more modern UTF-8) representation as 8-bit hexadecimal numbers is:

 F R A N K NUL k e f w 4616 5216 4116 4E16 4B16 0016 6B16 6516 6616 7716

The length of the string in the above example, "FRANK", is 5 characters, but it occupies 6 bytes. Characters after the terminator do not form part of the representation; they may be either part of other data or just garbage. (Strings of this form are sometimes called ASCIZ strings, after the original assembly language directive used to declare them.)

Using a special byte other than null for terminating strings has historically appeared in both hardware and software, though sometimes with a value that was also a printing character. $ was used by many assembler systems, : used by CDC systems (this character had a value of zero), and the ZX80 used "[5] since this was the string delimiter in its BASIC language. Somewhat similar, "data processing" machines like the IBM 1401 used a special word mark bit to delimit strings at the left, where the operation would start at the right. This bit had to be clear in all other parts of the string. This meant that, while the IBM 1401 had a seven-bit word, almost no-one ever thought to use this as a feature, and override the assignment of the seventh bit to (for example) handle ASCII codes. Early microcomputer software relied upon the fact that ASCII codes do not use the high-order bit, and set it to indicate the end of a string. It must be reset to 0 prior to output.[6] #### Length-prefixed The length of a string can also be stored explicitly, for example by prefixing the string with the length as a byte value; a convention used in many Pascal dialects, as a consequence, some people call such a string a Pascal string or P-string. Storing the string length as byte limits the maximum string length to 255. To avoid such limitations, improved implementations of P-strings use 16-, 32-, or 64-bit words to store the string length. When the length field covers the address space, strings are limited only by the available memory. If the length is bounded, then it can be encoded in constant space, typically a machine word, thus leading to an implicit data structure, taking n + k space, where k is the number of characters in a word (8 for 8-bit ASCII on a 64-bit machine, 1 for 32-bit UTF-32/UCS-4 on a 32-bit machine, etc.). If the length is not bounded, encoding a length n takes log(n) space (see fixed-length code), so length-prefixed strings are a succinct data structure, encoding a string of length n in log(n) + n space. In the latter case, the length-prefix field itself doesn't have fixed length, therefore the actual string data needs to be moved when the string grows such that the length field needs to be increased. Here is a Pascal string stored in a 10-byte buffer, along with its ASCII / UTF-8 representation:  length F R A N K k e f w 0516 4616 5216 4116 4E16 4B16 6B16 6516 6616 7716 #### Strings as records Many languages, including object-oriented ones, implement strings as records with an internal structure like: class string { size_t length; char *text; };  However, since the implementation is usually hidden, the string must be accessed and modified through member functions. text is a pointer to a dynamically allocated memory area, which might be expanded as needed. See also string (C++). #### Other representations Both character termination and length codes limit strings: For example, C character arrays that contain null (NUL) characters cannot be handled directly by C string library functions: Strings using a length code are limited to the maximum value of the length code. Both of these limitations can be overcome by clever programming. It is possible to create data structures and functions that manipulate them that do not have the problems associated with character termination and can in principle overcome length code bounds. It is also possible to optimize the string represented using techniques from run length encoding (replacing repeated characters by the character value and a length) and Hamming encoding[clarification needed]. While these representations are common, others are possible. Using ropes makes certain string operations, such as insertions, deletions, and concatenations more efficient. The core data structure in a text editor is the one that manages the string (sequence of characters) that represents the current state of the file being edited. While that state could be stored in a single long consecutive array of characters, a typical text editor instead uses an alternative representation as its sequence data structure--a gap buffer, a linked list of lines, a piece table, or a rope--which makes certain string operations, such as insertions, deletions, and undoing previous edits, more efficient.[7] ### Security concerns The differing memory layout and storage requirements of strings can affect the security of the program accessing the string data. String representations requiring a terminating character are commonly susceptible to buffer overflow problems if the terminating character is not present, caused by a coding error or an attacker deliberately altering the data. String representations adopting a separate length field are also susceptible if the length can be manipulated. In such cases, program code accessing the string data requires bounds checking to ensure that it does not inadvertently access or change data outside of the string memory limits. String data is frequently obtained from user-input to a program. As such, it is the responsibility of the program to validate the string to ensure that it represents the expected format. Performing limited or no validation of user-input can cause a program to be vulnerable to code injection attacks. ## Literal strings Sometimes, strings need to be embedded inside a text file that is both human-readable and intended for consumption by a machine. This is needed in, for example, source code of programming languages, or in configuration files. In this case, the NUL character doesn't work well as a terminator since it is normally invisible (non-printable) and is difficult to input via a keyboard. Storing the string length would also be inconvenient as manual computation and tracking of the length is tedious and error-prone. Two common representations are: • Surrounded by quotation marks (ASCII 0x22 double quote or ASCII 0x27 single quote), used by most programming languages. To be able to include special characters such as the quotation mark itself, newline characters, or non-printable characters, escape sequences are often available, usually prefixed with the backslash character (ASCII 0x5C). • Terminated by a newline sequence, for example in Windows INI files. ## Non-text strings While character strings are very common uses of strings, a string in computer science may refer generically to any sequence of homogeneously typed data. A bit string or byte string, for example, may be used to represent non-textual binary data retrieved from a communications medium. This data may or may not be represented by a string-specific datatype, depending on the needs of the application, the desire of the programmer, and the capabilities of the programming language being used. If the programming language's string implementation is not 8-bit clean, data corruption may ensue. C programmers draw a sharp distinction between a "string", aka a "string of characters", which by definition is always null terminated, vs. a "byte string" or "pseudo string" which may be stored in the same array but is often not null terminated. Using C string handling functions on such a "byte string" often seems to work, but later leads to security problems.[8][9][10] ## String processing algorithms There are many algorithms for processing strings, each with various trade-offs. Some categories of algorithms include: Advanced string algorithms often employ complex mechanisms and data structures, among them suffix trees and finite state machines. The name stringology was coined in 1984 by computer scientist Zvi Galil for the issue of algorithms and data structures used for string processing.[11] ## Character string-oriented languages and utilities Character strings are such a useful datatype that several languages have been designed in order to make string processing applications easy to write. Examples include the following languages: Many Unix utilities perform simple string manipulations and can be used to easily program some powerful string processing algorithms. Files and finite streams may be viewed as strings. Some APIs like Multimedia Control Interface, embedded SQL or printf use strings to hold commands that will be interpreted. Recent scripting programming languages, including Perl, Python, Ruby, and Tcl employ regular expressions to facilitate text operations. Perl is particularly noted for its regular expression use,[12] and many other languages and applications implement Perl compatible regular expressions. Some languages such as Perl and Ruby support string interpolation, which permits arbitrary expressions to be evaluated and included in string literals. ## Character string functions String functions are used to manipulate a string or change or edit the contents of a string. They also are used to query information about a string. They are usually used within the context of a computer programming language. The most basic example of a string function is the string length function - the function that returns the length of a string (not counting any terminator characters or any of the string's internal structural information) and does not modify the string. This function is often named length or len. For example, length("hello world") would return 11. ## String buffers In some programming languages, a string buffer is an alternative to a string. It has the ability to be altered through adding or appending, whereas a String is normally fixed or immutable. ### In Java #### Theory Java's standard way to handle text is to use its String class. Any given String in Java is an immutable object, which means its state cannot be changed. A String has an array of characters. Whenever a String must be manipulated, any changes require the creation of a new String (which, in turn, involves the creation of a new array of characters, and copying of the original array). This happens even if the original String's value or intermediate Strings used for the manipulation are not kept. Java provides two alternate classes for string manipulation, called StringBuffer and StringBuilder. Both of these, like String, each has an array to hold characters. They, however, are mutable (its state can be altered). Their array of characters is not necessarily completely filled (as opposed to a String, whose array is always the exact required length for its contents). Thus, a StringBuffer or StringBuilder has the capability to add, remove, or change its state without creating a new object (and without the creation of a new array, and array copying). The exception to this is when its array is no longer of suitable length to hold its content (a case which rarely happens because of the default Dynamic memory allocation provided by the JVM). In this case, it is required to create a new array, and copy the contents. For these reasons, Java would handle an expression like String newString = aString + anInt + aChar + aDouble;  like this: String newString = (new StringBuilder(aString)).append(anInt).append(aChar).append(aDouble).toString;  #### Implications Generally, a StringBuffer is more efficient than a String in string handling. However, this is not necessarily the case, since a StringBuffer will be required to recreate its character array when it runs out of space. Theoretically, this is possible to happen the same number of times as a new String would be required, although this is unlikely (and the programmer can provide length hints to prevent this). Either way, the effect is not noticeable in modern desktop computers. As well, the shortcomings of arrays are inherent in a StringBuffer. In order to insert or remove characters at arbitrary positions, whole sections of arrays must be moved. The method by which a StringBuffer is attractive in an environment with low processing power takes this ability by using too much memory, which is likely also at a premium in this environment. This point, however, is trivial, considering the space required for creating many instances of Strings in order to process them. As well, the StringBuffer can be optimized to "waste" as little memory as possible. The StringBuilder class, introduced in J2SE 5.0, differs from StringBuffer in that it is unsynchronized. When only a single thread at a time will access the object, using a StringBuilder processes more efficiently than using a StringBuffer. StringBuffer and StringBuilder are included in the java.lang package. ### In .NET Microsoft's .NET Framework has a StringBuilder class in its Base Class Library. ### In other languages • In C++ and Ruby, the standard string class is already mutable, with the ability to change the contents and append strings, etc., so a separate mutable string class is unnecessary. • In Objective-C (Cocoa/OpenStep frameworks), the NSMutableString class is the mutable version of the NSString class. ### String instructions Some microprocessor's instruction set architectures contain direct support for string operations, such as block copy (e.g. In intel x86m REPNZ MOVSB).[13] ## See also ## References 1. ^ "Introduction To Java - MFC 158 G". String literals (or constants) are called 'anonymous strings' 2. ^ a b Barbara H. Partee; Alice ter Meulen; Robert E. Wall (1990). Mathematical Methods in Linguistics. Kluwer. 3. ^ John E. Hopcroft, Jeffrey D. Ullman (1979). Introduction to Automata Theory, Languages, and Computation. Addison-Wesley. ISBN 0-201-02988-X. Here: sect.1.1, p.1 4. ^ Bryant, Randal E.; David, O'Hallaron (2003), Computer Systems: A Programmer's Perspective (2003 ed.), Upper Saddle River, NJ: Pearson Education, p. 40, ISBN 0-13-034074-X 5. ^ Wearmouth, Geoff. "An Assembly Listing of the ROM of the Sinclair ZX80". Archived from the original on August 15, 2015. 6. ^ Allison, Dennis. "Design Notes for Tiny BASIC". 7. ^ Charles Crowley. "Data Structures for Text Sequences". Section "Introduction". 8. ^ "strlcpy and strlcat - consistent, safe, string copy and concatenation." 9. ^ "A rant about strcpy, strncpy and strlcpy." 10. ^ Keith Thompson. "No, strncpy is not a "safer" strcpy". 2012. 11. ^ "The Prague Stringology Club". stringology.org. Retrieved 2015. 12. ^ "Essential Perl". Perl's most famous strength is in string manipulation with regular expressions. 13. ^ This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0. Connect with defaultLogic What We've Done Led Digital Marketing Efforts of Top 500 e-Retailers. Worked with Top Brands at Leading Agencies. Successfully Managed Over$50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.