R plot text: How to add regular text prefix to polynomial rendered in exponent form (not ^)

I’m trying to add this text to a plot: “Model: y = 1 + 2x – 3x^2 + 4x^3” where actual exponents are rendered as such (no ^ chars). (See screenshot)

Below is repro code. The first text() call works fine (no prepended regular text), but the second does not (with prepended text). (Execute soTest() to repro.)

Any suggestions? I guess I don’t know which R keywords to search for to find a solution. Any help would be appreciated! (Please pardon the camel-casing, I’m writing a slide deck for an audience with at least a few non-R coders.)

evalPoly = function( x, coeff ) {     if ( length( coeff ) < 1 ) return( c(0) )        termSum <- 0     for ( i in 1:length(coeff) ) {         termSum <- termSum + coeff[i] * x^(i-1)     }     return( termSum ) }  soTest <- function() {     coeff <- c( 1, 2, -3, 4 )     x <- 1:8     y <- evalPoly( x, coeff )     plot( x, y )     text( 2, 1600, parse( text="1+2*x-3*x^2+4*x^3" ), adj=0 )     text( 2, 1400, parse( text="Model:  y = 1+2*x-3*x^2+4*x^3" ), adj=0 ) } 

resulting plot

Finding $k$-th element in prefix of size $i$

Let’s say we are given array $ A$ of size $ n$ . We need to answer some numbers of queries. For each query we are given index $ i$ and integer value $ k$ , $ k \le i$ . If we take the first $ i$ elements of the array $ A$ and we sort them we should return the one on index $ k$ (we assume everything is 1 indexed).

I know that this can be solved in $ O(Q\log N)$ if $ Q$ is the number of our queries in offline way (we sort all queries by their index) and if we use persistent segment trees we can even make it work in online way (we can answer queries immediately), however I was wondering if there is simpler solution?

Permutation to maximise strings’ common prefix

Is there a good algorithm for finding a permutation which, applied to all the strings in a set, maximises the weight of those with a common fixed length prefix.

Given a set $ S=\{(s,w)\}$ of pairs of fixed length bit strings and weights and an integer k find a permutation p of {1..k} and bit string v of length k to maximise

$ $ \Sigma \{ w_i | (s_i,w_i)\in S\land s_i[p(1)]=v[1] \land s_i[p(2)]=v[2]\land…s_i[p(k)]=v[k] \} $ $

I can think of an obvious greedy algorithm where we

  1. pick the index i and value v which maximises the weights of the strings with $ s[i]=v$
  2. delete position i from all strings.
  3. Repeat until we’ve chosen k bits.

Is it possible to do better?

The problem I’m trying to solve is a compression one where the bits in the data can be reordered and each compressed item can be either the original or the suffix from the original which is concatenated with a common prefix when decompressed.

I need to find a reordering and prefix which maximises the number of items which can use the second form. If p is the permutation and v the prefix

Compression for s:

sp = permute(p, s). If sp[1..k]=v then      # Does the permuted s have the prefix v     return sp[k+1..n]   # Compressed case else      return sp           # Uncompressed case 

Decompression for s:

if len(s)=k then      su = concat(v,s) # Compressed case, add the prefix. else     su = s  # Uncompressed case output inverse_permutation(p, su) 

