HP Forums
[HP PPL] Concatenation inside CAS(..) command does not work - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: [HP PPL] Concatenation inside CAS(..) command does not work (/thread-22126.html)



[HP PPL] Concatenation inside CAS(..) command does not work - Le0ssa - 08-04-2024 03:44 PM

Hello, new Prime user here. I have the following program:

Code:

  local d, f, expression;
  if input({{f,[2]}}, "Derivate", "f(x)=") 
  then       
    expression:="diff(x^2,x)";
    d:= CAS(expression);
    return d; 
  end;

This program doesn´t work. It returns the string "diff(x^2,x")" instead of the actual differentiation result.

But if replace the above CAS call with:

Code:

    d:= CAS("diff(x^2,x)");

Then I get the proper diff output. Why?


RE: [HP PPL] Concatenation inside CAS(..) command does not work - komame - 08-05-2024 05:55 AM

When using a variable in a CAS call on the PPL side, you should indicate that it contains an expression rather than a string.

Use expr like this:
Code:
    expression:="2^3";
    d:=CAS(expr(expression));

However, this still won't work in your case because PPL program cannot return symbolic results (Home doesn't work with symbols).

Programs that operate on symbolic expressions should be written in CAS, not PPL.


RE: [HP PPL] Concatenation inside CAS(..) command does not work - Le0ssa - 08-05-2024 05:52 PM

(08-05-2024 05:55 AM)komame Wrote:  When using a variable in a CAS call on the PPL side, you should indicate that it contains an expression rather than a string.

Use expr like this:
Code:
    expression:="2^3";
    d:=CAS(expr(expression));

However, this still won't work in your case because PPL program cannot return symbolic results (Home doesn't work with symbols).

Programs that operate on symbolic expressions should be written in CAS, not PPL.

I was actually able to work by receiving the symbolic function as a string argument on input, then solving integrals and derivatives using the CAS. prefix:

Code:

  if input(
  {{f, [2]}, {var, [2]}, {lower,[2]}, {upper,[2]}},
        "Prob Ψ",
        {"Ψ=", "var=", "lower=", "upper="}
      )
  then

    f := "(" + f + ")^2";
    e := "∫(" + f + ", " + var + ", " + lower + ", " + upper + ")";
    result:= CAS.expr(e);
    result:= CAS.simplify(result);
    return result;
  end;

That worked best on real calculator.


RE: [HP PPL] Concatenation inside CAS(..) command does not work - roadrunner - 08-05-2024 06:12 PM

This:

local d, f, expression;
if input({{f,[2]}}, "Derivate", "f(x)=")
then
expression:="diff(x^2,x)";
d:= CAS(eval(expression));
return d;
end;

should work. At least it does for me.

-road


RE: [HP PPL] Concatenation inside CAS(..) command does not work - komame - 08-06-2024 04:08 AM

I know that the result can be displayed, but that's just a side effect of the approach you used. The Home mode, even though it displays the result, doesn't actually understand it.

So, the question is, why do it in Home mode when doing it in CAS allows you not only to get the result but also to continue operating on it? For instance, you can substitute the result of one of your functions into another one of your functions (without using strings, just regular symbolic expressions as input).

The HP Prime is designed to do such things on the CAS side (CAS program with #CAS #END region).

Is there a particular reason why you need to do it in PPL (Home)?


RE: [HP PPL] Concatenation inside CAS(..) command does not work - roadrunner - 08-06-2024 03:51 PM

(08-06-2024 04:08 AM)komame Wrote:  Is there a particular reason why you need to do it in PPL (Home)?

No, I rarely do that. I think it is best practice to write cas programs in cas and home programs in ppl. As i recall (and my memory is a little fuzzy so i may not have all the details right) when the prime was in it's infancy it was hard (or impossible) to do what the OP wanted, especially when passing many variables back and forth between cas and home. There were so many complaints that the software was modified to make it easier (or possible).

People still ask that question so i just give an answer.

-road