Declaring symbolic variables

Messages in english

Modérateur : xcasadmin

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

Declaring symbolic variables

Message par compsystems » ven. févr. 02, 2018 4:02 am

three ways to define a symbolic variable

Code : Tout sélectionner

fa(x):={
  local y; // "Unitialized local variable y"
  return x*y;
}:;


fb(x):={
  local y; purge(y) // y as symvar
  return x*y;
}:;

fc(x):={
  local y; assume(y,symbol);
  return x*y;
}:;


fd(x):={
  local y; y=assume[expression];
  return x*y;
}:;



Dernière modification par compsystems le sam. févr. 03, 2018 4:40 pm, modifié 1 fois.

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

Re: Declaring symbolic variables

Message par parisse » sam. févr. 03, 2018 7:57 am

It should be assume(y,symbol).

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

Re: Declaring symbolic variables

Message par compsystems » sam. févr. 03, 2018 2:39 pm

when compiling the program the result between the following sentences is the same?

local y; purge(y)

versus

local y; assume(y,symbol);

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

Re: Declaring symbolic variables

Message par parisse » sam. févr. 03, 2018 3:12 pm

Yes.

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

Re: Declaring symbolic variables

Message par compsystems » sam. févr. 03, 2018 4:28 pm

BP, please add to the template PRG/NewProgram a new field, "Symbolic Variables" after the "local" field, so that they are automatically added to the code:

example
Symbolic Variables []

Symbolic Variables [ y ] =>
assume(y, symbol);

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

Re: Declaring symbolic variables

Message par parisse » sam. févr. 03, 2018 4:44 pm

I don't think it's a good idea, it would be confusing for those who are learning programming with Xcas. I can modify the tooltip to explain how to declare symbolic variables.

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

Re: Declaring symbolic variables

Message par compsystems » sam. févr. 03, 2018 5:03 pm

I think that on the contrary, many algorithms require the manipulation of symbolic variables, that is, they remain unassigned, throughout the code, it is recurrent in the hpmuseum forum of how to define symbolic variables, also allows to differentiate numerical variables (assigned to a value)

You can add information on how to define this type of variables, but within a template is directly appreciated.

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

Re: Declaring symbolic variables

Message par parisse » sam. févr. 03, 2018 5:42 pm

I have made the templates for *beginners*. Beginners do not write programs with symbolic local variables, that's something advanced programmers may do (intermediate programmers will not declare symbolic variables and keep them global and the program will also work)

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

Re: Declaring symbolic variables

Message par compsystems » sam. févr. 03, 2018 6:52 pm

keep global variables, is not always a very practical programming, also leaves garbage in the worksheet, this makes the commands work badly, if you have not deleted variables previously.
http://www.hpmuseum.org/forum/thread-10064.html

I think that one more line, to define sym variables, instead of creating confusion, gives clarity when differentiating the numerical variables from the sym vars, In addition, warning messages are avoided:

// Warning: "* var" declared as global variable(s). If symbolic variables are required, declare them as local and run purge.

Image

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

Re: Declaring symbolic variables

Message par compsystems » lun. févr. 05, 2018 12:31 pm

if a variable is defined as symbolic, but not local, the warning message should only show that the variable was defined as global.

Code : Tout sélectionner

f(x):={
  assume(y, symbol);
  return x*y;
}:;
[ok]
// Parsing f
// Warning: y, declared as global variable(s). If symbolic variables are required, declare them as local and run purge
// compiling f

Done

best =>

// Parsing f
// Warning: y, declared as global variable(s).
// compiling f

f(z) [enter]z*y

Répondre