Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fractional part function {x} #21232

Closed
rwst opened this issue Aug 12, 2016 · 12 comments
Closed

Fractional part function {x} #21232

rwst opened this issue Aug 12, 2016 · 12 comments

Comments

@rwst
Copy link

rwst commented Aug 12, 2016

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

https://en.wikipedia.org/wiki/Fractional_part

Component: symbolics

Author: Ralf Stephan

Branch/Commit: 141a784

Reviewer: Matthias Koeppe

Issue created by migration from https://trac.sagemath.org/ticket/21232

@rwst rwst added this to the sage-7.4 milestone Aug 12, 2016
@rwst
Copy link
Author

rwst commented Aug 13, 2016

Branch: u/rws/fractional_part_function__x_

@rwst
Copy link
Author

rwst commented Aug 13, 2016

Commit: 3fcaf85

@rwst
Copy link
Author

rwst commented Aug 13, 2016

New commits:

3fcaf8521232: Fractional part function {x}

@rwst
Copy link
Author

rwst commented Aug 13, 2016

Author: Ralf Stephan

@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 13, 2016

comment:3
+            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?

@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 13, 2016

Reviewer: Matthias Koeppe

@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 13, 2016

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

Also, going through int seems dangerous here

@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 13, 2016

comment:7

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.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 17, 2016

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

141a78421232: change LaTeX, return shortcut

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 17, 2016

Changed commit from 3fcaf85 to 141a784

@mkoeppe
Copy link
Contributor

mkoeppe commented Aug 17, 2016

comment:10

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?

@vbraun
Copy link
Member

vbraun commented Aug 19, 2016

Changed branch from u/rws/fractional_part_function__x_ to 141a784

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants