# How to Calculate the Integral of Floor function / ⌊x⌋ using SymPy or CalculusWithJulia Correctly?

**URL:** <https://discourse.julialang.org/t/how-to-calculate-the-integral-of-floor-function-x-using-sympy-or-calculuswithjulia-correctly/90998>\
**Category:** General Usage\
**Tags:** package\
**Created:** [November 29, 2022, 2:32pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-integral-of-floor-function-x-using-sympy-or-calculuswithjulia-correctly/90998 "2022-11-29T14:32:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [November 29, 2022, 2:32pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-integral-of-floor-function-x-using-sympy-or-calculuswithjulia-correctly/90998/1 "2022-11-29T14:32:56Z")

</div>

Hi all,

I tried Sympy and the integral of a floor function can’t be calculated well. Here you go:  
 ![Capture d’écran_2022-11-29_21-29-36](https://global.discourse-cdn.com/julialang/original/3X/c/c/cc5eba292d5cf681cb1cdce3f753f8f123624956.png)

The code to plot the floor function works well:

```julia
using Plots,LaTeXStrings,Colors
gr()

f(x) = floor(x)
x = -4:1:4
y = f.(x)
plot(x[1:2], [y[1], y[1]], label=L"f(x) = x^{2} \lfloor x \rfloor", legend=:topleft,legend_foreground_color=:white, legend_font_color=:blue3, color=:blue3, showaxis=false, tickfontcolor=:white)
# axis and 
hline!((0,0), color=:black, label="")
vline!((0,0), color=:black, label="")
for i in x
	if i!= 0
		annotate!(i,-0.2, (i, 7))
	end
end
for i in y
	if i != 0
		annotate!(-.2, i, (i, 7))
	end
end
annotate!(-.2, -.2, ("0", 7))
for i in 2:length(x)-1
	plot!(x[i:i+1], [y[i], y[i]], label="", color=:blue3, lw=2)
	scatter!(x[i], y[i], marker=:circle, markersize=8, label="")
end
scatter!(x[1:end-1], y[1:end-1], markersize=3, markercolor=:blue4, label="")
scatter!(x[2:end], y[1:end-1], markersize=3, markercolor=:white, label="")

```

But, is the integral of ` ⌊x⌋` unable to be calculated with my simple code:

```julia
using SymPy

x = symbols("x")

integrate(f(x),x)

```

Thanks all!

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [November 29, 2022, 6:58pm UTC](https://discourse.julialang.org/t/how-to-calculate-the-integral-of-floor-function-x-using-sympy-or-calculuswithjulia-correctly/90998/2 "2022-11-29T18:58:45Z")

</div>

The SymPy Python library doesn’t integrate `floor`, so you aren’t going to get the answer you want. This particular function lends itself to a geometric answer for a definite integral, as all involved areas are rectangles with base at most 1. (The integral from 0 to a positive x could be found with ` n,r = divrem(x, 1); n*(n-1)/2 + r*n`)
