jEuclid: how to show bar in formula with subscript - math

In case of mathml:
<math>
<mrow>
<mover accent="true">
<mrow>
<mi> x </mi>
<mo> + </mo>
<mi> y </mi>
<mo> + </mo>
<mi> z </mi>
</mrow>
<mo>¯</mo>
</mover>
</mrow>
</math>
jEuclid shows bar over whole formula:
and it's ok.
But if I add subscript text:
<math>
<msub>
<mrow>
<mover accent="true">
<mrow>
<mi> x </mi>
<mo> + </mo>
<mi> y </mi>
<mo> + </mo>
<mi> z </mi>
</mrow>
<mo>¯</mo>
</mover>
</mrow>
<mrow>
<mtext>v</mtext>
</mrow>
</msub>
</math>
jEuclid shows bar above y and in small font size:
Is is a jEuclid bug? Is there a workaround solution for this?

Can you please try:
<math>
<msub>
<mrow>
<mover accent="true">
<mrow>
<mi> x </mi>
<mo> + </mo>
<mi> y </mi>
<mo> + </mo>
<mi> z </mi>
</mrow>
<mo>&lowbar;</mo>
</mover>
</mrow>
<mrow>
<mtext>v</mtext>
</mrow>
</msub>
</math>

I've found a workaround solution - first mrow should be enclosed in mstyle:
<math>
<msub>
<mstyle>
<mrow>
<mover accent="true">
<mrow>
<mi> x </mi>
<mo> + </mo>
<mi> y </mi>
<mo> + </mo>
<mi> z </mi>
</mrow>
<mo>¯</mo>
</mover>
</mrow>
</mstyle>
<mrow>
<mtext>v</mtext>
</mrow>
</msub>
</math>
The equation displays as expected:

Related

Latex math expression alignment

