Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.maple > #1132 > unrolled thread

Simplify Difficulty

Started by"Thomas D. Dean" <tomdean@speakeasy.org>
First post2015-05-09 12:13 -0700
Last post2015-05-10 17:10 -0700
Articles 6 — 3 participants

Back to article view | Back to comp.soft-sys.math.maple


Contents

  Simplify Difficulty "Thomas D. Dean" <tomdean@speakeasy.org> - 2015-05-09 12:13 -0700
    Re: Simplify Difficulty Axel Vogt <&noreply@axelvogt.de> - 2015-05-09 22:38 +0200
      Re: Simplify Difficulty "Thomas D. Dean" <tomdean@speakeasy.org> - 2015-05-09 15:49 -0700
        Re: Simplify Difficulty Axel Vogt <&noreply@axelvogt.de> - 2015-05-10 13:30 +0200
    Re: Simplify Difficulty Joe Riel <joer@san.rr.com> - 2015-05-10 08:50 -0700
      Re: Simplify Difficulty "Thomas D. Dean" <tomdean@speakeasy.org> - 2015-05-10 17:10 -0700

#1132 — Simplify Difficulty

From"Thomas D. Dean" <tomdean@speakeasy.org>
Date2015-05-09 12:13 -0700
SubjectSimplify Difficulty
Message-ID<g9ednZAkrPT5wdPInZ2dnUU7-K-dnZ2d@megapath.net>
I want to get a simpler expression for a function from C code.

I have the inductance calculations from the National Bureau of 
Standards, developed by Grover.

I copied the C function to a proc, with some minor edits, such as making 
variable declarations local, changing = to :=, asinh to arcsinh, etc. 
with evalf, Maple 15 produces the same result as the C code, so my edits 
were correct.

If I call the proc as
   rectangle(ht, wd, len, turns)
I get a very complicated expression, as expected.

I have been attempting, unsuccessfully to simplify this and am about to 
try manually.  Simple is 10 to 12 terms.

Before I do this, will Maple do it?

Tom Dean

rectangle := proc(a, a1, b, N)
   local p, q, r, s, t, L;
   local aob, a1ob, g2, b2, a2ob2, aa1, b2oaa1;

   a1ob := a1 / b;
   aob := a / b;

   t := ((1/2) / a1ob) * arcsinh (aob);
   L := t;

   t := ((1/2) / aob) * arcsinh (a1ob);
   L := L + t;

   q := a1ob * a1ob;
   r := (1/2) * (1 - q) / a1ob;
   s := a / (b * sqrt (1 + q));
   t := -r * arcsinh (s);
   L := L + t;

   a2ob2 := aob * aob;
   r := (1/2) * (1 - a2ob2) / aob;
   s := a1 / (b * sqrt (1 + a2ob2));
   t := -r * arcsinh (s);
   L := L + t;

   t := -(1/2) * a1ob * arcsinh (a / a1);
   L := L + t;

   t := -(1/2) * aob * arcsinh (a1 / a);
   L := L + t;

   b2 := b * b;
   g2 := a * a + a1 * a1;
   q := sqrt (1 + g2 / b2);
   aa1 := a * a1;
   b2oaa1 := b2 / aa1;
   s := 1 / (b2oaa1 * q);
   t := ((1/2) * Pi - arctan (s));
   L := L + t;

   r := b2oaa1 / 3;
   t := r * q * (1 - ((1/2) * g2) / b2);
   L := L + t;

   t := r;
   L := L + t;

   t := -r * sqrt (1 + a2ob2) * (1 - (1/2) * a2ob2);
   L := L + t;

   q := (a1 * a1) / b2;
   p := sqrt (1 + q);
   t := -r * p * (1 - (1/2) * q);
   L := L + t;

   p := b / (6 * aa1);
   q := g2 * sqrt(g2);  ## g^2 := a^2 + a1^2 */
   q := (q - (a * a * a) - (a1 * a1 * a1)) / b2;
   t := p * q;
   L := L + t;
   L := 8*(10^(-7)) * N * N * L * aa1 / b
end proc;

[toc] | [next] | [standalone]


#1133

