|
1 | 1 | # utils |
| 2 | +# todo: check todo's in source |
2 | 3 |
|
3 | 4 | """ |
4 | 5 | $(TYPEDSIGNATURES) |
|
63 | 64 | """ |
64 | 65 | $(TYPEDSIGNATURES) |
65 | 66 |
|
| 67 | +Substitute x[i] by y[i, j], whatever i, in e. |
| 68 | +
|
| 69 | +# Examples |
| 70 | +```@example |
| 71 | +julia> e = :(x0[1] * 2xf[3] - cos(xf[2]) * 2x0[2]) |
| 72 | +:(x0[1] * (2 * xf[3]) - cos(xf[2]) * (2 * x0[2])) |
| 73 | +
|
| 74 | +julia> subs2(subs2(e, :x0, :x, 0), :xf, :x, :N) |
| 75 | +:(x[1, 0] * (2 * x[3, N]) - cos(x[2, N]) * (2 * x[2, 0])) |
| 76 | +
|
| 77 | +julia> e = :(x0 * 2xf[3] - cos(xf) * 2x0[2]) |
| 78 | +:(x0 * (2 * xf[3]) - cos(xf) * (2 * x0[2])) |
| 79 | +
|
| 80 | +julia> subs2(subs2(e, :x0, :x, 0), :xf, :x, :N) |
| 81 | +:(x0 * (2 * x[3, N]) - cos(xf) * (2 * x[2, 0])) |
| 82 | +``` |
| 83 | +""" |
| 84 | +function subs2(e, x, y, j) |
| 85 | + foo(x, y, j) = (h, args...) -> begin |
| 86 | + f = Expr(h, args...) |
| 87 | + @match f begin |
| 88 | + :($xx[$i]) && if (xx == x) end => :($y[$i, $j]) |
| 89 | + _ => f |
| 90 | + end |
| 91 | + end |
| 92 | + expr_it(e, foo(x, y, j), x -> x) |
| 93 | +end |
| 94 | + |
| 95 | +""" |
| 96 | +$(TYPEDSIGNATURES) |
| 97 | +
|
| 98 | +Substitute x[rg] by y[i, j], whatever rg, in e. |
| 99 | +
|
| 100 | +# Examples |
| 101 | +```@example |
| 102 | +julia> e = :(x0[1:2:d] * 2xf[1:3]) |
| 103 | +:(x0[1:2:d] * (2 * xf[1:3])) |
| 104 | +
|
| 105 | +julia> subs3(e, :x0, :x, :i, 0) |
| 106 | +:(x[i, 0] * (2 * xf[1:3])) |
| 107 | +
|
| 108 | +julia> subs3(e, :xf, :x, 1, :N) |
| 109 | +:(x0[1:2:d] * (2 * x[1, N])) |
| 110 | +``` |
| 111 | +""" |
| 112 | +function subs3(e, x, y, i, j) |
| 113 | + foo(x, y, i, j) = (h, args...) -> begin |
| 114 | + f = Expr(h, args...) |
| 115 | + @match f begin |
| 116 | + :($xx[$rg]) && if (xx == x) end => :($y[$i, $j]) |
| 117 | + _ => f |
| 118 | + end |
| 119 | + end |
| 120 | + expr_it(e, foo(x, y, i, j), x -> x) |
| 121 | +end |
| 122 | + |
| 123 | +""" |
| 124 | +$(TYPEDSIGNATURES) |
| 125 | +
|
| 126 | +Substitute x[rg] by y[i], whatever rg, in e. |
| 127 | +
|
| 128 | +# Examples |
| 129 | +```@example |
| 130 | +julia> e = :(v[1:2:d] * 2xf[1:3]) |
| 131 | +:(v[1:2:d] * (2 * xf[1:3])) |
| 132 | +
|
| 133 | +julia> subs4(e, :v, :v, :i) |
| 134 | +:(v[i] * (2 * xf[1:3])) |
| 135 | +
|
| 136 | +julia> subs4(e, :xf, :xf, 1) |
| 137 | +:(v[1:2:d] * (2 * xf[1])) |
| 138 | +``` |
| 139 | +""" |
| 140 | +function subs4(e, x, y, i) # todo: remove since unused (check) |
| 141 | + foo(x, y, i) = (h, args...) -> begin |
| 142 | + f = Expr(h, args...) |
| 143 | + @match f begin |
| 144 | + :($xx[$rg]) && if (xx == x) end => :($y[$i]) |
| 145 | + _ => f |
| 146 | + end |
| 147 | + end |
| 148 | + expr_it(e, foo(x, y, i), x -> x) |
| 149 | +end |
| 150 | + |
| 151 | +""" |
| 152 | +$(TYPEDSIGNATURES) |
| 153 | +
|
66 | 154 | Replace calls in e of the form `(...x...)(t)` by `(...y...)`. |
67 | 155 |
|
68 | 156 | # Example |
|
0 commit comments