I have an issue with aligning some math expressions. Is it possible to make some expressions aligned to "&" sign and some to the center of the page with align? I've done it as seen in the screenshot but there are some empty lines in between. I would like to align the first and the second last line to center and the rest to "&" sign without the empty spaces.
Thank you in advance
\begin{gather}
|e(t)| \leq e_{lim} \Rightarrow t \in \left\langle t_{set}; \infty\right) \label{eq:settling_time}
\end{gather}
\begin{align}
\left|\frac{1}{K_p\cdot K_s - p_1}\cdot \left[K_p\cdot K_s\cdot e^{(p_1 - K_p\cdot K_s)\cdot t} - p_1\right]\right| &\leq e_{lim} \nonumber \\
\frac{1}{K_p\cdot K_s - p_1}\cdot \left[K_p\cdot K_s\cdot e^{(p_1 - K_p\cdot K_s)\cdot t} - p_1\right] &> 0; \quad t \in \mathbb{R}_0^+ \nonumber \\
\frac{1}{K_p\cdot K_s - p_1}\cdot \left[K_p\cdot K_s\cdot e^{(p_1 - K_p\cdot K_s)\cdot t} - p_1\right] &\leq e_{lim} \nonumber \\
K_p\cdot K_s\cdot e^{(p_1 - K_p\cdot K_s)\cdot t} - p_1 &\leq e_{lim}\cdot (K_p\cdot K_s - p_1) \nonumber \\
K_p\cdot K_s\cdot e^{(p_1 - K_p\cdot K_s)\cdot t} &\leq e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1 \nonumber \\
e^{(p_1 - K_p\cdot K_s)\cdot t} &\leq \frac{e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1}{K_p\cdot K_s} \nonumber \\
(p_1 - K_p\cdot K_s)\cdot t &\leq \ln \left[\frac{e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1}{K_p\cdot K_s}\right] \nonumber \\
t &\geq \frac{\displaystyle \ln \left[\frac{\displaystyle e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1}{\displaystyle K_p\cdot K_s}\right]}{\displaystyle p_1 - K_p\cdot K_s} \nonumber
\end{align}
\begin{gather}
t \in \Bigg \langle \frac{\displaystyle \ln \left[\frac{\displaystyle e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1}{\displaystyle K_p\cdot K_s}\right]}{\displaystyle p_1 - K_p\cdot K_s}; \infty \Bigg) \in \left\langle t_{set}; \infty \right) \nonumber \\
t_{set} = \frac{\displaystyle \ln \left[\frac{\displaystyle e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1}{\displaystyle K_p\cdot K_s}\right]}{\displaystyle p_1 - K_p\cdot K_s} \label{eq:settling_time_1st_order_P_reg}
\end{gather}
You can set the aligned components within the gather using aligned:
\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{gather}
| e(t) | \leq e_{\text{lim}} \Rightarrow t \in \langle t_{\text{set}}; \infty ) \\
\begin{aligned}
\biggl| \frac{1}{K_p \cdot K_s - p_1} \cdot \bigl[ K_p \cdot K_s \cdot e^{(p_1 - K_p \cdot K_s) \cdot t} - p_1 \bigr] \biggr| &
\leq e_{\text{lim}} \\
\frac{1}{K_p \cdot K_s - p_1} \cdot \bigl[ K_p \cdot K_s \cdot e^{(p_1 - K_p \cdot K_s) \cdot t} - p_1 \bigr] &
> 0; \quad t \in \mathbb{R}_0^+ \\
\frac{1}{K_p \cdot K_s - p_1} \cdot \bigl[ K_p \cdot K_s \cdot e^{(p_1 - K_p \cdot K_s) \cdot t} - p_1 \bigr] &
\leq e_{\text{lim}} \\
K_p \cdot K_s \cdot e^{(p_1 - K_p \cdot K_s) \cdot t} - p_1 &
\leq e_{\text{lim}} \cdot (K_p \cdot K_s - p_1) \\
K_p \cdot K_s \cdot e^{(p_1 - K_p \cdot K_s) \cdot t} &
\leq e_{\text{lim}} \cdot (K_p \cdot K_s - p_1) + p_1 \\
e^{(p_1 - K_p \cdot K_s) \cdot t} &
\leq \frac{e_{\text{lim}} \cdot (K_p \cdot K_s - p_1) + p_1}{K_p \cdot K_s} \\
(p_1 - K_p \cdot K_s) \cdot t &
\leq \ln \biggl[ \frac{e_{\text{lim}} \cdot (K_p \cdot K_s - p_1) + p_1}{K_p \cdot K_s} \biggr] \\
t &
\geq \frac{\ln \biggl[ \dfrac{e_{\text{lim}} \cdot (K_p \cdot K_s - p_1) + p_1}{K_p \cdot K_s} \biggr]}{p_1 - K_p \cdot K_s}
\end{aligned} \nonumber \\
t \in \Bigg \langle \frac{ \ln \biggl[ \dfrac{e_{\text{lim}} \cdot (K_p \cdot K_s - p_1) + p_1}{K_p \cdot K_s} \biggr]}{p_1 - K_p \cdot K_s}; \infty \Bigg) \in \langle t_{\text{set}}; \infty ) \nonumber \\
t_{\text{set}} = \frac{\ln \biggl[ \dfrac{e_{\text{lim}} \cdot (K_p \cdot K_s - p_1) + p_1}{K_p \cdot K_s} \biggr]}{p_1 - K_p \cdot K_s}
\end{gather}
\end{document}
I would suggest using the \IEEEeqnarray environment. If you use the * version of this, you can get rid of all the \nonumber commands (9 in this case) and insert \yesnumber commands (2 in this case) where equation no is necessary.
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{IEEEtrantools}
%-------Shows page layout-------------------
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%-------------------------------------------
\begin{document}
\begin{IEEEeqnarray*}{rcl}
\IEEEeqnarraymulticol{3}{c}{|e(t)| \leq e_{lim} \Rightarrow t \in \left\langle t_{set}; \infty\right)} \yesnumber \label{eq:settling_time}\\
\left|\frac{1}{K_p\cdot K_s - p_1}\cdot \left[K_p\cdot K_s\cdot e^{(p_1 - K_p\cdot K_s)\cdot t} - p_1\right]\right| & \leq & e_{lim} \\
\frac{1}{K_p\cdot K_s - p_1}\cdot \left[K_p\cdot K_s\cdot e^{(p_1 - K_p\cdot K_s)\cdot t} - p_1\right] & > & 0; \quad t \in \mathbb{R}_0^+ \\
\frac{1}{K_p\cdot K_s - p_1}\cdot \left[K_p\cdot K_s\cdot e^{(p_1 - K_p\cdot K_s)\cdot t} - p_1\right] & \leq & e_{lim} \\
K_p\cdot K_s\cdot e^{(p_1 - K_p\cdot K_s)\cdot t} - p_1 & \leq & e_{lim}\cdot (K_p\cdot K_s - p_1) \\
K_p\cdot K_s\cdot e^{(p_1 - K_p\cdot K_s)\cdot t} & \leq & e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1 \\
e^{(p_1 - K_p\cdot K_s)\cdot t} & \leq & \frac{e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1}{K_p\cdot K_s} \\
(p_1 - K_p\cdot K_s)\cdot t & \leq & \ln \left[\frac{e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1}{K_p\cdot K_s}\right] \\
t & \geq & \frac{\displaystyle \ln \left[\frac{\displaystyle e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1}{\displaystyle K_p\cdot K_s}\right]}{\displaystyle p_1 - K_p\cdot K_s} \\
\IEEEeqnarraymulticol{3}{c}{t \in \Bigg \langle \frac{\displaystyle \ln \left[\frac{\displaystyle e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1}{\displaystyle K_p\cdot K_s}\right]}{\displaystyle p_1 - K_p\cdot K_s}; \infty \Bigg) \in \left\langle t_{set}; \infty \right)} \\
\IEEEeqnarraymulticol{3}{c}{t_{set} = \frac{\displaystyle \ln \left[\frac{\displaystyle e_{lim}\cdot (K_p\cdot K_s - p_1) + p_1}{\displaystyle K_p\cdot K_s}\right]}{\displaystyle p_1 - K_p\cdot K_s}} \yesnumber \label{eq:settling_time_1st_order_P_reg}
\end{IEEEeqnarray*}
\end{document}
Appendix F of this document covers the use of the IEEEeqnarray commands.
As mentioned in the comment, you may find quicker responses in TEX.SE

