-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-usage-by-object.raku
More file actions
29 lines (21 loc) · 879 Bytes
/
Copy pathbasic-usage-by-object.raku
File metadata and controls
29 lines (21 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use v6.d;
# The Cortex-JS Compute Engine can be used in Raku via a
# CortexJS::ComputationEngine object or by "free functions",
# https://mathlive.io/compute-engine/#free-functions
# This file shows the use with an object.
# use lib <. lib>;
use CortexJS;
my $ce = CortexJS::ComputeEngine.new;
# Note the computation object has to destroyed
LEAVE $ce.close;
say "ping: " ~ $ce.ping.raku;
say "version: " ~ $ce.version.raku;
my $parsed = $ce.parse-latex('x^2+2x+1');
say "parsed: " ~ $parsed.raku;
say "parsed latex: " ~ $ce.to-latex($parsed);
my $simplified = $ce.simplify(["Add", ["Power", "x", 1], ["Multiply", 2, "x"], 1]);
say "simplified: " ~ $simplified.raku;
say "simplified latex: " ~ $ce.to-latex($simplified);
my $evaluated = $ce.evaluate(["Sin", ["Divide", "Pi", 2]]);
say "evaluated: " ~ $evaluated.raku;
say "evaluated latex: " ~ $ce.to-latex($evaluated);