FromAxel Vogt <&noreply@axelvogt.de>
Date2015-05-09 22:38 +0200
Message-ID<cr79ivFs49hU1@mid.individual.net>
In reply to#1132
On 09.05.2015 21:13, Thomas D. Dean wrote:
> I want to get a simpler expression for a function from C code.
>
> I have the inductance calculations from the National Bureau of Standards, developed by Grover.
>
> I copied the C function to a proc, with some minor edits, such as making variable declarations local, changing = to :=,
> asinh to arcsinh, etc. with evalf, Maple 15 produces the same result as the C code, so my edits were correct.
>
> If I call the proc as
>    rectangle(ht, wd, len, turns)
> I get a very complicated expression, as expected.
>
> I have been attempting, unsuccessfully to simplify this and am about to try manually.  Simple is 10 to 12 terms.
>
> Before I do this, will Maple do it?
>
> Tom Dean
>
> rectangle := proc(a, a1, b, N)...
 > ...
>  end proc;

Not quite sure, what you want (or the proc should do), but for coding:

   with(codegen);

   mpl:=codegen[optimize](rectangle, tryhard):
   'original'=cost(mpl);
   'maple'=cost(rectangle);

   original = 25 storage + 57 assignments + 10 divisions
          + 47 multiplications + 28 additions + 16 functions


   maple = 13 storage + 45 assignments + 21 divisions
          + 38 multiplications + 13 functions + 29 additions

[toc] | [prev] | [next] | [standalone]


#1134

From"Thomas D. Dean" <tomdean@speakeasy.org>
Date2015-05-09 15:49 -0700
Message-ID<msydnSq0R4qYEtPInZ2dnUU7-TednZ2d@megapath.net>
In reply to#1133
On 05/09/15 13:38, Axel Vogt wrote:

> Not quite sure, what you want (or the proc should do), but for coding:

The proc calculates the inductance of a coil wound on a rectangular 
form, where the diameter of the wire is small compared the smallest 
dimension of the form.  The dimensions are in meters:
  a = largest cross section measurement
  a1 = the smaller cross section measurement
  b = the length of the coil
  N = the number of turns

I don't know the cost of operations in maple 15, but, it seems optimize 
can sometimes make things worse.

 > restart; with(codegen);

 > read "rectangle.mpl";
 > opt_rect := optimize(rectangle,tryhard):
 > cost(rectangle);
13 storage + 45 assignments + 21 divisions + 38 multiplications + 13 
functions + 29 additions
 > cost(opt_rect);
25 storage + 57 assignments + 10 divisions + 45 multiplications + 28 
additions + 16 functions

 > read "grover.mpl";
 > opt_grovr:=optimize(grover,tryhard):
 > cost(grover);
5 storage + 3 assignments + 26 additions + 67 multiplications + 14 
functions + 39 divisions
 > cost(opt_grovr);
16 storage + 16 assignments + 46 multiplications + 8 divisions + 23 
additions + 12 functions

Tom Dean

grover := proc (a, a1, b, N)
description "Inductance of a single layer solenoid wound on a 
rectangular form. From Grover.  Dimensions in meters. a = largest cross 
section measurement.  a1 = the smaller cross section measurement.  b is 
the length of the coil.  N is the number of turns";
local g, g2, L;
     g2 := a^2 + a1^2;
     g := sqrt(g2);
     L := 10^(-4)*(1/125) * N^2 *a *a1/b
     * ( (1/2)*(b/a1)*arcsinh(a/b)
         + (1/2)*(b/a)*arcsinh(a1/b)
         - (1/2)*(1 - a1^2/b^2)*(b/a1)*arcsinh(a/(b*sqrt(1+a1^2/b^2)))
         - (1/2)*(1 - a^2/b^2)*(b/a)*arcsinh(a1/(b*sqrt(1+a^2/b^2)))
         - (1/2)*(a1/b)*arcsinh(a/a1)
         - (1/2)*(a/b)*arcsinh(a1/a)
         + Pi/2
         - arctan(a*a1/(b^2*sqrt(1+g2/b^2)))
         + (1/3)*(b^2/(a*a1))*sqrt(1+g2/b^2)*(1-(1/2)*g2/b^2)
         + (1/3)*b^2/(a*a1)
         - (1/3)*b^2/(a*a1)*sqrt(1+a^2/b^2)*(1-(1/2)*a^2/b^2)
         - (1/3)*b^2/(a*a1)*sqrt(1+a1^2/b^2)*(1-(1/2)*a1^2/b^2)
         + (1/6)*b/(a*a1)*(g^3 -a^3 -a1^3)/b^2
       ) ;