Change LaTeX equation font size within `eqnarray` in RMarkdown

I have a latex equation as part of an RMarkdown document that I'm knitting to an HTML file using knitr. I would like to use the LaTeX eqnarray to align the equality signs. However, I would also like to change font sizes from the first equation to the next.
This works, but equality signs are not lined up:
---
title: "Test"
author: "Eric"
date: "5/14/2020"
output: html_document
---
\[
\large a = b \times (c + d)\\
{\small\begin{eqnarray}
a &=& \mathrm{var ~a}\\
b &=& \mathrm{var ~b}\\
c &=& \mathrm{var ~c}
\end{eqnarray}}
\]
The result:
I tried many different arrangements of brackets and terms. Here is an example that does not work:
---
title: "Test"
author: "Eric"
date: "5/14/2020"
output: html_document
---
#### Try to line up equal signs AND change font sizes (doesn't work)
\[
\begin{eqnarray}
\large a &=& b \times (c + d)\\
{\small
a &=& \mathrm{var ~a}\\
b &=& \mathrm{var ~b}\\
c &=& \mathrm{var ~c}}
\end{eqnarray}
\]
#### Try again (doesn't work):
\[
\begin{eqnarray}
{\large a &=& b \times (c + d)}
{\small
\\a &=& \mathrm{var ~a}\\
b &=& \mathrm{var ~b}\\
c &=& \mathrm{var ~c}}
\end{eqnarray}
\]
How do I line up the equal signs using eqnarray while changing font sizes?
This seems to be what you'd want:
\[
\small
\begin{eqnarray}
{\large a}\ & {\large =} & {\large b \times (c + d)}\\
a &=& \mathrm{var ~a}\\
b &=& \mathrm{var ~b}\\
c &=& \mathrm{var ~c}
\end{eqnarray}
\]
The spacing for the a is a little bit off, which is why I added the \ after it. You might want to fiddle with that.

