question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Distinguish between variable names a_b and indexing a_1

See original GitHub issue

Sometimes, there are variables with a subscript. For example, when one has a triangle and a square and wants to calculate their areas: A_tri and A_squ. In this case, they’re clearly two different variables.

However, in a different context, one has matrices. To index the first row/column (depending on convention), one would write a_1. To index the second one, it would be a_2. In that case, they’re referring to the same variable.

The same thing applies to

  • function f(x) = 3x^2 + 2x, then f' means “the first derivative of f”
  • but it’s also possible to define a variable a'

Is there a general way of distinguishing between those two options? As in, something along the lines of ["Symbol/Variable/Function/..", ["Subscript", "a", "t"]] vs ["Subscript", "a", "1"]. The former would mean “this entire thing is the variable name” while the latter would mean “the subscript probably has a special meaning”

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
arnogcommented, Feb 10, 2022

By default (i.e. the version that’s in the Compute Engine default dictionary), the OverTilde is an “inert” function, that is it is used to “decorate” another expression, and provide some information about it. However, evaluating it does not change it, that is ce.box(["OverTilde", "f"]).evaluate().json is ["OverTilde", "f"].

The Hold function is useful to prevent an evaluation, but in this case, since the evaluation doesn’t do anything, the Hold function is not necessary.

1reaction
arnogcommented, Feb 10, 2022

You have two options:

  • The parser can parse these LaTeX expressions (presumably, the first one is something like \overset{\triangle}f and the other one \tilde{f} and map them to whatever symbol name you’d like, perhaps f_with_triangle_above and f_with_tilde_above, or something more semantic if appropriate (which would be preferred)

  • Represent the “decorations” around the symbol as function applications, so \tilde{f} would become ["OverTilde", "f"]. This is how the Compute Engine currently handles it, although of course you can override it to implement the first solution if you prefer (with a custom parsing dictionary). The default Compute Engine dictionary does not have a definition for the delta-above, though, so one would need to be added.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FAQ: How can I create variables A1, A2,...,A10 in a loop?
The fields of the structure can be the variable names you want. And you can index into them with dynamic field references. For...
Read more >
1.3. Variables and Data Types — AP CSAwesome
A variable is a name associated with a memory location in the computer, where you can store a value that can change or...
Read more >
Frequently Asked Questions about data.table
1.5 I assigned a variable mycol = "x" but then DT[ , mycol] returns "x" . How do I get it to look...
Read more >
3. Strings, lists, and tuples — Beginning Python Programming ...
The indexing operator ( [ ] ) selects a single element from a sequence. The expression inside brackets is called the index, and...
Read more >
Naming Objects - GeoGebra Manual
You can create indices within the names of objects by using an underscore. For example A1 is entered as A_1 and sAB is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found