Dear erentar,

There are two types of objects involved here: "symbolic functions" that 
live as objects in SR and "python functions" which are part of python 
itself. "hold" is only a directive that applies to symbolic expressions, 
whereas "def" defines a python function. Hence, the "hold" directive never 
applies.

Looking into what you are trying to compute, it would seem you want to 
replace g(x) by g(SR(x)). Replacing that another time would get you 
g(SR(SR(x))). However, no matter what x is, if SR(x) succeeds properly, 
then y=SR(x) will be an element of the symbolic ring and applying SR to an 
element of the symbolic ring should return exactly the same thing, so 
SR(y=SR(SR(x))=SR(x).

But then g(SR(SR(SR(x))))=g(SR(x)) and g(SR(SR(SR(SR(x)))))=g(SR(x)) . So 
by the properties of the system, applying SR repeatedly is not going to 
make a difference.

Is it that you want to define a symbolic function `g` *and* a convenience 
python function that forces the argument into SR? I don't think you need 
that, since symbolic functions will try to put their argument into SR when 
called (because SR arguments are the only thing they can work on. Hence, if 
I'm right in guessing what you want, the following would already do the job:

sage: g = function('g')  ## on top-level you could also just use 
`function('g')` for convenience
sage: a=10
sage: parent(a) #a is not an object in SR
Integer Ring
sage: E = g(a); E
g(10)
sage: E.operands()[0]
10
sage: parent(E.operands()[0]) #but the argument in the expression E is
Symbolic Ring

Note that g is not a python function:
sage: type(g)
<class 
'sage.symbolic.function_factory.function_factory.<locals>.NewSymbolicFunction'>

(quite a mouth-full, but notably different from the type of an object that 
results from a "def" statement)






On Sunday 25 August 2024 at 13:17:16 UTC-7 erentar wrote:

> Greetings,
>
> I am trying to return a function call from the function itself with the 
> context `hold`
>
> The following example does not behave as i'd want:
>
> ```
> def g(x):
>     with hold:
>         held = sqrt(x)
>     return held
>
> g(4)
> > 2
> ```
>
> To get around this, i make the change SR(x):
>
> ```
> def g(x):
>     with hold:
>         held = sqrt(SR(x))
>     return held
>
> g(4)
> > sqrt(4)
> ```
>
> This is what i want.
>
> Now, i want to return the function call `g(4)` rather than `sqrt(4)`.
> This is what i've tried:
>
> ```
> def g(x):
>     with hold:
>         held = g(SR(x))
>     return held
> ```
>
> Sadly it reaches recursion limit and exits, which means it does not hold 
> the function call.
>
> How can i return the function call from the function itself?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/4695021e-be4f-4eb8-a929-1097e7271dban%40googlegroups.com.

Reply via email to