Re: Matheval (was: Dos32Lib, Win32Lib)
- Posted by Beaumont Furniss <bfurniss at IHUG.CO.NZ> Jun 06, 2000
- 470 views
On 2000-06-02 EUPHORIA at LISTSERV.MUOHIO.EDU said: EU>By normal, I really mean mathematical notation as you would write EU>it with paper and pencil. Of course, some things aren't really EU>possible, especially in a text environment. Eventually, it may EU>support some scripting to allow actual algorithms, but no Eu or C EU>code or anything like that. Sounds ... different. EU>Yeah, Matheval was never really intended for speed/computation EU>intensive applications. My real goal is the symbolic manipulation. I'd say that you going to require a database for this . EU>Unfortunately, the project has been shelved for a while...ran into EU>a brick wall, where the only solution I see is a dramatic slash and EU>burn and a new approach to my pattern recognition/substitution EU>algorithms. Maybe I'll bring it back out and polish up the parts EU>that do seem to work. If I were to liken this to kayaking , I'd say that I go back to a stream that can be navigated when the rapids appear to be too daunting. Then return to the previous for yet another attempt ; if at all possible. EU>There are several quirks about the parser and naming EU>conventions (eg, can't have a var begin with the same EU>characters as an existing function), but it eu> seems to work fast enough. You would only EU>need to parse an expression once, and then you'd have the EU>expression in matheval format, able to pass it directly to EU>the evaluation routines. EU>> Are right brackets automatically appended now , or are these EU>>seen as being unnecessary clutter. EU>I'm not sure what you mean here. when I entered an expression into eval.e , it returned something like this for the expression sin(x*(a*x+ , without the closing right bracketts. EU>> I'm a little unfamiliar with recursion , hence my tendency EU>> to bury my EU>> head in the sand , a bit more familarity might put me at ease EU>>with this approach. EU>Basically, I tried to take each operation, and make sure that it's EU>function 'knows' how to handle any other data type (constant, EU>matrix, etc) and return a proper value. If an argument for the EU>operation is some other function (or a variable), the appropriate EU>routine is simply called. I tend to visualize this as 'diving EU>into' the nested sequences, and in effect, evaluating the most EU>deeply nested sequences first, and passing the value 'up'. It EU>allows pretty easy addition of new operations. Getting into that 'mind set' , again , seems a little foreign to me ; and certainly to most persons. EU>> F(x1,x2,x3,....,xn) = type functions are readily EU>> available with my EU>> approach , is this true of yours also ? EU>This is easy to do, however, it works a little differently. EU>Actually, there are several ways to go about it. One would be to EU>assign the function to variable F: EU>F = Parse("x1+x2+x3+...+xn") -- we'd currently have to rename the EU>x's without numbers EU>SetVar("F", F ) EU>SetVar("x1",x1) -- where xi is either an atom or any matheval EU>sequence SetVar("x2",x2) EU>SetVar("x3",x3) EU>.. EU>.. EU>SetVar("xn",xn) EU>F = Evaluate(F) EU>If you take a look at the regression example I posted with matheval, EU>I take a slightly different approach, by defining constants which EU>hold the functions. Granted, these aren't parsed, but written EU>directly in matheval sequence format. I'm having some difficulty locating matheval EU>-- Begin code EU>include matheval.e EU>include G1.e -- your graphics include per parr1.txt -- u1.e ? EU>sequence F, f EU>F = Parse("x^2+X+1") EU>for x = -5 to 5 by .5 -- change .5 to whatever interval you'd like EU>SetVar("x",x) EU>f = Evaluate( F ) EU>GraphPoint(x, f[2][1]) -- since f = {CONSTANT, {F(x)}, {} } EU>-- or whatever your graphics routine might be... EU>end for EU>-- end code EU>> By collapsing the token I assume you mean making a EU>>corresponding sequence , to the equation , that can be more EU>>quickly evaluated ; within EU>> a loop ; perhaps even an assembly language loop. To date I EU>>haven't bothered with this possibility as once the function has EU>> been defined , EU>> within the editable include file I can generate an output EU>> sequence of EU>> values from an input sequence of values in the usual manner EU>> with just EU>> a few lines of euphoria code. EU>More or less. Everything gets mapped to a sequence. The parser EU>makes two passes (not counting recursive parentheses handling). EU>The first pass identifies functions, variables and constants, and EU>puts them into sequences, but most things require additional EU>arguments. In order to properly parse things, I have to take into EU>account the proper order of precendence (ie, + vs *). By EU>collapsing, I'm really talking about shoving adjacent sequences EU>into each other to fill out required arguments: EU>"1+1" => EU>{ {CONSTANT, {1},{}}, {ADD,{},{}}, {CONSTANT,{1},{} } => EU>{ {ADD, {CONSTANT, {1},{}},{CONSTANT, {1},{}} } } Sounds like sequences are useful in this aspect. EU>> Hence , understandably , your reluctance to be overly EU>> public with your EU>> code. EU>Actually, I'm fine with this stuff being public. I just don't get EU>to work on it much, so there's not a lot of progress. And I'd be EU>happy if someone else could make it better. So where can I find the most recent version , I was unable to locate this on d.cunys website , certainly not within the more recent versions of dos32lib.* or win32lib.* . EU>> With the type of EU>> convoluted code EU>> you might be involved with I'd be even more reluctant to EU>> post. Parsers , EU>> especially small functional ones can appear to be real mind EU>>benders. Some of the literature surrounding these , as you're EU>> probably aware , EU>> is pretty daunting until you break through some unknown barrier EU>>of comprehension. To some extent I managed this , though not EU>> at the basic EU>> level of understanding I'd prefer. EU>I think the biggest reason I made my own was that I didn't really EU>understand the other code/literature out there, so I came up with a EU>solution that made sense to me. I'm just happy that this was one EU>occasion where it actually worked. :) Similarly here , though I'd very much prefer a clear and concise text about this ; from somewhere . One that a developer might keep in their library , alongside info' about assembly and C/C++ coding , standard graphics routines , unlimited precision etc .Written in , or understandable in , any type of language. EU>> The sequence that contains the, syntax corrected , expression EU>> might be manipulated symbolically , I haven't really looked EU>> into this , as EU>> potentially , this involves more complexity than attempting EU>> to parse the EU>> sequence using the basic concepts. EU>Definitely more complexity. :) But a really interesting problem. EU>It does very simple things, so far, and if I can get the pattern EU>match/substitution working, it should really improve the EU>functionality (using things like trig id's and a table of EU>integration). I can imagine using lot's of neat techniques, like EU>completing the square, or the quadratic equation. Polynomial roots , via newtons' method are possible , especially if you have an equation/expression that has a few dominant roots. EU>> Anyway , I should get some text , if I don't have an EU>> unexpected brainwave first . EU>> hint: EU>> Associative sequences. EU>This is basically the approach that I'm taking. As an aside, I use EU>an associated sequence to keep track of variables. They seem to be adding or improving upon the associative method , at the moment. Basic notions with diverse applications. EU>> As this type of software might not exist , except for the EU>>features available through euphoria , I don't mind discussing EU>>this at all , probably I should make all of the code available . EU>>A bit of scrutiny from more competent software developers, than EU>>I, might lead off into new directions. EU>> I suppose I could send , in plain text format , the code EU>> to this list EU>> server ; I think it's about 120k . I shall do this only if EU>> requested. EU>Sending to the list might not be a good idea, but I'd appreciate if EU>you could send it to me: EU>matthewlewis at hotmail.com As you should be aware now , I uploaded this ; via email to you ; a few days ago. I understand , you might have numerous other concerns at this time , therefore you haven't evaluated this.