# Worksheet to generate the random examples in Gao, Kaltofen, May, Yang, # & Zhi: # 'Approximate Factorization of Multivariate polynomials via # differential Equations' > # The routine used to generate random polynomials # This routine generates a polynomial with random dense factors of the # given degrees with integer coefficents smaller than N. Another random # dense polynomial (noise) with the same degree as the product and # coeffients smaller than 10^(-e) is generated then added to the # product. > randp:=proc(vars::list # the variables > ,list_deg_factor::list # the list of the degree of the > factors > ,N::integer # absolute maximum of > coefficients of the factors > ,e::integer # the perturbation size: 10^(-e) > ,dn) # Optional: number between 0 and > 1 giving the how dense the perturbation should be compared to product > default = 1. > > local i,f0,fac,pert_pol,res, deg_pert, dd; > > if nops([args]) = 4 then dd:=1 else dd:=dn end if; > > deg_pert := convert(list_deg_factor, `+`); > > f0:=1; > for i from 1 to nops(list_deg_factor) do > > fac:=randpoly(vars,degree=list_deg_factor[i],coeffs=rand(-N..N),dense) > ; > f0:=f0*fac; > end do; > > dd:=round(nops(convert(expand(f0),list))*dd); > > print('noise_terms' = dd); > > pert_pol:=randpoly(vars,degree=deg_pert,coeffs=rand(-10^(e)..10^(e)), > terms=dd); > > return(f0,'`*`'(10^(-e)*norm(expand(f0),2)/norm(pert_pol, > 2),pert_pol)); > #return(res); > > end proc: # The Random Examples # Set the path to the subdirectory where the example files will be # stored > path:="examples\/"; path := "examples/" # Example 6: Three Factors (6, 6, 10), Moderate Noise -5 # This example is a polynomial with three factors with coefficients in # [-5, 5], two factors with total degree 6 and one with total degree 10; # the added noise is of order 10^(-5). # > cleanF6, noiseF6:=randp([x,y],[6,6,10],5,5,.25): > > save cleanF6, noiseF6, cat(path,"exF06"); > noise_terms = 69 # Example 7: Two Factors (9, 7), Moderate Noise -4 # This example is a polynomial with two factors with coefficients in # [-5, 5], one factor with total degree 9and one with total degree 7; # the added noise is of order 10^(-4). # > cleanF7, noiseF7:=randp([x,y],[9,7],5,4,.25): noise_terms = 38 > save cleanF7, noiseF7, cat(path,"exF07"); > # Example 8: Five Factors (4,4,4,4,4), Moderate Noise -5 # This example is a polynomial with five factors with coefficients in # [-5, 5] all of total degree 4; the added noise is of order 10^(-5). # > cleanF8, noiseF8:=randp([x,y],[4,4,4,4,4],5,5,.25): noise_terms = 57 > save cleanF8, noiseF8, cat(path,"exF08"); > # Example 9: Three Factors (3,3,3), Large Noise -1 # This example is a polynomial with three factors with coefficients in # [-5, 5] all of total degree 3; the added noise is of order 10^(-1). # > cleanF9, noiseF9:=randp([x,y],[3,3,3],5,1,.25): noise_terms = 14 > save cleanF9, noiseF9, cat(path,"exF09"); > # Examples 10, 11 & 12: One polynomial (12, 7, 5) with perturbations # added: # This example we generate a polynomial with three factors, then add the # same noise first with order -2 then with order -1 to generate examples # 11 and 12 respectively. # # Example 10: Three Factors (12, 7, 5), Large Noise -5 > cleanF10, noiseF10 := randp([x,y], [12,7,5], 5, 5, .05): noise_terms = 16 > save cleanF10, noiseF10, cat(path,"exF10"); > # Example 11: Three Factors (12, 7, 5), Large Noise -5 > cleanF11, noiseF11 := randp([x,y], [12,7,5], 5, 5, .50): noise_terms = 161 > cleanF11 := cleanF10: > save cleanF11, noiseF11, cat(path,"exF11"); > # Example 12: Three Factors (12, 7, 5), Larger Noise -3 > cleanF12 := cleanF11: > noiseF12 := '`*`'(10^2, noiseF11): > > save cleanF12, noiseF12, cat(path,"exF12"); > # Example 13: Two Factors (5, 5^2), Moderate Noise -5 # This example is a polynomial with two factors with coefficients in # [-5, 5] both of total degree 8; the added noise is of order 10^(-1). # > cleanF13, noiseF13:=randp([x,y],[5,5,5],5,5,.25): noise_terms = 34 > cleanF13:=op(1,cleanF13)*op(2,cleanF13)^2: > save cleanF13, noiseF13, cat(path,"exF13"); > # Example 15: Two Factors (5, 5), Moderate Noise -5, three vars > cleanF15, noiseF15 := randp([x,y,z], [5,5], 5, 5, .25): noise_terms = 70 > > save cleanF15, noiseF15, cat(path,"exF15"); > # Example 16: Two Factors (18, 18), Moderate Noise -6 # This example is a polynomial with two factors with coefficients in # [-5, 5] both of total degree 18; the added noise is of order 10^(-6). # > cleanF16, noiseF16:=randp([x,y],[18,18],5,6,.25): noise_terms = 175 > save cleanF16, noiseF16, cat(path,"exF16"); # Example 17: Two Factors (18, 18), Moderate Noise -6 in 99% of the # terms # This example is a polynomial with two factors with coefficients in # [-5, 5] both of total degree 18; the added noise is of order 10^(-6). # > cleanF17, noiseF17:=randp([x,y],[18,18],5,6,.99): noise_terms = 691 > save cleanF17, noiseF17, cat(path,"exF17"); > # Example 18: Complex example : Two Factors(6,6), Moderate Noise -6 > fa18:=randpoly([x,y],degree=6,coeffs=rand(-5..5),dense) > +I*randpoly([x,y],degree=6,coeffs=rand(-5..5),dense): > ga18:=randpoly([x,y],degree=6,coeffs=rand(-5..5),dense) > +I*randpoly([x,y],degree=6,coeffs=rand(-5..5),dense): > cleanF18:=fa18*ga18: > noiseF18:='`*`'(10^(-6),randpoly([x,y],degree=12,coeffs=rand(-5..5),de > nse) > +I*randpoly([x,y],degree=12,coeffs=rand(-5..5),dense)): > save cleanF18, noiseF18, cat(path,"exF18"); > #