Perl 6 - the future is here, just unevenly distributed

IRC log for #pdl, 2015-04-07

| Channels | #pdl index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
02:23 popl joined #pdl
02:24 krismatrix joined #pdl
02:25 krismatrix How do I paste a script here?
02:26 krismatrix http://paste.scsys.co.uk/471266
02:27 krismatrix I am trying to figure out how to take a string and get it to do a calculation based on pdl
02:29 sivoais krismatrix: ok, so what you want to do is do expression evaluation, right?
02:29 krismatrix yes.
02:30 sivoais ok, do you know about eval ?
02:30 krismatrix Basically if $A = "2+6*j" where j is elec engr notation for complex i
02:30 sivoais perldoc -f eval
02:30 krismatrix I think I have read it before but don't use it
02:31 sivoais yeah, Perl has two ways of calling eval
02:31 sivoais eval BLOCK
02:31 sivoais and
02:31 sivoais eval STRING
02:31 krismatrix ok
02:31 sivoais eval BLOCK looks like
02:32 krismatrix I am assuming that here STRING is same as EXPR in the  perldoc?
02:32 mohawk you are correct
02:32 sivoais ah, yes... EXPR is a string
02:33 sivoais now, people try to avoid the eval EXPR form because if the value of EXPR comes from an outside source, this can lead to all kinds of nasty security vulnerabilities
02:34 krismatrix ok
02:34 sivoais but if you are sure that the code you are evaluating is safe, eval EXPR can be very powerful for generating code at runtime
02:34 sivoais in this case, you could use it like this
02:34 sivoais instead of
02:34 sivoais $x = $line;
02:35 sivoais do
02:35 sivoais $x = eval $line;
02:35 sivoais this will run the Perl code in the $line variable and return what it evaluates to
02:35 mohawk krismatrix, may i ask why your input is constrained to be "Z = 5 + 6j" rather than making it be "$z = 5 + 6*j"?
02:36 sivoais control theory stuff? :-)
02:36 krismatrix Here is the think...I am attempting to make a command line type program...say like octave...I want the use to use octave like commands...They have no knowledge of perl
02:36 krismatrix So..let us say they say Z = 5 + 6j
02:37 krismatrix And then want to 1/Z...i want my program to read their input, compute and produce a result
02:37 mohawk you'll probably be better off with a tokeniser etc
02:37 krismatrix I am trying to do something that can do any basic mathematical problem.
02:37 sivoais I see. How complex is the input going to be?
02:37 sivoais how much of the Octave language do you need? Just expressions?
02:37 mohawk i gather arbitrarily complex - "any basic" sounds big
02:38 krismatrix sivoais...it can be anything...i am trying to slowly build a larger program....but for what I am asking today...it needs to do any BODMAS or PEMDAS equation including complex numbers
02:39 mohawk i think if you train your users to use $var and * for multi, they can just use one of the PDL shells
02:39 sivoais krismatrix: well, it's your lucky day! CPAN to the rescue! Try <https://metacpan.org/pod/Math::Symbolic>
02:39 mohawk the amount of agony you'll go through writing a maths parser...
02:39 sivoais Math::Symbolic->parse_from_string( ) looks like it will do all that for you!
02:39 mohawk on the other hand, sivoais is a whizkid ;-)
02:39 sivoais :-P
02:40 mohawk man smueller gets everywhere
02:40 sivoais I'm actually going to work on an Octave/MATLAB language parser later, but this should do it for math expressions
02:40 krismatrix okay...you guys are saying...better to use this instead of pdl?
02:40 sivoais you can probably pass PDLs into the compiled code, but I haven't tried
02:41 mohawk that might be the tricky bit
02:41 sivoais PDL would be good if you are trying to crunch lots of data in vectors
02:41 sivoais but it isn't made for parsing non-Perl expressions like this
02:41 mohawk sivoais, sounds like M::S should get a REPL
02:43 krismatrix ok..give me a few...I am testing that module out to see it is what I need. Also...what is REPL>
02:43 popl achtung, there are no bots here
02:43 popl krismatrix: read eval print loop
02:43 sivoais hey popl!
02:44 popl hi
02:44 mohawk sivoais is our REPL guy
02:44 * sivoais blushes...
02:44 mohawk one day
02:44 mohawk and that day may never come
02:44 mohawk he may publish iPerl in a ready to use format
02:45 sivoais hey, bundling Perl, PDL, and IPerl together is on my radar! :-)
02:45 mohawk bundling? do you know about strawberry's PDL edition?
02:45 sivoais no, I do not... link?
02:46 mohawk http://strawberryperl.com/
02:46 sivoais cool  <http://strawberryperl.com/releases.html>!!!
02:46 mohawk ask kmx
02:46 mohawk he's the strawperl guy
02:46 popl sivoais: eval my @results = map { $_ ** $_ } 1 .. 10; [@results]
02:46 sivoais "PortableZIP edition + extra PDL related libs"
02:46 popl oh, that's not what you meant by "our REPL guy"
02:46 popl ;)
02:46 sivoais hahah
02:47 sivoais BEEP BOOP CAN NOT COMPUTE
02:47 sivoais *EXPLODES*
02:49 mohawk where's my PDL 2.008?
02:49 mohawk sort it out people
02:50 krismatrix I take it you guys no Math::Symbolic?
02:50 mohawk sivoais is an expert on it
02:50 mohawk he can answer any questions you have
02:50 sivoais loool
02:50 krismatrix I was able to do the first line of synopis ...which is the parse. It does it nicely.
02:50 mohawk krismatrix, what are you trying to achieve? why don't they just use octave?
02:51 sivoais I'm assuming this is in a bigger application :-)
02:51 krismatrix Maybe...not necessarily bigger...but for the use of a specific field. It is a home project.
02:52 krismatrix So the Math::Symbolic....does it actually do computations or no?
02:52 sivoais is this control theory or circuits stuff? Reminds me of my engineering days
02:52 sivoais krismatrix: it can generate Perl code from the parse
02:52 sivoais which means you can evaluate expressions safely
02:53 sivoais the problem with eval EXPR is that EXPR can be entirely arbitrary code
02:53 sivoais like something dangerous: "rm -Rf --no-preserve-root /"
02:53 mohawk krismatrix, what is the problem you're actually trying to solve?
02:53 krismatrix right now circuit stuff
02:54 mohawk let's not get too far in the weeds just yet
02:54 krismatrix The problem I want to solve is quite simple..
02:55 krismatrix I want the user to be able to enter an mathematical expression... say A = 2 +5 * 3 (6j)
02:55 krismatrix I should then be able to do any other mathematical computation...such as A+A or 2A or A*A or A/A
02:57 mohawk so short version, someone enters arbitrary mathematical expression
02:57 mohawk then what?
02:57 mohawk that's not a problem, that's an activity
02:58 krismatrix I am not sure I understand
02:59 mohawk so the user has entered an expression
02:59 mohawk now what
02:59 mohawk why are they doing that?
02:59 mohawk what do they, and you, want to achieve?
02:59 krismatrix They are doing that so that they can perform other computations
02:59 krismatrix Like I mentioned before...they set A equal to something
02:59 krismatrix Then they can set B = something
03:00 krismatrix Then if they want to, they can do A*B and I want my code to return the correct answer
03:00 mohawk so it's a symbolic maths REPL
03:00 mohawk sivoais, take over please :-)
03:01 sivoais right...that means you will want to have a table of variables, right?
03:01 krismatrix yes
03:01 krismatrix Well...i am not worrying about that yet
03:02 krismatrix I just want the user to enter something...and I want my code to compute it.
03:02 sivoais right
03:03 sivoais I'm thinking...
03:03 krismatrix Using symbolic math...i was able to neatly organize a expression written by user
03:03 krismatrix For example..from the synopsis
03:04 krismatrix my $tree = Math::Symbolic->parse_from_string('1/2*m*v^2')
03:04 krismatrix $tree now contains ((1 / 2) * m) * (v ^ 2)
03:04 krismatrix If I had m set to 10 and v set 5...i not need to compute the above equation in $tree
03:05 sivoais right
03:06 sivoais and you can go ahead and store the result
03:06 sivoais into the variable that was assigned
03:08 mohawk sivoais, i'm predicting this will be straightforward enough and should probably be doc-patched on that module
03:08 mohawk i'll bug smueller about it if you make a patch
03:08 sivoais definitely would make a good example
03:08 krismatrix ok...how do i post a script here?
03:09 krismatrix I want to show an error I am seeing..that I don't understand
03:09 mohawk krismatrix, look in the /topic
03:09 mohawk you'll see "Pasting"
03:09 sivoais is it the explicit_reference thing?
03:10 shadowpaste Someone at 217.168.150.38 pasted "code" (26 lines) at http://paste.scsys.co.uk/471270
03:11 krismatrix I am just attempting the synopsis in that module.
03:12 krismatrix For some reason I get some errors about uninitialized values
03:12 krismatrix I also don't know why they have my ($sub) instead of my $sub
03:13 sivoais krismatrix: that is because the original method returns 2 results as a list
03:14 sivoais <https://metacpan.org/pod/Math::Symbolic::C​ompiler#sub-trees-compile_to_sub-tree-vars>
03:14 sivoais > ($sub, $trees) = compile_to_sub($tree, $vars)
03:14 sivoais and you only want to keep the first value
03:14 sivoais a bit like how Octave can have multiple outputs
03:14 krismatrix ah
03:14 sivoais but you have to be explicit about the number of outputs because Perl has a list-context and scalar-context
03:15 sivoais otherwise if you did
03:15 sivoais my $sub = ....
03:15 sivoais $sub would contain 2
03:15 sivoais why?
03:15 sivoais because the list returned by compile_to_sub() is of length two
03:15 sivoais just like
03:15 krismatrix $line = @array
03:15 sivoais yep!
03:16 krismatrix got it
03:16 krismatrix so...does this mean..i am suppsoed to use say use Math::Symbolic; and use Math::Symbolic::Compiler;   ?
03:17 sivoais you don't need to because Math::Symbolic loads it
03:17 sivoais <https://metacpan.org/source/SMUELLER/Math​-Symbolic-0.612/lib/Math/Symbolic.pm#L138>
03:18 krismatrix It seemed that way...but I am still stuck with my error about uninitialization
03:18 sivoais I'm looking into it :-)
03:20 mohawk don't pressure him
03:20 mohawk he's trying to figure whether to cut the red or the green wire
03:20 sivoais hehe
03:21 krismatrix that's fine...i am trying to do the other examples in that page
03:23 sivoais krismatrix: how are you setting the variables?
03:23 krismatrix I am not doing anything more that what you see
03:23 mohawk krismatrix, look in the test files
03:24 mohawk they will show you what definitely works because it's tested
03:24 mohawk https://metacpan.org/source/S​MUELLER/Math-Symbolic-0.612/t
03:24 mohawk https://metacpan.org/source/SMUELLER/Mat​h-Symbolic-0.612/t/15total_derivatives.t
03:26 sivoais krismatrix: did you set $mass and $velocity to values?
03:26 krismatrix sivoais....no i did not set them in any way
03:26 sivoais ah, that's the issue!
03:27 krismatrix I didn't think I had even gotten to that point according to the synopiss
03:27 krismatrix mohawk...the example worked...
03:27 krismatrix I haven't read through it...but no erro
03:27 krismatrix sivoais...so set mass and velocity to something?
03:27 krismatrix ok will do
03:27 sivoais yep
03:28 krismatrix yep..that worked.
03:29 sivoais what Math::Symbolic::Compiler does is generate Perl code and gives you a Perl function that you can call. This is called a closure (CS term) or a coderef (Perl term)
03:29 krismatrix it even computed it
03:29 sivoais \o/
03:29 sivoais now you'll want to know what variables you have
03:29 sivoais try
03:30 krismatrix so basically it seems like the in the original equation 1/2  * m * v....the sub->($mass, $velocity) assign them to the beginning two variables in order...i.e. m = $mass and v= $velocity?
03:31 sivoais yep, it uses the variables in sorted order
03:31 krismatrix nice...this is much more fun
03:31 sivoais :-)
03:32 krismatrix I guess...i'll have to see what it will do if I do Z = 2 + 3j
03:32 sivoais yeah, I played around with that a bit and noticed that it can't handle 3j... but you can turn 3j into 3*j with a simple regex
03:33 sivoais regexes are fine here if you make them very tight...
03:33 sivoais $line =~ s/(?<number>\d+)j\b/$+{number}*j/; # like this
03:34 krismatrix that is fine... i can figure that out....it doesn't like Z = though
03:34 krismatrix it is fine if I provide 2 + 3 * j
03:34 mohawk leave that for the next version
03:34 krismatrix Not a problem...I can regex that Z = portion
03:35 krismatrix next version?
03:35 mohawk suggest a doc patch for M::S
03:35 sivoais yeah, you will want to extract out the assignment. There may be a way to extend the compiler, but making it cleaner can be done later
03:35 mohawk of your product
03:35 krismatrix ah..
03:35 sivoais yeah, once you use this in your project, krismatrix, you should like SMUELLER know and have the docs point to it as an example :-)
03:36 krismatrix sure.
03:36 sivoais <https://github.com/tsee/p5-math-symbolic> is the github page
03:36 krismatrix you mean point to my project as an example or provide the portion of code where I used it?
03:37 sivoais Both would be good!
03:38 sivoais as in... point to the project and then explain how it is used
03:40 krismatrix Ok...I can do that.
03:40 krismatrix Thanks.
03:40 krismatrix Well...I am going to experiment with Math::Symbolic
03:42 mohawk good luck
03:42 sivoais krismatrix: feel free to share / think aloud in here as you work on the project
03:43 sivoais #pdl is good for that... ;-)
03:43 krismatrix Sure. I appreciate it. The goal of the project is to eventually be able to draw some thing too.
03:43 krismatrix I hear GD is the module for that?
03:43 krismatrix But i am thinking I will get to that when I get to that.
03:43 mohawk if you want to draw graphs and shiz, there's far better
03:44 mohawk PGPLOT among others
03:44 mohawk look at the PDL modules for that
03:44 krismatrix Not plot...although that too...I am thinking of something to draw an electrical circuit
03:45 sivoais krismatrix: there might be several ways to approach that :-)
03:46 mohawk sivoais, PDL got circuit stuff?
03:46 sivoais TIMTOWDI ;-)
03:46 mohawk might be a bit outside its bailiwick
03:46 sivoais mohawk: nope, out of the scope of PDL
03:46 sivoais yeah!! :-P
03:46 mohawk holy cow, we found something that's outside PDL
03:46 sivoais quick, bundle it in!
03:46 sivoais ;-)
03:49 sivoais krismatrix: question: how do you store the elements of your circuit?
03:50 sivoais is this a thing you ask the user to draw or is it a list of nodes and elements
03:50 krismatrix Lol...you do realize that I just barely started right....
03:50 krismatrix no...the goal is for perl (or someway) to draw the circuit based on a text based model/heirarchy
03:50 sivoais hah, ok, we'll get to that then :-P
03:51 mohawk sivoais, I WILL END YOU
03:51 sivoais Have you looked at XCircuit and ng-spice?
03:51 sivoais mohawk: :-D
03:51 krismatrix nope
03:52 sivoais right, so for drawing, XCircuit is really interesting. <https://www.ctan.org/pkg/circuitikz?lang=en> might also be interesting
03:53 sivoais ng-spice is for simulation and will give you an idea of how to input the circuit network
03:53 sivoais The only issue is that none of the circuit drawing programs will do automatic layout for you
03:54 sivoais that's kinda a problem of its own. It's like graph layouts, but humans have their own rules for what makes a readable circuit diagram
03:55 krismatrix I understand that complexity...even professionals working at companies with millions behind them struggle with that.
03:55 sivoais funny thing is, those rules have changed slightly over the years. Check out old circuit diagrams and compare them to newer ones
03:56 sivoais heh, yeah. That will be interesting when you get to that. PDL could actually help with those calculations
03:56 krismatrix Well...anyway..i am going to exit for now. I'll be back here as I am making progress and have more to ask.
03:57 mohawk look forward to it
03:57 mohawk hasta la pasta
03:57 krismatrix And I thought you said PDL was for plotting..not calculations?
03:58 sivoais PDL is mainly for calculations. Fast matrix operations and the like. It also includes some plotting libraries.
03:58 krismatrix oops...i think I misunderstood...yep I get it.
03:58 krismatrix alright out.
03:58 krismatrix left #pdl
03:59 sivoais o/
04:14 sivoais I made an example of using Math::Symbolic with PDL <https://gist.github.com/6af59541692250123d99>
04:49 mohawk awww yeah
04:49 mohawk that neats PRing
04:49 mohawk neats -> needs
04:49 mohawk except...
04:49 mohawk why isn't it a REPL?
05:02 sivoais I suppose I could
05:02 sivoais it would be interesting to have it also call PDL functions
05:03 mohawk KISS
09:02 lungching joined #pdl
11:48 popl joined #pdl
15:18 circ-user-TA5Gz joined #pdl
15:25 circ-user-TA5Gz left #pdl
16:11 circ-user-TA5Gz_ joined #pdl
16:20 circ-user-BlDBR joined #pdl
17:42 popl left #pdl

| Channels | #pdl index | Today | | Search | Google Search | Plain-Text | summary