# Equation involving floor function

How can I solve the following in Julia;
6t^2 - 7floor(t) - 3 = 0
I thought when I define t, with Sym(“t”), it would work. Instead it gives me

Is there a workaround. By the way I’m interested in exact solutions and not approximations, which in this case are t_1 = sqrt(5/3), t_2 = sqrt(1/2) (solved them with wolframalpha)

From the SymPy documentation: https://docs.sympy.org/latest/tutorial/solvers.html#solving-equations-algebraically

if it is not able to find solutions then a `ConditionSet` is returned.

It seems that SymPy is not yet equipped to solve the above equation, like WolframAlpha is. You can try to open a feature request on the SymPy github about it: GitHub - sympy/sympy: A computer algebra system written in pure Python

As for a Julia library Symbolics.jl’s `solve_for` only works for linear equations. I’m afraid for algebraic solves WolframAlpha is currently your best bet.

If you are find with numerical solves you can use NLsolve.jl: GitHub - JuliaNLSolvers/NLsolve.jl: Julia solvers for systems of nonlinear equations and mixed complementarity problems

``````julia> using NLsolve

julia> function f!(F, x)
F[1] = 6 * x[1]^2 - 7 * floor(x[1]) - 3
end
f! (generic function with 1 method)

julia> nlsolve(f!, [0.1], autodiff = :forward)
Results of Nonlinear Solver Algorithm
* Algorithm: Trust-region with dogleg and autoscaling
* Starting Point: [0.1]
* Zero: [0.707106781481149]
* Inf-norm of residuals: 0.000000
* Iterations: 6
* Convergence: true
* |x - x'| < 0.0e+00: false
* |f(x)| < 1.0e-08: true
* Function Calls (f): 7
* Jacobian Calls (df/dx): 7

julia> nlsolve(f!, [1.5], autodiff = :forward)
Results of Nonlinear Solver Algorithm
* Algorithm: Trust-region with dogleg and autoscaling
* Starting Point: [1.5]
* Zero: [1.2909944487358056]
* Inf-norm of residuals: 0.000000
* Iterations: 4
* Convergence: true
* |x - x'| < 0.0e+00: false
* |f(x)| < 1.0e-08: true
* Function Calls (f): 5
* Jacobian Calls (df/dx): 5

julia> sqrt(5/3)
1.2909944487358056

julia> sqrt(1/2)
0.7071067811865476
``````
1 Like

This is an area where WolframAlpha really shines and floor equations are unlikely to be a priority for most symbolic algebra packages. It might help if you explain why you need an exact solution and what generalizations of the equation are of interest (apparently you already know the answer to this one).

For this particular equation it is immediately obvious that any solution must be of the form `t = sqrt((7n + 3) / 6)` for some integer `n` and if it turns out that `n <= t < n + 1` it is a valid solution. Then all that remains is to determine which integers `n` satisfy that relation.