Is there a formal language of Combinatory Logic’s expressions?

The Combinatory Logic uses expressions of the form (x y) called “applications” (here, we have an “application of x to y”). Thus, the language of CL is a set of “parenthetic expressions”, each looking like a string of variables to which pairs of balanced parentheses are multiply applied in an exhaustive manner (that is, you cannot insert yet another pair of parentheses).

Is there a grammar which defines this language?
(I am a novice in formal languages and I am not sure my question is correctly formulated)

What are lambda expressions?

I haven’t been understanding them clearly so can someone please explain it?

functions – Behaviour of Coefficient[] for negative exponents in rational expressions

I’ve observed a puzzling behaviour of Coefficient() for negative exponents and I’m wondering if I was always just relying on undefined behaviour or if there is a bug in recent versions of Mathematica.

So far, if I had an expression of the form

expr = a/x + b/(1+x) + c

and ran

Coefficient(expr,x,-1)

I’ve always gotten

a

as the answer, which made a lot of sense to me.
I’ve tried this with a number of different versions of Mathematica (all on Linux if that matters) that I had access to and the behaviour described above is true for 8.0.0, 8.0.1, 8.0.4, 9.0.0, 9.0.1, 10.0.0, 10.0.1, 10.4.0, 10.4.1, 11.0.0 and 11.0.1.

With 11.1.0, 11.1.1, 11.3.0 and 12.0.0 I got the answer

a + b/(1+x)

which I find a bit weird, but maybe I can come up with a rationale behind this.

Finally, with 12.1.1 I get

a/(1+x) + b/(1+x) + c/(1+x)

which makes absolutely no sense at all to me.

My question is: Is this a bug in the newer versions of Mathematica or was the answer of 8.0.0 to 11.0.1 always just undefined behaviour? And is there a workaround, which would allow me to extract the coefficient a from expressions like the one above (i.e. after partial fractioning a rational function, take only the term that is multiplied by x^k with k a negative integer)? If this is indeed undefined behaviour, shouldn’t Mathematica issue a warning or something like that in this case?

vb.net evaluate simple math expressions natively

like evaluate() in VBA, is there any native way of evaluating a simple math expression in vb.net ?

ex :

Dim exp as String
exp = "2+3"
MsgBox(exp)

expecting 5 in message box.

simplifying expressions – Simplify is giving wrong result in Mathematica

I am trying to do a simple multiplication of variables in Mathematica:

Simplify(n*(n + 1)*(n + 2)) /. {n -> 6*p + 1}

This gives me the output:

(1 + 6 p)^2 (2 + 6 p)

However, this is clearly wrong (unless I missed something).

The same things happens with Factor:

Factor(n*(n + 1)*(n + 2)) /. {n -> 6*p + 1}

I get the output:

12 p (1 + 3 p) (2 + 6 p)

This is also incorrect.

The correct answer would have been:

6 (6p + 1) (3p + 1) (2p + 1)

Why is Mathematica giving different results and how can I get the correct results?

Thanks.

simplifying expressions – How to express sum of rational functions as a single term

I have rational functions $dfrac{q_1(x)}{p_1(x)},ldots,dfrac{q_n(x)}{p_n(x)}$ whose numerator I am trying to compute.

I want mathematica to take the lcm of $p_1(x),ldots,p_n(x)$ and express the sum

$$dfrac{q_1(x)}{p_1(x)}+ldots+dfrac{q_n(x)}{p_n(x)}$$ as a single rational expression with polynomials $dfrac{q(x)}{p(x)}$ such that $p(x)$ is the lcm of $p_i(x)$. The thing is these rational functions are quite ugly and their denominators do not share a many factors (at most 1 with another rational term in the sum).

I think because of this, expand, simplify and fullsimplify are not working as I envisioned them to work.

My main interest here are the coefficients of $p(x)$ in the resulting sum. How can I compute this? I appreciate your time spent on this.

webforms – Regular expressions in validation

I’m trying to make sense of the application of regular expression validation.

In my particular case, I want to block any use of “href” from a textarea field. The existence of a regular expression pattern field would suggest that I supply something typical like /^((?!href).)*$/, but that winds up having the unexpected effect of rejecting pretty much any text.

I looked at where the pattern is applied, and found this at line 296 of TextBase.php of Webform 8.5.23:

$pattern = '{^(?:' . $pcre_pattern . ')$}u';

