# Working with Julia Symbolics

**URL:** <https://discourse.julialang.org/t/working-with-julia-symbolics/94933>\
**Category:** General Usage\
**Tags:** symbolics\
**Created:** [February 20, 2023, 8:42pm UTC](https://discourse.julialang.org/t/working-with-julia-symbolics/94933 "2023-02-20T20:42:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cougar](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@Cougar](https://discourse.julialang.org/u/Cougar)\
**Post date:** [February 20, 2023, 8:42pm UTC](https://discourse.julialang.org/t/working-with-julia-symbolics/94933/1 "2023-02-20T20:42:46Z")

</div>

* * *

Using [Symbolics](https://symbolics.juliasymbolics.org), wanting Julia to determine that \lfloor\, 10 \sqrt{3} \,\rfloor = 17, and print `17` instead of `floor(10sqrt(3))` …

```julia
julia> x = 10 * Symbolics.Term(sqrt,[3])
10sqrt(3)

julia> y = floor(x)
floor(10sqrt(3))

```

Also, for `x`, wanting to print `10 √3` instead of `10sqrt(3)` .

Any advice much-appreciated.

* * *

Also, I’d like to mimic …

> `if sqrt(3) < sqrt(2) print("true") else print("false") end`

… with …

> `if Symbolics.Term(sqrt,[3]) < Symbolics.Term(sqrt,[2]) print("true") else print("false") end`

However, I’m getting …

> `TypeError: non-boolean (SymbolicUtils.BasicSymbolic{Bool}) used in boolean context`

Again, any insight would be much-appreciated.

* * *

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [February 20, 2023, 10:15pm UTC](https://discourse.julialang.org/t/working-with-julia-symbolics/94933/2 "2023-02-20T22:15:32Z")

</div>

> [@Cougar](#):
>
> Symbolics.Term(sqrt,[3]) \< Symbolics.Term(sqrt,[2])

That’s an expression not a value.

> [@Cougar](#):
>
> ⌊10√3⌋=17

Again, if you want a value, then don’t use symbolics.

> [@Cougar](#):
>
> ```julia
> julia> y = floor(x)
> floor(10sqrt(3))
> 
> ```

The point of symbolics is to allow for construction of lazy expressions. If you just run `floor(10sqrt(3))` then you get 17.

I guess the real question is, what are you trying to do?

---

<div class="post-metadata">

**Author:** ![Cougar](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@Cougar](https://discourse.julialang.org/u/Cougar)\
**Post date:** [February 20, 2023, 10:35pm UTC](https://discourse.julialang.org/t/working-with-julia-symbolics/94933/3 "2023-02-20T22:35:41Z")

</div>

* * *

I’m trying to use [**Dirichlet’s Approximation Theorem**](https://en.wikipedia.org/wiki/Dirichlet%27s_approximation_theorem) to find integers a and b such that 1 \le a \le 10 and | a \sqrt{3} - b | \lt \frac{1}{10} . I’d like to express, for example, that when j = 3 and k = 7 …

- a = k - j = 7 - 3 = 4
- b = \lfloor k \sqrt{3} \rfloor - \lfloor j \sqrt{3} \rfloor = \lfloor 7 \sqrt{3} \rfloor - \lfloor 3 \sqrt{3} \rfloor = 12 - 5 = 7
- | a \sqrt{3} - b | = | 4 \sqrt{3} - 7 | \lt \frac{1}{10} .

* * *

I’d like to use Julia to do the calculations symbolically, rather than use floating-point approximations such as \sqrt{3} \approx 1.73205 .

* * *
