Skip to content

Commit

Permalink
Lazy loading of Rubi rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Nov 26, 2018
1 parent b4d0068 commit da73d3a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions expreduce.go
Expand Up @@ -24,7 +24,7 @@ var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var netprofile = flag.Bool("netprofile", false, "Enable live profiling at http://localhost:8080/debug/pprof/")
var scriptfile = flag.String("script", "", "script `file` to read from")
var initfile = flag.String("initfile", "", "A script to run on initialization.")
var loadRubi = flag.Bool("loadrubi", true, "Load the Rubi definitions for integral support on startup.")
var preloadRubi = flag.Bool("preloadrubi", false, "Preload the Rubi definitions for integral support on startup.")

func main() {
flag.Parse()
Expand All @@ -44,8 +44,8 @@ func main() {
fmt.Printf("Welcome to Expreduce!\n\n")

es := expreduce.NewEvalState()
if *loadRubi {
fmt.Println("Loading Rubi snapshot for integral support. Disable with -loadrubi=false.")
if *preloadRubi {
fmt.Println("Pre-loading Rubi snapshot for integral support. Disable with -preloadrubi=false.")
es.Eval(atoms.E(atoms.S("LoadRubiBundledSnapshot")))
fmt.Println("Done loading Rubi snapshot.")
fmt.Print("\n")
Expand Down
3 changes: 3 additions & 0 deletions expreduce/atoms/ex_complex.go
Expand Up @@ -24,6 +24,9 @@ func (cmplx *Complex) AsExpr() expreduceapi.Ex {
}
return E(S("Times"), cmplx.Im, iSym)
}
if imIsInt && imInt.Val.Int64() == 1 {
return E(S("Plus"), cmplx.Re, iSym)
}
return E(S("Plus"), cmplx.Re, E(S("Times"), cmplx.Im, iSym))
}

Expand Down
4 changes: 2 additions & 2 deletions expreduce/resources.go
Git LFS file not shown
4 changes: 4 additions & 0 deletions expreduce/resources/calculus.m
Expand Up @@ -67,6 +67,10 @@
Integrate[a_,{x_Symbol,start_,end_}] :=
(ReplaceAll[Integrate[a, x],x->end] - ReplaceAll[Integrate[a, x],x->start]) // Simplify;
Integrate[a_,x_Symbol] := Module[{cleanedA, replaceRules},
If[!MemberQ[$ContextPath, "Rubi`"],
Print["Loading Rubi rules for integration. This happens once. Preload on startup with -preloadrubi."];
LoadRubiBundledSnapshot[]
];
replaceRules = genSubscriptReplacements[a];
cleanedA = a /. replaceRules[[1]];
(Rubi`Int[cleanedA, x] /. replaceRules[[2]]) // Simplify
Expand Down

0 comments on commit da73d3a

Please sign in to comment.