…which means that the preg_match pattern is being converted to {^(?:/^((?!href).)*$/$}u, which obviously isn’t very helpful.

So, what are appropriate pattern formats for entering into the regular expression field of a validation? And as an aside, why does the pattern concantenator shown lack / delimiters?

Equivalence of regular expressions – Computer Science Stack Exchange

This seems like a dupe, but I couldn’t find one in a cursory search. Given that, we can solve your problem as follows:

  1. Generate NFAs $N_1$ and $N_2$ for the regular expressions $r_1$ and $r_2$;
  2. Generate DFAs $M_1$ and $M_2$ for the NFAs $N_1$ and $N_2$;
  3. Generate DFAs $D_1$ and $D_2$ such that $L(D_1) = L(M_1) setminus L(M_2)$ and $L(D_2) = L(M_2) setminus L(M_1)$;
  4. Determine whether $L(D_1) = L(D_2) = emptyset$; if so, $L(r_1) = L(r_2)$; else, $L(r_1) neq L(r_2)$.

You can do (1) by using Kleene’s theorem demonstrating that regular expressions and finite automata have the same expressive power. To each of the operations union, concatenation, and Kleene closure, there corresponds an automaton-based construction which accepts what the regular expression generates. By recursivly applying these constructions to subexpressions you can build an NFA to accept the language generated by a regular expression.

To do (2), you typically will want to use the powerset construction (sometimes called the subset construction). This involves constructing a DFA whose set of states equals the set of subsets of stats from the NFA. Transitions now connect subsets of states which are reachable from each other. The resulting DFA may have up to $2^{|Q|}$ states, where $Q$ is the set of states in your NFA.

To do (3), you can use the Cartesian product machine construction to generate machines with up to $|Q_1| times |Q_2|$ states. Every state in your product machine will correspond to a pair of states from the operand machines. You must choose the set of accepting states to effect the correct operation; in our case, set difference.

To do (4), you can try all strings of length up to and including $|Q|$. If the machine accepts anything, it must accept some string of such a length. If you check all the strings and nothing’s accepted, you know that $L(M) = emptyset$. If that’s the case, by construction, then the one language is a subset of the other. If both languages are subsets of each other, the languages are equal, by definition of set equality.

simplifying expressions – How to efficiently simplify the product?

Let $h_r$ denote the complete homogeneous symmetric polynomial of degree $r$ and let $S_lambda$ denote the Schur polynomial of partition $lambda$. By Pieri’s formula, we know that $h_rS_lambda=sum_nu S_nu$ where the sum ranges over all the partition $nu$ obtained by adding $r$ boxes in $lambda$ with no two in the same column.

I have successfully found how to code the expression of $h_rS_lambda$ in terms of $S_nu$‘s if we are given arbitrary $r,ninmathbb Z_{ge 0}$ and $lambdavdash n$.


My question is: If we are given an arbitrary $$h_{r_1}^{k_1}cdot h_{r_2}^{k_2}cdots h_{r_m}^{k_m}cdot S_{lambda}$$ for some $r_1,…,r_m,k_1,…,k_m,ninmathbb Z_{> 0}$, $lambdavdash n$ where $r_1,…,r_m$ are distinct, how to simplify this product so that we can express this product in terms of a sum of $S_{nu}$ where $nu$ ranges over all the partition obtained by adding $sum_{i=1}^m r_ik_i$ boxes to $lambda$ with no two in the same column?

My attempt:
I have found a function SchurTimesH[partition_,r_] such that it returns the desired sum whenever we feed the list of partition and the degree $r$ of the complete homogeneous symmetric polynomial into the function. But I have been getting stuck for hours finding how to do the simplification described above. I am a novice at Mathematica, the problem itself should not be hard, but I am not familiar with the grammar. Can someone give me a hint? Thank you!

matrix – Do loop with multiple expressions does not seem to evaluate all of them

Below is my code and I am having problems running the StdMPC function that I am trying to define. Running my code gives me the error that the matrix A and Xopt((i)) are not of compatible shapes for matrix multiplication.

OptControlVector is a custom function I have defined in another package that gives me a list. In my code, I want to get the output from OptControlVector, take its first ‘m’ elements and store in a row of a matrix Uopt, calculate and assign the next row of Xopt (using the previous row of Xopt and same row no. of Uopt) and do this iteratively T number of times. So, I use the Do loop.

StdMPC(A_,B_,Ax_,Au_,Af_,bx_,bu_,bf_,Q_,Qf_,R_,initcond_,N_,T_):=
Module({Uopt=ConstantArray(0,{T,1}),Uopttemp,m=Dimensions(B)((2)),Xopt=ConstantArray(0,{T+1,1})},
Xopt((1))=initcond; 
Do(Uopttemp=OptControlVector(A,B,Ax,Au,Af,bx,bu,bf,Q,Qf,R,Xopt((i)),N);
Uopt((i))=Uopttemp((1;;m));Xopt((i+1))=A.Xopt((i))+B.Uopt((i)),{i,T});Uopt)

This error made me suspicious that all the expressions in my Do loop are not being evaluated and that Xopt((i+1)) was not being evaluated which resulted in Xopt((2)) and so on being {0}. I then did this: In first case, I inserted Print(i) as the first expression in the Do loop and then in another case, put it as the second or third expression in the Do loop. The below code shows the first case I tried.

 StdMPC(A_,B_,Ax_,Au_,Af_,bx_,bu_,bf_,Q_,Qf_,R_,initcond_,N_,T_):=
Module({Uopt=ConstantArray(0,{T,1}),Uopttemp,m=Dimensions(B)((2)),Xopt=ConstantArray(0,{T+1,1})},
Xopt((1))=initcond; 
Do(Print(i);Uopttemp=OptControlVector(A,B,Ax,Au,Af,bx,bu,bf,Q,Qf,R,Xopt((i)),N);
Uopt((i))=Uopttemp((1;;m));Xopt((i+1))=A.Xopt((i))+B.Uopt((i)),{i,T});Uopt)

The output for this printed i=1,2,3 for T=3, as expected. However, for the second case, all I got was i=2 printed three times for T=3. The code for the second case is

StdMPC(A_,B_,Ax_,Au_,Af_,bx_,bu_,bf_,Q_,Qf_,R_,initcond_,N_,T_):=
Module({Uopt=ConstantArray(0,{T,1}),Uopttemp,m=Dimensions(B)((2)),Xopt=ConstantArray(0,{T+1,1})},
Xopt((1))=initcond; 
Do(Uopttemp=OptControlVector(A,B,Ax,Au,Af,bx,bu,bf,Q,Qf,R,Xopt((i)),N);Print(i);
Uopt((i))=Uopttemp((1;;m));Xopt((i+1))=A.Xopt((i))+B.Uopt((i)),{i,T});Uopt)

I have been trying to debug this for the past 3-4 hours now and I would be extremely grateful is someone could point out any mistakes here.