Recently Facebook people (G. Lample and F. Charton) wrote about
training neural network to integrate based on derivatives of
random functions.  And they showed not so favourable figures
for Mathematica and Maple.

I implemented a little generator which should give similar
distribution as used by Lample and Charton.  I write
"similar" as they skip some concrete details and overall
description seem unnecesarily complicated.  Anyway,
when you save the attached script 'tree2.input' and do:

)read tree2.input
gen_file("foo_ii.input")

it will generate file with 1000 random integration problems.

ATM there is trouble that some problem contain division by 0.
OTOH it was enough to uncover several bugs in FriCAS
integrator.

It seems that currently FriCAS is able to do about 78% of
random problem.  Few relatively simple changes to handle
easy special cases should move this up quite a bit.  But
there is also trouble with long running time on some
examples...

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/20200102190239.GA6595%40math.uni.wroc.pl.
-- s_tab(n) counts of all unary-binary trees with n internal nodes
s_tab := new(31, 0)$IndexedOneDimensionalArray(Integer, 0)
-- b_tab(n, j) like above, but having binary top node with j
-- internal nodes to the left
b_tab := new(31, 30, 0)$IndexedTwoDimensionalArray(Integer, 0, 0)

s_tab(0) := 1
s_tab(1) := 2

for i in 2..30 repeat
    bs : Integer := 0
    for j in 0..(i-1) repeat
        b_tab(i, j) := s_tab(j)*s_tab(i - j - 1)
        bs := bs + b_tab(i, j)
    s_tab(i) := s_tab(i - 1) + bs

-- Probabities of havinig top unary node
u_prob := new(30, 0)$OneDimensionalArray(DoubleFloat)
-- Probabities for top binary node
b_prob := new(30, 30, 0)$IndexedTwoDimensionalArray(DoubleFloat, 1, 0)

for i in 1..30 repeat
    den : DoubleFloat := 1/convert(s_tab(i))@DoubleFloat
    u_prob(i) := den*convert(s_tab(i - 1))@DoubleFloat
    bsf := u_prob(i)
    for j in 0..(i-1) repeat
        bsf := bsf + den*convert(b_tab(i, j))@DoubleFloat
        b_prob(i, j) := bsf

get_j(p, i) ==
    for j in 0..(i - 1) repeat
        if p < b_prob(i, j) then return j
    i - 1

LARGE := 10^16
I_LARGE := 1/convert(LARGE)@DoubleFloat


get_tree(i) == tree(0, get_tl(i))$Tree(Integer)

-- main workhorse: generate list of childeren
-- with uniform probability
get_tl(i : Integer) : List(Tree(Integer)) ==
    i = 0 => []
    p := I_LARGE*convert(random(LARGE))@DoubleFloat
    p < u_prob(i) => [get_tree(i - 1)]
    j := get_j(p, i)
    [get_tree(j), get_tree(i - j - 1)]

get_fun(i) == get_fun1(get_tree(i))

u_ops := construct(['log, 'exp, 'sqrt, _
                    'sin, 'cos, 'tan, 'asin, 'acos, 'atan, _
                    'sinh, 'cosh, 'tanh, 'atanh, 'acosh, 'asinh _
                   ])$OneDimensionalArray(Symbol)
nu_ops := #u_ops
b_ops := construct(['+, '-, '*, '/])$OneDimensionalArray(Symbol)
nb_ops := #b_ops

-- convert tree to InputForm
get_fun1(t) ==
    ch_l := children(t)
    empty?(ch_l) =>
        k := random(10)
        k < 5 => convert(k + 1)@InputForm
        convert('x)@InputForm
    #ch_l = 1 =>
        convert([convert(u_ops(random(nu_ops) + 1))@InputForm,
                 get_fun1(first(ch_l))])@InputForm
    convert([convert(b_ops(random(nb_ops) + 1))@InputForm,
             get_fun1(first(ch_l)), get_fun1(second(ch_l))])@InputForm

rline(i) == unparse(get_fun(i))

gen_file(s) ==
    f := open("rint0.input", "output")$TextFile
    for j in 1..1000 repeat
        write!(f, "f := ")
        writeLine!(f, rline(15))
        writeLine!(f, "integrate(D(f, x), x)")
    close!(f)

Reply via email to