Opened 5 years ago

Closed 5 years ago

# Fractional part function {x}

Reported by: Owned by: rws major sage-7.4 symbolics Ralf Stephan Matthias Koeppe N/A 141a784 141a784aac9d083327f9e8907583ac7a99cc5a31

### Description

This symbolic function will also be needed by the periodic piecewise function enhancement (#21215). It is in Sympy too.

### comment:1 Changed 5 years ago by rws

• Branch set to u/rws/fractional_part_function__x_

### comment:2 Changed 5 years ago by rws

• Authors set to Ralf Stephan
• Commit set to 3fcaf85fe46b32f7408f07cd4484761666463aa6
• Status changed from new to needs_review

New commits:

 ​3fcaf85 21232: Fractional part function {x}

### comment:3 Changed 5 years ago by mkoeppe

+            if isinstance(x, (int, long)):
+                return x - Integer(x)


Probably can just return Integer(0)

+    def _print_latex_(self, x):
+        r"""
+        EXAMPLES::
+
+            sage: latex(frac(x))
+            \left\{ x \right\}
+        """
+        return r"\left\{ %s \right\}"%latex(x)


I use this braces notation myself, but I can imagine that it's not universally used, and some people may prefer \mathop{\mathrm{frac}}(x). Perhaps a global option?

### comment:4 Changed 5 years ago by mkoeppe

• Reviewers set to Matthias Koeppe

### comment:5 follow-up: ↓ 7 Changed 5 years ago by mkoeppe

+            elif isinstance(x, (float, complex)):
+                return x - Integer(int(math.floor(x)))


Also, going through int seems dangerous here

### comment:6 Changed 5 years ago by mkoeppe

• Status changed from needs_review to needs_work

### comment:7 in reply to: ↑ 5 Changed 5 years ago by mkoeppe

+            elif isinstance(x, (float, complex)):
+                return x - Integer(int(math.floor(x)))


Also, going through int seems dangerous here

I retract this comment. I didn't realize int() makes Python bignums.

### comment:8 Changed 5 years ago by git

• Commit changed from 3fcaf85fe46b32f7408f07cd4484761666463aa6 to 141a784aac9d083327f9e8907583ac7a99cc5a31

Branch pushed to git repo; I updated commit sha1. New commits:

 ​141a784 21232: change LaTeX, return shortcut

### comment:9 Changed 5 years ago by rws

• Status changed from needs_work to needs_review

### comment:10 Changed 5 years ago by mkoeppe

• Status changed from needs_review to positive_review

Looks good to me.

For full symbolic functionality (which I never use), I guess one would need to tie this in with the simplification and assumptions machinery, so that things like this behave better:

sage: simplify(frac(frac(x)))
frac(frac(x))
sage: simplify(frac(floor(x)))
frac(floor(x))
sage: assume(x, 'integer')
sage: simplify(frac(x))
frac(x)


Perhaps on a follow-up ticket?

### comment:11 Changed 5 years ago by vbraun

• Branch changed from u/rws/fractional_part_function__x_ to 141a784aac9d083327f9e8907583ac7a99cc5a31
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.