end proc:

[toc] | [prev] | [next] | [standalone]


#1135

FromAxel Vogt <&noreply@axelvogt.de>
Date2015-05-10 13:30 +0200
Message-ID<cr8tpvF9oviU1@mid.individual.net>
In reply to#1134
On 10.05.2015 00:49, Thomas D. Dean wrote:
> On 05/09/15 13:38, Axel Vogt wrote:
>
>> Not quite sure, what you want (or the proc should do), but for coding:
>
> The proc calculates the inductance of a coil wound on a rectangular form, where the diameter of the wire is small
> compared the smallest dimension of the form.  The dimensions are in meters:
>   a = largest cross section measurement
>   a1 = the smaller cross section measurement
>   b = the length of the coil
>   N = the number of turns
>
> I don't know the cost of operations in maple 15, but, it seems optimize can sometimes make things worse.
>
>  > restart; with(codegen);
>
>  > read "rectangle.mpl";
>  > opt_rect := optimize(rectangle,tryhard):
>  > cost(rectangle);
> 13 storage + 45 assignments + 21 divisions + 38 multiplications + 13 functions + 29 additions
>  > cost(opt_rect);
> 25 storage + 57 assignments + 10 divisions + 45 multiplications + 28 additions + 16 functions
>
>  > read "grover.mpl";
>  > opt_grovr:=optimize(grover,tryhard):
>  > cost(grover);
> 5 storage + 3 assignments + 26 additions + 67 multiplications + 14 functions + 39 divisions
>  > cost(opt_grovr);
> 16 storage + 16 assignments + 46 multiplications + 8 divisions + 23 additions + 12 functions
>
> Tom Dean
>
> grover := proc (a, a1, b, N)
> description "Inductance of a single layer solenoid wound on a rectangular form. From Grover.  Dimensions in meters. a =
> largest cross section measurement.  a1 = the smaller cross section measurement.  b is the length of the coil.  N is the
> number of turns";
> local g, g2, L;
>      g2 := a^2 + a1^2;
>      g := sqrt(g2);
>      L := 10^(-4)*(1/125) * N^2 *a *a1/b
>      * ( (1/2)*(b/a1)*arcsinh(a/b)
>          + (1/2)*(b/a)*arcsinh(a1/b)
>          - (1/2)*(1 - a1^2/b^2)*(b/a1)*arcsinh(a/(b*sqrt(1+a1^2/b^2)))
>          - (1/2)*(1 - a^2/b^2)*(b/a)*arcsinh(a1/(b*sqrt(1+a^2/b^2)))
>          - (1/2)*(a1/b)*arcsinh(a/a1)
>          - (1/2)*(a/b)*arcsinh(a1/a)
>          + Pi/2
>          - arctan(a*a1/(b^2*sqrt(1+g2/b^2)))
>          + (1/3)*(b^2/(a*a1))*sqrt(1+g2/b^2)*(1-(1/2)*g2/b^2)
>          + (1/3)*b^2/(a*a1)
>          - (1/3)*b^2/(a*a1)*sqrt(1+a^2/b^2)*(1-(1/2)*a^2/b^2)
>          - (1/3)*b^2/(a*a1)*sqrt(1+a1^2/b^2)*(1-(1/2)*a1^2/b^2)
>          + (1/6)*b/(a*a1)*(g^3 -a^3 -a1^3)/b^2
>        ) ;
> end proc:
>
>

Usually 'tryhard' works fine. It never checks the cost of a function.

PS:
I think you can do a bit more in your proc, for example some division
occure often, dito squares. But it may depend on what you want to 'see'.

[toc] | [prev] | [next] | [standalone]


