Skip to main content
Added some new examples
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Here is something that I think will work. I didn't have time to do a lot of testing, so maybe it's needs more work.

SetAttributes[zf, HoldAllComplete]

zf[expr : Times[n_, Power[d_, k_]]] /; k < 0 := If[d == 0, n, expr]
zf[expr_] := expr

zf[1/2]

1/2

zf[1/Cos[-(3*Pi)/2]]

1

zf[1/0]

1

zf[n^-2]

1/n^2

n = 0; zf[1zf[84/2/n]

142

However,

n = 0; zf[84/n/2]

ComplexInfinity

Not sure this last is acceptable.

Here is something that I think will work. I didn't have time to do a lot of testing, so maybe it's needs more work.

SetAttributes[zf, HoldAllComplete]

zf[expr : Times[n_, Power[d_, k_]]] /; k < 0 := If[d == 0, n, expr]
zf[expr_] := expr

zf[1/2]

1/2

zf[1/Cos[-(3*Pi)/2]]

1

zf[1/0]

1

zf[n^-2]

1/n^2

n = 0; zf[1/n]

1

Here is something that I think will work. I didn't have time to do a lot of testing, so maybe it's needs more work.

SetAttributes[zf, HoldAllComplete]

zf[expr : Times[n_, Power[d_, k_]]] /; k < 0 := If[d == 0, n, expr]
zf[expr_] := expr

zf[1/2]

1/2

zf[1/Cos[-(3*Pi)/2]]

1

zf[1/0]

1

zf[n^-2]

1/n^2

n = 0; zf[84/2/n]

42

However,

n = 0; zf[84/n/2]

ComplexInfinity

Not sure this last is acceptable.

Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Here is something that I think will work. I didn't have time to do a lot of testing, so maybe it's needs more work.

SetAttributes[zf, HoldAllComplete]

zf[expr : Times[n_, Power[d_, k_]]] /; k < 0 := If[d == 0, n, expr]
zf[expr_] := expr

zf[1/2]

1/2

zf[1/Cos[-(3*Pi)/2]]

1

zf[1/0]

1

zf[n^-2]

1/n^2

n = 0; zf[1/n]

1