Opened 4 years ago
Closed 4 years ago
#21232 closed enhancement (fixed)
Fractional part function {x}
Reported by:  rws  Owned by:  

Priority:  major  Milestone:  sage7.4 
Component:  symbolics  Keywords:  
Cc:  Merged in:  
Authors:  Ralf Stephan  Reviewers:  Matthias Koeppe 
Report Upstream:  N/A  Work issues:  
Branch:  141a784 (Commits)  Commit:  141a784aac9d083327f9e8907583ac7a99cc5a31 
Dependencies:  Stopgaps: 
Description
This symbolic function will also be needed by the periodic piecewise function enhancement (#21215). It is in Sympy too.
Change History (11)
comment:1 Changed 4 years ago by
 Branch set to u/rws/fractional_part_function__x_
comment:2 Changed 4 years ago by
 Commit set to 3fcaf85fe46b32f7408f07cd4484761666463aa6
 Status changed from new to needs_review
comment:3 Changed 4 years ago by
+ 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 4 years ago by
 Reviewers set to Matthias Koeppe
comment:5 followup: ↓ 7 Changed 4 years ago by
+ elif isinstance(x, (float, complex)): + return x  Integer(int(math.floor(x)))
Also, going through int seems dangerous here
comment:6 Changed 4 years ago by
 Status changed from needs_review to needs_work
comment:7 in reply to: ↑ 5 Changed 4 years ago by
Replying to 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 4 years ago by
 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 4 years ago by
 Status changed from needs_work to needs_review
comment:10 Changed 4 years ago by
 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 followup ticket?
comment:11 Changed 4 years ago by
 Branch changed from u/rws/fractional_part_function__x_ to 141a784aac9d083327f9e8907583ac7a99cc5a31
 Resolution set to fixed
 Status changed from positive_review to closed
New commits:
21232: Fractional part function {x
}