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

Implement symbolic Kronecker delta and also make current signum (sgn) symbolic #6803

Closed
golam-m-hossain opened this issue Aug 22, 2009 · 13 comments

Comments

@golam-m-hossain
Copy link

We should have a symbolic Kronecker delta in Sage.

Also, current implementation of signum (sgn) function
returns wrong answer for symbolic input.

sage: sgn(x)
1
sage: sgn(-x)
1

So we should make sgn() symbolic aware. Given, implementation of
these functions in new symbolics should be very similar to the existing generalized function Dirac delta and Heaviside, I am putting them together here.

Also, ticket #777 should be closed down as Sign is already in Sage
and this ticket will further enhance it.

Patch:

Apart from implementing these two symbolic functions, attached patch slightly speeds up three other generalized functions by avoiding default __call__ method of PrimitiveFunction. These functions take explicit value either 0,-1,1 so those checks are not needed.

Timing before the patches:

sage: timeit('dirac_delta(1.0)')
625 loops, best of 3: 179 µs per loop
sage: timeit('unit_step(1.0)')
625 loops, best of 3: 345 µs per loop
sage: timeit('heaviside(1.0)')
625 loops, best of 3: 344 µs per loop

Timing after the patches:

sage: timeit('dirac_delta(1.0)')
625 loops, best of 3: 159 µs per loop
sage: timeit('heaviside(1.0)')
625 loops, best of 3: 324 µs per loop
sage: timeit('unit_step(1.0)')
625 loops, best of 3: 323 µs per loop

Also, it does slight re-arrangements of references.

Component: symbolics

Author: Golam Mortuza Hossain

Reviewer: Karl-Dieter Crisman

Merged: sage-4.3.alpha0

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

@golam-m-hossain
Copy link
Author

comment:1

Attachment: trac_6803-symbolic-kronecker-n-signum.patch.gz

@golam-m-hossain

This comment has been minimized.

@golam-m-hossain
Copy link
Author

Author: Golam Mortuza Hossain

@kcrisman
Copy link
Member

Reviewer: Karl-Dieter Crisman

@kcrisman
Copy link
Member

comment:2

Overall this is good, and should get positive review. However, there is a doctest failure (very typical when one adds a new symbolic function in line 204 of symbolic/random_tests.py, with random_expr(). This should be easy to fix.

@kcrisman kcrisman added this to the sage-4.1.2 milestone Sep 23, 2009
@kcrisman
Copy link
Member

comment:3

I have attached the patch, but with the random test fixed as a reviewer patch. Apply only this patch.

@kcrisman
Copy link
Member

Based on 4.2.1.alpha0, apply only this patch.

@kcrisman
Copy link
Member

comment:4

Attachment: trac_6803-symbolic-kronecker-n-signum-review.patch.gz

@mwhansen
Copy link
Contributor

comment:5

I had to add a small patch to the doctest for sage.quadratic_forms.extras.sgn to make sure that the doctest was actually doctesting that function.

@mwhansen
Copy link
Contributor

Merged: sage-4.3.alpha0

@kcrisman
Copy link
Member

comment:6

Replying to @mwhansen:

I had to add a small patch to the doctest for sage.quadratic_forms.extras.sgn to make sure that the doctest was actually doctesting that function.

Can you post that here, or at least the code in braces - just for posterity?

@sagetrac-mvngu
Copy link
Mannequin

sagetrac-mvngu mannequin commented Dec 9, 2009

apply after previous

@sagetrac-mvngu
Copy link
Mannequin

sagetrac-mvngu mannequin commented Dec 9, 2009

comment:7

Attachment: trac_6803-sgn.patch.gz

Replying to @kcrisman:

Can you post that here, or at least the code in braces - just for posterity?

mhansen's patch is contained in trac_6803-sgn.patch

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