FunctionCall works with Sum not Product

Not sure if it is my coding or the capability of CL.

I can use functionCall with patterns.sum or patterns.difference, but not with patterns.product.

I can’t help you, sorry, but I’m interested to understand more about what functionCall actually is/does? I can’t find it documented anywhere…

It was described in the May newsletter. Are you subscribed to that?

No, I’m not - I usually access them through the archives but just assumed there hadn’t been one since March…

Guess I ought to actually subscribe, then!

I’m just getting around now to playing with this, and seeing the same thing - can’t get the functionCall to work with the product pattern. Is this a bug? @Jay @Daniel_Grubbs

Looks to me as though the parentheses for a product pattern clash with functionCall somehow. It will separate 3sinx into parts A and B, but still not find the operator.

Edit: Further investigating, functionCall will not yield sin as the identifier if in the form sinx, but will if using sin(x).

I was trying to get it to match f(x) + n as a sum and n•f(x) as a product. Sum works as expected but product doesn’t match.

Takes some hacking, but have it functioning. Essentially, you can identify latex containing p.functionCall. Once that’s done, you can pull the identifier and parameter(s), then reconstruct the function and replace it with a dummy variable. Once that’s done you can follow the basic pattern.

I’m trying to use this technique to parse 3f(x) + 2 but I can’t seem to get it to work. The dummy substitution doesn’t seem to do anything. Can you see what I’m doing wrong? function call in pattern • Activity Builder by Desmos

I guess I should’ve actually built it out fully! Can’t replace the expression using substituteLatex. I guess the final goal is what matters. You should be able to parse the sum of a product and number, and probably should be able to identify where a term’s latex is equivalent to the identifier and term1. I think I’d need to know the objective though.

If I show two graphs f(x) and g(x) where g(x) is a vertical translation of 3, I want them to write f(x) + 3 and be able to parse out the 3. So that should work fine with functionCall.

But if g(x) is say 3f(x) + 2, I want to parse out the 3 and the 2 from their entered expression. I can use that complicated CL that Mike Gleeson wrote here: Function Transformations in af(k(x-c))+d Form | Component Based Approach , but I was hoping to use a simpler pattern approach.

I’ve got Screen 2 matching a particular pattern, but Screen 1 I think I need to step back. I was able to parse out the 2, but stuck at the moment for the other portion.

I suspect the reason functionCall doesn’t work is related to the fact that Desmos treats function products very inconistently. I made a note about that in the code for Function Transformations in af(k(x-c))+d Form | Component Based Approach. If that is indeed the reason, it will require Desmos to rewrite some handling on its end to change that.

Bad news is that code is complicated. Good news is that it works every time.

If there’s anything I can do to make it simpler to implement, please do ask. I could take a look at it again.

Hi Mike, I didn’t mean to sound unappreciative! I’ve used your code in a couple of projects so far and it has been a real time saver. I didn’t mean complicated as “overly complicated” but just that it seems like it would be much simpler if the function call pattern just worked well with the other patterns, so the overall code would be more clear and consistent.

Oh i didn’t take negatively at all. That code is complicated and I’d rather it wasn’t necessary at all.

I’m glad it’s been of use to you, and my comments were more for everyone else coming across this thread - I hope how complicated it looks under the hood doesn’t dissaude anyone else away from simply dropping it into a project and using it. It simply works and does things other tools can’t, and I just hope that’s enough for most everyone to make their lives easier.

Sometimes it’s better not to know how the sausage is made, but I’m always open to making a better sausage, so really for everyone, if you have any comments about code clarity or ways to improve it, I’m very open to that.

1 Like