Comparing strings to numeric

When I write the following code
"hello" > 9
It is assessed as TRUE. Why is that the case? What is the coercion that happens in the background for R to assess this as TRUE?
I was thinking 9 would be coerced to '9' but didn't know how R establishes the order of strings.
"Hello" > 9
[1] TRUE
You're right that > coerces the number to a string before comparing.
?">" says:
Comparison of strings in character vectors is lexicographic within
the strings using the collating sequence of the locale in use: see
‘locales’. The collating sequence of locales such as ‘en_US’ is
normally different from ‘C’ (which should use ASCII) and can be
surprising.
Lexicographic order means letter-by-letter comparison as in a dictionary; one often-surprising result of this is that "10"<"2".
Interpreting this, it means that whether "9" is greater or less than "H" in your example will depend on where "9" and "H" fall in the collating sequence (the internal order of symbols/letters/numbers etc.)
The end of example(">") generates a table of the collating sequence: on my machine, you can see that the numbers come before all of the letters ...
writeLines(strwrap(paste(sort(x), collapse=" "), width = 60))
­   _ - , ; : ! ¡ ? ¿ . · ' " « » ( ) [ ] { } § ¶ # * / \ &
# % ` ´ ^ ¯ ¨ ¸ ° © ® + ± ÷ × < = > ¬ | ¦ ~ ¤ ¢ $ £ ¥ 0 1 ¹
½ ¼ 2 ² 3 ³ ¾ 4 5 6 7 8 9 a A ª á Á à À â Â å Å ä Ä ã Ã æ Æ
b B c C ç Ç d D ð Ð e E é É è È ê Ê ë Ë f F g G h H i I í Í
ì Ì î Î ï Ï j J k K l L m M n N ñ Ñ o O º ó Ó ò Ò ô Ô ö Ö õ
Õ ø Ø p P q Q r R s S ß t T u U ú Ú ù Ù û Û ü Ü v V w W x X
y Y ý Ý ÿ z Z þ Þ µ

Why do simplified maths equations run (slightly) slower than their equivalences with far more operations in Julia-Lang?

