Carl Love

Carl Love

28035 Reputation

25 Badges

12 years, 321 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@vv Oops, I just made a small change to the example code. Please try it again. If you read the plaintext file, you'll understand why the switch makes a difference. This time, there's definitely a difference between .m and .mpl files.

So, the issue has nothing to do with tables or eval.

@jthress1 Hmm. Over the years, I have occasionally noticed non-idempotency in simplify. That is, one hopes that for any X the following relation is true:

simplify(X) = simplify(simplify(X))

But I have definitely (although rarely) encountered situations where the right side is simpler. This may apply in your situation. These should be considered bugs.

Regarding your attempt at further simplification: subs is not algebraically sophisticated. In order for subs(A= B, C) to work, A must be a distinct entity with its own memory address that C has a link (or links) to. Another way of looking at it: If you think of C as a tree of its subexpressions, then A must be a node (or nodes) in that tree.

You can do some more sophisticated substituting like this:

simplify(X, {n__x*u + n__y*v + n__z*w= lambda});

However, this only works for expressions that are essentially polynomials.

@acer If DF is a DataFrame containing columns C1, ..., Cn, then with(DF) is like C1:= DF[C1]; ...; Cn:= DF[Cn];

@bliengme Plot axes can be any variable that you want. And you can include units in the labels. For example (assuming that Z is a function of t, not of x):

plot(Z, t= -6..2, labels= [time*Unit(hour), Temp*Unit(Fahrenheit)]);

@jthress1 You wrote:

  •  Here is my attempt with your method. Did I input this in incorrectly?

It looks correct to me. Is there something that made you supect that it was wrong?

Here's a systematic way to check such a large expression. The command for searching an expression for subexpressions of a certain type is indets. Square roots are stored internally as expressions raised to fractional powers whose denominators are 2. The command for extracting the denominator of a fraction is denom. So the type spec for a square root is anything^(2 &under denom). So the indets command to check your matrix X is

indets(X, anything^(2 &under denom));

If I do the substitution and call the res ulting matrix X1 and rerun the indets with X1 in place of X, the empty set is returned, indicating that there are no more square roots.

@Joe Riel I had the same experience as the OP: On some runs, the solution is simpler: One way that it's simpler is that there are no square roots in denominators.

@jthress1 You're not doing anything wrong. The issue is as Joe said. Square roots that appear in denominators are stored internally differently than square roots in the numerator, even though the two may appear the same in the GUI display. (You can use lprint to view something  that's much closer to the internal storage format.) Thus they need to be subsed separately (which nonetheless can be done in a single Maple command).

However, for some unknown reason, my original X has no square roots in denominators, so my subs works.

@awass If I cut and paste your procedure and correct the quotes, then everything is fine. So, I'd like to see your worksheet to see where these quotes come from. I am absolutely certain that those quotes are the problem.

The help page says that description should be followed by a "sequence of strings". Strings have quotes.

@mehdibaghaee The easiest way free up the memory used by A, whether it's an Array or something else, is

A:= 'A':

The memory may not be immediately freed, but the garbage collector will eventually get around to it.

@Joe Riel I totally understand the unfortunate theoretical need to substitute for both term and 1/term; however, did you find that necessary in this particular case? I did not.

@Carl Love I just noticed that you did something in your worksheet that provides examples of why you shouldn't re-enter output as input. When you assigned the value of Z, you changed the independent variable from t to x. In this case, that change does not cause any error, but in some other situations it could've. Another problem with it is that it seems unmotivated, and therefore could be confusing to the reader.

I don't know what you mean by f(x,1)=2x^2-x-1. Do you mean that you have a surface z = f(x,y), and you want to show its intersection with the plane y=1? I could show you how to do that with spacecurve; however, you may find the command plots:-intersectplot more convenient for your overall project.

@Rohith You wrote:

  • I absolutely not expectede that I would end up at this stage. I would like to say sorry for extending this and kindly, excuse me.

It's no problem for me. I consider what we've done so far to be trivial, and I'm hoping that you will be providing more-complicated cases. Indeed, I will be disappointed if you don't.

So, in the present situation, you want associative operators (`+``*`) with three or more operands to have their operands grouped pairwise. This is called folding, and the Maple commands that handle it are named foldl and foldr, the difference in the two being whether a+b+c is changed to (a+b)+c or a+(b+c)

Here's the code that handles this new issue, as well as all previous cases. I have handled the folding by active manipulation of the Parsed input rather than the type specifications that I used for the previous cases.

RohithExtract:= module()
uses TT= TypeTools, IN= InertForm;
local
   TryRemoveType:= (T::name)-> if TT:-Exists(T) then TT:-RemoveType(T) else fi,
   TryAddType:= (TH::(name= anything))-> (TryRemoveType(lhs(TH)), TT:-AddType(op(TH))),
   AddedTypes,
   ModuleUnload:= proc()
      (TryRemoveType@lhs)~(AddedTypes);
      :-`print/Rohith`:= ':-`print/Rohith`';
      NULL
   end proc,
   ModuleLoad:= proc()
      TryAddType~(
         (AddedTypes:= [
            #With recursive types, put base cases at beginning to avoid infinite loops!
            'Atomic'=     'Or'('name', 'numeric', 'InertRecip', 'Negated'),
            'InertRecip'= 1 %/ 'Atomic',
            'Negated'=    (-1) &* 'Atomic',
            'AssocOps'=   'And'('specfunc'({`%+`, `%*`}), 'patfunc'('anything'$4)),
            'Operators'=  'specfunc'('Atomic', {`%+`, `%*`, `%/`, `%^`}),
            'Rohith'=     'And'('Operators', 'Not'('InertRecip'), 2 &under nops)
         ])
      );
      :-`print/Rohith`:= Rohith-> value({args});
      NULL
   end proc,

   #Associative operators with > 2 operands are regrouped pairwise.
   Fold:= E-> subsindets(E, AssocOps, OP-> foldl(op(0,OP), op(OP))),
 
   ModuleApply:= (E::string)-> 'Rohith'(indets(Fold(IN:-Parse(E)), 'Rohith')[])
;
   ModuleLoad()
end module:

I've changed the way that the output is handled, so that it comes in both an inert form and a prettyprinted evaluated form. The "actual" output is the inert form, and you can view it as it's actually stored by using the lprint command. The fully evaluated output, which is what all prior versions returned, is displayed (aka "prettyprinted") by the GUI.

I've thought of one case of a Maple command that returns an unevaluated form with a bound variable that doesn't handle it in a way that is 100% naive: RootOf. Whatever bound variable that it's given on input, it changes to _Z for the returned form. This is still quite crude, and the protection of the bound variable is based only on convention. But it's a step in the right direction. One can see an example of the use of the convention in lines 6 - 8 of showstat(`diff/RootOf`).

@vv Thanks for the corrections. I was unaware of the distinction between functional and prefix, so you've taught me, and I've now removed the latter from my post. Do you think it'd be okay if I say functional form rather than functional notation?

Regarding not: It was my oversight to call it infix. It can't possibly be because it only takes one operand. I have corrected that.

Regarding `!`: It is true as you say that it doesn't mean factorial (nor did I claim that it does) and also (in Maple 2018) that it has no assigned value (nor did I claim that it does). I mentioned it because it's possible to assign a procedure to it and then use as an unary postfix operator for whatever purpose one wants.

First 305 306 307 308 309 310 311 Last Page 307 of 708