problem with convert( array, list)

Messages in english

Modérateur : xcasadmin

Répondre
compsystems
Messages : 624
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

problem with convert( array, list)

Message par compsystems » mar. nov. 11, 2025 6:00 pm

Hi, when converting an array to a list, the visual conversion looks fine, but when reading the list, it appears as a formatting instruction equal( , ). For this reason, I think Solve can't calculate it.

solve(convert([[(α1+α2-α3) = 1],[(α1-α2-α3) = 1],[(α1-α2+α3) = 2],[(α1+α2+α3) = 3]],list),{α1,α2,α3},'=') [Enter] []

convert([[(α1+α2-α3) = 1],[(α1-α2-α3) = 1],[(α1-α2+α3) = 2],[(α1+α2+α3) = 3]],list

[enter]
[[equal(α1+α2-α3,1)],[equal(α1-α2-α3,1)],[equal(α1-α2+α3,2)],[equal(α1+α2+α3,3)]]

=>
[(α1+α2-α3) = 1,(α1-α2-α3) = 1,(α1-α2+α3) = 2,(α1+α2+α3) = 3]

parisse
Messages : 5935
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: problem with convert( array, list)

Message par parisse » mer. nov. 12, 2025 11:13 am

You have 4 equations for 3 unknowns, it's not really surprising that there is no solution...

compsystems
Messages : 624
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: problem with convert( array, list)

Message par compsystems » mer. nov. 12, 2025 11:50 am

I copied the first independent term incorrectly =) and the list of variables enclosed in curly braces {}

solve( convert( [[(α1+α2-α3) = 2],[(α1-α2-α3) = 1],[(α1-α2+α3) = 2],[(α1+α2+α3) = 3]],list), [α1,α2,α3],'=')

=>

set[[equal(α1,2),equal(α2,1/2),equal(α3,1/2)]]

But when copying the output, it decodes it with the equal operator, and pasting it into a document doesn't produce a normal mathematical expression.

parisse
Messages : 5935
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: problem with convert( array, list)

Message par parisse » mer. nov. 12, 2025 1:13 pm

Make sure you are running the "pure" Xcas interpreter, not the Python-compatible mode, to get = for = in text outputs.

compsystems
Messages : 624
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: problem with convert( array, list)

Message par compsystems » mer. nov. 12, 2025 4:47 pm

Running in xcas mode, correct.

To avoid converting to a list, the solve cmd it should accept an array of equations that come from, for example, a linear combination.

solve(
[[(α1+α2-α3) = 2],
[(α1-α2-α3) = 1],
[(α1-α2+α3) = 2],
[(α1+α2+α3) = 3]],

[α1,α2,α3],'=')

---------------------------
([[1,1,-1],[1,-1,-1],[1,-1,1],[1,1,1]]*[[α1],[α2],[α3]]) = [[2],[1],[2],[3]]

[[(α1+α2-α3) = 2],
[(α1-α2-α3) = 1],
[(α1-α2+α3) = 2],
[(α1+α2+α3) = 3]]

solve( array, var )

parisse
Messages : 5935
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: problem with convert( array, list)

Message par parisse » jeu. nov. 13, 2025 7:21 am

It already does :
solve([[1,1,-1],[1,-1,-1],[1,-1,1],[1,1,1]]*[[α1],[α2],[α3]] = [[2],[1],[2],[3]],[α1,α2,α3],'=')

compsystems
Messages : 624
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: problem with convert( array, list)

Message par compsystems » sam. nov. 15, 2025 1:37 pm

Okay, it works correctly.

A situation where the evaluation operator appears to malfunction.

[[1,0],
[0,1]]
*
[[α1],
[α2]]
=
[[(-1/3)*x+(2/3)*y],
[(2/3)*x-(1/3)*y]]
=>
[[α1=(-x/3+2*y/3)],
[α2=(2*x/3-y/3)]]

simplify( α1*[[1],[2]]+ α2*[[2],[1]]=[[x],[y]] | [[α1=(-x/3+2*y/3)],[α2=(2*x/3-y/3)]]
=>
[[α1+2*α2],[2*α1+α2]]=[[x],[y]]
does not perform the evaluation.

now, converting to a list of equations
simplify( α1*[[1],[2]]+ α2*[[2],[1]]=[[x],[y]] | convert([[α1=(-x/3+2*y/3)],[α2=(2*x/3-y/3)]], list))
=>
"Invalid | Error: Bad Argument Value"

but doing the operation separately

convert(set[[α1=2,α2=(1/2),α3=(1/2)]],list)
=>
[α1=(-x/3+2*y/3),α2=(2*x/3-y/3)]

simplify( α1*[[1],[2]]+ α2*[[2],[1]]=[[x],[y]] | [α1=(-x/3+2*y/3),α2=(2*x/3-y/3)])
=>
[[x],
[y]]
=
[[x],
[y]] // ok

parisse
Messages : 5935
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: problem with convert( array, list)

Message par parisse » mar. nov. 18, 2025 6:56 am

What about using subst?

compsystems
Messages : 624
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: problem with convert( array, list)

Message par compsystems » mar. nov. 18, 2025 2:02 pm

subst works well, but the | operator is a more natural notation. I say this so that students use the encoding closest to what appears in the math books, so it would be a good idea to make the | operator accept special arguments as an operation.

Furthermore, using mathematical symbols instead of nested operations makes it easier to read. function( function( function() )

=)

parisse
Messages : 5935
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: problem with convert( array, list)

Message par parisse » mar. nov. 18, 2025 8:39 pm

Unfortunately, | and subst do not follow the same evaluation rules. Modifying | to mimic subst would certainly break some code...

Répondre