In a C++ course, I was taught that tricks like avoid repeating computation, use more additions instead of more multiplications, avoiding powers and so on to improve performance. When I tried them to optimize code in Julia-Lang, however, I was surprised with the opposite result.
For example, here are a few equations without maths optimization (All codes written in Julia 1.1, not JuliaPro):
function OriginalFunction( a,b,c,d,E )
# Oprations' count:
# sqrt: 4
# ^: 14
# * : 14
# / : 10
# +: 20
# -: 6
# = : 0+4
x1 = (1/(1+c^2))*(-c*d+a+c*b-sqrt(E))
y1 = d-(c^2*d)/(1+c^2)+(c*a)/(1+c^2)+(c^2*b)/(1+c^2)-(c*sqrt(E))/(1+c^2)
x2 = (1/(1+c^2))*(-c*d+a+c*b+sqrt(E))
y2 = d-(c^2*d)/(1+c^2)+(c*a)/(1+c^2)+(c^2*b)/(1+c^2)+(c*sqrt(E))/(1+c^2)
return [ [x1;y1] [x2;y2] ]
end
I optimized them with a few tricks, including:
(a*b + a*c) -> a*(b+c)
because addition is faster than multiplication.
a^2 -> a*a
to avoid power operation.
If there is a long operation used at least twice, assign it to a variable to avoid repeated computation. For example:
x = a * (1+c^2); y = b * (1+c^2)
->
temp = 1+c^2
x = a * temp; y = b * temp
Convert Int to Float64, so that computer doesn't have to do it (in run time or compile time). For example:
1/x -> 1.0/x
The result gives equivalent equations with far fewer operations:
function SimplifiedFunction( a,b,c,d,E )
# Oprations' count:
# sqrt: 1
# ^: 0
# *: 9
# /: 1
# +: 4
# -: 6
# = : 5+4
temp1 = sqrt(E)
temp2 = c*(b - d) + a
temp3 = 1.0/(1.0+c*c)
temp4 = d - (c*(c*(d - b) - a))*temp3
temp5 = (c*temp1)*temp3
x1 = temp3*(temp2-temp1)
y1 = temp4-temp5
x2 = temp3*(temp2+temp1)
y2 = temp4+temp5
return [ [x1;y1] [x2;y2] ]
end
Then I tested them with the following function, expecting the version with far less operations to fun faster or the same:
function Test2Functions( NumberOfTests::Real )
local num = Int(NumberOfTests)
# -- Generate random numbers
local rands = Array{Float64,2}(undef, 5,num)
for i in 1:num
rands[:,i:i] = [rand(); rand(); rand(); rand(); rand()]
end
local res1 = Array{Array{Float64,2}}(undef, num)
local res2 = Array{Array{Float64,2}}(undef, num)
# - Test OriginalFunction
#time for i in 1:num
a,b,c,d,E = rands[:,i]
res1[i] = OriginalFunction( a,b,c,d,E )
end
# - Test SimplifiedFunction
#time for i in 1:num
a,b,c,d,E = rands[:,i]
res2[i] = SimplifiedFunction( a,b,c,d,E )
end
return res1, res2
end
Test2Functions( 1e6 )
However, it turned out that the 2 functions use the same amount of memory allocation, but the simplified one has more garbage collection time, and runs about 5% slower:
julia> Test2Functions( 1e6 )
1.778731 seconds (7.00 M allocations: 503.540 MiB, 47.35% gc time)
1.787668 seconds (7.00 M allocations: 503.540 MiB, 50.92% gc time)
julia> Test2Functions( 1e6 )
1.969535 seconds (7.00 M allocations: 503.540 MiB, 52.05% gc time)
2.221151 seconds (7.00 M allocations: 503.540 MiB, 56.68% gc time)
julia> Test2Functions( 1e6 )
1.946441 seconds (7.00 M allocations: 503.540 MiB, 55.23% gc time)
2.099875 seconds (7.00 M allocations: 503.540 MiB, 59.33% gc time)
julia> Test2Functions( 1e6 )
1.836350 seconds (7.00 M allocations: 503.540 MiB, 53.37% gc time)
2.011242 seconds (7.00 M allocations: 503.540 MiB, 58.43% gc time)
julia> Test2Functions( 1e6 )
1.856081 seconds (7.00 M allocations: 503.540 MiB, 53.44% gc time)
2.002087 seconds (7.00 M allocations: 503.540 MiB, 58.21% gc time)
julia> Test2Functions( 1e6 )
1.833049 seconds (7.00 M allocations: 503.540 MiB, 53.55% gc time)
1.996548 seconds (7.00 M allocations: 503.540 MiB, 58.41% gc time)
julia> Test2Functions( 1e6 )
1.846894 seconds (7.00 M allocations: 503.540 MiB, 53.53% gc time)
2.053529 seconds (7.00 M allocations: 503.540 MiB, 58.30% gc time)
julia> Test2Functions( 1e6 )
1.896265 seconds (7.00 M allocations: 503.540 MiB, 54.11% gc time)
2.083253 seconds (7.00 M allocations: 503.540 MiB, 58.10% gc time)
julia> Test2Functions( 1e6 )
1.910244 seconds (7.00 M allocations: 503.540 MiB, 53.79% gc time)
2.085719 seconds (7.00 M allocations: 503.540 MiB, 58.36% gc time)
Could anyone kindly tell me why? 5% speed probably isn't something worth fighting for even in some performance critical codes, but I'm still curious: how can I help Julia compiler to produce faster code?
The reason is that you are running into garbage collection in the second loop (and not in the first). If you do GC.gc() before the loops you get more comparable results:
function Test2Functions( NumberOfTests::Real )
local num = Int(NumberOfTests)
# -- Generate random numbers
local rands = Array{Float64,2}(undef, 5,num)
for i in 1:num
rands[:,i:i] = [rand(); rand(); rand(); rand(); rand()]
end
local res1 = Array{Array{Float64,2}}(undef, num)
local res2 = Array{Array{Float64,2}}(undef, num)
# - Test OriginalFunction
GC.gc()
#time for i in 1:num
a,b,c,d,E = rands[:,i]
res1[i] = OriginalFunction( a,b,c,d,E )
end
# - Test SimplifiedFunction
GC.gc()
#time for i in 1:num
a,b,c,d,E = rands[:,i]
res2[i] = SimplifiedFunction( a,b,c,d,E )
end
return res1, res2
end
# call this twice as the first time you may have precompilation issues
Test2Functions( 1e6 )
Test2Functions( 1e6 )
However, in general to do benchmarking it is better to use BenchmarkTools.jl package.
julia> function OriginalFunction()
a,b,c,d,E = rand(5)
x1 = (1/(1+c^2))*(-c*d+a+c*b-sqrt(E))
y1 = d-(c^2*d)/(1+c^2)+(c*a)/(1+c^2)+(c^2*b)/(1+c^2)-(c*sqrt(E))/(1+c^2)
x2 = (1/(1+c^2))*(-c*d+a+c*b+sqrt(E))
y2 = d-(c^2*d)/(1+c^2)+(c*a)/(1+c^2)+(c^2*b)/(1+c^2)+(c*sqrt(E))/(1+c^2)
return [ [x1;y1] [x2;y2] ]
end
OriginalFunction (generic function with 2 methods)
julia>
julia> function SimplifiedFunction()
a,b,c,d,E = rand(5)
temp1 = sqrt(E)
temp2 = c*(b - d) + a
temp3 = 1.0/(1.0+c*c)
temp4 = d - (c*(c*(d - b) - a))*temp3
temp5 = (c*temp1)*temp3
x1 = temp3*(temp2-temp1)
y1 = temp4-temp5
x2 = temp3*(temp2+temp1)
y2 = temp4+temp5
return [ [x1;y1] [x2;y2] ]
end
SimplifiedFunction (generic function with 2 methods)
julia>
julia> using BenchmarkTools
julia> #btime OriginalFunction()
136.211 ns (7 allocations: 528 bytes)
2×2 Array{Float64,2}:
-0.609035 0.954271
0.724708 0.926523
julia> #btime SimplifiedFunction()
137.201 ns (7 allocations: 528 bytes)
2×2 Array{Float64,2}:
0.284514 1.58639
0.922347 0.979835
julia> #btime OriginalFunction()
137.301 ns (7 allocations: 528 bytes)
2×2 Array{Float64,2}:
-0.109814 0.895533
0.365399 1.08743
julia> #btime SimplifiedFunction()
136.429 ns (7 allocations: 528 bytes)
2×2 Array{Float64,2}:
0.516157 1.07871
0.219441 0.361133
And we see that they have comparable performance. In general you can expect that Julia and LLVM compilers will do most of the optimizations of this kind for you (of course it is not guaranteed always but in this case it seems it happens).
EDIT
I have simplified the functions as follows:
function OriginalFunction( a,b,c,d,E )
x1 = (1/(1+c^2))*(-c*d+a+c*b-sqrt(E))
y1 = d-(c^2*d)/(1+c^2)+(c*a)/(1+c^2)+(c^2*b)/(1+c^2)-(c*sqrt(E))/(1+c^2)
x2 = (1/(1+c^2))*(-c*d+a+c*b+sqrt(E))
y2 = d-(c^2*d)/(1+c^2)+(c*a)/(1+c^2)+(c^2*b)/(1+c^2)+(c*sqrt(E))/(1+c^2)
x1, y1, x2, y2
end
function SimplifiedFunction( a,b,c,d,E )
temp1 = sqrt(E)
temp2 = c*(b - d) + a
temp3 = 1.0/(1.0+c*c)
temp4 = d - (c*(c*(d - b) - a))*temp3
temp5 = (c*temp1)*temp3
x1 = temp3*(temp2-temp1)
y1 = temp4-temp5
x2 = temp3*(temp2+temp1)
y2 = temp4+temp5
x1, y1, x2, y2
end
To concentrate only on the core of the calculations and run #code_native on them. Here are they (stripped of comments to shorten them).
.text
pushq %rbp
movq %rsp, %rbp
subq $112, %rsp
vmovaps %xmm10, -16(%rbp)
vmovaps %xmm9, -32(%rbp)
vmovaps %xmm8, -48(%rbp)
vmovaps %xmm7, -64(%rbp)
vmovaps %xmm6, -80(%rbp)
vmovsd 56(%rbp), %xmm8 # xmm8 = mem[0],zero
vxorps %xmm4, %xmm4, %xmm4
vucomisd %xmm8, %xmm4
ja L229
vmovsd 48(%rbp), %xmm9 # xmm9 = mem[0],zero
vmulsd %xmm9, %xmm3, %xmm5
vsubsd %xmm5, %xmm1, %xmm5
vmulsd %xmm3, %xmm2, %xmm6
vaddsd %xmm5, %xmm6, %xmm10
vmulsd %xmm3, %xmm3, %xmm6
movabsq $526594656, %rax # imm = 0x1F633260
vmovsd (%rax), %xmm7 # xmm7 = mem[0],zero
vaddsd %xmm7, %xmm6, %xmm0
vdivsd %xmm0, %xmm7, %xmm7
vsqrtsd %xmm8, %xmm8, %xmm4
vsubsd %xmm4, %xmm10, %xmm5
vmulsd %xmm5, %xmm7, %xmm8
vmulsd %xmm9, %xmm6, %xmm5
vdivsd %xmm0, %xmm5, %xmm5
vsubsd %xmm5, %xmm9, %xmm5
vmulsd %xmm3, %xmm1, %xmm1
vdivsd %xmm0, %xmm1, %xmm1
vaddsd %xmm5, %xmm1, %xmm1
vmulsd %xmm2, %xmm6, %xmm2
vdivsd %xmm0, %xmm2, %xmm2
vaddsd %xmm1, %xmm2, %xmm1
vmulsd %xmm3, %xmm4, %xmm2
vdivsd %xmm0, %xmm2, %xmm0
vsubsd %xmm0, %xmm1, %xmm2
vaddsd %xmm10, %xmm4, %xmm3
vmulsd %xmm3, %xmm7, %xmm3
vaddsd %xmm1, %xmm0, %xmm0
vmovsd %xmm8, (%rcx)
vmovsd %xmm2, 8(%rcx)
vmovsd %xmm3, 16(%rcx)
vmovsd %xmm0, 24(%rcx)
movq %rcx, %rax
vmovaps -80(%rbp), %xmm6
vmovaps -64(%rbp), %xmm7
vmovaps -48(%rbp), %xmm8
vmovaps -32(%rbp), %xmm9
vmovaps -16(%rbp), %xmm10
addq $112, %rsp
popq %rbp
retq
L229:
movabsq $throw_complex_domainerror, %rax
movl $72381680, %ecx # imm = 0x45074F0
vmovapd %xmm8, %xmm1
callq *%rax
ud2
ud2
nop
and
.text
pushq %rbp
movq %rsp, %rbp
subq $64, %rsp
vmovaps %xmm7, -16(%rbp)
vmovaps %xmm6, -32(%rbp)
vmovsd 56(%rbp), %xmm0 # xmm0 = mem[0],zero
vxorps %xmm4, %xmm4, %xmm4
vucomisd %xmm0, %xmm4
ja L178
vmovsd 48(%rbp), %xmm4 # xmm4 = mem[0],zero
vsqrtsd %xmm0, %xmm0, %xmm0
vsubsd %xmm4, %xmm2, %xmm5
vmulsd %xmm3, %xmm5, %xmm5
vaddsd %xmm1, %xmm5, %xmm5
vmulsd %xmm3, %xmm3, %xmm6
movabsq $526593928, %rax # imm = 0x1F632F88
vmovsd (%rax), %xmm7 # xmm7 = mem[0],zero
vaddsd %xmm7, %xmm6, %xmm6
vdivsd %xmm6, %xmm7, %xmm6
vsubsd %xmm2, %xmm4, %xmm2
vmulsd %xmm3, %xmm2, %xmm2
vsubsd %xmm1, %xmm2, %xmm1
vmulsd %xmm3, %xmm1, %xmm1
vmulsd %xmm1, %xmm6, %xmm1
vsubsd %xmm1, %xmm4, %xmm1
vmulsd %xmm3, %xmm0, %xmm2
vmulsd %xmm2, %xmm6, %xmm2
vsubsd %xmm0, %xmm5, %xmm3
vmulsd %xmm3, %xmm6, %xmm3
vsubsd %xmm2, %xmm1, %xmm4
vaddsd %xmm5, %xmm0, %xmm0
vmulsd %xmm0, %xmm6, %xmm0
vaddsd %xmm1, %xmm2, %xmm1
vmovsd %xmm3, (%rcx)
vmovsd %xmm4, 8(%rcx)
vmovsd %xmm0, 16(%rcx)
vmovsd %xmm1, 24(%rcx)
movq %rcx, %rax
vmovaps -32(%rbp), %xmm6
vmovaps -16(%rbp), %xmm7
addq $64, %rsp
popq %rbp
retq
L178:
movabsq $throw_complex_domainerror, %rax
movl $72381680, %ecx # imm = 0x45074F0
vmovapd %xmm0, %xmm1
callq *%rax
ud2
ud2
nopl (%rax,%rax)
Probably you will not want to digest it in detail, but you can see that the simplified function uses a few less instructions, but only a few, which can be surprising if you compare the original codes. For example both codes call sqrt only once (so multiple calls to sqrt in the fist function got optimized out).
Lots of the reason is that Julia automatically performs some of your optimizations (specifically I know fixed integer powers are compiled to efficient sequences of multiplications). Constant propagation probably also can let the compiler turn the 1 into a 1.0. In general, Julia's compiler is very aggressive at making your code fast as long as it can do type inference.

changing specific letters in a Turkish text with R

I am analyzing a Turkish text. I need to change some letters in the text. Since in Turkish there are ş ç ı ğ ü ö letters. I want to change them with s c i g u o. How can I handle it?
I have used following for the one letter, but it did not work, nothing changed in the text.
gsub("s","ş" , text)
Any help would be appreciated.
We can use chartr. Example
> string <- "ş ç ı ğ ü ö f s x q"
> chartr("ş ç ı ğ ü ö", "s c i g u o", string)
[1] "s c i g u o f s x q"
Another alternative is stri_trans_general from stringi package
> library(stringi)
> stri_trans_general(string, "latin-ascii")
[1] "s c i g u o f s x q"

Resources