Skip to content

Commit

Permalink
combined compiled functions for RRi with CCi
Browse files Browse the repository at this point in the history
  • Loading branch information
mahrud committed Jun 5, 2023
1 parent a533ee3 commit 90cf2b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 91 deletions.
86 changes: 2 additions & 84 deletions M2/Macaulay2/d/actors4.d
Original file line number Diff line number Diff line change
Expand Up @@ -1402,87 +1402,6 @@ toRRi(e:Expr):Expr := (
else buildErrorPacket(EngineError("The first argument should be an integer")))
else WrongArg(1,"a pair or triple of integral, rational, or real numbers"));
setupfun("toRRi",toRRi);

rightRR(e:Expr):Expr := (
when e
is x:RRicell do toExpr(rightRR(x.v))
else WrongArg("an interval"));
setupfun("right",rightRR);

leftRR(e:Expr):Expr := (
when e
is x:RRicell do toExpr(leftRR(x.v))
else WrongArg("an interval"));
setupfun("left",leftRR);

widthRR(e:Expr):Expr := (
when e
is x:RRicell do toExpr(widthRR(x.v))
else WrongArg("an interval"));
setupfun("diameter",widthRR).Protected = false;

midpointRR(e:Expr):Expr := (
when e
is x:RRicell do toExpr(midpointRR(x.v))
else WrongArg("an interval"));
setupfun("midpoint",midpointRR);

isEmptyRRi(e:Expr):Expr := (
when e
is x:RRicell do toExpr(isEmpty(x.v))
else WrongArg("an interval"));
setupfun("isEmptyRRi",isEmptyRRi);

subsetRRi(e:Expr):Expr := (
when e is s:Sequence do (
if length(s) > 3 then WrongNumArgs(1,3) else
if length(s) == 2 then (
when s.0 is x:ZZcell do (
when s.1 is y:ZZcell do (toExpr(x.v===y.v))
is y:QQcell do (toExpr(x.v===y.v))
is y:RRcell do (toExpr(x.v===y.v))
is y:RRicell do (toExpr(contains(x.v,y.v)))
else WrongArg(1,"a pair of integral, rational, real numbers or intervals"))
is x:QQcell do (
when s.1 is y:ZZcell do (toExpr(x.v===y.v))
is y:QQcell do (toExpr(x.v===y.v))
is y:RRcell do (toExpr(x.v===y.v))
is y:RRicell do (toExpr(contains(x.v,y.v)))
else WrongArg(1,"a pair of integral, rational, real numbers or intervals"))
is x:RRcell do (
when s.1 is y:ZZcell do (toExpr(x.v===y.v))
is y:QQcell do (toExpr(x.v===y.v))
is y:RRcell do (toExpr(x.v===y.v))
is y:RRicell do (toExpr(contains(x.v,y.v)))
else WrongArg(1,"a pair of integral, rational, real numbers or intervals"))
is x:RRicell do (
when s.1 is y:ZZcell do (toExpr(x.v===y.v))
is y:QQcell do (toExpr(x.v===y.v))
is y:RRcell do (toExpr(x.v===y.v))
is y:RRicell do (toExpr(contains(x.v,y.v)))
else WrongArg(1,"a pair of integral, rational, real numbers or intervals"))
else WrongArg(1,"a pair of integral, rational, real numbers or intervals")) else
WrongArg(1,"a pair of integral, rational, real numbers or intervals"))
else WrongArg(1,"a pair of integral, rational, real numbers or intervals"));
setupfun("subsetRRi",subsetRRi);

intersectRRi(e:Expr):Expr := (
when e
is s:Sequence do (
if length(s) > 3 then WrongNumArgs(1,3) else
if length(s) == 2 then (
when s.0 is x:RRicell do (
when s.1 is y:RRicell do toExpr(intersectRRi(x.v,y.v))
else WrongArg(1,"a pair of intervals"))
else WrongArg("a pair of intervals"))
else when s.0 is prec:ZZcell do (
when s.1 is x:RRicell do (
when s.2 is y:RRicell do toExpr(intersectRRi(x.v,y.v,toULong(prec.v)))
else WrongArg(1,"a pair of intervals"))
else WrongArg(1,"a pair of intervals"))
else WrongArg(1,"a pair of intervals"))
else WrongArg("a pair of intervals"));
setupfun("intersectRRi",intersectRRi);

