how to determine a rational is square free? - wolfram-mathematica

We know that if $μ(n)=0$ then the integer n has at least one factor with multiplicity.
Now how can we determine if in the decomposition of a rational (m/n)>1 to prime factors, we have a power less than (-1)? For example
m=2*3*5*7*11;
n=2^2*3^3*5;
m/n=2^(-1)*3^(-2)*7*11
f(m/n)=0 (*for example*)
Is there any function similar to Moebius function μ in Mathematica which does this job for me?
I think I can write the code, but I need a defined function in Mathematica?
thanks

I think I found it,
It should be
f[x_]:=If[SquareFreeQ[x]==True,1,0]

Related

Check whether a system of linear equations has a a solution

What is the fastest way to check whether a system of linear equations has a solution?
All numbers are rational numbers and the (large) coefficient matrix can be given in the form of SparseArray.
I know that LinearSolve can solve this problem, but if you don't need to know what the solution is, but only need to judge the existence, is there a more efficient method?
The way to calculate rank seems to be slower when there is no solution.
By the way, when I use 'LinearSolve', the form of 'SparseArray' can't help me get faster, even if there are only very limited non-zero elements in each row.
One idea is verifying
Det[PseudoInverse[m]] == 0.
where m is the square matrix of the coefficients.

calculate logarithm for very large numbers

I would like to calculate the following function for very large number (for example e^e^e^e^10) and would like to know the sign of the following term in general. I tried for some numbers, but it is negative. Is there any m0 such that for all n>m>m0, the following function is positive.
where n is greater than m.
I tied with Mathematica, but it does not compute for the above number. Should I use special package?
thanks

Excel Polynomial Curve-Fitting Algorithm

What is the algorithm that Excel uses to calculate a 2nd-order polynomial regression (curve fitting)? Is there sample code or pseudo-code available?
I found a solution that returns the same formula that Excel gives:
Put together an augmented matrix of values used in a Least-Squares Parabola. See the sum equations in http://www.efunda.com/math/leastsquares/lstsqr2dcurve.cfm
Use Gaussian elimination to solve the matrix. Here is C# code that will do that http://www.codeproject.com/Tips/388179/Linear-Equation-Solver-Gaussian-Elimination-Csharp
After running that, the left-over values in the matrix (M) will equal the coefficients given in Excel.
Maybe I can find the R^2 somehow, but I don't need it for my purposes.
The polynomial trendlines in charts use least squares based on a QR decomposition method like the LINEST worksheet function ( http://support.microsoft.com/kb/828533 ). A second order or quadratic trend for given (x,y) data could be calculated using =LINEST(y,x^{1,2}).
You can call worksheet formulas from C# using the Worksheet.Evaluate method.
It depends, because there are a lot of ways to do such a thing depending on the data you supply and how important it is to have the curve pass through those points.
I'm guessing that you have many more points than you do coefficients in the polynomial (e.g. more than three points for a 2nd order curve).
If that's true, then the best you can do is least square fitting, which calculates the coefficients that minimize the mean square error between all the points and the resulting curve.
Since this is second order, my recommendation would be just create the damn second order terms and do a linear regression.
Ex. If you are doing z~second_order(x,y), it is equivalent to doing z~first_order(x,y,x^2,y^2, xy).

Generate code from id using a 1-1 function

Is there any good invertible 1-1 function that maps an integer to another integer?
for eg, given the range 0-5, I want to find one that maps:
0->3
1->2
2->4
3->5
4->1
5->0
Also, the mapping should look random.
You can fill an array in ascending order and shuffle it. This will usually perform reasonably well, if not being the most efficient memorywise.
You can also rely on a closed discrete transformation, such as multiplication. If you have 2 numbers, P and K, then (I think) as long as P and K are coprime, P^n mod K will produce a nonrepeating, pseudorandom sequence of values of length (K - 1), ranging from 1 to K. This particular manifestation of discrete math is one of the premises of cryptography. Going backwards from sequence to exponent is known as the discrete logarithm problem and is the reason traditional RSA is secure.
You asked for a reversible algorithm. If you keep track of the exponent, you can go from P^n mod K to P^(n-1) mod K without much difficulty. You can take a few shortcuts to go backwards from power to exponent that don't work in cryptography because certain parameters of the algorithm are intentionally discarded to make it harder.
That said, if you happen to break RSA by solving the discrete log problem while you're working on this, be sure to let me know.
How about permutation polynomials? See section 3 in this article: http://webstaff.itn.liu.se/~stegu/jgt2012/article.pdf It is used for noise there, but it looks exactly like what you want.
It suggest to construct functions of the form (Ax^2 + Bx) mod M. Only a small subset of those functions are invertible/produce permutations, but it shouldn't be hard to find the actual inverse if it exists.
Something similar to this was discussed in Non-repetitive random seek in a range Algorithm. I was intrigued enough to put some ideas down at http://www.mcdowella.demon.co.uk/PermutationFromHash.html
You can generate such a permutation using a block cipher, without having to hold the entire thing in memory (as you would if you were to shuffle the list). I wrote a blog post about it some time ago, which you can find here.

Convert rounded decimal to (approximate) radical value?

I've made a lot of random math programs to help me with my homework (synthetic division being the most fun) and now I'm wanting to reverse a radical expression.
For instance, in my handy TI calculator I get
.2360679775
Well, I want to convert that number to it's equivalent irrational expression, which is
sqrt(5)-2
I realize I could brute force it... but that takes out the fun, and isn't nearly so easy when you consider the significant round-off error of floating point.
So how would you do it? Is there is a trivial algorithm?
Inverse Symbolic Calculator
(I originally linked to this which seems to be gone.)
Well, your example hasn't actually transformed the input to the equivalent irrational expression, but to an equivalent irrational expression. As the Inverse Symbolic Calculator indicates, there are many candidate irrational expressions within a tolerance of the decimal number in your example, and there will be just as many irrationals within any degree of tolerance of any decimal number you specify. It's all to do with the density of irrationals along the number line.
So to answer your questions:
I would limit myself to a number of terms such as sqrt(2), sqrt(3), sqrt(small prime numbers), e, pi, and integers, plus rationals with small prime denominators and approximate the decimals with a few terms based on those plus the four basic arithmetical operators;
Is this algorithm trivial ? You decide. In general, though, I think it will be impossible to find an algorithm for determining a canonical representation of any decimal fraction as a series of irrational terms and integers, for the simple reason that no such canonical representation exists.
But then, my real and irrational maths is very rusty, I look forward to proofs that I am wrong and counter-examples.

Resources