-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Approach For Working With Equations #47
Comments
This approach is super interesting! I'm definitely thinking about how to integrate something like it, what the implications would be, which parts would end up being much neater and which parts would be less than ideal. Here are some initial thoughts, mainly from the perspectives of a software engineer and also someone who likes mathematics
|
Here's how I imagine the scopes would work in some more detail. All variables in a block are local to that block. The name of the block though can be referenced from any other block. When you reference Block1 from Block2 say, the equations in Block1 become part of Block2, and so Block2 has access to Block1 variables. If contradictory equations are in the same block, it will say there's a contradiction when it previews the solution:
If they're in separate blocks, there is no issue as their scopes are local to that block.
I don't see how it would leak variables into the global scope, although there might be something I'm missing. |
You persuaded me that functions would be good to have. (The derivative example could be done without it, but it would require 4 blocks, which would be pretty ugly). I think the simplest approach would be to have an expression default as a function. The block would contain a single expression (only one would be allowed, or else the function would have multiple definitions) and it's name would be the name of the function. So this would be your example:
The name "f" would then be accessible from all other blocks since it's the name of a block. The user could then plug in values of x or do operations on the function to create a new function. This would also solve some other issues:
|
This seems like a super interesting approach! I find it really nice how it generalizes to other things, like implicit functions. Another thing that would 'just work' would be this So, I went though my notes and my mathematics exercises and found a few more things that we could eventually support. I'd be delighted to hear your thoughts on those things: Functions
TextWe need text blocks. Is there a shortcut or anything you'd suggest? Unevaluated math/LaTeXA simple LaTeX math block, where the user can type anything they want and QuantumSheet will just ignore it would be useful. It would mainly be used for documenting something or jotting down some very fancy mathematical notes. TablesShould we have a custom block type for tables? Expression rewriting and solving with stepsThose features are features for the far future.
Optional auto evaluationAuto evaluation is definitely super interesting, but there are times when an advanced user might just want to turn it off
|
@phcreery If you've got any thoughts on this matter, I'd love to hear them! Or if you have any interesting examples, please do share them |
To regurgitate, you are proposing using Input | Type | Result
Here's an interesting case:
From my perspective, this can be very confusing, for the user and computer to understand. In the case of |
To stefnotch: I think a lot of those are neat ideas, some of which I've thought about a lot, some less so. I think we can make separate issues for those. I wasn't really thinking of using recursive functions (I'm afraid that could get really messy). However, for something like the Fibonacci numbers, I was thinking of a block like: F[1]=0 Where F is an array (I'll make an issue where I'll say why I think that's better than having a for loop keyword). I definitely want to add piecewise functions and tables, and I thought about (and started working on) how to implement them. Text blocks would be nice and pretty easy I think (maybe just some button to click for it). I haven't thought about anonymous functions; maybe you could talk about that a bit more. Adding steps might be nice. |
To phcreery: "To regurgitate, you are proposing using = for equality, solve and assignment." Not quite (I may have said something like this before, which is my bad, the terminology gets a bit messy). Essentially naming a block is assignment. I would want to use the "solve" keyword to solve. The basic reason for using this approach is I would want to make sheets of common (likely engineering) equations (you could call them libraries) which could be easily added by other people to their work. There has to be a way of easily naming systems of equations, substituting in values, solving for what you want, and using the results later. This could get very messy, so this provides a simple, easy to read framework for users. I realize the best way of showing examples is through a Google Sheet; here's one with your examples. We can then just add more cases and comment on them easily. |
Recursive functions
Recursive functions usually pop up when a problem is best specified in terms of itself. One place where I encountered them was in algorithmics class, when trying to figure out how fast an algorithm is. For example, merge sort, which can be used for sorting a list of numbers, is a recursive algorithm. Its runtime is approximately Because a recursive function can be a nightmare to calculate, there is the process of finding a 'closed form' solution. When it works out, everyone is happy, because you end up with a slightly unwieldy, but perfectly reasonable solution. Failing that, one can try to approximate the closed form solution. For merge sort, this ends up being approximately I hope this is some useful background info on recursive functions. Mind elaborating what you have in mind with the array option? Equalityphcreery raised an interesting point with Depending on the context, an equals sign can mean a lot of different things:
On that note, the 3blue1brown contest submission uses re-assigning. It takes the current price and adds something to it. I took the liberty of adding some more examples to your worksheet. Let me know what you think Anonymous functions
It's a function that one defines inline, whenever they need a function. It practically never comes up in mathematics, but comes up all the time in computer science. The computer science example is, you have a list of fruits. And you have a cute sorting algorithm. But your sorting algorithm has no idea how it should sort the fruits. (By weight? By name? By color?) |
I think I see now. So essentially, everything is named. It kinda reminded me of programming functions where every block has a name. The way Mathcad does this is by using a "Program" symbol "||" (two vertical bars). This function is fed the nominal dimensions and respective tolerances stacks as single column matrices. It then returns the nominal distance, the (furthest) worst-case distance, the MRSS distance, and the RSS distance. The function can then be called like With this function defined (or imported), anyone can call |
Yeah that's the idea. You would either name a system of equations or (after stefnotch's suggestion) a function. The motivation behind this approach is to create an environment where users can easily build off of other work -- I think it opens up a lot more possibilities for something cloud-based. For example, we might want to have the equation for Reynold's number for users. We don't know what the user would solve for and how they will use it, so we should have an equation named Reynolds with the equation as opposed to just a function which outputs the value. That way, they could, for example, find the required viscosity and then use that value to find what liquid they should choose from a table they added to the sheet as well. Others could then build off of that procedure. Software like MathCAD seem good for a specific project, but I imagine you would have trouble using that work for a different project. (I notice that MathCAD example is more of a programming function. At least for the example shown, I think that could be done easily using a system of equations and the solve keyword on the name of that system). (I also think that functions alleviate the need for the substitute keyword and previewing as well. This means it should only require system of equation definition, function definition, and the solve keyword, which I think is a pretty elegant approach). |
Oh okay, that's actually an impressive approach. So, instead of functions with pre-defined parameters (in the case of Reynolds number, up to 4 variables) and a predefined metric to output (Re), you import the entire "equation" and it can be Again, playing the devil's advocate :), what if you use 2 equations with overlapping variable names? |
I'm assuming in this example the user doesn't want the variables to refer to the same thing. The user would just put the two equations in separate blocks (they are each their own system of one equation). The user could substitute in different values for the variable by adding equations to the systems (e.g. "x=3" and "x=4") Then the user can solve each of these equations in separate blocks and the results would also be separated. If the user wants the variable name to refer to the same variable, they can put them in the same block (a single system). They can substitute a value for the variable by adding an equation (e.g. "x=3") and solve the system. If the user wants the equations to be separate but substitute a value for all cases of the variable (maybe they want some variables to refer to the same thing but not others), they can create a function block assigning a value to that variable. |
I see. I would love to see this implemented as it is very useful. |
That's great to hear; the code I wrote still needs to be fixed up a bit, functions need to be added, and it would have to be incorporated into this project. |
My approach is to use just equality, solve and substitute for algebraic manipulation. I think that would be sufficient and make it simple to use. as well as easy to build off of.
I know this is very different from the MathCAD approach, so we'll have to figure out what would work best.
Layout
Each block contains a system of equations. The user types stuff in on the left side and the result is shown on the right side. Farther right than that, it could potentially show numeric results if there are any.
Scopes
For each line in the block, you can type an equation or the name of another block. In this way, you can create nested scopes, where in this case, Block2 has access to Block1 and Block3 has access to Block2 and Block1.
Evaluation
Numeric evaluation would occur automatically on the result side:
Assignment
The equivalent of assignment can be performed as shown:
which is analogous to:
Functions
The equivalent of functions would be created as shown:
The advantage of this is that the "function" can consist of a system of equations and you could solve for any variable. I think this would be useful if we want to make libraries for engineering, where we would write the equations, and the user would choose how to combine them and what to solve for.
The text was updated successfully, but these errors were encountered: