Page 1 sur 1

Declaring symbolic variables

Publié : ven. févr. 02, 2018 4:02 am
par compsystems
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;
}:;




Re: Declaring symbolic variables

Publié : sam. févr. 03, 2018 7:57 am
par parisse
It should be assume(y,symbol).

Re: Declaring symbolic variables

Publié : sam. févr. 03, 2018 2:39 pm
par compsystems
when compiling the program the result between the following sentences is the same?

local y; purge(y)

versus

local y; assume(y,symbol);

Re: Declaring symbolic variables

Publié : sam. févr. 03, 2018 3:12 pm
par parisse
Yes.

Re: Declaring symbolic variables

Publié : sam. févr. 03, 2018 4:28 pm
par compsystems
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);

Re: Declaring symbolic variables

Publié : sam. févr. 03, 2018 4:44 pm
par parisse
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.

Re: Declaring symbolic variables

Publié : sam. févr. 03, 2018 5:03 pm
par compsystems
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.

Re: Declaring symbolic variables

Publié : sam. févr. 03, 2018 5:42 pm
par parisse
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)

Re: Declaring symbolic variables

Publié : sam. févr. 03, 2018 6:52 pm
par compsystems
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

Re: Declaring symbolic variables

Publié : lun. févr. 05, 2018 12:31 pm
par compsystems
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