Skip to content

updated arg, re, im, conj, sign (now working also with Lists and Units)#1666

Closed
mipa83 wants to merge 1 commit intoc3d:stablefrom
mipa83:complex
Closed

updated arg, re, im, conj, sign (now working also with Lists and Units)#1666
mipa83 wants to merge 1 commit intoc3d:stablefrom
mipa83:complex

Conversation

@mipa83
Copy link
Copy Markdown

@mipa83 mipa83 commented Mar 16, 2026

Proposal - functions work also with units, lists, vectors, matrix:

{ 230∡0° V 230∡120° V 230∡-120° V } re --> { 230 V -115 V -115 V }
{ 230∡0° V 230∡120° V 230∡-120° V } im --> { 0 V 199.18584 287 V -199.18584 287 V }
{ 230∡0° V 230∡120° V 230∡-120° V } arg --> { 0 ° 120 ° -120 ° }
{ 230∡0° V 230∡120° V 230∡-120° V } abs --> { 230 V 230 V 230 V }
{ 230∡0° V 230∡120° V 230∡-120° V } conj --> { 230∡0° V 230∡-120° V 230∡120° V }

{ 1+2ⅈ V 3+4ⅈ V -5+6ⅈ V -7-8ⅈ V } re --> { 1 V 3 V -5 V -7 V }
{ 1+2ⅈ V 3+4ⅈ V -5+6ⅈ V -7-8ⅈ V } im --> { 2 V 4 V 6 V -8 V }
{ 1+2ⅈ V 3+4ⅈ V -5+6ⅈ V -7-8ⅈ V } arg --> { 63.4349 ° 53.1301 ° 129.8056 ° -131.1859 ° }
{ 1+2ⅈ V 3+4ⅈ V -5+6ⅈ V -7-8ⅈ V } abs --> { 2.2361 V 5.0000 V 7.8102 V 10.6301 V }
{ 1+2ⅈ V 3+4ⅈ V -5+6ⅈ V -7-8ⅈ V } conj --> { 1-2ⅈ V 3-4ⅈ V -5-6ⅈ V -7+8ⅈ V }

[ 230∡0° V 230∡120° V 230∡-120° V ] re --> [ 230 V -115 V -115 V ]
[ 230∡0° V 230∡120° V 230∡-120° V ] im --> [ 0 V 199.18584 287 V -199.18584 287 V ]
[ 230∡0° V 230∡120° V 230∡-120° V ] arg --> [ 0 ° 120 ° -120 ° ]
[ 230∡0° V 230∡120° V 230∡-120° V ] abs --> 0.0000 V
[ 230∡0° V 230∡120° V 230∡-120° V ] conj --> [ 230∡0° V 230∡-120° V 230∡120° V ]

[ 1+2ⅈ V 3+4ⅈ V -5+6ⅈ V -7-8ⅈ V ] re --> [ 1 V 3 V -5 V -7 V ]
[ 1+2ⅈ V 3+4ⅈ V -5+6ⅈ V -7-8ⅈ V ] im --> [ 2 V 4 V 6 V -8 V ]
[ 1+2ⅈ V 3+4ⅈ V -5+6ⅈ V -7-8ⅈ V ] arg --> [ 63.4349 ° 53.1301 ° 129.8056 ° -131.1859 ° ]
[ 1+2ⅈ V 3+4ⅈ V -5+6ⅈ V -7-8ⅈ V ] abs --> 5.0856+7.8653ⅈ V
[ 1+2ⅈ V 3+4ⅈ V -5+6ⅈ V -7-8ⅈ V ] conj --> [ 1-2ⅈ V 3-4ⅈ V -5-6ⅈ V -7+8ⅈ V ]

[[ 1+2ⅈ V 3+4ⅈ V][ -5+6ⅈ V -7-8ⅈ V ]] re --> [[ 1 V 3 V ] [ -5 V -7 V ]]
[[ 1+2ⅈ V 3+4ⅈ V][ -5+6ⅈ V -7-8ⅈ V ]] im --> [[ 2 V 4 V ] [ 6 V -8 V ]]
[[ 1+2ⅈ V 3+4ⅈ V][ -5+6ⅈ V -7-8ⅈ V ]] arg --> [[ 63.4349 ° 53.1301 ° ] [ 129.8056 ° -131.1859 ° ]]
[[ 1+2ⅈ V 3+4ⅈ V][ -5+6ⅈ V -7-8ⅈ V ]] abs --> 5.0856+7.8653ⅈ V
[[ 1+2ⅈ V 3+4ⅈ V][ -5+6ⅈ V -7-8ⅈ V ]] conj --> [[ 1-2ⅈ V 3-4ⅈ V ] [ -5-6ⅈ V -7+8ⅈ V ]]

The bolded text shows the inconsistance of abs for vectors and matrixes.
Just a proposal form my side: split/introduce a new function:

The propsed functions are programmed with switch-case.
Is it preferable to code the proposed functions with switch-case rather than if(should_be_symbolic(xt))?

@c3d
Copy link
Copy Markdown
Owner

c3d commented Apr 1, 2026

Thanks @mipa83. As a general rule, changing the style locally is not a good idea.

  • if statements are preferable when we deal with larger categories, because the types in the categories tend to evolve over time, and it's much better to change one place than many.
  • Using switch makes sense in cases where the expectation is that the treatment is specific to a given type and not to a category of types. For example, decimal promotion is really specific to each individual type, as is the Cycle command.

Neg and Abs fall into the latter category because the way to compute the opposite is very specific to individual types. You don't get the abs of a neg_integer like the abs of a integer. So there aren't broad category types that fit.

c3d added a commit that referenced this pull request Apr 2, 2026
Implementing the kind of cases identified in PR #1666.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
@c3d c3d added enhancement New feature or request user Reported by an actual user, yay! done Issues that are done on dev (will be in next release) labels Apr 11, 2026
@c3d
Copy link
Copy Markdown
Owner

c3d commented Apr 11, 2026

Thanks a lot @mipa83. I've used your test cases but I implemented the changes using a slightly different approach that takes advantage of existing DB48x infrastructure a bit more efficiently. Closing this PR for now.

@c3d c3d closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

done Issues that are done on dev (will be in next release) enhancement New feature or request user Reported by an actual user, yay!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants