Equation simplification in Maxima - maxima

I have the following expression:
(x^2*α^2*(α/β)^m*β^m-x^2*α^(m+2))/(2*β^2)
I think the numerator should simplify to zero, but I can't seem to get Maxima to do so.

Related

Find unknown parameters of the function, if f(x) and x are given

I need some help.
I have an equation:
f(x) = acos(x) + (bsqrt(x) + ctg(x))^2,
where a, b, c are unknown parameters.
Also I have a few pairs of x -> f(x) like in Supervised ML problem.
How can I find parameters? I'm thinking of some numerical methods and linear regression, but actually I don't know what to do.
The unknown parameters would minimize the sum of squared differences between computed function values and observed function values.
You could define such a sum of squared errors in Excel and use Excel Solver to minimize it.
From a Python program, you could try Scipy fsolve.

Speed up Z3 to CNF conversion

I have predicate that operates with 32bit numbers and I want to convert it to CNF.
I'm using Z3py for that the following way:
value = compute_value(BitVec("x", 32))
threshold = compute_threshold(BitVec("y", 32))
is_valid = value < threshold
g = Goal()
g.add(is_valid)
t = Then('simplify', 'bit-blast', 'tseitin-cnf')
result = t(g)
print(result)
Listings of compute_value and compute_threshold are few hundreds lines of code. I don't think it's reasonable to show them. Output of both is also 32bit BitVec.
I also tried to use tseitin-cnf-core and elim-and tactics, but I always have to break computation because Z3 consumes all my RAM.
That seems strange. As far as I know tseitin conversion requires only O(n) time and space. I suspect Z3 performs unnecessary simplifications of formula which requires so many resources.
What tactics should I use to speed up? Or maybe you know tool better than Z3 to convert predicate with arithmetic expressions to CNF?

Maxima solve returns no solutions

I defined a function like this:
f(x):=(4*x^4+7*x^3+(-3)*x)/(2*x^2+5)
And then assign the derivative to df like this:
df(x):=''(diff(f(x), x))
Maxima then prints this as the calculated derivative:
df(x):=(16*x^3+21*x^2-3)/(2*x^2+5)-(4*x*(4*x^4+7*x^3-3*x))/(2*x^2+5)^2
Then I try to solve the derivative for df(x)=0 to find stationary points of f:
solve(df(x)=0, x);
But instead of solutions, Maxima gives me this:
[0=16*x^5+14*x^4+80*x^3+111*x^2-15]
Which suggests that there are no solutions. But if I plot the function df, it crosses the x-axis 3 times. So clearly there are 3 points where df(x)=0. Why can't Maxima find them? Am I doing something wrong?
df(x) is a quintic (i.e., degree 5) polynomial, and as such it probably does not have a solution in terms of radicals. There are solvable quintics, although I suspect Maxima cannot determine whether a quintic is solvable or not. For more about the general theory about quintics, take a look at https://en.wikipedia.org/wiki/Quintic_function#Finding_roots_of_a_quintic_equation .
I think a workable approach is to look for numerical approximations. Take a look at the Maxima functions realroots and allroots.

What function does the "//" operator provide in Lua?

I've been seeing the // operator a whole bunch as I work with Lua on the TIC-80. However, I've been unable to find any documentation on it. The use cases for this that I've generally seen are something like this:
n = t%60//30*2
the input/output table for this function is as follows:
t|n
0 |0
15|0
30|2
45|2
60|0
75|0
etc...
This is often used for switching between sprites at set rates, and I understand what comes out of it, I just don't understand how.
From the Lua reference manual, 3.4.1 Arrithmetic Operators:
Lua supports the following arithmetic operators:
+: addition
-: subtraction
*: multiplication
/: float division
//: floor division
%: modulo
^: exponentiation
-: unary minus
Floor division (//) is a division that rounds the quotient towards
minus infinity, that is, the floor of the division of its operands.
The floor division operator was introduced in Lua 5.3
Please refer to manuals.

Good way to approximate a floating point number

I have a program that solves equations and sometimes the solutions x1 and x2 are numbers with a lot of decimal numbers. For example when Δ = 201 (Δ = discriminant) the square root gives me a floating point number.
I need a good approximation of that number because I also have a function that converts it into a fraction. So I thought to do this:
Result := FormatFloat('0.#####', StrToFloat(solx1));
The solx1 is a double. In this way, the number '456,9067896' becomes '456,90679'.
My question is this: if I approximate in this way, the fraction of 456,9067896 will be correct (and the same) if I have 456,90679?
the fraction of 456,9067896 will be correct (and the same) if I have 456,90679?
No, because 0.9067896 is unequal to 0.90679.
But why do you want to round the numbers? Just let them be as they are. Shorten them only for visual representation.
If you are worried about complete correctness of the result, you should not use floating point numbers at all, because floating points are, by definition, a rounding of real numbers. Only the first 5-6 decimal digits of a 32-bit floating point are generally reliable, the following ones are unreliable, due to machine error.
If you want complete precision, you should be using symbolic maths (rational numbers and symbolic representation for irrational/imaginary numbers).
To compare two floating point values with a given precision, just use the SameValue() function from Math unit or its sibbling CompareValue().
if SameValue(456.9067896, 456.90679, 1E-5) then ...
You can specify the precision on which the comparision will take place.
Or you can use a currency value, which has fixed arithmetic precision of 4 digits. So, it won't have rounding issue any more. But you can not do all mathematic computation with it (huge or tiny numbers are not handled properly): its main use is for accounting computations.
You should better never use string representations to compare floats, since it may be very confusing, and do not have good rounding abilities.

Resources