#1136

FromJoe Riel <joer@san.rr.com>
Date2015-05-10 08:50 -0700
Message-ID<87d2284eky.fsf@san.rr.com>
In reply to#1132
"Thomas D. Dean" <tomdean@speakeasy.org> writes:

About a dozen years ago I wrote a Maple package using many of the
inductance formulas in Grover and elsewhere.  Never got around to
pushing it to the web.  I should try to hunt it down.

Joe

> I want to get a simpler expression for a function from C code.
>
> I have the inductance calculations from the National Bureau of
> Standards, developed by Grover.
>
> I copied the C function to a proc, with some minor edits, such as
> making variable declarations local, changing = to :=, asinh to
> arcsinh, etc. with evalf, Maple 15 produces the same result as the C
> code, so my edits were correct.
>
> If I call the proc as
>   rectangle(ht, wd, len, turns)
> I get a very complicated expression, as expected.
>
> I have been attempting, unsuccessfully to simplify this and am about
> to try manually.  Simple is 10 to 12 terms.
>
> Before I do this, will Maple do it?
>
> Tom Dean
>
> rectangle := proc(a, a1, b, N)
>   local p, q, r, s, t, L;
>   local aob, a1ob, g2, b2, a2ob2, aa1, b2oaa1;
>
>   a1ob := a1 / b;
>   aob := a / b;
>
>   t := ((1/2) / a1ob) * arcsinh (aob);
>   L := t;
>
>   t := ((1/2) / aob) * arcsinh (a1ob);
>   L := L + t;
>
>   q := a1ob * a1ob;
>   r := (1/2) * (1 - q) / a1ob;
>   s := a / (b * sqrt (1 + q));
>   t := -r * arcsinh (s);
>   L := L + t;
>
>   a2ob2 := aob * aob;
>   r := (1/2) * (1 - a2ob2) / aob;
>   s := a1 / (b * sqrt (1 + a2ob2));
>   t := -r * arcsinh (s);
>   L := L + t;
>
>   t := -(1/2) * a1ob * arcsinh (a / a1);
>   L := L + t;
>
>   t := -(1/2) * aob * arcsinh (a1 / a);
>   L := L + t;
>
>   b2 := b * b;
>   g2 := a * a + a1 * a1;
>   q := sqrt (1 + g2 / b2);
>   aa1 := a * a1;
>   b2oaa1 := b2 / aa1;
>   s := 1 / (b2oaa1 * q);
>   t := ((1/2) * Pi - arctan (s));
>   L := L + t;
>
>   r := b2oaa1 / 3;
>   t := r * q * (1 - ((1/2) * g2) / b2);
>   L := L + t;
>
>   t := r;
>   L := L + t;
>
>   t := -r * sqrt (1 + a2ob2) * (1 - (1/2) * a2ob2);
>   L := L + t;
>
>   q := (a1 * a1) / b2;
>   p := sqrt (1 + q);
>   t := -r * p * (1 - (1/2) * q);
>   L := L + t;
>
>   p := b / (6 * aa1);
>   q := g2 * sqrt(g2);  ## g^2 := a^2 + a1^2 */
>   q := (q - (a * a * a) - (a1 * a1 * a1)) / b2;
>   t := p * q;
>   L := L + t;
>   L := 8*(10^(-7)) * N * N * L * aa1 / b
> end proc;

-- 
Joe Riel

[toc] | [prev] | [next] | [standalone]


#1137

From"Thomas D. Dean" <tomdean@speakeasy.org>
Date2015-05-10 17:10 -0700
Message-ID<vI6dnfbx-v3gbtLInZ2dnUU7-budnZ2d@megapath.net>
In reply to#1136
On 05/10/15 08:50, Joe Riel wrote:
>
> About a dozen years ago I wrote a Maple package using many of the
> inductance formulas in Grover and elsewhere.  Never got around to
> pushing it to the web.  I should try to hunt it down.

That package is interesting.

Inductance is hard to calculate.  It always seemed strange that "THE" 
reference book was written in 1946!  Of course, I have Terman and 
Skilling...

Tom Dean

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.maple


csiph-web