mac won’t start after “sudo chown -R $(whoami) $(brew –prefix)/*” command

I tried to install a program and it alwaysed lacked permission on /usr/local. I tried sudo chown -R $ USER /usr/local but then found out that doesn’t work anymore with High Sierra. So I tried sudo chown -R $ (whoami) $ (brew –prefix)/* . That brought an awful lot of “Operation not permitted” in the terminal.

After that I wanted to install again with sudo. Then an error message showed sth like “sudoers uid is 501 should be 0” (cant exactly remember it)

Then I tried to restart the mac, but it never did… Just black screen. I heard the starting sound once or twice, but it never booted again or showed anything on the screen. Anyone any idea what happend and how to fix it?

Proving a language comprised of 2 languages is regular(with suffix and prefix)

I am having hard time proving that the following language,comprised from two regular languages $ L_1,L_2$ (over the same $ \Sigma$ )is indeed regular:

$ $ L^\frown = \{ w\in \Sigma^* | w=u\sigma_1\mu_1…\sigma_n\mu_nv\}$ $

  • $ u,v \in \Sigma^*$

  • $ 0\leq n$ , for every i($ 1\leq i \leq n$ ): $ \sigma_i,\mu_i \in \Sigma$

  • $ \sigma_1…\sigma_n \in L_1$

  • $ \mu_1…\mu_n \in L_2$

I don’t understand how to prove if because of the suffix and prefix(u,v accordingly).

If it weren’t for u,v what I think I would’ve done is building an automaton(Deterministic finite automaton): $ A=\left(Σ,Q1xQ2x\left\{1,2\right\},\left(q01,q02,2\right),F1xF2x2,δ\right)$ , Ending in accepting iff both automatons that accept each language end in an accepting state, and $ L_2$ needs to be after $ L_1$ from the language’s description. However, I don’t know how to deal with the u,v in the beginning and in the end. I am not sure how to configure it correctly to prove $ L^\frown$ is regular.

Would very much appreciate your assistance with it.

Completition of language $L = \{ x \in \{a,b,c,d\} : \exists $prefix y of x that $||y|_a – |y|_b|

Completition of language $ L = \{ x \in \{a,b,c,d\} : \exists $ prefix y of x that $ ||y|_a – |y|_b|<= 10 $ }

The first thought is that this is not a regular language because finite automata can’t store information about the number of a and b in x, but I guess I do not understand what is the meaning of the prefix here. Could someone help me with that?

“Prefix found” error while extracting RAR file with Archive Manager

I have a RAR archive file, and I get this “Prefix found” error message when I try to extract its contents using the built-in Archive Manager (file-roller 3.28.0) in Ubuntu 18.04:

An error occurred while extracting files. Prefix found

I would assume that if it can read the archive’s file list, then it could also extract the files. I was able to extract the file using the unrar command in the terminal, but I would still like to know what’s wrong with Archive Manager, and if there’s a way to fix it so that it can extract RAR files.

Understanding handle, viable prefix and valid item in the context of LR(0) and LR(1) items

Dragon book gives definition of handle, viable prefix and valid item at various different places. I am trying to understand these definitions in each other’s context. Various definitions given are as below.

In the bottom up parser section, it gives following definition of handle:

  • Handle: If $ S\xrightarrow{*rm} \alpha A \omega \xrightarrow{rm} \alpha\beta w$ , then production $ A\rightarrow \beta$ in the position following $ \alpha$ is a handle of $ \alpha\beta\omega$ . For covenience, we refer to the body $ \beta$ rather than $ A\rightarrow\beta$ as a handle. enter image description here

(Above, $ \xrightarrow{*rm}$ means rightmost derivation of length $ n$ and $ \xrightarrow{rm}$ means rightmost derivation of length 1)

Then after some pages, in SLR parser section, it gives below definitions:

  • Viable prefix: A viable prefix is a prefix of a right sentential form that does not continue past the right end of the rightmost handle of that sentential form.
  • Valid item: We say item $ A\rightarrow\beta_1.\beta_2$ is valid for a viable prefix $ \alpha\beta_1$ if there is a derivation $ S’\xrightarrow{*rm}\alpha A\omega\xrightarrow{rm}\alpha\beta_1\beta_2\omega$

The book further says:

The fact that $ A\rightarrow \beta_1.\beta_2$ is valid for $ \alpha\beta_1$ tells us a lot about whether to shift or reduce when we find $ \alpha\beta_1$ on the parsing stack. In particular, if $ \beta_2\neq \epsilon$ , then it suggests that we have not yet shifted the handle onto the stack, so shift is our move. If $ \beta_2=\epsilon$ , then it looks as if $ A\rightarrow\beta_1$ is the handle, and we should reduce by this production.

Doubts:

  1. In most discussions, the book uses all these definitions together. However, above the definitions are given separately but not together. How can I relate them together? Can I relate them as follows:

    a. In the definition of handle, can we say $ A\rightarrow\ \beta$ is a valid item?
    b. In the definition of valid item, can we say $ \beta_1.\beta_2$ is a handle?

Definition of handle is given in the section 4.5.2. (Section 4.5 is of bottom up parsers) Definition of viable prefix and valid item is given in the section 4.6.5 (Section 4.6 is of SLR parsers). So none of these definitions are given in the context of LR(1) items or CLR(1) or LALR(1) items. So I want to know whether these definitions applies to LR(1) items too without modifications and if not then what will be corresponding definitions for LR(1) items. Below questions detail this doubt.

  1. For canonical collection state with final item $ E\rightarrow \gamma$ , SLR parser reduces $ \gamma$ to $ E$ , if next input symbol is in $ FOLLOW(E)$ . Does the above definition of valid items adheres with this? That is, does that definition gives sense that $ FIRST(\omega)\in FOLLOW(A)$ ? (In other words, does this definition applies to LR(0) items?) If yes, how? I feel, this definition means $ FIRST(\omega) = LOOKAHEAD(A) \neq FOLLOW(A)$ , and hence it is talking about LR(1) items and applies to CLR/LALR parsers, but not to SLR parsers, as stated by the book. Am I wrong? If yes, how? Do these definition apply to both LR(0) and LR(1) items equally and I am unable to see how? If even that is not the case (that is above definitions apply only to LR(0) items, not to the LR(1) items), how we can give equivalent definitions for LR(1) items?

When is the $SPUrl Token Prefix Needed?

I have been doing some research and testing and found that the $ SPUrl tokens (e.g. ~site and ~sitecollection) can be used in various scenarios to reference the root of the current site or web. However, I cannot seem to find information on when the $ SPUrl prefix is required to reference these tokens.

For example, I know that when using a token like this in a CssRegistration control, we must use a syntax like so:

<SharePoint:CssRegistration ID="CssRegistration1" Name="<% $  SPUrl:~sitecollection/Style Library/custom.css %>" runat="server" /> 

However, I have also seen examples of using these tokens with a ScriptLink control that utilize the token with no $ SPUrl prefix (and no <% %> tags) as follows:

<SharePoint:ScriptLink Language="javascript" Name="~sitecollection/SiteScripts/custom.js" runat="server" Localizable="false" /> 

Can someone explain why the <% %> tags and $ SPUrl prefix are required in some situations but not others when using these tokens?

Show delegated ipv6 prefix at command line in OpenWRT

In OpenWRT’s gui “LuCI“ the delegated IPv6 Prefix provided by the ISP is diplayed in the status page in overview. Normally it will be shown under “IPv6 WAN Status“ in the “Network“ section like

IPv6 WAN Status  Type: dhcpv6-pd                  Prefix Delegated: 2001:db8:1234:5678::/56                  Address: 2001:db8::abcd/128                  […] 

However I would like to figure out the delegated prefix on the command line. I am aware I can get the addresses assigned via ip a or the gateway and other routes via ip r but never manged to retrieve the prefix delegated by the router.

How can I show the delegated ipv6 prefix in the command line interface? Is there a command I am missing or some file it is written into that I am not aware of?