-
-
Save zmughal/6af59541692250123d99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
use PDL; | |
use PDL::Complex; | |
use Math::Symbolic; | |
my $z = 2 + 6*i; | |
print "$z\n"; | |
my ($x,$y); | |
my $line = "Z = 5 + 6j + a"; | |
my $vars; | |
$vars->{j} = i; | |
$vars->{a} = sequence(10); | |
if ($line =~ m/=/) { | |
$line =~ s/^(?<varname>\w+)\s*=//; | |
my $variable_name = $+{varname}; | |
# change <number>j into <number>*j | |
$line =~ s/(?<number>\d+)j\b/$+{number}*j/; | |
my $tree = Math::Symbolic->parse_from_string($line); | |
print "$line\n"; | |
print "$tree\n"; | |
my @expr_vars = $tree->explicit_signature; | |
use DDP; p @expr_vars; | |
#my ($code) = Math::Symbolic::Compiler->compile_to_code($tree); | |
#use DDP; p $code; | |
my ($sub) = Math::Symbolic::Compiler->compile_to_sub($tree); | |
my $result = $sub->( @$vars{ @expr_vars } ); | |
$vars->{ $variable_name } = $result; | |
use DDP; p $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment