## 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.

## 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!

## Help with simplifying very complicated expressions

The following forms the matrix b:

``````A := Simplify(D((Sqrt(2)*k*Pi^2*x^2*(x + y + z)*(x + y + z + j + m))/((x + y)*(x + y + z + j)*Sqrt(x + y + z + j + m + n)), {{k, x, y, z, j, m, n}}))

B := Simplify(D((Sqrt(2)*k*Pi^2*(x + y + z)*z^2*(y + z + j)*(x + y + z + j + m)*(z + j + m)*Sqrt(y + z + j + m + n))/((y + z)*(x + y + z + j)*(z + j)*(y + z + j + m)*Sqrt((x + y + z + j + m + n)*(z + j + m + n))), {{k, x, y, z, j, m, n}}))

F := Simplify(D((Sqrt(2)*k*Pi^2*(x + y + z + j + m)*(z + j + m)*m^2*Sqrt(((y + z + j + m + n)*(j + m + n))/((x + y + z + j + m + n)*(z + j + m + n)*(m + n))))/((y + z + j + m)*(j + m)), {{k, x, y, z, j, m, n}}))

G := Simplify(D(-((2*(-1 + k)*Pi)/k)/(8*Pi), {{k, x, y, z, j, m, n}}))

H := Simplify(D(-(2*Pi*(1 - ((x + y)*(y + z)*(x + y + z + j)*(y + z + j + m)*Sqrt((x + y + z + j + m + n)/(y + z + j + m + n)))/(k*y*(x + y + z)*(y + z + j)*(x + y + z + j + m))))/(8*Pi), {{k, x, y, z, j, m, n}}))

J := Simplify(D(-(2*Pi*(1 - ((x + y + z + j)*(z + j)*(y + z + j + m)*(j + m)*Sqrt(((x + y + z + j + m + n)*(z + j + m + n))/((y + z + j + m + n)*(j + m + n))))/(k*(y + z + j)*j*(x + y + z + j + m)*(z + j + m))))/(8*Pi), {{k, x, y, z, j, m, n}}))

K := Simplify(D(-(2*Pi - (2*Pi*Sqrt((x + y + z + j + m + n)*(z + j + m + n)*(m + n)))/(k*Sqrt((y + z + j + m + n)*(j + m + n)*n)))/(8*Pi), {{k, x, y, z, j, m, n}}))

b := {A, B, F, G, H, J, K}
``````

Now, I need the 2nd, 4th and 6th elements of the first column of the inverted matrix. Instead of manually finding each component, I opted to use:

``````f := LinearSolve(b, {1, 0, 0, 0, 0, 0, 0})
``````

Next, I used:

``````f((2)) + f((4)) + f((6))
``````

to extract the required elements.

Here comes the part I have problems with. In my attempt to simplify the result of the actual sum I want, I used:

