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

symbolic_expression(lambda x, y: ...) #32103

Closed
mkoeppe opened this issue Jul 3, 2021 · 26 comments
Closed

symbolic_expression(lambda x, y: ...) #32103

mkoeppe opened this issue Jul 3, 2021 · 26 comments

Comments

@mkoeppe
Copy link
Member

mkoeppe commented Jul 3, 2021

We extend the global binding symbolic_expression to accept a callable such as those created by lambda expressions.

The result is a callable symbolic expression, in which the formal arguments of the callable are the symbolic arguments.

Example:

symbolic_expression(lambda x,y: x^2+y^2) == (SR.var("x")^2 + SR.var("y")^2).function(SR.var("x"), SR.var("y"))

This will provide convenient syntax in particular in connection to ConditionSet (#32089).

Instead of

sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12  # preparser syntax, creates globals
sage: ConditionSet(ZZ^3, predicate)

one would then be able to write

sage: ConditionSet(ZZ^3, symbolic_expression(lambda x, y, z: 
....:     sqrt(x^2 + y^2 + z^2) < 12))

CC: @egourgoulhon @tscrim @nbruin @kcrisman

Component: symbolics

Author: Matthias Koeppe

Branch/Commit: 2b5535f

Reviewer: Travis Scrimshaw, Karl-Dieter Crisman

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

@mkoeppe mkoeppe added this to the sage-9.4 milestone Jul 3, 2021
@mkoeppe

This comment has been minimized.

@mkoeppe

This comment has been minimized.

@mkoeppe

This comment has been minimized.

@mkoeppe mkoeppe changed the title function(lambda x, y: ...) symbolic_expression(lambda x, y: ...) Jul 3, 2021
@mkoeppe
Copy link
Member Author

mkoeppe commented Jul 3, 2021

@mkoeppe
Copy link
Member Author

mkoeppe commented Jul 3, 2021

Author: Matthias Koeppe

@mkoeppe
Copy link
Member Author

mkoeppe commented Jul 3, 2021

Changed branch from u/mkoeppe/symbolic_expression_lambda_x__y______ to none

@mkoeppe

This comment has been minimized.

@slel
Copy link
Member

slel commented Jul 3, 2021

comment:7

Guessing the branch field got emptied by mistake.


New commits:

e523ac0sage.calculus.all.symbolic_expression: Handle callables

@slel
Copy link
Member

slel commented Jul 3, 2021

Commit: e523ac0

@slel
Copy link
Member

slel commented Jul 3, 2021

@mkoeppe
Copy link
Member Author

mkoeppe commented Jul 3, 2021

comment:8

Thanks for catching this!

@tscrim
Copy link
Collaborator

tscrim commented Jul 5, 2021

comment:10

Green bot => positive review.

@tscrim
Copy link
Collaborator

tscrim commented Jul 5, 2021

Reviewer: Travis Scrimshaw

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 6, 2021

Changed commit from e523ac0 to d2e8c8f

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 6, 2021

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

d2e8c8fsymbolic_expression: Update doctest output

@kcrisman
Copy link
Member

kcrisman commented Jul 6, 2021

comment:12

On a second pass, I think this code (and the related at #32103) looks good. An additional (TEST only) of this using several types of non-lambda functions could be useful. Patchbot seems to be not giving info at the current time.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 6, 2021

Changed commit from d2e8c8f to 2b5535f

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 6, 2021

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

2b5535fsage.calculus.all.symbolic_expression: Add more tests

@mkoeppe
Copy link
Member Author

mkoeppe commented Jul 6, 2021

comment:14

Good idea, done.

@kcrisman
Copy link
Member

kcrisman commented Jul 6, 2021

comment:15

Great. And good call on the second set of tests confirming only (Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD) works. Once patchbot says yes I say this is fine, unless Travis has something additional to say about the new tests.

@kcrisman
Copy link
Member

kcrisman commented Jul 6, 2021

Changed reviewer from Travis Scrimshaw to Travis Scrimshaw, Karl-Dieter Crisman

@tscrim
Copy link
Collaborator

tscrim commented Jul 7, 2021

comment:16

Nope, I have no additional comments.

@mkoeppe
Copy link
Member Author

mkoeppe commented Jul 17, 2021

comment:17

Then let's get this in please

@kcrisman
Copy link
Member

comment:18

Patchbot green is all I wanted, and sounds like Travis is okay with it.

@mkoeppe
Copy link
Member Author

mkoeppe commented Jul 17, 2021

comment:19

Thanks!

@vbraun
Copy link
Member

vbraun commented Jul 23, 2021

Changed branch from u/mkoeppe/symbolic_expression_lambda_x__y______ to 2b5535f

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

5 participants