How to take a part from a list without evaluating it

Consider I have a list l

l = {
b + Integrate[Sin[t*q], {t, 0, 1.1}]^2 == b + Integrate[Cos[t*q], {t, 0, 1.1}]
, a + Integrate[Sin[t*p], {t, 0, 1.1}]^2 ==  b + Integrate[Cos[t*q], {t, 0, 1.1}]
}


Now I want another function to take just take one part of the expression without evaluating it. How do I do it? Basically I want something along the lines of

ExtractUnevaluated[l, 1]


With result

b + Integrate[Sin[t*q], {t, 0, 1.1}]^2 == b + Integrate[Cos[t*q], {t, 0, 1.1}]


How do I do this? Specificically how do I define ExtractUnevalued[l_List,n_]:= ????

To be a bit clearer I want to pass the part of the list to a function defined by:

SetAttributes[DiscretizeIntegralOnSet,HoldFirst]

DiscretizeIntegralOnSet[ Integrate[A_,{t_,tmin_,tmax_}], discretpointlist_
]:=some stuff(not relevant)

DiscretizeIntegralOnSet[ A_+B_, discretpointlist_
]:=some other stuff(not relevant)


That then allows me to symbolically write a discretized integral as sum over a set.

• If l is not already evaluated you can use Inactivate as follows: l2 =Inactivate[{b + Integrate[Sin[t*q], {t, 0, 1.1}]^2 == b + Integrate[Cos[t*q], {t, 0, 1.1}], a + Integrate[Sin[t*p], {t, 0, 1.1}]^2 == b + Integrate[Cos[t*q], {t, 0, 1.1}]}, Integrate]; l2[[2]]
– kglr
Jun 12, 2018 at 9:01
• If you're going to pass it into another function, Extract[list, pos, Unevaluated] should do the trick. However, you need to make sure the list doesn't evaluate when you define it (by using Hold instead of List, for example). Jun 12, 2018 at 9:45
• Regrettably this does not work either because I am stuck with a hold that remains Jun 12, 2018 at 9:48
• That's why you have to use Unevaluated when extracting the elements from the held list. Jun 12, 2018 at 10:20

Here's a way to do it: you store the equations in Hold to prevent evaluation and then use Extract to get the elements out unevaluated:

l = Hold[
b + Integrate[Sin[t*q], {t, 0, 1.1}]^2 == b + Integrate[Cos[t*q], {t, 0, 1.1}],
a + Integrate[Sin[t*p], {t, 0, 1.1}]^2 == b + Integrate[Cos[t*q], {t, 0, 1.1}]
]

ClearAll[DiscretizeIntegralOnSet]
DiscretizeIntegralOnSet[i : Integrate[A_, {t_, tmin_, tmax_}], discretpointlist_] :=
Hold[i, A, t, tmin, tmax];

With[{int = Extract[l, {1, 1, 2, 1}, Unevaluated]},
DiscretizeIntegralOnSet[int, points]]


Assuming DiscretizeIntegralOnSet is fixed and you don't want /it is not possible to add any syntactic sugar, you can do this:

l = Hold @ {..., ...};

l[[ {1}, n ]] /. Hold[x_]:> DiscretizeIntegralOnSet[x, whatever]


or

Function[
x, DiscretizeIntegralOnSet[x, whatever], HoldFirst
] @@ l[[{1}, n]]


Regarding the first method you may reference:

• I hope you don't mind my edit; I think it's needed to understand what's going on there if you area not already quite familiar with Mathematica. Jun 12, 2018 at 13:06
• @Mr.Wizard Indeed, I was planning to, the first day since posting is for updates :) Thanks for edits.
– Kuba
Jun 12, 2018 at 13:15

Is this what you are looking for?

SetAttributes[ExtractUnevaluated, HoldFirst]
ExtractUnevaluated[l_List, n_] :=  ReleaseHold[Map[Hold, Hold@l, {2}]][[n]]

• The hold that remains makes it regrettably not what I wanted Jun 12, 2018 at 8:58