``````\$Assumptions = Element(k, PositiveReals) && z1 <= z2 <= z3 <= z4 <= z5 <= z6 <= z7 && Element(z1, Reals) && Element(z2, Reals) && Element(z3, Reals) && Element(z4, Reals) && Element(z5, Reals) && Element(z6, Reals) && Element(z7, Reals)
TimeConstrained(Simplify(Together(((3*Pi)/4)*(f((2)) + f((4)) + f((6))) //. {x -> z2 - z1, y -> z3 - z2, z -> z4 - z3, j -> z5 - z4, m -> z6 - z5, n -> z7 - z6})), 3600)
``````

Even with an hour, Mathematica couldn’t simplify the result.

The result I want is:

``````((-z1 + z3)*(-z1 + z5)*Sqrt(-z1 + z7))/(2*Pi*Sqrt(2)*k*(-z1 + z2)*(-z1 + z4)*(-z1 + z6))
``````

How should I proceed?

## Simplifying Floor/Ceiling expressions – Mathematica Stack Exchange

I’m working with symbolic expressions using `Floor` and `Ceiling`, and I’m unable to get `Simplify` to evaluate them. For instance, I would expect:

`Assuming(Element(n,Integers), Simplify(Ceiling(n/2) + Floor(n/2) == n)`

to result in `True`, but it doesn’t. (`FullSimplify` doesn’t work either.)

There is a work-around using `Resolve` given in the comment to this question.

However, I would like to somehow implement `Assuming` and `Simplify` to achieve the same result. Is this possible? It seems such a simple, obvious expression…

## function construction – simplifying indefinite sums containing Kronecker Deltas

I want to simplify indefinite sums containing KroneckerDeltas, e.g:

``````Sum[ β[q] β[k + q + k1] KroneckerDelta[k1 + q], k, k1,q]
Sum[ β[q] β[k + q + k1] KroneckerDelta[k1 + q], k, k1, q] // FullSimplify
``````

doesn’t work, i.e I don’t get

``````Sum[β[q] β[k ], k, q]
``````

I have found here a custom `MyDiscreteDelta` function which also doesn’t work.
Is there a way to achieve such simplifications?

## evaluation – Simplifying expression involving Boson operators

I want to do calculations involving Boson operators $$a(k), a^{dagger}(k)$$, e.g $$(x + a(k))(y+a^{dagger}(k))$$. My code is:

``````NCM(x___) := NonCommutativeMultiply(x);
NCM() := 1
NCM(___, 0, ___) := 0
NCM(H___, 1, T___) := NCM(H, T)

NCM(left___, a(k1_), SuperDagger(a)(k2_), right___) :=
NCM(left, SuperDagger(a)(k2), a(k1), right) +
NCM(left, right)*KroneckerDelta(k1 - k2)

Unprotect(NCM);
NCM(left___, HoldPattern(Times(id, x_)), right___) :=
x  NCM(left, right)
NCM(left___, HoldPattern(Times(a(k_), x_)), right___) :=
x   NCM(left, a(k), right)
NCM(left___, HoldPattern(Times(SuperDagger(a)(k_), x_)), right___) :=
x NCM(left, SuperDagger(a)(k), right)

Protect(NCM);
``````

where based on Simplifying expression with non-commutating entries
I introduced the unit `id` and based on Boson Commutation relations’s first reply I constructed the $$(a(k),a^{dagger}(k’))=delta_{kk’}$$ relation.

Now if I try:

``````Distribute((x id + a(k)) ** (y id - SuperDagger(a)(k)))
(* I get *)
(id x) ** (id y) + (id x) ** (-SuperDagger(a)(k)) + a(k) ** (id y) +
a(k) ** (-SuperDagger(a)(k))
``````

and not `x y -x SuperDagger(a)(k) + y a(k) - a(k) **SuperDagger(a)(k)`

I can’t figure out why…

## simplifying expressions – Simplify and solve an N-term exponential sum

How does one express this sum into Mathematica:

$$10^{k-1} + 10^{k-2} +….+ 10 + 1$$

I think I have to use the Sum function? Then run it over N=K..1? But then I want to substitute and evaluate it for various k’s.

Ok once I get that input correctly, my ultimate goal is to Simplify this for P, Q, R, and k positive integers:

$$P(10^{2k-1} + 10^{2k-2} + 10^{2k-3} +….+ 10^k + 10^{k-1} + … +10 + 1) – Q(10^{k-1} + 10^{k-2} +….+ 10 + 1) = R^2(10^{k-1} + 10^{k-2} +….+ 10 + 1)^2$$

I need to have Mathematica Simplify that, then run it over some large values of the 4 variables and try and see which ones solve the equality.

P.S. in a Nutshell what that is saying is this: Find me a series of 2k repeated digits then subtract another series of k digits from it, that will result in a new set of digits squared – the multiplier of which is also squared.
So say for a fake example: $$444444-222=2^2(333)^2$$ I just made that up to show you what it looks like, that equality is 666 off! Just notice how the first number has 6 digits and the next 2 have half (3 digits), etc. In this case P=4, Q=2, R=2, and k=3 . I want Mathematical to go over all k’s (say for k from 1 to 10000) and give me exact solutions and tell me for what values of P, Q, and R, the equality is satisfied over that range of k.

## simplifying expressions – RecurrentTable is not honoring FullSimplify

``````\$Version

(* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)

Clear("Global`*")

nextK(k3_) := FullSimplify(3 + k3 + 2 Sqrt(2 + 3 k3));
``````

Add memorization to the definition of `G`

``````G(y_) := G(y) = nextK(G(y - 1));
G(1) := 3
Table(G(i), {i, 3})

(* {3, 2 (3 + Sqrt(11)), 15 + 4 Sqrt(11)} *)
``````

The `RecurrenceTable` results have not been simplified. Presumably, `nextK` is first evaluated symbolically where the simplification does not change the form. Subsequent numeric values do not then have the simplification applied.

``````seq = RecurrenceTable({a(n + 1) == nextK(a(n)), a(1) == 3}, a, {n, 1, 5})

(* {3, 6 + 2 Sqrt(11), 9 + 2 Sqrt(11) + 2 Sqrt(2 + 3 (6 + 2 Sqrt(11))),
12 + 2 Sqrt(11) + 2 Sqrt(2 + 3 (6 + 2 Sqrt(11))) +
2 Sqrt(2 + 3 (9 + 2 Sqrt(11) + 2 Sqrt(2 + 3 (6 + 2 Sqrt(11))))),
15 + 2 Sqrt(11) + 2 Sqrt(2 + 3 (6 + 2 Sqrt(11))) +
2 Sqrt(2 + 3 (9 + 2 Sqrt(11) + 2 Sqrt(2 + 3 (6 + 2 Sqrt(11))))) +
2 (Sqrt)(2 +
3 (12 + 2 Sqrt(11) + 2 Sqrt(2 + 3 (6 + 2 Sqrt(11))) +
2 Sqrt(2 + 3 (9 + 2 Sqrt(11) + 2 Sqrt(2 + 3 (6 + 2 Sqrt(11)))))))} *)

seq = seq // FullSimplify

(* {3, 2 (3 + Sqrt(11)), 15 + 4 Sqrt(11), 6 (5 + Sqrt(11)), 51 + 8 Sqrt(11)} *)
``````

Note that `FindSequenceFunction` can be used to generalize from the sequence provided by `RecurrenceTable`

``````f(n_) = FindSequenceFunction(seq, n) // FullSimplify

(* 6 - 2 Sqrt(11) + n (-6 + 2 Sqrt(11) + 3 n) *)
``````

Verifying that this result is equivalent to `G`

``````And @@ Table(G(n) == f(n), {n, 50})

(* True *)
``````

However, the results of `f` must also be subsequently simplified to obtain the same form as `G`

``````f /@ Range(3)

(* {3, 6 + 2 Sqrt(11), 6 - 2 Sqrt(11) + 3 (3 + 2 Sqrt(11))} *)

% // FullSimplify

(* {3, 2 (3 + Sqrt(11)), 15 + 4 Sqrt(11)} *)
``````

## c# – Simplifying these methods for iterating through object and modifying string fields

I have this method (consisting of three methods) that I need to use for looking through objects that are going to be serializes and logged as json objects.

a bit of intro (not necessary to read)

The initial problem was that I noticed that sometimes I would receive data in objects from external api’s that would contain personal sensitive data i.e social security numbers. I would still like to log these objets though, I just want to sanitize the social sec numbers away, and I also would like to have some method that could this for object with any kind of internal structure, such that I could reuse it, and would’nt need to rewrite a new sanitization method for each log.

The problem

So now I wanted these methods that could look into objects of any type, and sanitize all the string fields, such that the strings would look the same, but for any string field with a social security number of the type 123456-7891, should be replaced with XXXXXX-XXXX.

``````   public static  void DoitNow(object obj)
{
Queue<PropertyInfo> properties = new Queue<PropertyInfo>(obj.GetType().GetProperties());
while (properties.Count != 0)
{
PropertyInfo property = properties.Dequeue();

if (property.GetValue(obj) is string)
{

string stringField = property.GetValue(obj).ToString();

String sanitizedField = sanitizeSensitiveString(stringField);
property.SetValue(obj, sanitizedField);

}
else if (property.GetValue(obj) is IList)
{
IList y = (IList)property.GetValue(obj);

if (y.Count != 0)
{
if (y(0) is string)
{
for (int i = 0; i < y.Count; i++)
y(i) = sanitizeSensitiveString((string)y(i));
}
else if (IsNested(y(0)))
{
for (int i = 0; i < y.Count; i++)
{
DoitNow(y(i));
}
}
}
}
else if (IsNested(property.GetValue(obj)))
{

var l = property.GetValue(obj);

DoitNow(l);
}

}
}
public static string sanitizeSensitiveString(string sensitiveString)
{
return Regex.Replace(sensitiveString, @"d{6}-?d{4}(0-9)*", " XXXXXX-XXXX ");
}
public static bool IsNested(object value)
{

Type t = value.GetType();
if (t.IsPrimitive || value is string)
{
return false;
}
FieldInfo() fields = t.GetFields(BindingFlags.NonPublic |
BindingFlags.Public |
BindingFlags.Instance);
if (fields.Any())
{
return true;
}
return false;
}
``````

Now, the method DoitNow is the core method here, it takes any object as a parameter, and uses projection to look through all the properties of it. If a field is a string field, we use the method sanitizeSensitiveString to sanitize the string. I a property is itself a object (I use the method isNested to determine this) I will call the method recursively on it. If a property is a List type, I look into the list and sanitize if it contains stirngs, and recurse if it contains complex objects.

I would like to get some tips on my Isnested method, am I using projection right? In general am I using projection In a way that makes sense to acces the fields and modify them?

Also, In order to be able to operate with many list types, I use the IList interface, however this has led me to using for-loops in a way that I find very un-elegant, can I replace some of my loops with some functional type function calls? I also use if (list.count != 0) to test if a list is empty, I just find this plain stupid.

Any other optimizations are welcomed!

## simplifying expressions – How to put numerator and denominator in a canonical form?

So I have the following expression that I obtained after some computation:

``````TDiscrete=-(R2/(R1 tauC^2 (R2/(R4 tauC^2) + (CC2 R2 (1 - y^2))/(
CC1 R3 tauC^2 y) + (CC2^2 (1 - y^2)^2)/(CC1^2 tauC^2 y^2))))
``````

Now I want that Mathematica displays this in a canonical form, meaning, has a fraction of two polynomials dependent on y. Any idea on how to do that?