Re: [sage-support] Re: 2 questions on var

2022-04-16 Thread G. M.-S.
Thanks for the explanation, Nils (even if I am not sure to have understood
everything).

Guillermo

On Sat, 16 Apr 2022 at 22:56, Nils Bruin  wrote:

> On Saturday, 16 April 2022 at 05:37:16 UTC-7 list...@gmail.com wrote:
>
>>
>> Thanks Samuel and Emmanuel.
>>
>> Follow up question:  Why does
>> var('lambda',n=1)
>> fail?
>>
>
> Because the code in question tests the string actually passed in for
> whether it's a valid python identifier.
>
> Probably this is because the "n" optional argument was only added later.
> However, there's been quite a discussion on what the appropriate binding
> behaviour should be. One option would be to bind the actual returned result
> (a tuple of the constructed symbols) to a name in the current namespace.
> i.e., the result of
>
> x = SR.var('x',n=3)
>
> For that behaviour, the passed-in name would have to be a valid
> identifier. So to future-proof sage, perhaps it's better to have this
> stricter check.
>
> You can create symbols without the check: SR.symbol('lambda') works just
> fine. To create the symbols you'd like, you can do:
>
> L = (SR.symbol("lambda{}".format(i)) for i in range(3))
>
> binding them to corresponding symbols would require a little more work .
> It's basically
>
> for c in L:
> globals()[str(c)] = c
>
> which works when typed in as-is, but requires some more trickery if it is
> wrapped in a function in some module, due to the semantics of the actual
> "globals()" call in python.
>
> [in general, for anything other than direct interactive use, you should
> probably not rely on binding injections]
>

-- 
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/CANnG18_GP8Y0Ftx-Gt0RFM4KUd3%2B%3Dueh%3DQTBQ_jGsrAJoPKwpg%40mail.gmail.com.


Re: [sage-support] Re: 2 questions on var

2022-04-16 Thread Nils Bruin
On Saturday, 16 April 2022 at 05:37:16 UTC-7 list...@gmail.com wrote:

>
> Thanks Samuel and Emmanuel.
>
> Follow up question:  Why does
> var('lambda',n=1)
> fail?
>

Because the code in question tests the string actually passed in for 
whether it's a valid python identifier.

Probably this is because the "n" optional argument was only added later. 
However, there's been quite a discussion on what the appropriate binding 
behaviour should be. One option would be to bind the actual returned result 
(a tuple of the constructed symbols) to a name in the current namespace. 
i.e., the result of

x = SR.var('x',n=3) 

For that behaviour, the passed-in name would have to be a valid identifier. 
So to future-proof sage, perhaps it's better to have this stricter check.

You can create symbols without the check: SR.symbol('lambda') works just 
fine. To create the symbols you'd like, you can do:

L = (SR.symbol("lambda{}".format(i)) for i in range(3))

binding them to corresponding symbols would require a little more work . 
It's basically

for c in L:
globals()[str(c)] = c

which works when typed in as-is, but requires some more trickery if it is 
wrapped in a function in some module, due to the semantics of the actual 
"globals()" call in python.

[in general, for anything other than direct interactive use, you should 
probably not rely on binding injections]

-- 
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/99f5b3eb-5e57-4f3f-922c-4a907cea4ba2n%40googlegroups.com.


Re: [sage-support] Re: 2 questions on var

2022-04-16 Thread G. M.-S.
Thanks Samuel and Emmanuel.

Follow up question:  Why does
var('lambda',n=1)
fail?

I know that the name "lambda" is not a valid Python identifier, but I am
asking for "lambda0", "lambda1".

Guillermo

On Tue, 8 Mar 2022 at 19:19, Emmanuel Charpentier <
emanuel.charpent...@gmail.com> wrote:

> even more simpler :-) :
>
> sage: V=var("v", n=8)
> sage: V
> (v0, v1, v2, v3, v4, v5, v6, v7)
> sage: v2
> v2
> sage: V[2]
> v2
>
> *“Who could ask for anything more ?”*
> Le mardi 8 mars 2022 à 08:20:07 UTC+1, slelievre a écrit :
>
>> Even more practical, I find, is to name the tuple of indexed variables:
>> ```
>> sage: v = SR.var('v', n=8)
>> sage: v
>> (v0, v1, v2, v3, v4, v5, v6, v7)
>> ```
>> and to use index notation `v[k]` instead of `vk` to use the variables.
>> ```
>> sage: v[0]
>> v0
>> sage: v[7]
>> v7
>> ```
>>
>> That does not assign the variables to the names `v0` to `v7`:
>> ```
>> sage: v2
>> Traceback (most recent call last)=
>> ...
>> NameError: name 'v2' is not defined
>> ```
>>
>> If you really want to use `v0` to `v7` instead of `v[0]` to `v[7]`,
>> follow the implementation in `var` (accessed with `var??`),
>> which simply amounts to:
>> ```
>> G = globals()
>> for vk in v:
>> G[repr(vk)] = vk
>> ```
>>
>> After that:
>> ```
>> sage: v2
>> v2
>> ```
>>
>

-- 
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/CANnG18_%2BFg%2B5xuwgJBN_-HH5UgGnmCwdz_3si10hgfv3HhU8tA%40mail.gmail.com.


[sage-support] Quaternions and Lorentz Transformations

2022-04-16 Thread Marco Pereira
I am trying to understand how to use Quaternions within sagemath to
replicate Lorentz transforms.

In other words, Lorentz transforms are rotations within a 4D spacetime and
I need to understand how they can be expressed in terms of quaternions.

I looked up examples of quaternions usage and they seem cryptic...

Since I suspect this issue has been solved a long time ago, I am asking for
help finding the appropriate code.

Cheers,

Marco

-- 
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/CABs1CmUsuD-NBZB6AhKGqt%2BDUc44903dqSqT%3DTqPAt5_47_eEg%40mail.gmail.com.