toCC(e:Expr):Expr := (
when e
Expand Down Expand Up @@ -1546,7 +1465,6 @@ toCC(e:Expr):Expr := (
else WrongArg("a real or complex number, or 2 or 3 arguments"));
setupfun("toCC",toCC);


toCCi(e:Expr):Expr := (
when e
is x:ZZcell do toExpr(toCCi(x.v,defaultPrecision)) -- # typical value: toCCi, ZZ, CCi
Expand Down Expand Up @@ -1639,14 +1557,14 @@ widthCC(e:Expr):Expr := (
is x:CCicell do toExpr(toCC(widthRR(x.v.re),widthRR(x.v.im)))
else WrongArg("an interval"));
setupfun("diameter",widthCC).Protected = false;

midpointCC(e:Expr):Expr := (
when e
is x:RRicell do toExpr(midpointRR(x.v))
is x:CCicell do toExpr(toCC(midpointRR(x.v.re),midpointRR(x.v.im)))
else WrongArg("an interval"));
setupfun("midpoint",midpointCC);

isEmptyCCi(e:Expr):Expr := (
when e
is x:RRicell do toExpr(isEmpty(x.v))
Expand Down
13 changes: 6 additions & 7 deletions M2/Macaulay2/m2/intervals.m2
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,13 @@ span RRi := {Precision => -1} >> opts -> N -> interval(left N,right N,opts)

span List := span Sequence := {Precision => -1} >> opts -> L -> fold(L, (N, M) -> spanRRi(N, M, opts))

for A in {ZZ,QQ,RR} do
isMember(A,RRi) := (N,M) -> subsetRRi(N,M);
isMember(CC,RRi) := (N,M) -> subsetCCi(N,M);
for A in {ZZ,QQ,RR,ZZ} do
isMember(A,RRi) := (N,M) -> subsetCCi(N,M);

for A in {ZZ,QQ,RR,CC} do
isMember(A,CCi) := (N,M) -> subsetCCi(N,M);

isSubset(RRi,RRi) := (N,M) -> subsetRRi(N,M);
isSubset(RRi,RRi) := (N,M) -> subsetCCi(N,M);
isSubset(CCi,RRi) := (N,M) -> subsetCCi(N,M);
isSubset(CCi,CCi) := (N,M) -> subsetCCi(N,M);

Expand All @@ -121,8 +120,8 @@ intersection(CCi,CCi) := {Precision => -1} >> opts -> (N,M) -> (
intersect RRi := RRi => { Precision => -1 } >> opts -> identity
intersect CCi := CCi => { Precision => -1 } >> opts -> identity
intersect(RRi, RRi) := RRi => { Precision => -1 } >> opts -> (N, M) -> (
if opts.Precision < 0 then intersectRRi(N,M)
else intersectRRi(opts.Precision,N,M))
if opts.Precision < 0 then intersectCCi(N,M)
else intersectCCi(opts.Precision,N,M))
intersect(RRi, CCi) := CCi => { Precision => -1 } >> opts -> (N, M) -> (
if opts.Precision < 0 then intersectCCi(N,M)
else intersectCCi(opts.Precision,N,M))
Expand All @@ -133,7 +132,7 @@ intersect(CCi, CCi) := CCi => { Precision => -1 } >> opts -> (N, M) -> (
if opts.Precision < 0 then intersectCCi(N,M)
else intersectCCi(opts.Precision,N,M))

isEmpty RRi := Boolean => isEmptyRRi
isEmpty RRi :=
isEmpty CCi := Boolean => isEmptyCCi

toExternalString CCi :=
Expand Down

0 comments on commit 90cf2b4

Please sign in to comment.